use of org.apache.sysml.runtime.instructions.cp.ComputationCPInstruction in project incubator-systemml by apache.
the class ProgramBlock method executePredicateInstructions.
protected ScalarObject executePredicateInstructions(ArrayList<Instruction> inst, ValueType retType, ExecutionContext ec) throws DMLRuntimeException {
ScalarObject ret = null;
String retName = null;
//execute all instructions
for (int i = 0; i < inst.size(); i++) {
//indexed access required due to debug mode
Instruction currInst = inst.get(i);
if (!isRemoveVariableInstruction(currInst)) {
//execute instruction
ec.updateDebugState(i);
executeSingleInstruction(currInst, ec);
//get last return name
if (currInst instanceof ComputationCPInstruction)
retName = ((ComputationCPInstruction) currInst).getOutputVariableName();
else if (currInst instanceof VariableCPInstruction && ((VariableCPInstruction) currInst).getOutputVariableName() != null)
retName = ((VariableCPInstruction) currInst).getOutputVariableName();
}
}
//get return value TODO: how do we differentiate literals and variables?
ret = (ScalarObject) ec.getScalarInput(retName, retType, false);
//execute rmvar instructions
for (int i = 0; i < inst.size(); i++) {
//indexed access required due to debug mode
Instruction currInst = inst.get(i);
if (isRemoveVariableInstruction(currInst)) {
ec.updateDebugState(i);
executeSingleInstruction(currInst, ec);
}
}
//check and correct scalar ret type (incl save double to int)
if (ret.getValueType() != retType)
switch(retType) {
case BOOLEAN:
ret = new BooleanObject(ret.getName(), ret.getBooleanValue());
break;
case INT:
ret = new IntObject(ret.getName(), ret.getLongValue());
break;
case DOUBLE:
ret = new DoubleObject(ret.getName(), ret.getDoubleValue());
break;
case STRING:
ret = new StringObject(ret.getName(), ret.getStringValue());
break;
default:
}
return ret;
}
Aggregations