Search in sources :

Example 76 with AggregateOperator

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

the class UaggOuterChainSPInstruction method parseInstruction.

public static UaggOuterChainSPInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    if (opcode.equalsIgnoreCase(UAggOuterChain.OPCODE)) {
        AggregateUnaryOperator uaggop = InstructionUtils.parseBasicAggregateUnaryOperator(parts[1]);
        BinaryOperator bop = InstructionUtils.parseBinaryOperator(parts[2]);
        CPOperand in1 = new CPOperand(parts[3]);
        CPOperand in2 = new CPOperand(parts[4]);
        CPOperand out = new CPOperand(parts[5]);
        // derive aggregation operator from unary operator
        String aopcode = InstructionUtils.deriveAggregateOperatorOpcode(parts[1]);
        CorrectionLocationType corrLoc = InstructionUtils.deriveAggregateOperatorCorrectionLocation(parts[1]);
        String corrExists = (corrLoc != CorrectionLocationType.NONE) ? "true" : "false";
        AggregateOperator aop = InstructionUtils.parseAggregateOperator(aopcode, corrExists, corrLoc.toString());
        return new UaggOuterChainSPInstruction(bop, uaggop, aop, in1, in2, out, opcode, str);
    } else {
        throw new DMLRuntimeException("UaggOuterChainSPInstruction.parseInstruction():: Unknown opcode " + opcode);
    }
}
Also used : AggregateUnaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) BinaryOperator(org.apache.sysml.runtime.matrix.operators.BinaryOperator) CorrectionLocationType(org.apache.sysml.lops.PartialAggregate.CorrectionLocationType) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 77 with AggregateOperator

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

the class ExtractGroup method execute.

protected Iterable<Tuple2<MatrixIndexes, WeightedCell>> execute(MatrixIndexes ix, MatrixBlock group, MatrixBlock target) throws Exception {
    // sanity check matching block dimensions
    if (group.getNumRows() != target.getNumRows()) {
        throw new Exception("The blocksize for group and target blocks are mismatched: " + group.getNumRows() + " != " + target.getNumRows());
    }
    // output weighted cells
    ArrayList<Tuple2<MatrixIndexes, WeightedCell>> groupValuePairs = new ArrayList<>();
    long coloff = (ix.getColumnIndex() - 1) * _bclen;
    // local pre-aggregation for sum w/ known output dimensions
    if (_op instanceof AggregateOperator && _ngroups > 0 && OptimizerUtils.isValidCPDimensions(_ngroups, target.getNumColumns())) {
        MatrixBlock tmp = group.groupedAggOperations(target, null, new MatrixBlock(), (int) _ngroups, _op);
        for (int i = 0; i < tmp.getNumRows(); i++) {
            for (int j = 0; j < tmp.getNumColumns(); j++) {
                double tmpval = tmp.quickGetValue(i, j);
                if (tmpval != 0) {
                    WeightedCell weightedCell = new WeightedCell();
                    weightedCell.setValue(tmpval);
                    weightedCell.setWeight(1);
                    MatrixIndexes ixout = new MatrixIndexes(i + 1, coloff + j + 1);
                    groupValuePairs.add(new Tuple2<>(ixout, weightedCell));
                }
            }
        }
    } else // general case without pre-aggregation
    {
        for (int i = 0; i < group.getNumRows(); i++) {
            long groupVal = UtilFunctions.toLong(group.quickGetValue(i, 0));
            if (groupVal < 1) {
                throw new Exception("Expected group values to be greater than equal to 1 but found " + groupVal);
            }
            for (int j = 0; j < target.getNumColumns(); j++) {
                WeightedCell weightedCell = new WeightedCell();
                weightedCell.setValue(target.quickGetValue(i, j));
                weightedCell.setWeight(1);
                MatrixIndexes ixout = new MatrixIndexes(groupVal, coloff + j + 1);
                groupValuePairs.add(new Tuple2<>(ixout, weightedCell));
            }
        }
    }
    return groupValuePairs;
}
Also used : WeightedCell(org.apache.sysml.runtime.matrix.data.WeightedCell) MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) Tuple2(scala.Tuple2) MatrixIndexes(org.apache.sysml.runtime.matrix.data.MatrixIndexes) ArrayList(java.util.ArrayList) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator)

Example 78 with AggregateOperator

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

Example 79 with AggregateOperator

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

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

Aggregations

AggregateOperator (org.apache.sysml.runtime.matrix.operators.AggregateOperator)83 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)34 AggregateBinaryOperator (org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator)32 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)24 AggregateUnaryOperator (org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator)21 CPOperand (org.apache.sysml.runtime.instructions.cp.CPOperand)20 CorrectionLocationType (org.apache.sysml.lops.PartialAggregate.CorrectionLocationType)17 CompressedMatrixBlock (org.apache.sysml.runtime.compress.CompressedMatrixBlock)16 CM (org.apache.sysml.runtime.functionobjects.CM)15 CMOperator (org.apache.sysml.runtime.matrix.operators.CMOperator)14 KahanObject (org.apache.sysml.runtime.instructions.cp.KahanObject)10 WeightedCell (org.apache.sysml.runtime.matrix.data.WeightedCell)10 MatrixIndexes (org.apache.sysml.runtime.matrix.data.MatrixIndexes)8 BinaryOperator (org.apache.sysml.runtime.matrix.operators.BinaryOperator)8 Operator (org.apache.sysml.runtime.matrix.operators.Operator)8 ArrayList (java.util.ArrayList)6 SparkAggType (org.apache.sysml.hops.AggBinaryOp.SparkAggType)6 SparkExecutionContext (org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext)6 CM_COV_Object (org.apache.sysml.runtime.instructions.cp.CM_COV_Object)6 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)6