Search in sources :

Example 1 with AggregateUnaryOperator

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

the class UaggOuterChainSPInstruction method parseInstruction.

public static UaggOuterChainSPInstruction parseInstruction(String str) throws DMLRuntimeException {
    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 2 with AggregateUnaryOperator

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

the class InstructionUtils method parseBasicAggregateUnaryOperator.

public static AggregateUnaryOperator parseBasicAggregateUnaryOperator(String opcode) {
    AggregateUnaryOperator aggun = null;
    if (opcode.equalsIgnoreCase("uak+")) {
        AggregateOperator agg = new AggregateOperator(0, KahanPlus.getKahanPlusFnObject(), true, CorrectionLocationType.LASTCOLUMN);
        aggun = new AggregateUnaryOperator(agg, ReduceAll.getReduceAllFnObject());
    } else if (opcode.equalsIgnoreCase("uark+")) {
        // RowSums
        AggregateOperator agg = new AggregateOperator(0, KahanPlus.getKahanPlusFnObject(), true, CorrectionLocationType.LASTCOLUMN);
        aggun = new AggregateUnaryOperator(agg, ReduceCol.getReduceColFnObject());
    } else if (opcode.equalsIgnoreCase("uack+")) {
        // ColSums
        AggregateOperator agg = new AggregateOperator(0, KahanPlus.getKahanPlusFnObject(), true, CorrectionLocationType.LASTROW);
        aggun = new AggregateUnaryOperator(agg, ReduceRow.getReduceRowFnObject());
    } else if (opcode.equalsIgnoreCase("uasqk+")) {
        AggregateOperator agg = new AggregateOperator(0, KahanPlusSq.getKahanPlusSqFnObject(), true, CorrectionLocationType.LASTCOLUMN);
        aggun = new AggregateUnaryOperator(agg, ReduceAll.getReduceAllFnObject());
    } else if (opcode.equalsIgnoreCase("uarsqk+")) {
        // RowSums
        AggregateOperator agg = new AggregateOperator(0, KahanPlusSq.getKahanPlusSqFnObject(), true, CorrectionLocationType.LASTCOLUMN);
        aggun = new AggregateUnaryOperator(agg, ReduceCol.getReduceColFnObject());
    } else if (opcode.equalsIgnoreCase("uacsqk+")) {
        // ColSums
        AggregateOperator agg = new AggregateOperator(0, KahanPlusSq.getKahanPlusSqFnObject(), true, CorrectionLocationType.LASTROW);
        aggun = new AggregateUnaryOperator(agg, ReduceRow.getReduceRowFnObject());
    } else if (opcode.equalsIgnoreCase("uamean")) {
        // Mean
        AggregateOperator agg = new AggregateOperator(0, Mean.getMeanFnObject(), true, CorrectionLocationType.LASTTWOCOLUMNS);
        aggun = new AggregateUnaryOperator(agg, ReduceAll.getReduceAllFnObject());
    } else if (opcode.equalsIgnoreCase("uarmean")) {
        // RowMeans
        AggregateOperator agg = new AggregateOperator(0, Mean.getMeanFnObject(), true, CorrectionLocationType.LASTTWOCOLUMNS);
        aggun = new AggregateUnaryOperator(agg, ReduceCol.getReduceColFnObject());
    } else if (opcode.equalsIgnoreCase("uacmean")) {
        // ColMeans
        AggregateOperator agg = new AggregateOperator(0, Mean.getMeanFnObject(), true, CorrectionLocationType.LASTTWOROWS);
        aggun = new AggregateUnaryOperator(agg, ReduceRow.getReduceRowFnObject());
    } else if (opcode.equalsIgnoreCase("uavar")) {
        // Variance
        CM varFn = CM.getCMFnObject(AggregateOperationTypes.VARIANCE);
        CorrectionLocationType cloc = CorrectionLocationType.LASTFOURCOLUMNS;
        AggregateOperator agg = new AggregateOperator(0, varFn, true, cloc);
        aggun = new AggregateUnaryOperator(agg, ReduceAll.getReduceAllFnObject());
    } else if (opcode.equalsIgnoreCase("uarvar")) {
        // RowVariances
        CM varFn = CM.getCMFnObject(AggregateOperationTypes.VARIANCE);
        CorrectionLocationType cloc = CorrectionLocationType.LASTFOURCOLUMNS;
        AggregateOperator agg = new AggregateOperator(0, varFn, true, cloc);
        aggun = new AggregateUnaryOperator(agg, ReduceCol.getReduceColFnObject());
    } else if (opcode.equalsIgnoreCase("uacvar")) {
        // ColVariances
        CM varFn = CM.getCMFnObject(AggregateOperationTypes.VARIANCE);
        CorrectionLocationType cloc = CorrectionLocationType.LASTFOURROWS;
        AggregateOperator agg = new AggregateOperator(0, varFn, true, cloc);
        aggun = new AggregateUnaryOperator(agg, ReduceRow.getReduceRowFnObject());
    } else if (opcode.equalsIgnoreCase("ua+")) {
        AggregateOperator agg = new AggregateOperator(0, Plus.getPlusFnObject());
        aggun = new AggregateUnaryOperator(agg, ReduceAll.getReduceAllFnObject());
    } else if (opcode.equalsIgnoreCase("uar+")) {
        // RowSums
        AggregateOperator agg = new AggregateOperator(0, Plus.getPlusFnObject());
        aggun = new AggregateUnaryOperator(agg, ReduceCol.getReduceColFnObject());
    } else if (opcode.equalsIgnoreCase("uac+")) {
        // ColSums
        AggregateOperator agg = new AggregateOperator(0, Plus.getPlusFnObject());
        aggun = new AggregateUnaryOperator(agg, ReduceRow.getReduceRowFnObject());
    } else if (opcode.equalsIgnoreCase("ua*")) {
        AggregateOperator agg = new AggregateOperator(1, Multiply.getMultiplyFnObject());
        aggun = new AggregateUnaryOperator(agg, ReduceAll.getReduceAllFnObject());
    } else if (opcode.equalsIgnoreCase("uamax")) {
        AggregateOperator agg = new AggregateOperator(-Double.MAX_VALUE, Builtin.getBuiltinFnObject("max"));
        aggun = new AggregateUnaryOperator(agg, ReduceAll.getReduceAllFnObject());
    } else if (opcode.equalsIgnoreCase("uamin")) {
        AggregateOperator agg = new AggregateOperator(Double.MAX_VALUE, Builtin.getBuiltinFnObject("min"));
        aggun = new AggregateUnaryOperator(agg, ReduceAll.getReduceAllFnObject());
    } else if (opcode.equalsIgnoreCase("uatrace")) {
        AggregateOperator agg = new AggregateOperator(0, Plus.getPlusFnObject());
        aggun = new AggregateUnaryOperator(agg, ReduceDiag.getReduceDiagFnObject());
    } else if (opcode.equalsIgnoreCase("uaktrace")) {
        AggregateOperator agg = new AggregateOperator(0, KahanPlus.getKahanPlusFnObject(), true, CorrectionLocationType.LASTCOLUMN);
        aggun = new AggregateUnaryOperator(agg, ReduceDiag.getReduceDiagFnObject());
    } else if (opcode.equalsIgnoreCase("uarmax")) {
        AggregateOperator agg = new AggregateOperator(-Double.MAX_VALUE, Builtin.getBuiltinFnObject("max"));
        aggun = new AggregateUnaryOperator(agg, ReduceCol.getReduceColFnObject());
    } else if (opcode.equalsIgnoreCase("uarimax")) {
        AggregateOperator agg = new AggregateOperator(-Double.MAX_VALUE, Builtin.getBuiltinFnObject("maxindex"), true, CorrectionLocationType.LASTCOLUMN);
        aggun = new AggregateUnaryOperator(agg, ReduceCol.getReduceColFnObject());
    } else if (opcode.equalsIgnoreCase("uarmin")) {
        AggregateOperator agg = new AggregateOperator(Double.MAX_VALUE, Builtin.getBuiltinFnObject("min"));
        aggun = new AggregateUnaryOperator(agg, ReduceCol.getReduceColFnObject());
    } else if (opcode.equalsIgnoreCase("uarimin")) {
        AggregateOperator agg = new AggregateOperator(Double.MAX_VALUE, Builtin.getBuiltinFnObject("minindex"), true, CorrectionLocationType.LASTCOLUMN);
        aggun = new AggregateUnaryOperator(agg, ReduceCol.getReduceColFnObject());
    } else if (opcode.equalsIgnoreCase("uacmax")) {
        AggregateOperator agg = new AggregateOperator(-Double.MAX_VALUE, Builtin.getBuiltinFnObject("max"));
        aggun = new AggregateUnaryOperator(agg, ReduceRow.getReduceRowFnObject());
    } else if (opcode.equalsIgnoreCase("uacmin")) {
        AggregateOperator agg = new AggregateOperator(Double.MAX_VALUE, Builtin.getBuiltinFnObject("min"));
        aggun = new AggregateUnaryOperator(agg, ReduceRow.getReduceRowFnObject());
    }
    return aggun;
}
Also used : AggregateUnaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) CM(org.apache.sysml.runtime.functionobjects.CM) CorrectionLocationType(org.apache.sysml.lops.PartialAggregate.CorrectionLocationType)

