Search in sources :

Example 11 with Operator

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

the class MMTSJCPInstruction method parseInstruction.

public static MMTSJCPInstruction parseInstruction(String str) throws DMLRuntimeException {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    InstructionUtils.checkNumFields(parts, 4);
    String opcode = parts[0];
    CPOperand in1 = new CPOperand(parts[1]);
    CPOperand out = new CPOperand(parts[2]);
    MMTSJType titype = MMTSJType.valueOf(parts[3]);
    int k = Integer.parseInt(parts[4]);
    if (!opcode.equalsIgnoreCase("tsmm"))
        throw new DMLRuntimeException("Unknown opcode while parsing an MMTSJCPInstruction: " + str);
    else
        return new MMTSJCPInstruction(new Operator(true), in1, titype, out, k, opcode, str);
}
Also used : Operator(org.apache.sysml.runtime.matrix.operators.Operator) MMTSJType(org.apache.sysml.lops.MMTSJ.MMTSJType) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 12 with Operator

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

the class AppendCPInstruction method parseInstruction.

public static AppendCPInstruction parseInstruction(String str) throws DMLRuntimeException {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    InstructionUtils.checkNumFields(parts, 5);
    String opcode = parts[0];
    CPOperand in1 = new CPOperand(parts[1]);
    CPOperand in2 = new CPOperand(parts[2]);
    CPOperand in3 = new CPOperand(parts[3]);
    CPOperand out = new CPOperand(parts[4]);
    boolean cbind = Boolean.parseBoolean(parts[5]);
    AppendType type = (in1.getDataType() != DataType.MATRIX && in1.getDataType() != DataType.FRAME) ? AppendType.STRING : cbind ? AppendType.CBIND : AppendType.RBIND;
    if (!opcode.equalsIgnoreCase("append"))
        throw new DMLRuntimeException("Unknown opcode while parsing a AppendCPInstruction: " + str);
    Operator op = new ReorgOperator(OffsetColumnIndex.getOffsetColumnIndexFnObject(-1));
    if (type == AppendType.STRING)
        return new ScalarAppendCPInstruction(op, in1, in2, in3, out, type, opcode, str);
    else if (in1.getDataType() == DataType.MATRIX)
        return new MatrixAppendCPInstruction(op, in1, in2, in3, out, type, opcode, str);
    else
        //DataType.FRAME
        return new FrameAppendCPInstruction(op, in1, in2, in3, out, type, opcode, str);
}
Also used : Operator(org.apache.sysml.runtime.matrix.operators.Operator) ReorgOperator(org.apache.sysml.runtime.matrix.operators.ReorgOperator) ReorgOperator(org.apache.sysml.runtime.matrix.operators.ReorgOperator) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 13 with Operator

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

the class DataPartitionCPInstruction method parseInstruction.

public static DataPartitionCPInstruction parseInstruction(String str) throws DMLRuntimeException {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    InstructionUtils.checkNumFields(parts, 3);
    String opcode = parts[0];
    CPOperand in1 = new CPOperand(parts[1]);
    CPOperand out = new CPOperand(parts[2]);
    PDataPartitionFormat pformat = PDataPartitionFormat.valueOf(parts[3]);
    if (!opcode.equalsIgnoreCase("partition"))
        throw new DMLRuntimeException("Unknown opcode while parsing an DataPartitionCPInstruction: " + str);
    else
        return new DataPartitionCPInstruction(new Operator(true), in1, pformat, out, opcode, str);
}
Also used : Operator(org.apache.sysml.runtime.matrix.operators.Operator) PDataPartitionFormat(org.apache.sysml.runtime.controlprogram.ParForProgramBlock.PDataPartitionFormat) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 14 with Operator

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

the class GroupedAggMRCombiner method reduce.

@Override
public void reduce(TaggedMatrixIndexes key, Iterator<WeightedCell> values, OutputCollector<TaggedMatrixIndexes, WeightedCell> out, Reporter reporter) throws IOException {
    long start = System.currentTimeMillis();
    //get aggregate operator
    GroupedAggregateInstruction ins = grpaggInstructions.get(key.getTag());
    Operator op = ins.getOperator();
    boolean isPartialAgg = true;
    //combine iterator to single value
    try {
        if (//everything except sum
        op instanceof CMOperator) {
            if (((CMOperator) op).isPartialAggregateOperator()) {
                cmObj.reset();
                CM lcmFn = cmFn.get(key.getTag());
                //partial aggregate cm operator 
                while (values.hasNext()) {
                    WeightedCell value = values.next();
                    lcmFn.execute(cmObj, value.getValue(), value.getWeight());
                }
                outCell.setValue(cmObj.getRequiredPartialResult(op));
                outCell.setWeight(cmObj.getWeight());
            } else //forward tuples to reducer
            {
                isPartialAgg = false;
                while (values.hasNext()) out.collect(key, values.next());
            }
        } else if (//sum
        op instanceof AggregateOperator) {
            AggregateOperator aggop = (AggregateOperator) op;
            if (aggop.correctionExists) {
                KahanObject buffer = new KahanObject(aggop.initialValue, 0);
                KahanPlus.getKahanPlusFnObject();
                //partial aggregate with correction
                while (values.hasNext()) {
                    WeightedCell value = values.next();
                    aggop.increOp.fn.execute(buffer, value.getValue() * value.getWeight());
                }
                outCell.setValue(buffer._sum);
                outCell.setWeight(1);
            } else //no correction
            {
                double v = aggop.initialValue;
                //partial aggregate without correction
                while (values.hasNext()) {
                    WeightedCell value = values.next();
                    v = aggop.increOp.fn.execute(v, value.getValue() * value.getWeight());
                }
                outCell.setValue(v);
                outCell.setWeight(1);
            }
        } else
            throw new IOException("Unsupported operator in instruction: " + ins);
    } catch (Exception ex) {
        throw new IOException(ex);
    }
    //collect the output (to reducer)
    if (isPartialAgg)
        out.collect(key, outCell);
    reporter.incrCounter(Counters.COMBINE_OR_REDUCE_TIME, System.currentTimeMillis() - start);
}
Also used : CMOperator(org.apache.sysml.runtime.matrix.operators.CMOperator) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) Operator(org.apache.sysml.runtime.matrix.operators.Operator) WeightedCell(org.apache.sysml.runtime.matrix.data.WeightedCell) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) KahanObject(org.apache.sysml.runtime.instructions.cp.KahanObject) CM(org.apache.sysml.runtime.functionobjects.CM) IOException(java.io.IOException) CMOperator(org.apache.sysml.runtime.matrix.operators.CMOperator) GroupedAggregateInstruction(org.apache.sysml.runtime.instructions.mr.GroupedAggregateInstruction) IOException(java.io.IOException)

