Search in sources :

Example 31 with AggregateOperator

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

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

the class AggregateUnarySPInstruction method processInstruction.

@Override
public void processInstruction(ExecutionContext ec) {
    SparkExecutionContext sec = (SparkExecutionContext) ec;
    MatrixCharacteristics mc = sec.getMatrixCharacteristics(input1.getName());
    // get input
    JavaPairRDD<MatrixIndexes, MatrixBlock> in = sec.getBinaryBlockRDDHandleForVariable(input1.getName());
    JavaPairRDD<MatrixIndexes, MatrixBlock> out = in;
    // filter input blocks for trace
    if (getOpcode().equalsIgnoreCase("uaktrace"))
        out = out.filter(new FilterDiagBlocksFunction());
    // execute unary aggregate operation
    AggregateUnaryOperator auop = (AggregateUnaryOperator) _optr;
    AggregateOperator aggop = _aop;
    // perform aggregation if necessary and put output into symbol table
    if (_aggtype == SparkAggType.SINGLE_BLOCK) {
        JavaRDD<MatrixBlock> out2 = out.map(new RDDUAggFunction2(auop, mc.getRowsPerBlock(), mc.getColsPerBlock()));
        MatrixBlock out3 = RDDAggregateUtils.aggStable(out2, aggop);
        // drop correction after aggregation
        out3.dropLastRowsOrColumns(aggop.correctionLocation);
        // put output block into symbol table (no lineage because single block)
        // this also includes implicit maintenance of matrix characteristics
        sec.setMatrixOutput(output.getName(), out3, getExtendedOpcode());
    } else // MULTI_BLOCK or NONE
    {
        if (_aggtype == SparkAggType.NONE) {
            // in case of no block aggregation, we always drop the correction as well as
            // use a partitioning-preserving mapvalues
            out = out.mapValues(new RDDUAggValueFunction(auop, mc.getRowsPerBlock(), mc.getColsPerBlock()));
        } else if (_aggtype == SparkAggType.MULTI_BLOCK) {
            // in case of multi-block aggregation, we always keep the correction
            out = out.mapToPair(new RDDUAggFunction(auop, mc.getRowsPerBlock(), mc.getColsPerBlock()));
            out = RDDAggregateUtils.aggByKeyStable(out, aggop, false);
            // partitioning, drop correction via partitioning-preserving mapvalues)
            if (auop.aggOp.correctionExists)
                out = out.mapValues(new AggregateDropCorrectionFunction(aggop));
        }
        // put output RDD handle into symbol table
        updateUnaryAggOutputMatrixCharacteristics(sec, auop.indexFn);
        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) AggregateDropCorrectionFunction(org.apache.sysml.runtime.instructions.spark.functions.AggregateDropCorrectionFunction) MatrixCharacteristics(org.apache.sysml.runtime.matrix.MatrixCharacteristics) FilterDiagBlocksFunction(org.apache.sysml.runtime.instructions.spark.functions.FilterDiagBlocksFunction) AggregateUnaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) SparkExecutionContext(org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext)

Example 33 with AggregateOperator

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

the class MapmmSPInstruction method parseInstruction.

public static MapmmSPInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    if (!opcode.equalsIgnoreCase(MapMult.OPCODE))
        throw new DMLRuntimeException("MapmmSPInstruction.parseInstruction():: Unknown opcode " + opcode);
    CPOperand in1 = new CPOperand(parts[1]);
    CPOperand in2 = new CPOperand(parts[2]);
    CPOperand out = new CPOperand(parts[3]);
    CacheType type = CacheType.valueOf(parts[4]);
    boolean outputEmpty = Boolean.parseBoolean(parts[5]);
    SparkAggType aggtype = SparkAggType.valueOf(parts[6]);
    AggregateOperator agg = new AggregateOperator(0, Plus.getPlusFnObject());
    AggregateBinaryOperator aggbin = new AggregateBinaryOperator(Multiply.getMultiplyFnObject(), agg);
    return new MapmmSPInstruction(aggbin, in1, in2, out, type, outputEmpty, aggtype, opcode, str);
}
Also used : SparkAggType(org.apache.sysml.hops.AggBinaryOp.SparkAggType) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) AggregateBinaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) CacheType(org.apache.sysml.lops.MapMult.CacheType)

Example 34 with AggregateOperator

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

the class PMapmmSPInstruction method parseInstruction.

public static PMapmmSPInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    if (opcode.equalsIgnoreCase(PMapMult.OPCODE)) {
        CPOperand in1 = new CPOperand(parts[1]);
        CPOperand in2 = new CPOperand(parts[2]);
        CPOperand out = new CPOperand(parts[3]);
        AggregateOperator agg = new AggregateOperator(0, Plus.getPlusFnObject());
        AggregateBinaryOperator aggbin = new AggregateBinaryOperator(Multiply.getMultiplyFnObject(), agg);
        return new PMapmmSPInstruction(aggbin, in1, in2, out, opcode, str);
    } else {
        throw new DMLRuntimeException("PMapmmSPInstruction.parseInstruction():: Unknown opcode " + opcode);
    }
}
Also used : AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) AggregateBinaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 35 with AggregateOperator

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

