Search in sources :

Example 66 with AggregateOperator

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

the class AggregateUnarySPInstruction method parseInstruction.

public static AggregateUnarySPInstruction parseInstruction(String str) {
    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]);
    SparkAggType aggtype = SparkAggType.valueOf(parts[3]);
    String aopcode = InstructionUtils.deriveAggregateOperatorOpcode(opcode);
    CorrectionLocationType corrLoc = InstructionUtils.deriveAggregateOperatorCorrectionLocation(opcode);
    String corrExists = (corrLoc != CorrectionLocationType.NONE) ? "true" : "false";
    AggregateUnaryOperator aggun = InstructionUtils.parseBasicAggregateUnaryOperator(opcode);
    AggregateOperator aop = InstructionUtils.parseAggregateOperator(aopcode, corrExists, corrLoc.toString());
    return new AggregateUnarySPInstruction(SPType.AggregateUnary, aggun, aop, in1, out, aggtype, opcode, str);
}
Also used : SparkAggType(org.apache.sysml.hops.AggBinaryOp.SparkAggType) AggregateUnaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) CorrectionLocationType(org.apache.sysml.lops.PartialAggregate.CorrectionLocationType)

Example 67 with AggregateOperator

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

the class AggregateBinaryInstruction method parseInstruction.

public static AggregateBinaryInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionParts(str);
    byte in1, in2, out;
    String opcode = parts[0];
    in1 = Byte.parseByte(parts[1]);
    in2 = Byte.parseByte(parts[2]);
    out = Byte.parseByte(parts[3]);
    if (opcode.equalsIgnoreCase("cpmm") || opcode.equalsIgnoreCase("rmm") || opcode.equalsIgnoreCase(MapMult.OPCODE)) {
        AggregateOperator agg = new AggregateOperator(0, Plus.getPlusFnObject());
        AggregateBinaryOperator aggbin = new AggregateBinaryOperator(Multiply.getMultiplyFnObject(), agg);
        AggregateBinaryInstruction inst = new AggregateBinaryInstruction(aggbin, opcode, in1, in2, out, str);
        if (parts.length == 5) {
            inst.setMMCJType(MMCJType.valueOf(parts[4]));
        } else if (parts.length == 6) {
            // mapmm
            inst.setCacheTypeMapMult(CacheType.valueOf(parts[4]));
            inst.setOutputEmptyBlocksMapMult(Boolean.parseBoolean(parts[5]));
        }
        return inst;
    }
    throw new DMLRuntimeException("AggregateBinaryInstruction.parseInstruction():: Unknown opcode " + opcode);
}
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 68 with AggregateOperator

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

the class MatrixBlock method min.

/**
 * Wrapper method for reduceall-min of a matrix.
 *
 * @return ?
 */
public double min() {
    // construct operator
    AggregateOperator aop = new AggregateOperator(Double.POSITIVE_INFINITY, Builtin.getBuiltinFnObject("min"));
    AggregateUnaryOperator auop = new AggregateUnaryOperator(aop, ReduceAll.getReduceAllFnObject());
    // execute operation
    MatrixBlock out = new MatrixBlock(1, 1, false);
    LibMatrixAgg.aggregateUnaryMatrix(this, out, auop);
    return out.quickGetValue(0, 0);
}
Also used : AggregateUnaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator)

Example 69 with AggregateOperator

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

the class MatrixBlock method max.

/**
 * Wrapper method for reduceall-max of a matrix.
 *
 * @return ?
 */
public double max() {
    // construct operator
    AggregateOperator aop = new AggregateOperator(Double.NEGATIVE_INFINITY, Builtin.getBuiltinFnObject("max"));
    AggregateUnaryOperator auop = new AggregateUnaryOperator(aop, ReduceAll.getReduceAllFnObject());
    // execute operation
    MatrixBlock out = new MatrixBlock(1, 1, false);
    LibMatrixAgg.aggregateUnaryMatrix(this, out, auop);
    return out.quickGetValue(0, 0);
}
Also used : AggregateUnaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator)

Example 70 with AggregateOperator

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

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