Example 3 with AggregateUnaryOperator

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

the class CumulativeAggregateSPInstruction method processInstruction.

@Override
public void processInstruction(ExecutionContext ec) throws DMLRuntimeException {
    SparkExecutionContext sec = (SparkExecutionContext) ec;
    MatrixCharacteristics mc = sec.getMatrixCharacteristics(input1.getName());
    long rlen = mc.getRows();
    int brlen = mc.getRowsPerBlock();
    int bclen = mc.getColsPerBlock();
    //get input
    JavaPairRDD<MatrixIndexes, MatrixBlock> in = sec.getBinaryBlockRDDHandleForVariable(input1.getName());
    //execute unary aggregate (w/ implicit drop correction)
    AggregateUnaryOperator auop = (AggregateUnaryOperator) _optr;
    JavaPairRDD<MatrixIndexes, MatrixBlock> out = in.mapToPair(new RDDCumAggFunction(auop, rlen, brlen, bclen));
    out = RDDAggregateUtils.mergeByKey(out, false);
    //put output handle in symbol table
    sec.setRDDHandleForVariable(output.getName(), out);
    sec.addLineageRDD(output.getName(), input1.getName());
}
Also used : MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) MatrixIndexes(org.apache.sysml.runtime.matrix.data.MatrixIndexes) AggregateUnaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator) SparkExecutionContext(org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext) MatrixCharacteristics(org.apache.sysml.runtime.matrix.MatrixCharacteristics)

