Search in sources :

Example 11 with CompressedMatrixBlock

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

the class BasicMatrixQuantileTest 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, 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();
        // quantile uncompressed
        MatrixBlock tmp1 = (MatrixBlock) mb.sortOperations(null, new MatrixBlock());
        double ret1 = tmp1.pickValue(0.95);
        // quantile compressed
        MatrixBlock tmp2 = (MatrixBlock) cmb.sortOperations(null, new MatrixBlock());
        double ret2 = tmp2.pickValue(0.95);
        // compare result with input
        TestUtils.compareScalars(ret1, ret2, 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)

Example 12 with CompressedMatrixBlock

use of org.apache.sysml.runtime.compress.CompressedMatrixBlock in project incubator-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 13 with CompressedMatrixBlock

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

the class BasicUnaryAggregateTest method runUnaryAggregateTest.

private static void runUnaryAggregateTest(SparsityType sptype, ValueType vtype, AggType aggtype, 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);
        // uc group
        mb = mb.append(MatrixBlock.seqOperations(0.1, rows - 0.1, 1), new MatrixBlock());
        // prepare unary aggregate operator
        AggregateUnaryOperator auop = null;
        switch(aggtype) {
            case SUM:
                auop = InstructionUtils.parseBasicAggregateUnaryOperator("uak+");
                break;
            case ROWSUMS:
                auop = InstructionUtils.parseBasicAggregateUnaryOperator("uark+");
                break;
            case COLSUMS:
                auop = InstructionUtils.parseBasicAggregateUnaryOperator("uack+");
                break;
            case SUMSQ:
                auop = InstructionUtils.parseBasicAggregateUnaryOperator("uasqk+");
                break;
            case ROWSUMSSQ:
                auop = InstructionUtils.parseBasicAggregateUnaryOperator("uarsqk+");
                break;
            case COLSUMSSQ:
                auop = InstructionUtils.parseBasicAggregateUnaryOperator("uacsqk+");
                break;
            case MAX:
                auop = InstructionUtils.parseBasicAggregateUnaryOperator("uamax");
                break;
            case ROWMAXS:
                auop = InstructionUtils.parseBasicAggregateUnaryOperator("uarmax");
                break;
            case COLMAXS:
                auop = InstructionUtils.parseBasicAggregateUnaryOperator("uacmax");
                break;
            case MIN:
                auop = InstructionUtils.parseBasicAggregateUnaryOperator("uamin");
                break;
            case ROWMINS:
                auop = InstructionUtils.parseBasicAggregateUnaryOperator("uarmin");
                break;
            case COLMINS:
                auop = InstructionUtils.parseBasicAggregateUnaryOperator("uacmin");
                break;
        }
        // compress given matrix block
        CompressedMatrixBlock cmb = new CompressedMatrixBlock(mb);
        if (compress)
            cmb.compress();
        // matrix-vector uncompressed
        MatrixBlock ret1 = (MatrixBlock) mb.aggregateUnaryOperations(auop, new MatrixBlock(), 1000, 1000, null, true);
        // matrix-vector compressed
        MatrixBlock ret2 = (MatrixBlock) cmb.aggregateUnaryOperations(auop, new MatrixBlock(), 1000, 1000, null, true);
        // compare result with input
        double[][] d1 = DataConverter.convertToDoubleMatrix(ret1);
        double[][] d2 = DataConverter.convertToDoubleMatrix(ret2);
        int dim1 = (aggtype == AggType.ROWSUMS || aggtype == AggType.ROWSUMSSQ || aggtype == AggType.ROWMINS || aggtype == AggType.ROWMINS) ? rows : 1;
        int dim2 = (aggtype == AggType.COLSUMS || aggtype == AggType.COLSUMSSQ || aggtype == AggType.COLMAXS || aggtype == AggType.COLMINS) ? cols1 : 1;
        TestUtils.compareMatrices(d1, d2, dim1, dim2, 0.00000000001);
    } 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) AggregateUnaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator)

Example 14 with CompressedMatrixBlock

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

the class BasicVectorMatrixMultTest 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(1, 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 = vector.aggregateBinaryOperations(vector, mb, new MatrixBlock(), abop);
        // matrix-vector compressed
        MatrixBlock ret2 = cmb.aggregateBinaryOperations(vector, cmb, new MatrixBlock(), abop);
        // compare result with input
        double[][] d1 = DataConverter.convertToDoubleMatrix(ret1);
        double[][] d2 = DataConverter.convertToDoubleMatrix(ret2);
        TestUtils.compareMatrices(d1, d2, 1, 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 15 with CompressedMatrixBlock

use of org.apache.sysml.runtime.compress.CompressedMatrixBlock in project incubator-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)

Aggregations

CompressedMatrixBlock (org.apache.sysml.runtime.compress.CompressedMatrixBlock)39 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)38 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)9 AggregateBinaryOperator (org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator)9 AggregateOperator (org.apache.sysml.runtime.matrix.operators.AggregateOperator)8 ArrayList (java.util.ArrayList)5 ExecutorService (java.util.concurrent.ExecutorService)5 Future (java.util.concurrent.Future)5 DenseBlock (org.apache.sysml.runtime.matrix.data.DenseBlock)5 AggregateUnaryOperator (org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator)3 KahanFunction (org.apache.sysml.runtime.functionobjects.KahanFunction)2 ValueFunction (org.apache.sysml.runtime.functionobjects.ValueFunction)2 DoubleObject (org.apache.sysml.runtime.instructions.cp.DoubleObject)2 RightScalarOperator (org.apache.sysml.runtime.matrix.operators.RightScalarOperator)2 ScalarOperator (org.apache.sysml.runtime.matrix.operators.ScalarOperator)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 Checkpoint (org.apache.sysml.lops.Checkpoint)1