Search in sources :

Example 16 with SimpleOperator

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

the class ParameterizedBuiltinSPInstruction method parseInstruction.

public static ParameterizedBuiltinSPInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    // first part is always the opcode
    String opcode = parts[0];
    if (opcode.equalsIgnoreCase("mapgroupedagg")) {
        CPOperand target = new CPOperand(parts[1]);
        CPOperand groups = new CPOperand(parts[2]);
        CPOperand out = new CPOperand(parts[3]);
        HashMap<String, String> paramsMap = new HashMap<>();
        paramsMap.put(Statement.GAGG_TARGET, target.getName());
        paramsMap.put(Statement.GAGG_GROUPS, groups.getName());
        paramsMap.put(Statement.GAGG_NUM_GROUPS, parts[4]);
        Operator op = new AggregateOperator(0, KahanPlus.getKahanPlusFnObject(), true, CorrectionLocationType.LASTCOLUMN);
        return new ParameterizedBuiltinSPInstruction(op, paramsMap, out, opcode, str, false);
    } else {
        // last part is always the output
        CPOperand out = new CPOperand(parts[parts.length - 1]);
        // process remaining parts and build a hash map
        HashMap<String, String> paramsMap = constructParameterMap(parts);
        // determine the appropriate value function
        ValueFunction func = null;
        if (opcode.equalsIgnoreCase("groupedagg")) {
            // check for mandatory arguments
            String fnStr = paramsMap.get("fn");
            if (fnStr == null)
                throw new DMLRuntimeException("Function parameter is missing in groupedAggregate.");
            if (fnStr.equalsIgnoreCase("centralmoment")) {
                if (paramsMap.get("order") == null)
                    throw new DMLRuntimeException("Mandatory \"order\" must be specified when fn=\"centralmoment\" in groupedAggregate.");
            }
            Operator op = GroupedAggregateInstruction.parseGroupedAggOperator(fnStr, paramsMap.get("order"));
            return new ParameterizedBuiltinSPInstruction(op, paramsMap, out, opcode, str, false);
        } else if (opcode.equalsIgnoreCase("rmempty")) {
            boolean bRmEmptyBC = false;
            if (parts.length > 6)
                bRmEmptyBC = Boolean.parseBoolean(parts[5]);
            func = ParameterizedBuiltin.getParameterizedBuiltinFnObject(opcode);
            return new ParameterizedBuiltinSPInstruction(new SimpleOperator(func), paramsMap, out, opcode, str, bRmEmptyBC);
        } else if (opcode.equalsIgnoreCase("rexpand") || opcode.equalsIgnoreCase("replace") || opcode.equalsIgnoreCase("transformapply") || opcode.equalsIgnoreCase("transformdecode")) {
            func = ParameterizedBuiltin.getParameterizedBuiltinFnObject(opcode);
            return new ParameterizedBuiltinSPInstruction(new SimpleOperator(func), paramsMap, out, opcode, str, false);
        } else {
            throw new DMLRuntimeException("Unknown opcode (" + opcode + ") for ParameterizedBuiltin Instruction.");
        }
    }
}
Also used : SimpleOperator(org.apache.sysml.runtime.matrix.operators.SimpleOperator) Operator(org.apache.sysml.runtime.matrix.operators.Operator) CMOperator(org.apache.sysml.runtime.matrix.operators.CMOperator) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) ValueFunction(org.apache.sysml.runtime.functionobjects.ValueFunction) SimpleOperator(org.apache.sysml.runtime.matrix.operators.SimpleOperator) HashMap(java.util.HashMap) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 17 with SimpleOperator

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

the class IndexingCPInstruction method parseInstruction.

public static IndexingCPInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    if (opcode.equalsIgnoreCase(RightIndex.OPCODE)) {
        if (parts.length == 7) {
            CPOperand in, rl, ru, cl, cu, out;
            in = new CPOperand(parts[1]);
            rl = new CPOperand(parts[2]);
            ru = new CPOperand(parts[3]);
            cl = new CPOperand(parts[4]);
            cu = new CPOperand(parts[5]);
            out = new CPOperand(parts[6]);
            if (in.getDataType() == DataType.MATRIX)
                return new MatrixIndexingCPInstruction(new SimpleOperator(null), in, rl, ru, cl, cu, out, opcode, str);
            else if (in.getDataType() == DataType.FRAME)
                return new FrameIndexingCPInstruction(new SimpleOperator(null), in, rl, ru, cl, cu, out, opcode, str);
            else
                throw new DMLRuntimeException("Can index only on Frames or Matrices");
        } else {
            throw new DMLRuntimeException("Invalid number of operands in instruction: " + str);
        }
    } else if (opcode.equalsIgnoreCase(LeftIndex.OPCODE)) {
        if (parts.length == 8) {
            CPOperand lhsInput, rhsInput, rl, ru, cl, cu, out;
            lhsInput = new CPOperand(parts[1]);
            rhsInput = new CPOperand(parts[2]);
            rl = new CPOperand(parts[3]);
            ru = new CPOperand(parts[4]);
            cl = new CPOperand(parts[5]);
            cu = new CPOperand(parts[6]);
            out = new CPOperand(parts[7]);
            if (lhsInput.getDataType() == DataType.MATRIX)
                return new MatrixIndexingCPInstruction(new SimpleOperator(null), lhsInput, rhsInput, rl, ru, cl, cu, out, opcode, str);
            else if (lhsInput.getDataType() == DataType.FRAME)
                return new FrameIndexingCPInstruction(new SimpleOperator(null), lhsInput, rhsInput, rl, ru, cl, cu, out, opcode, str);
            else
                throw new DMLRuntimeException("Can index only on Frames or Matrices");
        } else {
            throw new DMLRuntimeException("Invalid number of operands in instruction: " + str);
        }
    } else {
        throw new DMLRuntimeException("Unknown opcode while parsing a MatrixIndexingCPInstruction: " + str);
    }
}
Also used : SimpleOperator(org.apache.sysml.runtime.matrix.operators.SimpleOperator) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 18 with SimpleOperator

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

