Search in sources :

Example 1 with ComputationCPInstruction

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;
}
Also used : ScalarObject(org.apache.sysml.runtime.instructions.cp.ScalarObject) IntObject(org.apache.sysml.runtime.instructions.cp.IntObject) VariableCPInstruction(org.apache.sysml.runtime.instructions.cp.VariableCPInstruction) DoubleObject(org.apache.sysml.runtime.instructions.cp.DoubleObject) StringObject(org.apache.sysml.runtime.instructions.cp.StringObject) ComputationCPInstruction(org.apache.sysml.runtime.instructions.cp.ComputationCPInstruction) VariableCPInstruction(org.apache.sysml.runtime.instructions.cp.VariableCPInstruction) Instruction(org.apache.sysml.runtime.instructions.Instruction) ComputationCPInstruction(org.apache.sysml.runtime.instructions.cp.ComputationCPInstruction) BooleanObject(org.apache.sysml.runtime.instructions.cp.BooleanObject)

Aggregations

Instruction (org.apache.sysml.runtime.instructions.Instruction)1 BooleanObject (org.apache.sysml.runtime.instructions.cp.BooleanObject)1 ComputationCPInstruction (org.apache.sysml.runtime.instructions.cp.ComputationCPInstruction)1 DoubleObject (org.apache.sysml.runtime.instructions.cp.DoubleObject)1 IntObject (org.apache.sysml.runtime.instructions.cp.IntObject)1 ScalarObject (org.apache.sysml.runtime.instructions.cp.ScalarObject)1 StringObject (org.apache.sysml.runtime.instructions.cp.StringObject)1 VariableCPInstruction (org.apache.sysml.runtime.instructions.cp.VariableCPInstruction)1