Skip to content

Commit f7746cb

Browse files
committed
[MINOR] Add ColGroupFactory logging tests
1 parent 82b7728 commit f7746cb

File tree

3 files changed

+120
-6
lines changed

3 files changed

+120
-6
lines changed

src/main/java/org/apache/sysds/runtime/compress/colgroup/ColGroupFactory.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -617,11 +617,9 @@ private void countElementsDenseGeneric(DoubleCountHashMap map, int col) {
617617
private AColGroup directCompressDDC(IColIndex colIndexes, CompressedSizeInfoColGroup cg) throws Exception {
618618
// testing multicol
619619
if(colIndexes.size() > 1) {
620-
LOG.debug("DDC multi column");
621620
return directCompressDDCMultiCol(colIndexes, cg);
622621
}
623622
else {
624-
LOG.debug("DDC single column");
625623
return directCompressDDCSingleCol(colIndexes, cg);
626624
}
627625
}
@@ -665,11 +663,9 @@ private AColGroup directCompressDDCMultiCol(IColIndex colIndexes, CompressedSize
665663
final DblArrayCountHashMap map = new DblArrayCountHashMap(Math.max(cg.getNumVals(), 64));
666664
boolean extra;
667665
if(nRow < CompressionSettings.PAR_DDC_THRESHOLD || k < csi.getNumberColGroups() || pool == null) {
668-
LOG.debug("Non parallel");
669666
extra = readToMapDDC(colIndexes, map, d, 0, nRow, fill);
670667
}
671668
else {
672-
LOG.debug("Parallel");
673669
extra = parallelReadToMapDDC(colIndexes, map, d, nRow, fill, k);
674670
}
675671

src/main/java/org/apache/sysds/runtime/instructions/InstructionParser.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ public static Instruction[] parseMixedInstructions ( String str ) {
6363
return null;
6464
String[] strlist = str.split(Instruction.INSTRUCTION_DELIM);
6565
Instruction[] inst = new Instruction[strlist.length];
66-
for ( int i=0; i < inst.length; i++ ) {
66+
for ( int i=0; i < inst.length; i++ )
6767
inst[i] = parseSingleInstruction ( strlist[i] );
68-
}
6968
return inst;
7069
}
7170
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.sysds.test.component.compress.colgroup;
21+
22+
import static org.junit.Assert.fail;
23+
24+
import java.util.ArrayList;
25+
import java.util.List;
26+
27+
import org.apache.commons.logging.Log;
28+
import org.apache.commons.logging.LogFactory;
29+
import org.apache.log4j.Level;
30+
import org.apache.log4j.Logger;
31+
import org.apache.log4j.spi.LoggingEvent;
32+
import org.apache.sysds.runtime.compress.CompressedMatrixBlockFactory;
33+
import org.apache.sysds.runtime.compress.CompressionSettings;
34+
import org.apache.sysds.runtime.compress.CompressionSettingsBuilder;
35+
import org.apache.sysds.runtime.compress.colgroup.AColGroup.CompressionType;
36+
import org.apache.sysds.runtime.compress.colgroup.ColGroupFactory;
37+
import org.apache.sysds.runtime.compress.colgroup.indexes.ColIndexFactory;
38+
import org.apache.sysds.runtime.compress.colgroup.indexes.IColIndex;
39+
import org.apache.sysds.runtime.compress.cost.ACostEstimate;
40+
import org.apache.sysds.runtime.compress.cost.MemoryCostEstimator;
41+
import org.apache.sysds.runtime.compress.estim.CompressedSizeInfo;
42+
import org.apache.sysds.runtime.compress.estim.CompressedSizeInfoColGroup;
43+
import org.apache.sysds.runtime.compress.estim.EstimationFactors;
44+
import org.apache.sysds.runtime.matrix.data.MatrixBlock;
45+
import org.apache.sysds.test.LoggingUtils;
46+
import org.apache.sysds.test.LoggingUtils.TestAppender;
47+
import org.apache.sysds.test.TestUtils;
48+
import org.junit.Test;
49+
50+
public class ColGroupFactoryLoggingTest {
51+
protected static final Log LOG = LogFactory.getLog(ColGroupFactoryLoggingTest.class.getName());
52+
53+
54+
@Test
55+
public void factoryLoggingTest_accurate(){
56+
final TestAppender appender = LoggingUtils.overwrite();
57+
58+
try {
59+
CompressionSettings.printedStatus = false;
60+
Logger.getLogger(ColGroupFactory.class).setLevel(Level.TRACE);
61+
MatrixBlock mb = TestUtils.generateTestMatrixBlock(1000, 5, 1, 1, 0.5, 235);
62+
MatrixBlock m2 = CompressedMatrixBlockFactory.compress(mb).getLeft();
63+
TestUtils.compareMatrices(mb, m2, 0.0);
64+
final List<LoggingEvent> log = LoggingUtils.reinsert(appender);
65+
for(LoggingEvent l : log) {
66+
if(l.getMessage().toString().contains("wanted:"))
67+
return;
68+
}
69+
fail("Log did not contain wanted message");
70+
}
71+
catch(Exception e) {
72+
e.printStackTrace();
73+
fail(e.getMessage());
74+
}
75+
finally {
76+
Logger.getLogger(ColGroupFactory.class).setLevel(Level.WARN);
77+
LoggingUtils.reinsert(appender);
78+
}
79+
}
80+
81+
82+
@Test
83+
public void factoryLoggingTest_offestimate(){
84+
final TestAppender appender = LoggingUtils.overwrite();
85+
86+
try {
87+
CompressionSettings.printedStatus = false;
88+
Logger.getLogger(ColGroupFactory.class).setLevel(Level.TRACE);
89+
90+
MatrixBlock mb = TestUtils.generateTestMatrixBlock(1000, 5, 1, 30, 1.0, 235);
91+
mb = TestUtils.floor(mb);
92+
93+
CompressionSettingsBuilder cs = new CompressionSettingsBuilder().setSamplingRatio(0.02);
94+
final IColIndex cols = ColIndexFactory.create(mb.getNumColumns());
95+
final List<CompressedSizeInfoColGroup> es = new ArrayList<>();
96+
final EstimationFactors f = new EstimationFactors(mb.getNumRows(), mb.getNumRows(), mb.getSparsity());
97+
es.add(new CompressedSizeInfoColGroup(cols, f, 10, CompressionType.DDC));
98+
99+
CompressedSizeInfo csi = new CompressedSizeInfo(es);
100+
ACostEstimate ce = new MemoryCostEstimator();
101+
ColGroupFactory.compressColGroups(mb, csi, cs.create(), ce, 1);
102+
103+
final List<LoggingEvent> log = LoggingUtils.reinsert(appender);
104+
for(LoggingEvent l : log) {
105+
if(l.getMessage().toString().contains("The estimate cost is significantly off"))
106+
return;
107+
}
108+
// fail("Log did not contain Dictionary sizes");
109+
}
110+
catch(Exception e) {
111+
e.printStackTrace();
112+
fail(e.getMessage());
113+
}
114+
finally {
115+
Logger.getLogger(ColGroupFactory.class).setLevel(Level.WARN);
116+
LoggingUtils.reinsert(appender);
117+
}
118+
}
119+
}

0 commit comments

Comments
 (0)