the class BooleanUnaryCPInstruction method processInstruction.

@Override
public void processInstruction(ExecutionContext ec) throws DMLRuntimeException {
    // 1) Obtain data objects associated with inputs 
    ScalarObject so = ec.getScalarInput(input1.getName(), input1.getValueType(), input1.isLiteral());
    // 2) Compute the result value & make an appropriate data object 
    SimpleOperator dop = (SimpleOperator) _optr;
    boolean rval = dop.fn.execute(so.getBooleanValue());
    ScalarObject sores = (ScalarObject) new BooleanObject(rval);
    // 3) Put the result value into ProgramBlock
    ec.setScalarOutput(output.getName(), sores);
}
Also used : SimpleOperator(org.apache.sysml.runtime.matrix.operators.SimpleOperator)

Example 19 with SimpleOperator

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

the class ScalarBuiltinCPInstruction method processInstruction.

@Override
public void processInstruction(ExecutionContext ec) throws DMLRuntimeException {
    String opcode = getOpcode();
    SimpleOperator dop = (SimpleOperator) _optr;
    ScalarObject sores = null;
    ScalarObject so = null;
    //get the scalar input 
    so = ec.getScalarInput(input1.getName(), input1.getValueType(), input1.isLiteral());
    //core execution
    if (opcode.equalsIgnoreCase("print")) {
        String outString = so.getLanguageSpecificStringValue();
        // The flag will be set, for example, when SystemML is invoked in fenced mode from Jaql.
        if (!DMLScript.suppressPrint2Stdout())
            System.out.println(outString);
        // String that is printed on stdout will be inserted into symbol table (dummy, not necessary!) 
        sores = new StringObject(outString);
    } else if (opcode.equalsIgnoreCase("stop")) {
        throw new DMLScriptException(so.getStringValue());
    } else {
        //Inputs for all builtins other than PRINT are treated as DOUBLE.
        if (so instanceof IntObject && output.getValueType() == ValueType.INT) {
            long rval = (long) dop.fn.execute(so.getLongValue());
            sores = (ScalarObject) new IntObject(rval);
        } else {
            double rval = dop.fn.execute(so.getDoubleValue());
            sores = (ScalarObject) new DoubleObject(rval);
        }
    }
    ec.setScalarOutput(output.getName(), sores);
}
Also used : SimpleOperator(org.apache.sysml.runtime.matrix.operators.SimpleOperator) DMLScriptException(org.apache.sysml.runtime.DMLScriptException)

Aggregations

SimpleOperator (org.apache.sysml.runtime.matrix.operators.SimpleOperator)19 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)14 CPOperand (org.apache.sysml.runtime.instructions.cp.CPOperand)7 ValueFunction (org.apache.sysml.runtime.functionobjects.ValueFunction)6 Operator (org.apache.sysml.runtime.matrix.operators.Operator)2 HashMap (java.util.HashMap)1 SparkAggType (org.apache.sysml.hops.AggBinaryOp.SparkAggType)1 LixCacheType (org.apache.sysml.lops.LeftIndex.LixCacheType)1 DMLScriptException (org.apache.sysml.runtime.DMLScriptException)1 FrameObject (org.apache.sysml.runtime.controlprogram.caching.FrameObject)1 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)1 FrameBlock (org.apache.sysml.runtime.matrix.data.FrameBlock)1 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)1 AggregateOperator (org.apache.sysml.runtime.matrix.operators.AggregateOperator)1 AggregateUnaryOperator (org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator)1 CMOperator (org.apache.sysml.runtime.matrix.operators.CMOperator)1 UnaryOperator (org.apache.sysml.runtime.matrix.operators.UnaryOperator)1 Decoder (org.apache.sysml.runtime.transform.decode.Decoder)1 Encoder (org.apache.sysml.runtime.transform.encode.Encoder)1