Search in sources :

Example 1 with CorrectionLocationType

use of org.apache.sysml.lops.PartialAggregate.CorrectionLocationType 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 2 with CorrectionLocationType

use of org.apache.sysml.lops.PartialAggregate.CorrectionLocationType in project incubator-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 3 with CorrectionLocationType

use of org.apache.sysml.lops.PartialAggregate.CorrectionLocationType in project incubator-systemml by apache.

the class UaggOuterChainCPInstruction method parseInstruction.

public static UaggOuterChainCPInstruction 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 UaggOuterChainCPInstruction(bop, uaggop, aop, in1, in2, out, opcode, str);
    } else {
        throw new DMLRuntimeException("UaggOuterChainCPInstruction.parseInstruction():: Unknown opcode " + opcode);
    }
}
Also used : AggregateUnaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) BinaryOperator(org.apache.sysml.runtime.matrix.operators.BinaryOperator) CorrectionLocationType(org.apache.sysml.lops.PartialAggregate.CorrectionLocationType) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 4 with CorrectionLocationType

use of org.apache.sysml.lops.PartialAggregate.CorrectionLocationType in project incubator-systemml by apache.

the class InstructionUtils method parseAggregateOperator.

public static AggregateOperator parseAggregateOperator(String opcode, String corrExists, String corrLoc) {
    AggregateOperator agg = null;
    if (opcode.equalsIgnoreCase("ak+") || opcode.equalsIgnoreCase("aktrace")) {
        boolean lcorrExists = (corrExists == null) ? true : Boolean.parseBoolean(corrExists);
        CorrectionLocationType lcorrLoc = (corrLoc == null) ? CorrectionLocationType.LASTCOLUMN : CorrectionLocationType.valueOf(corrLoc);
        agg = new AggregateOperator(0, KahanPlus.getKahanPlusFnObject(), lcorrExists, lcorrLoc);
    } else if (opcode.equalsIgnoreCase("asqk+")) {
        boolean lcorrExists = (corrExists == null) ? true : Boolean.parseBoolean(corrExists);
        CorrectionLocationType lcorrLoc = (corrLoc == null) ? CorrectionLocationType.LASTCOLUMN : CorrectionLocationType.valueOf(corrLoc);
        agg = new AggregateOperator(0, KahanPlusSq.getKahanPlusSqFnObject(), lcorrExists, lcorrLoc);
    } else if (opcode.equalsIgnoreCase("a+")) {
        agg = new AggregateOperator(0, Plus.getPlusFnObject());
    } else if (opcode.equalsIgnoreCase("a*")) {
        agg = new AggregateOperator(1, Multiply.getMultiplyFnObject());
    } else if (opcode.equalsIgnoreCase("arimax")) {
        agg = new AggregateOperator(Double.NEGATIVE_INFINITY, Builtin.getBuiltinFnObject("maxindex"), true, CorrectionLocationType.LASTCOLUMN);
    } else if (opcode.equalsIgnoreCase("amax")) {
        agg = new AggregateOperator(Double.NEGATIVE_INFINITY, Builtin.getBuiltinFnObject("max"));
    } else if (opcode.equalsIgnoreCase("amin")) {
        agg = new AggregateOperator(Double.POSITIVE_INFINITY, Builtin.getBuiltinFnObject("min"));
    } else if (opcode.equalsIgnoreCase("arimin")) {
        agg = new AggregateOperator(Double.POSITIVE_INFINITY, Builtin.getBuiltinFnObject("minindex"), true, CorrectionLocationType.LASTCOLUMN);
    } else if (opcode.equalsIgnoreCase("amean")) {
        boolean lcorrExists = (corrExists == null) ? true : Boolean.parseBoolean(corrExists);
        CorrectionLocationType lcorrLoc = (corrLoc == null) ? CorrectionLocationType.LASTTWOCOLUMNS : CorrectionLocationType.valueOf(corrLoc);
        agg = new AggregateOperator(0, KahanPlus.getKahanPlusFnObject(), lcorrExists, lcorrLoc);
    } else if (opcode.equalsIgnoreCase("avar")) {
        boolean lcorrExists = (corrExists == null) ? true : Boolean.parseBoolean(corrExists);
        CorrectionLocationType lcorrLoc = (corrLoc == null) ? CorrectionLocationType.LASTFOURCOLUMNS : CorrectionLocationType.valueOf(corrLoc);
        CM varFn = CM.getCMFnObject(AggregateOperationTypes.VARIANCE);
        agg = new AggregateOperator(0, varFn, lcorrExists, lcorrLoc);
    }
    return agg;
}
Also used : AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) CM(org.apache.sysml.runtime.functionobjects.CM) CorrectionLocationType(org.apache.sysml.lops.PartialAggregate.CorrectionLocationType)

Example 5 with CorrectionLocationType

use of org.apache.sysml.lops.PartialAggregate.CorrectionLocationType in project incubator-systemml by apache.

the class InstructionUtils method parseAggregateTernaryOperator.

public static AggregateTernaryOperator parseAggregateTernaryOperator(String opcode, int numThreads) {
    CorrectionLocationType corr = opcode.equalsIgnoreCase("tak+*") ? CorrectionLocationType.LASTCOLUMN : CorrectionLocationType.LASTROW;
    AggregateOperator agg = new AggregateOperator(0, KahanPlus.getKahanPlusFnObject(), true, corr);
    IndexFunction ixfun = opcode.equalsIgnoreCase("tak+*") ? ReduceAll.getReduceAllFnObject() : ReduceRow.getReduceRowFnObject();
    return new AggregateTernaryOperator(Multiply.getMultiplyFnObject(), agg, ixfun, numThreads);
}
Also used : IndexFunction(org.apache.sysml.runtime.functionobjects.IndexFunction) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) AggregateTernaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateTernaryOperator) CorrectionLocationType(org.apache.sysml.lops.PartialAggregate.CorrectionLocationType)

Aggregations

CorrectionLocationType (org.apache.sysml.lops.PartialAggregate.CorrectionLocationType)17 AggregateOperator (org.apache.sysml.runtime.matrix.operators.AggregateOperator)17 AggregateUnaryOperator (org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator)13 BinaryOperator (org.apache.sysml.runtime.matrix.operators.BinaryOperator)6 CM (org.apache.sysml.runtime.functionobjects.CM)5 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)4 CPOperand (org.apache.sysml.runtime.instructions.cp.CPOperand)4 SparkAggType (org.apache.sysml.hops.AggBinaryOp.SparkAggType)2 IndexFunction (org.apache.sysml.runtime.functionobjects.IndexFunction)2 ReduceAll (org.apache.sysml.runtime.functionobjects.ReduceAll)2 AggregateTernaryOperator (org.apache.sysml.runtime.matrix.operators.AggregateTernaryOperator)2