Search in sources :

Example 6 with AggregateBinaryOperator

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

the class CpmmSPInstruction method parseInstruction.

public static CpmmSPInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    if (!opcode.equalsIgnoreCase("cpmm"))
        throw new DMLRuntimeException("CpmmSPInstruction.parseInstruction(): Unknown opcode " + opcode);
    CPOperand in1 = new CPOperand(parts[1]);
    CPOperand in2 = new CPOperand(parts[2]);
    CPOperand out = new CPOperand(parts[3]);
    AggregateOperator agg = new AggregateOperator(0, Plus.getPlusFnObject());
    AggregateBinaryOperator aggbin = new AggregateBinaryOperator(Multiply.getMultiplyFnObject(), agg);
    SparkAggType aggtype = SparkAggType.valueOf(parts[4]);
    return new CpmmSPInstruction(aggbin, in1, in2, out, aggtype, opcode, str);
}
Also used : SparkAggType(org.apache.sysml.hops.AggBinaryOp.SparkAggType) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) AggregateBinaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 7 with AggregateBinaryOperator

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

the class AggregateBinaryCPInstruction method parseInstruction.

public static AggregateBinaryCPInstruction parseInstruction(String str) {
    CPOperand in1 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    CPOperand in2 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    if (!opcode.equalsIgnoreCase("ba+*")) {
        throw new DMLRuntimeException("AggregateBinaryInstruction.parseInstruction():: Unknown opcode " + opcode);
    }
    InstructionUtils.checkNumFields(parts, 4);
    in1.split(parts[1]);
    in2.split(parts[2]);
    out.split(parts[3]);
    int k = Integer.parseInt(parts[4]);
    AggregateOperator agg = new AggregateOperator(0, Plus.getPlusFnObject());
    AggregateBinaryOperator aggbin = new AggregateBinaryOperator(Multiply.getMultiplyFnObject(), agg, k);
    return new AggregateBinaryCPInstruction(aggbin, in1, in2, out, opcode, str);
}
Also used : AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) AggregateBinaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 8 with AggregateBinaryOperator

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

the class MMRJMRReducer method processAggBinaryPerGroup.

// perform pairwise aggregate binary, and added to the aggregates
private void processAggBinaryPerGroup(MatrixIndexes indexes, AggregateBinaryInstruction aggBinInstruction) throws IOException {
    IndexedMatrixValue left = cachedValues.getFirst(aggBinInstruction.input1);
    IndexedMatrixValue right = cachedValues.getFirst(aggBinInstruction.input2);
    if (left != null && right != null) {
        try {
            resultblock = ((MatrixBlock) left.getValue()).aggregateBinaryOperations((MatrixBlock) left.getValue(), (MatrixBlock) right.getValue(), resultblock, (AggregateBinaryOperator) aggBinInstruction.getOperator());
            IndexedMatrixValue out = cachedValues.getFirst(aggBinInstruction.output);
            if (out == null) {
                out = cachedValues.holdPlace(aggBinInstruction.output, valueClass);
                out.getIndexes().setIndexes(indexes);
                OperationsOnMatrixValues.startAggregation(out.getValue(), null, ((AggregateBinaryOperator) aggBinInstruction.getOperator()).aggOp, resultblock.getNumRows(), resultblock.getNumColumns(), resultblock.isInSparseFormat(), false);
            }
            OperationsOnMatrixValues.incrementalAggregation(out.getValue(), null, resultblock, ((AggregateBinaryOperator) aggBinInstruction.getOperator()).aggOp, false);
        } catch (Exception e) {
            throw new IOException(e);
        }
    }
}
Also used : MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) AggregateBinaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator) IOException(java.io.IOException) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) IOException(java.io.IOException)

Example 9 with AggregateBinaryOperator

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

the class ParVectorMatrixMultTest 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, InfrastructureAnalyzer.getLocalParallelism());
        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 10 with AggregateBinaryOperator

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

Aggregations

AggregateBinaryOperator (org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator)21 AggregateOperator (org.apache.sysml.runtime.matrix.operators.AggregateOperator)16 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)10 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)10 CompressedMatrixBlock (org.apache.sysml.runtime.compress.CompressedMatrixBlock)9 CPOperand (org.apache.sysml.runtime.instructions.cp.CPOperand)6 SparkAggType (org.apache.sysml.hops.AggBinaryOp.SparkAggType)2 CacheType (org.apache.sysml.lops.MapMult.CacheType)2 IndexedMatrixValue (org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue)2 IOException (java.io.IOException)1 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)1 Multiply (org.apache.sysml.runtime.functionobjects.Multiply)1 Plus (org.apache.sysml.runtime.functionobjects.Plus)1 MatrixIndexes (org.apache.sysml.runtime.matrix.data.MatrixIndexes)1 MatrixValue (org.apache.sysml.runtime.matrix.data.MatrixValue)1 DistributedCacheInput (org.apache.sysml.runtime.matrix.mapred.DistributedCacheInput)1