use of org.apache.sysml.runtime.instructions.cp.CPOperand in project incubator-systemml by apache.
the class CentralMomentSPInstruction method parseInstruction.
public static CentralMomentSPInstruction 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 CentralMomentSPInstruction(cm, in1, in2, in3, out, opcode, str);
}
use of org.apache.sysml.runtime.instructions.cp.CPOperand in project incubator-systemml by apache.
the class CentralMomentSPInstruction method processInstruction.
@Override
public void processInstruction(ExecutionContext ec) {
SparkExecutionContext sec = (SparkExecutionContext) ec;
// parse 'order' input argument
CPOperand scalarInput = (input3 == null ? input2 : input3);
ScalarObject order = ec.getScalarInput(scalarInput.getName(), scalarInput.getValueType(), scalarInput.isLiteral());
CMOperator cop = ((CMOperator) _optr);
if (cop.getAggOpType() == AggregateOperationTypes.INVALID) {
cop.setCMAggOp((int) order.getLongValue());
}
// get input
JavaPairRDD<MatrixIndexes, MatrixBlock> in1 = sec.getBinaryBlockRDDHandleForVariable(input1.getName());
// process central moment instruction
CM_COV_Object cmobj = null;
if (// w/o weights
input3 == null) {
cmobj = in1.values().map(new RDDCMFunction(cop)).fold(new CM_COV_Object(), new RDDCMReduceFunction(cop));
} else // with weights
{
JavaPairRDD<MatrixIndexes, MatrixBlock> in2 = sec.getBinaryBlockRDDHandleForVariable(input2.getName());
cmobj = in1.join(in2).values().map(new RDDCMWeightsFunction(cop)).fold(new CM_COV_Object(), new RDDCMReduceFunction(cop));
}
// create scalar output (no lineage information required)
double val = cmobj.getRequiredResult(_optr);
ec.setScalarOutput(output.getName(), new DoubleObject(val));
}
use of org.apache.sysml.runtime.instructions.cp.CPOperand in project incubator-systemml by apache.
the class CheckpointSPInstruction method parseInstruction.
public static CheckpointSPInstruction parseInstruction(String str) {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
InstructionUtils.checkNumFields(parts, 3);
String opcode = parts[0];
CPOperand in = new CPOperand(parts[1]);
CPOperand out = new CPOperand(parts[2]);
StorageLevel level = StorageLevel.fromString(parts[3]);
return new CheckpointSPInstruction(null, in, out, level, opcode, str);
}
use of org.apache.sysml.runtime.instructions.cp.CPOperand in project incubator-systemml by apache.
the class CpmmSPInstruction method parseInstruction.
public static CpmmSPInstruction parseInstruction(String str) {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
String opcode = parts[0];
if (!opcode.equalsIgnoreCase("cpmm"))
throw new DMLRuntimeException("CpmmSPInstruction.parseInstruction(): Unknown opcode " + 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);
SparkAggType aggtype = SparkAggType.valueOf(parts[4]);
return new CpmmSPInstruction(aggbin, in1, in2, out, aggtype, opcode, str);
}
use of org.apache.sysml.runtime.instructions.cp.CPOperand in project incubator-systemml by apache.
the class ExternalFunctionProgramBlock method getOperands.
/**
* Given a list of parameters as data identifiers, returns an array
* of instruction operands.
*
* @param params list of data identifiers
* @return operands
*/
protected CPOperand[] getOperands(ArrayList<DataIdentifier> params) {
CPOperand[] ret = new CPOperand[params.size()];
for (int i = 0; i < params.size(); i++) {
DataIdentifier param = params.get(i);
ret[i] = new CPOperand(param.getName(), param.getValueType(), param.getDataType());
}
return ret;
}
Aggregations