Search in sources :

Example 6 with AggregateOperationTypes

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

the class CentralMomentCPInstruction method parseInstruction.

public static CentralMomentCPInstruction parseInstruction(String str) {
    CPOperand in1 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    CPOperand in2 = null;
    CPOperand in3 = null;
    CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    // check supported opcode
    if (!opcode.equalsIgnoreCase("cm")) {
        throw new DMLRuntimeException("Unsupported opcode " + opcode);
    }
    if (parts.length == 4) {
        // Example: CP.cm.mVar0.Var1.mVar2; (without weights)
        in2 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
        parseUnaryInstruction(str, in1, in2, out);
    } else if (parts.length == 5) {
        // CP.cm.mVar0.mVar1.Var2.mVar3; (with weights)
        in2 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
        in3 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
        parseUnaryInstruction(str, in1, in2, in3, out);
    }
    /* 
		 * Exact order of the central moment MAY NOT be known at compilation time.
		 * We first try to parse the second argument as an integer, and if we fail, 
		 * we simply pass -1 so that getCMAggOpType() picks up AggregateOperationTypes.INVALID.
		 * It must be updated at run time in processInstruction() method.
		 */
    int cmOrder;
    try {
        if (in3 == null) {
            cmOrder = Integer.parseInt(in2.getName());
        } else {
            cmOrder = Integer.parseInt(in3.getName());
        }
    } catch (NumberFormatException e) {
        // unknown at compilation time
        cmOrder = -1;
    }
    AggregateOperationTypes opType = CMOperator.getCMAggOpType(cmOrder);
    CMOperator cm = new CMOperator(CM.getCMFnObject(opType), opType);
    return new CentralMomentCPInstruction(cm, in1, in2, in3, out, opcode, str);
}
Also used : AggregateOperationTypes(org.apache.sysml.runtime.matrix.operators.CMOperator.AggregateOperationTypes) CMOperator(org.apache.sysml.runtime.matrix.operators.CMOperator) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Aggregations

AggregateOperationTypes (org.apache.sysml.runtime.matrix.operators.CMOperator.AggregateOperationTypes)6 CMOperator (org.apache.sysml.runtime.matrix.operators.CMOperator)4 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)3 HashMap (java.util.HashMap)1 CompressedMatrixBlock (org.apache.sysml.runtime.compress.CompressedMatrixBlock)1 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)1 AggregateTernaryCPInstruction (org.apache.sysml.runtime.instructions.cp.AggregateTernaryCPInstruction)1 AggregateUnaryCPInstruction (org.apache.sysml.runtime.instructions.cp.AggregateUnaryCPInstruction)1 BinaryCPInstruction (org.apache.sysml.runtime.instructions.cp.BinaryCPInstruction)1 CPOperand (org.apache.sysml.runtime.instructions.cp.CPOperand)1 DataGenCPInstruction (org.apache.sysml.runtime.instructions.cp.DataGenCPInstruction)1 MMTSJCPInstruction (org.apache.sysml.runtime.instructions.cp.MMTSJCPInstruction)1 MultiReturnBuiltinCPInstruction (org.apache.sysml.runtime.instructions.cp.MultiReturnBuiltinCPInstruction)1 ParameterizedBuiltinCPInstruction (org.apache.sysml.runtime.instructions.cp.ParameterizedBuiltinCPInstruction)1 StringInitCPInstruction (org.apache.sysml.runtime.instructions.cp.StringInitCPInstruction)1 UnaryCPInstruction (org.apache.sysml.runtime.instructions.cp.UnaryCPInstruction)1 VariableCPInstruction (org.apache.sysml.runtime.instructions.cp.VariableCPInstruction)1 BinaryMRInstructionBase (org.apache.sysml.runtime.instructions.mr.BinaryMRInstructionBase)1 CM_N_COVInstruction (org.apache.sysml.runtime.instructions.mr.CM_N_COVInstruction)1 CtableInstruction (org.apache.sysml.runtime.instructions.mr.CtableInstruction)1