Search in sources :

Example 66 with CompressedMatrixBlock

use of org.apache.sysml.runtime.compress.CompressedMatrixBlock in project systemml by apache.

the class CompressedSerializationTest method runCompressedSerializationTest.

private static void runCompressedSerializationTest(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();
        // serialize compressed matrix block
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        DataOutputStream fos = new DataOutputStream(bos);
        cmb.write(fos);
        // deserialize compressed matrix block
        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
        DataInputStream fis = new DataInputStream(bis);
        CompressedMatrixBlock cmb2 = new CompressedMatrixBlock();
        cmb2.readFields(fis);
        // decompress the compressed matrix block
        MatrixBlock tmp = cmb2.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;
    }
}
Also used : CompressedMatrixBlock(org.apache.sysml.runtime.compress.CompressedMatrixBlock) CompressedMatrixBlock(org.apache.sysml.runtime.compress.CompressedMatrixBlock) MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream)

Example 67 with CompressedMatrixBlock

use of org.apache.sysml.runtime.compress.CompressedMatrixBlock in project systemml by apache.

the class LargeCompressionTest 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;
    }
}
Also used : CompressedMatrixBlock(org.apache.sysml.runtime.compress.CompressedMatrixBlock) CompressedMatrixBlock(org.apache.sysml.runtime.compress.CompressedMatrixBlock) MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock)

Example 68 with CompressedMatrixBlock

use of org.apache.sysml.runtime.compress.CompressedMatrixBlock in project systemml by apache.

the class LargeMatrixMatrixMultTest method runMatrixVectorMultTest.

private static void runMatrixVectorMultTest(MultType mtype, 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);
        }
        boolean right = (mtype == MultType.RIGHT);
        MatrixBlock mb = DataConverter.convertToMatrixBlock(input);
        MatrixBlock vect = DataConverter.convertToMatrixBlock(right ? TestUtils.generateTestMatrix(cols, cols2, -1, 1, 1.0, 3) : TestUtils.generateTestMatrix(cols2, rows, -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 = right ? mb.aggregateBinaryOperations(mb, vect, new MatrixBlock(), abop) : vect.aggregateBinaryOperations(vect, mb, new MatrixBlock(), abop);
        // matrix-vector compressed
        MatrixBlock ret2 = right ? cmb.aggregateBinaryOperations(cmb, vect, new MatrixBlock(), abop) : cmb.aggregateBinaryOperations(vect, cmb, new MatrixBlock(), abop);
        // compare result with input
        double[][] d1 = DataConverter.convertToDoubleMatrix(ret1);
        double[][] d2 = DataConverter.convertToDoubleMatrix(ret2);
        TestUtils.compareMatrices(d1, d2, right ? rows : cols2, right ? cols2 : cols, 0.0000001);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    } finally {
        CompressedMatrixBlock.ALLOW_DDC_ENCODING = true;
    }
}
Also used : CompressedMatrixBlock(org.apache.sysml.runtime.compress.CompressedMatrixBlock) CompressedMatrixBlock(org.apache.sysml.runtime.compress.CompressedMatrixBlock) MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) AggregateBinaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator)

Example 69 with CompressedMatrixBlock

use of org.apache.sysml.runtime.compress.CompressedMatrixBlock in project systemml by apache.

the class LargeMatrixVectorMultTest 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;
    }
}
Also used : CompressedMatrixBlock(org.apache.sysml.runtime.compress.CompressedMatrixBlock) CompressedMatrixBlock(org.apache.sysml.runtime.compress.CompressedMatrixBlock) MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) AggregateBinaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator)

Example 70 with CompressedMatrixBlock

use of org.apache.sysml.runtime.compress.CompressedMatrixBlock in project systemml by apache.

the class LargeParMatrixVectorMultTest 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, InfrastructureAnalyzer.getLocalParallelism());
        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;
    }
}
Also used : CompressedMatrixBlock(org.apache.sysml.runtime.compress.CompressedMatrixBlock) CompressedMatrixBlock(org.apache.sysml.runtime.compress.CompressedMatrixBlock) MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) AggregateBinaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator)

Aggregations

CompressedMatrixBlock (org.apache.sysml.runtime.compress.CompressedMatrixBlock)77 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)75 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)18 AggregateBinaryOperator (org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator)18 AggregateOperator (org.apache.sysml.runtime.matrix.operators.AggregateOperator)16 ArrayList (java.util.ArrayList)10 ExecutorService (java.util.concurrent.ExecutorService)10 Future (java.util.concurrent.Future)10 DenseBlock (org.apache.sysml.runtime.matrix.data.DenseBlock)10 AggregateUnaryOperator (org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator)6 KahanFunction (org.apache.sysml.runtime.functionobjects.KahanFunction)4 ValueFunction (org.apache.sysml.runtime.functionobjects.ValueFunction)4 DoubleObject (org.apache.sysml.runtime.instructions.cp.DoubleObject)4 RightScalarOperator (org.apache.sysml.runtime.matrix.operators.RightScalarOperator)4 ScalarOperator (org.apache.sysml.runtime.matrix.operators.ScalarOperator)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DataInputStream (java.io.DataInputStream)2 DataOutputStream (java.io.DataOutputStream)2 Checkpoint (org.apache.sysml.lops.Checkpoint)2