use of org.apache.sysml.runtime.compress.CompressedMatrixBlock in project incubator-systemml by apache.
the class BasicCompressionTest method runCompressionTest.
private static void runCompressionTest(SparsityType sptype, ValueType vtype, boolean compress) {
try {
// prepare sparsity for input data
double sparsity = -1;
switch(sptype) {
case DENSE:
sparsity = sparsity1;
break;
case SPARSE:
sparsity = sparsity2;
break;
case EMPTY:
sparsity = sparsity3;
break;
}
// generate input data
double min = (vtype == ValueType.CONST) ? 10 : -10;
double[][] input = TestUtils.generateTestMatrix(rows, cols, min, 10, sparsity, 7);
if (vtype == ValueType.RAND_ROUND_OLE || vtype == ValueType.RAND_ROUND_DDC) {
CompressedMatrixBlock.ALLOW_DDC_ENCODING = (vtype == ValueType.RAND_ROUND_DDC);
input = TestUtils.round(input);
}
MatrixBlock mb = DataConverter.convertToMatrixBlock(input);
// compress given matrix block
CompressedMatrixBlock cmb = new CompressedMatrixBlock(mb);
if (compress)
cmb.compress();
// decompress the compressed matrix block
MatrixBlock tmp = cmb.decompress();
// compare result with input
double[][] d1 = DataConverter.convertToDoubleMatrix(mb);
double[][] d2 = DataConverter.convertToDoubleMatrix(tmp);
TestUtils.compareMatrices(d1, d2, rows, cols, 0);
} catch (Exception ex) {
throw new RuntimeException(ex);
} finally {
CompressedMatrixBlock.ALLOW_DDC_ENCODING = true;
}
}
use of org.apache.sysml.runtime.compress.CompressedMatrixBlock in project incubator-systemml by apache.
the class BasicGetValueTest method runGetValueTest.
private static void runGetValueTest(SparsityType sptype, ValueType vtype, boolean compress) {
try {
// prepare sparsity for input data
double sparsity = -1;
switch(sptype) {
case DENSE:
sparsity = sparsity1;
break;
case SPARSE:
sparsity = sparsity2;
break;
case EMPTY:
sparsity = sparsity3;
break;
}
// generate input data
double min = (vtype == ValueType.CONST) ? 10 : -10;
double[][] input = TestUtils.generateTestMatrix(rows, cols, min, 10, sparsity, 7);
if (vtype == ValueType.RAND_ROUND_OLE || vtype == ValueType.RAND_ROUND_DDC) {
CompressedMatrixBlock.ALLOW_DDC_ENCODING = (vtype == ValueType.RAND_ROUND_DDC);
input = TestUtils.round(input);
}
MatrixBlock mb = DataConverter.convertToMatrixBlock(input);
// compress given matrix block
CompressedMatrixBlock cmb = new CompressedMatrixBlock(mb);
if (compress)
cmb.compress();
// iterate over all cells, get and compare
for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++) {
// calls quickGetValue internally
double ulaVal = mb.getValue(i, j);
// calls quickGetValue internally
double claVal = cmb.getValue(i, j);
Assert.assertTrue("Get returned wrong value: " + claVal + " (expected: " + ulaVal + ")", ulaVal == claVal);
}
} catch (Exception ex) {
throw new RuntimeException(ex);
} finally {
CompressedMatrixBlock.ALLOW_DDC_ENCODING = true;
}
}
use of org.apache.sysml.runtime.compress.CompressedMatrixBlock in project incubator-systemml by apache.
the class BasicMatrixAppendTest method runMatrixAppendTest.
private static void runMatrixAppendTest(SparsityType sptype, ValueType vtype, boolean compress) {
try {
// prepare sparsity for input data
double sparsity = -1;
switch(sptype) {
case DENSE:
sparsity = sparsity1;
break;
case SPARSE:
sparsity = sparsity2;
break;
case EMPTY:
sparsity = sparsity3;
break;
}
// generate input data
double min = (vtype == ValueType.CONST) ? 10 : -10;
double[][] input = TestUtils.generateTestMatrix(rows, cols1, min, 10, sparsity, 7);
if (vtype == ValueType.RAND_ROUND_OLE || vtype == ValueType.RAND_ROUND_DDC) {
CompressedMatrixBlock.ALLOW_DDC_ENCODING = (vtype == ValueType.RAND_ROUND_DDC);
input = TestUtils.round(input);
}
MatrixBlock mb = DataConverter.convertToMatrixBlock(input);
MatrixBlock vector = DataConverter.convertToMatrixBlock(TestUtils.generateTestMatrix(rows, cols2, 1, 1, 1.0, 3));
// compress given matrix block
CompressedMatrixBlock cmb = new CompressedMatrixBlock(mb);
if (compress)
cmb.compress();
// matrix-vector uncompressed
MatrixBlock ret1 = (MatrixBlock) mb.append(vector, new MatrixBlock());
// matrix-vector compressed
MatrixBlock ret2 = cmb.append(vector, new MatrixBlock());
if (compress)
ret2 = ((CompressedMatrixBlock) ret2).decompress();
// compare result with input
double[][] d1 = DataConverter.convertToDoubleMatrix(ret1);
double[][] d2 = DataConverter.convertToDoubleMatrix(ret2);
TestUtils.compareMatrices(d1, d2, rows, cols1 + cols2, 0);
} catch (Exception ex) {
throw new RuntimeException(ex);
} finally {
CompressedMatrixBlock.ALLOW_DDC_ENCODING = true;
}
}
use of org.apache.sysml.runtime.compress.CompressedMatrixBlock in project incubator-systemml by apache.
the class BasicMatrixTransposeSelfMultTest method runTransposeSelfMatrixMultTest.
private static void runTransposeSelfMatrixMultTest(SparsityType sptype, ValueType vtype, boolean compress) {
try {
// prepare sparsity for input data
double sparsity = -1;
switch(sptype) {
case DENSE:
sparsity = sparsity1;
break;
case SPARSE:
sparsity = sparsity2;
break;
case EMPTY:
sparsity = sparsity3;
break;
}
// generate input data
double min = (vtype == ValueType.CONST) ? 10 : -10;
double[][] input = TestUtils.generateTestMatrix(rows, cols, min, 10, sparsity, 7);
if (vtype == ValueType.RAND_ROUND_OLE || vtype == ValueType.RAND_ROUND_DDC) {
CompressedMatrixBlock.ALLOW_DDC_ENCODING = (vtype == ValueType.RAND_ROUND_DDC);
input = TestUtils.round(input);
}
MatrixBlock mb = DataConverter.convertToMatrixBlock(input);
// compress given matrix block
CompressedMatrixBlock cmb = new CompressedMatrixBlock(mb);
if (compress)
cmb.compress();
// matrix-vector uncompressed
MatrixBlock ret1 = mb.transposeSelfMatrixMultOperations(new MatrixBlock(), MMTSJType.LEFT);
// matrix-vector compressed
MatrixBlock ret2 = cmb.transposeSelfMatrixMultOperations(new MatrixBlock(), MMTSJType.LEFT);
// compare result with input
double[][] d1 = DataConverter.convertToDoubleMatrix(ret1);
double[][] d2 = DataConverter.convertToDoubleMatrix(ret2);
TestUtils.compareMatrices(d1, d2, cols, cols, 0.0000001);
} catch (Exception ex) {
throw new RuntimeException(ex);
} finally {
CompressedMatrixBlock.ALLOW_DDC_ENCODING = true;
}
}
use of org.apache.sysml.runtime.compress.CompressedMatrixBlock in project incubator-systemml by apache.
the class BasicMatrixVectorMultTest method runMatrixVectorMultTest.
private static void runMatrixVectorMultTest(SparsityType sptype, ValueType vtype, boolean compress) {
try {
// prepare sparsity for input data
double sparsity = -1;
switch(sptype) {
case DENSE:
sparsity = sparsity1;
break;
case SPARSE:
sparsity = sparsity2;
break;
case EMPTY:
sparsity = sparsity3;
break;
}
// generate input data
double min = (vtype == ValueType.CONST) ? 10 : -10;
double[][] input = TestUtils.generateTestMatrix(rows, cols, min, 10, sparsity, 7);
if (vtype == ValueType.RAND_ROUND_OLE || vtype == ValueType.RAND_ROUND_DDC) {
CompressedMatrixBlock.ALLOW_DDC_ENCODING = (vtype == ValueType.RAND_ROUND_DDC);
input = TestUtils.round(input);
}
MatrixBlock mb = DataConverter.convertToMatrixBlock(input);
MatrixBlock vector = DataConverter.convertToMatrixBlock(TestUtils.generateTestMatrix(cols, 1, 1, 1, 1.0, 3));
// compress given matrix block
CompressedMatrixBlock cmb = new CompressedMatrixBlock(mb);
if (compress)
cmb.compress();
// matrix-vector uncompressed
AggregateOperator aop = new AggregateOperator(0, Plus.getPlusFnObject());
AggregateBinaryOperator abop = new AggregateBinaryOperator(Multiply.getMultiplyFnObject(), aop);
MatrixBlock ret1 = mb.aggregateBinaryOperations(mb, vector, new MatrixBlock(), abop);
// matrix-vector compressed
MatrixBlock ret2 = cmb.aggregateBinaryOperations(cmb, vector, new MatrixBlock(), abop);
// compare result with input
double[][] d1 = DataConverter.convertToDoubleMatrix(ret1);
double[][] d2 = DataConverter.convertToDoubleMatrix(ret2);
TestUtils.compareMatrices(d1, d2, rows, 1, 0.0000001);
} catch (Exception ex) {
throw new RuntimeException(ex);
} finally {
CompressedMatrixBlock.ALLOW_DDC_ENCODING = true;
}
}
Aggregations