Skip to content

Commit 2a612ed

Browse files
committed
Additional test for best compression type match
1 parent f31cd36 commit 2a612ed

File tree

1 file changed

+60
-9
lines changed

1 file changed

+60
-9
lines changed

src/test/java/org/apache/sysds/test/component/compress/qcompress/CompareCompressionTypeTest.java

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@
4444
public class CompareCompressionTypeTest {
4545

4646
/**
47-
* Test 1: Compare the best compression types of two matrices, m0 and m1.
47+
* Test 1: Compare the best compression types of two matrices, m0 and m1: DDC.
4848
*
49-
* - m0 is generated as a floored matrix.
50-
* - m1 is generated as a full-precision matrix, but will be internally multiplied by 1.0 and floored.
51-
* - Since m1 undergoes an equivalent transformation (scaling by 1.0 and flooring), the best compression types
52-
* determined by the estimator should match elementwise for both matrices.
53-
* - This validates that the estimator correctly handles explicit flooring vs. internal scaling and flooring during quantization-fused compression.
49+
* - m0 is generated as a floored matrix. - m1 is generated as a full-precision matrix, but will be internally
50+
* multiplied by 1.0 and floored. - Since m1 undergoes an equivalent transformation (scaling by 1.0 and flooring),
51+
* the best compression types determined by the estimator should match elementwise for both matrices. - This
52+
* validates that the estimator correctly handles explicit flooring vs. internal scaling and flooring during
53+
* quantization-fused compression.
5454
*/
5555
@Test
56-
public void testCompareBestCompressionTypeForTwoMatrices() {
56+
public void testCompareBestCompressionTypeForTwoMatricesDDC() {
5757
try {
5858
Random r = new Random(1234);
5959
int k = 4;
@@ -65,7 +65,8 @@ public void testCompareBestCompressionTypeForTwoMatrices() {
6565
AComEst estimator0 = ComEstFactory.createEstimator(m0, cs0, k);
6666
CompressedSizeInfo compressedGroups0 = estimator0.computeCompressedSizeInfos(k);
6767

68-
// Generate second matrix full-precision matrix that will be internally scaled by 1.0 and floored and compute
68+
// Generate second matrix full-precision matrix that will be internally scaled by 1.0 and floored and
69+
// compute
6970
// compression info
7071
MatrixBlock m1 = generateTestMatrix(10000, 500, 1, 100, 1.0, r, false);
7172
double[] scaleFactor = {1.0};
@@ -80,7 +81,57 @@ public void testCompareBestCompressionTypeForTwoMatrices() {
8081
assertEquals("Mismatch in number of compressed groups", groups0.size(), groups1.size());
8182

8283
for(int i = 0; i < groups0.size(); i++) {
83-
assertEquals("Best compression type mismatch at index " + i, groups0.get(i).getBestCompressionType(), groups1.get(i).getBestCompressionType());
84+
assertEquals("Best compression type mismatch at index " + i, groups0.get(i).getBestCompressionType(),
85+
groups1.get(i).getBestCompressionType());
86+
}
87+
88+
}
89+
catch(Exception e) {
90+
e.printStackTrace();
91+
fail("Compression extraction failed: " + e.getMessage());
92+
}
93+
}
94+
95+
/**
96+
* Test 1: Compare the best compression types of two matrices, m0 and m1: CONST.
97+
*
98+
* - m0 is generated as a floored matrix. - m1 is generated as a full-precision matrix, but will be internally
99+
* multiplied by 1.0 and floored. - Since m1 undergoes an equivalent transformation (scaling by 1.0 and flooring),
100+
* the best compression types determined by the estimator should match elementwise for both matrices. - This
101+
* validates that the estimator correctly handles explicit flooring vs. internal scaling and flooring during
102+
* quantization-fused compression.
103+
*/
104+
@Test
105+
public void testCompareBestCompressionTypeForTwoMatricesConst() {
106+
try {
107+
Random r = new Random(1234);
108+
int k = 4;
109+
110+
// Generate first floored matrix and compute compression info
111+
MatrixBlock m0 = generateTestMatrix(10000, 500, 1, 1, 1.0, r, true);
112+
CompressionSettings cs0 = new CompressionSettingsBuilder().setColumnPartitioner(PartitionerType.GREEDY)
113+
.setSeed(1234).create();
114+
AComEst estimator0 = ComEstFactory.createEstimator(m0, cs0, k);
115+
CompressedSizeInfo compressedGroups0 = estimator0.computeCompressedSizeInfos(k);
116+
117+
// Generate second matrix full-precision matrix that will be internally scaled by 1.0 and floored and
118+
// compute
119+
// compression info
120+
MatrixBlock m1 = generateTestMatrix(10000, 500, 1, 1, 1.0, r, false);
121+
double[] scaleFactor = {1.0};
122+
CompressionSettings cs1 = new CompressionSettingsBuilder().setColumnPartitioner(PartitionerType.GREEDY)
123+
.setScaleFactor(scaleFactor).setSeed(1234).create();
124+
AComEst estimator1 = ComEstFactory.createEstimator(m1, cs1, k);
125+
CompressedSizeInfo compressedGroups1 = estimator1.computeCompressedSizeInfos(k);
126+
127+
List<CompressedSizeInfoColGroup> groups0 = compressedGroups0.getInfo();
128+
List<CompressedSizeInfoColGroup> groups1 = compressedGroups1.getInfo();
129+
130+
assertEquals("Mismatch in number of compressed groups", groups0.size(), groups1.size());
131+
132+
for(int i = 0; i < groups0.size(); i++) {
133+
assertEquals("Best compression type mismatch at index " + i, groups0.get(i).getBestCompressionType(),
134+
groups1.get(i).getBestCompressionType());
84135
}
85136

86137
}

0 commit comments

Comments
 (0)