Example 4 with AggregateUnaryOperator

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

the class BinUaggChainInstruction method parseInstruction.

public static BinUaggChainInstruction parseInstruction(String str) throws DMLRuntimeException {
    //check number of fields (2/3 inputs, output, type)
    InstructionUtils.checkNumFields(str, 4);
    //parse instruction parts (without exec type)
    String[] parts = InstructionUtils.getInstructionParts(str);
    BinaryOperator bop = InstructionUtils.parseBinaryOperator(parts[1]);
    AggregateUnaryOperator uaggop = InstructionUtils.parseBasicAggregateUnaryOperator(parts[2]);
    byte in1 = Byte.parseByte(parts[3]);
    byte out = Byte.parseByte(parts[4]);
    return new BinUaggChainInstruction(bop, uaggop, in1, out, str);
}
Also used : AggregateUnaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator) BinaryOperator(org.apache.sysml.runtime.matrix.operators.BinaryOperator)

Example 5 with AggregateUnaryOperator

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

the class BinUaggChainSPInstruction method parseInstruction.

public static BinUaggChainSPInstruction parseInstruction(String str) throws DMLRuntimeException {
    //parse instruction parts (without exec type)
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    InstructionUtils.checkNumFields(parts, 4);
    String opcode = parts[0];
    BinaryOperator bop = InstructionUtils.parseBinaryOperator(parts[1]);
    AggregateUnaryOperator uaggop = InstructionUtils.parseBasicAggregateUnaryOperator(parts[2]);
    CPOperand in = new CPOperand(parts[3]);
    CPOperand out = new CPOperand(parts[4]);
    return new BinUaggChainSPInstruction(in, out, bop, uaggop, opcode, str);
}
Also used : AggregateUnaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) BinaryOperator(org.apache.sysml.runtime.matrix.operators.BinaryOperator)

Aggregations

AggregateUnaryOperator (org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator)25 AggregateOperator (org.apache.sysml.runtime.matrix.operators.AggregateOperator)10 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)7 CorrectionLocationType (org.apache.sysml.lops.PartialAggregate.CorrectionLocationType)6 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)5 BinaryOperator (org.apache.sysml.runtime.matrix.operators.BinaryOperator)5 CPOperand (org.apache.sysml.runtime.instructions.cp.CPOperand)4 CompressedMatrixBlock (org.apache.sysml.runtime.compress.CompressedMatrixBlock)3 MatrixIndexes (org.apache.sysml.runtime.matrix.data.MatrixIndexes)3 SparkExecutionContext (org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext)2 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)2 ArrayList (java.util.ArrayList)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 SparkAggType (org.apache.sysml.hops.AggBinaryOp.SparkAggType)1 MMTSJType (org.apache.sysml.lops.MMTSJ.MMTSJType)1 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)1 CM (org.apache.sysml.runtime.functionobjects.CM)1 IndexFunction (org.apache.sysml.runtime.functionobjects.IndexFunction)1 ReduceAll (org.apache.sysml.runtime.functionobjects.ReduceAll)1