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);
}
Aggregations