Search in sources :

Example 21 with AggregateOperator

use of org.apache.sysml.runtime.matrix.operators.AggregateOperator 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 22 with AggregateOperator

use of org.apache.sysml.runtime.matrix.operators.AggregateOperator 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)

Example 23 with AggregateOperator

use of org.apache.sysml.runtime.matrix.operators.AggregateOperator in project incubator-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)

Example 24 with AggregateOperator

use of org.apache.sysml.runtime.matrix.operators.AggregateOperator in project incubator-systemml by apache.

the class LargeVectorMatrixMultTest 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 25 with AggregateOperator

use of org.apache.sysml.runtime.matrix.operators.AggregateOperator in project incubator-systemml by apache.

the class ParMatrixVectorMultTest 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

AggregateOperator (org.apache.sysml.runtime.matrix.operators.AggregateOperator)42 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)17 AggregateBinaryOperator (org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator)16 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)12 AggregateUnaryOperator (org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator)11 CPOperand (org.apache.sysml.runtime.instructions.cp.CPOperand)10 CorrectionLocationType (org.apache.sysml.lops.PartialAggregate.CorrectionLocationType)9 CompressedMatrixBlock (org.apache.sysml.runtime.compress.CompressedMatrixBlock)8 CM (org.apache.sysml.runtime.functionobjects.CM)8 CMOperator (org.apache.sysml.runtime.matrix.operators.CMOperator)7 KahanObject (org.apache.sysml.runtime.instructions.cp.KahanObject)5 WeightedCell (org.apache.sysml.runtime.matrix.data.WeightedCell)5 BinaryOperator (org.apache.sysml.runtime.matrix.operators.BinaryOperator)4 Operator (org.apache.sysml.runtime.matrix.operators.Operator)4 ArrayList (java.util.ArrayList)3 SparkAggType (org.apache.sysml.hops.AggBinaryOp.SparkAggType)3 SparkExecutionContext (org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext)3 CM_COV_Object (org.apache.sysml.runtime.instructions.cp.CM_COV_Object)3 MatrixIndexes (org.apache.sysml.runtime.matrix.data.MatrixIndexes)3 IOException (java.io.IOException)2