the class ParameterizedBuiltinSPInstruction method parseInstruction.

public static ParameterizedBuiltinSPInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    // first part is always the opcode
    String opcode = parts[0];
    if (opcode.equalsIgnoreCase("mapgroupedagg")) {
        CPOperand target = new CPOperand(parts[1]);
        CPOperand groups = new CPOperand(parts[2]);
        CPOperand out = new CPOperand(parts[3]);
        HashMap<String, String> paramsMap = new HashMap<>();
        paramsMap.put(Statement.GAGG_TARGET, target.getName());
        paramsMap.put(Statement.GAGG_GROUPS, groups.getName());
        paramsMap.put(Statement.GAGG_NUM_GROUPS, parts[4]);
        Operator op = new AggregateOperator(0, KahanPlus.getKahanPlusFnObject(), true, CorrectionLocationType.LASTCOLUMN);
        return new ParameterizedBuiltinSPInstruction(op, paramsMap, out, opcode, str, false);
    } else {
        // last part is always the output
        CPOperand out = new CPOperand(parts[parts.length - 1]);
        // process remaining parts and build a hash map
        HashMap<String, String> paramsMap = constructParameterMap(parts);
        // determine the appropriate value function
        ValueFunction func = null;
        if (opcode.equalsIgnoreCase("groupedagg")) {
            // check for mandatory arguments
            String fnStr = paramsMap.get("fn");
            if (fnStr == null)
                throw new DMLRuntimeException("Function parameter is missing in groupedAggregate.");
            if (fnStr.equalsIgnoreCase("centralmoment")) {
                if (paramsMap.get("order") == null)
                    throw new DMLRuntimeException("Mandatory \"order\" must be specified when fn=\"centralmoment\" in groupedAggregate.");
            }
            Operator op = GroupedAggregateInstruction.parseGroupedAggOperator(fnStr, paramsMap.get("order"));
            return new ParameterizedBuiltinSPInstruction(op, paramsMap, out, opcode, str, false);
        } else if (opcode.equalsIgnoreCase("rmempty")) {
            boolean bRmEmptyBC = false;
            if (parts.length > 6)
                bRmEmptyBC = Boolean.parseBoolean(parts[5]);
            func = ParameterizedBuiltin.getParameterizedBuiltinFnObject(opcode);
            return new ParameterizedBuiltinSPInstruction(new SimpleOperator(func), paramsMap, out, opcode, str, bRmEmptyBC);
        } else if (opcode.equalsIgnoreCase("rexpand") || opcode.equalsIgnoreCase("replace") || opcode.equalsIgnoreCase("transformapply") || opcode.equalsIgnoreCase("transformdecode")) {
            func = ParameterizedBuiltin.getParameterizedBuiltinFnObject(opcode);
            return new ParameterizedBuiltinSPInstruction(new SimpleOperator(func), paramsMap, out, opcode, str, false);
        } else {
            throw new DMLRuntimeException("Unknown opcode (" + opcode + ") for ParameterizedBuiltin Instruction.");
        }
    }
}
Also used : SimpleOperator(org.apache.sysml.runtime.matrix.operators.SimpleOperator) Operator(org.apache.sysml.runtime.matrix.operators.Operator) CMOperator(org.apache.sysml.runtime.matrix.operators.CMOperator) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) ValueFunction(org.apache.sysml.runtime.functionobjects.ValueFunction) SimpleOperator(org.apache.sysml.runtime.matrix.operators.SimpleOperator) HashMap(java.util.HashMap) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Aggregations

AggregateOperator (org.apache.sysml.runtime.matrix.operators.AggregateOperator)42 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)17 AggregateBinaryOperator (org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator)16 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)12 AggregateUnaryOperator (org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator)11 CPOperand (org.apache.sysml.runtime.instructions.cp.CPOperand)10 CorrectionLocationType (org.apache.sysml.lops.PartialAggregate.CorrectionLocationType)9 CompressedMatrixBlock (org.apache.sysml.runtime.compress.CompressedMatrixBlock)8 CM (org.apache.sysml.runtime.functionobjects.CM)8 CMOperator (org.apache.sysml.runtime.matrix.operators.CMOperator)7 KahanObject (org.apache.sysml.runtime.instructions.cp.KahanObject)5 WeightedCell (org.apache.sysml.runtime.matrix.data.WeightedCell)5 BinaryOperator (org.apache.sysml.runtime.matrix.operators.BinaryOperator)4 Operator (org.apache.sysml.runtime.matrix.operators.Operator)4 ArrayList (java.util.ArrayList)3 SparkAggType (org.apache.sysml.hops.AggBinaryOp.SparkAggType)3 SparkExecutionContext (org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext)3 CM_COV_Object (org.apache.sysml.runtime.instructions.cp.CM_COV_Object)3 MatrixIndexes (org.apache.sysml.runtime.matrix.data.MatrixIndexes)3 IOException (java.io.IOException)2