Search in sources :

Example 76 with CompressedMatrixBlock

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

the class BasicScalarOperationsTest method runScalarOperationsTest.

private static void runScalarOperationsTest(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-scalar uncompressed
        ScalarOperator sop = new RightScalarOperator(Multiply.getMultiplyFnObject(), 7);
        MatrixBlock ret1 = (MatrixBlock) mb.scalarOperations(sop, new MatrixBlock());
        // matrix-scalar compressed
        MatrixBlock ret2 = (MatrixBlock) cmb.scalarOperations(sop, 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, 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) RightScalarOperator(org.apache.sysml.runtime.matrix.operators.RightScalarOperator) ScalarOperator(org.apache.sysml.runtime.matrix.operators.ScalarOperator) CompressedMatrixBlock(org.apache.sysml.runtime.compress.CompressedMatrixBlock) MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) RightScalarOperator(org.apache.sysml.runtime.matrix.operators.RightScalarOperator)

Example 77 with CompressedMatrixBlock

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

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

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