|
| 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