Example 15 with Operator

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

the class GroupedAggMRReducer method reduce.

@Override
public void reduce(TaggedMatrixIndexes key, Iterator<WeightedCell> values, OutputCollector<MatrixIndexes, MatrixCell> out, Reporter report) throws IOException {
    commonSetup(report);
    //get operator
    GroupedAggregateInstruction ins = grpaggInstructions.get(key.getTag());
    Operator op = ins.getOperator();
    try {
        if (//all, but sum
        op instanceof CMOperator) {
            cmObj.reset();
            CM lcmFn = cmFn.get(key.getTag());
            while (values.hasNext()) {
                WeightedCell value = values.next();
                lcmFn.execute(cmObj, value.getValue(), value.getWeight());
            }
            outCell.setValue(cmObj.getRequiredResult(op));
        } else if (//sum
        op instanceof AggregateOperator) {
            AggregateOperator aggop = (AggregateOperator) op;
            if (aggop.correctionExists) {
                KahanObject buffer = new KahanObject(aggop.initialValue, 0);
                while (values.hasNext()) {
                    WeightedCell value = values.next();
                    aggop.increOp.fn.execute(buffer, value.getValue() * value.getWeight());
                }
                outCell.setValue(buffer._sum);
            } else {
                double v = aggop.initialValue;
                while (values.hasNext()) {
                    WeightedCell value = values.next();
                    v = aggop.increOp.fn.execute(v, value.getValue() * value.getWeight());
                }
                outCell.setValue(v);
            }
        } else
            throw new IOException("Unsupported operator in instruction: " + ins);
    } catch (Exception ex) {
        throw new IOException(ex);
    }
    outIndex.setIndexes(key.getBaseObject());
    cachedValues.reset();
    cachedValues.set(key.getTag(), outIndex, outCell);
    processReducerInstructions();
    //output the final result matrices
    outputResultsFromCachedValues(report);
}
Also used : CMOperator(org.apache.sysml.runtime.matrix.operators.CMOperator) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) Operator(org.apache.sysml.runtime.matrix.operators.Operator) WeightedCell(org.apache.sysml.runtime.matrix.data.WeightedCell) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) KahanObject(org.apache.sysml.runtime.instructions.cp.KahanObject) CM(org.apache.sysml.runtime.functionobjects.CM) IOException(java.io.IOException) CMOperator(org.apache.sysml.runtime.matrix.operators.CMOperator) GroupedAggregateInstruction(org.apache.sysml.runtime.instructions.mr.GroupedAggregateInstruction) IOException(java.io.IOException)

Aggregations

Operator (org.apache.sysml.runtime.matrix.operators.Operator)32 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)20 CPOperand (org.apache.sysml.runtime.instructions.cp.CPOperand)10 AggregateOperator (org.apache.sysml.runtime.matrix.operators.AggregateOperator)5 DataType (org.apache.sysml.parser.Expression.DataType)4 CMOperator (org.apache.sysml.runtime.matrix.operators.CMOperator)4 MMTSJType (org.apache.sysml.lops.MMTSJ.MMTSJType)3 IOException (java.io.IOException)2 DataGenMethod (org.apache.sysml.hops.Hop.DataGenMethod)2 VectorType (org.apache.sysml.lops.BinaryM.VectorType)2 CM (org.apache.sysml.runtime.functionobjects.CM)2 ValueFunction (org.apache.sysml.runtime.functionobjects.ValueFunction)2 KahanObject (org.apache.sysml.runtime.instructions.cp.KahanObject)2 GroupedAggregateInstruction (org.apache.sysml.runtime.instructions.mr.GroupedAggregateInstruction)2 WeightedCell (org.apache.sysml.runtime.matrix.data.WeightedCell)2 SimpleOperator (org.apache.sysml.runtime.matrix.operators.SimpleOperator)2 HashMap (java.util.HashMap)1 CacheType (org.apache.sysml.lops.PMMJ.CacheType)1 PDataPartitionFormat (org.apache.sysml.runtime.controlprogram.ParForProgramBlock.PDataPartitionFormat)1 AggregateUnaryOperator (org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator)1