Search in sources :

Example 6 with SimpleOperator

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

the class FileCPInstruction method parseInstruction.

public static FileCPInstruction parseInstruction(String str) throws DMLRuntimeException {
    String opcode = InstructionUtils.getOpCode(str);
    int _arity = 2;
    if (opcode.equalsIgnoreCase("rm"))
        _arity = 1;
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    // there is no output, so we just have _arity
    InstructionUtils.checkNumFields(parts, _arity);
    String in1, in2;
    opcode = parts[0];
    FileOperationCode focode = getFileOperationCode(opcode);
    in1 = parts[1];
    in2 = null;
    if (_arity == 2)
        in2 = parts[2];
    if (opcode.equalsIgnoreCase("rm")) {
        return new FileCPInstruction(new SimpleOperator(RemoveFile.getRemoveFileFnObject()), focode, in1, in2, _arity, opcode, str);
    } else if (opcode.equalsIgnoreCase("mv")) {
        return new FileCPInstruction(new SimpleOperator(RenameFile.getRenameFileFnObject()), focode, in1, in2, _arity, opcode, str);
    }
    return null;
}
Also used : SimpleOperator(org.apache.sysml.runtime.matrix.operators.SimpleOperator)

Example 7 with SimpleOperator

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

the class ParameterizedBuiltinCPInstruction method parseInstruction.

public static ParameterizedBuiltinCPInstruction parseInstruction(String str) throws DMLRuntimeException {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    // first part is always the opcode
    String opcode = parts[0];
    // 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("cdf")) {
        if (paramsMap.get("dist") == null)
            throw new DMLRuntimeException("Invalid distribution: " + str);
        func = ParameterizedBuiltin.getParameterizedBuiltinFnObject(opcode, paramsMap.get("dist"));
        // Determine appropriate Function Object based on opcode
        return new ParameterizedBuiltinCPInstruction(new SimpleOperator(func), paramsMap, out, opcode, str);
    } else if (opcode.equalsIgnoreCase("invcdf")) {
        if (paramsMap.get("dist") == null)
            throw new DMLRuntimeException("Invalid distribution: " + str);
        func = ParameterizedBuiltin.getParameterizedBuiltinFnObject(opcode, paramsMap.get("dist"));
        // Determine appropriate Function Object based on opcode
        return new ParameterizedBuiltinCPInstruction(new SimpleOperator(func), paramsMap, out, opcode, str);
    } else 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 ParameterizedBuiltinCPInstruction(op, paramsMap, out, opcode, str);
    } else if (opcode.equalsIgnoreCase("rmempty") || opcode.equalsIgnoreCase("replace") || opcode.equalsIgnoreCase("rexpand")) {
        func = ParameterizedBuiltin.getParameterizedBuiltinFnObject(opcode);
        return new ParameterizedBuiltinCPInstruction(new SimpleOperator(func), paramsMap, out, opcode, str);
    } else if (opcode.equals("transform") || opcode.equals("transformapply") || opcode.equals("transformdecode") || opcode.equals("transformmeta")) {
        return new ParameterizedBuiltinCPInstruction(null, paramsMap, out, opcode, str);
    } else if (opcode.equals("toString")) {
        return new ParameterizedBuiltinCPInstruction(null, paramsMap, out, opcode, str);
    } else {
        throw new DMLRuntimeException("Unknown opcode (" + opcode + ") for ParameterizedBuiltin Instruction.");
    }
}
Also used : ValueFunction(org.apache.sysml.runtime.functionobjects.ValueFunction) Operator(org.apache.sysml.runtime.matrix.operators.Operator) SimpleOperator(org.apache.sysml.runtime.matrix.operators.SimpleOperator) SimpleOperator(org.apache.sysml.runtime.matrix.operators.SimpleOperator) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 8 with SimpleOperator

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

the class AggregateUnaryCPInstruction method parseInstruction.

public static AggregateUnaryCPInstruction parseInstruction(String str) throws DMLRuntimeException {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    CPOperand in1 = new CPOperand(parts[1]);
    CPOperand out = new CPOperand(parts[2]);
    if (opcode.equalsIgnoreCase("nrow") || opcode.equalsIgnoreCase("ncol") || opcode.equalsIgnoreCase("length")) {
        return new AggregateUnaryCPInstruction(new SimpleOperator(Builtin.getBuiltinFnObject(opcode)), in1, out, opcode, str);
    } else //DEFAULT BEHAVIOR
    {
        AggregateUnaryOperator aggun = InstructionUtils.parseBasicAggregateUnaryOperator(opcode);
        aggun.setNumThreads(Integer.parseInt(parts[3]));
        return new AggregateUnaryCPInstruction(aggun, in1, out, opcode, str);
    }
}
Also used : SimpleOperator(org.apache.sysml.runtime.matrix.operators.SimpleOperator) AggregateUnaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator)

Example 9 with SimpleOperator

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

the class BuiltinUnaryCPInstruction method parseInstruction.

public static BuiltinUnaryCPInstruction parseInstruction(String str) throws DMLRuntimeException {
    CPOperand in = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = null;
    ValueFunction func = null;
    //print or stop or cumulative aggregates
    if (parts.length == 4) {
        opcode = parts[0];
        in.split(parts[1]);
        out.split(parts[2]);
        func = Builtin.getBuiltinFnObject(opcode);
        if (Arrays.asList(new String[] { "ucumk+", "ucum*", "ucummin", "ucummax" }).contains(opcode))
            return new MatrixBuiltinCPInstruction(new UnaryOperator(func, Integer.parseInt(parts[3])), in, out, opcode, str);
        else
            return new ScalarBuiltinCPInstruction(new SimpleOperator(func), in, out, opcode, str);
    } else //2+1, general case
    {
        opcode = parseUnaryInstruction(str, in, out);
        func = Builtin.getBuiltinFnObject(opcode);
        if (in.getDataType() == DataType.SCALAR)
            return new ScalarBuiltinCPInstruction(new SimpleOperator(func), in, out, opcode, str);
        else if (in.getDataType() == DataType.MATRIX)
            return new MatrixBuiltinCPInstruction(new UnaryOperator(func), in, out, opcode, str);
    }
    return null;
}
Also used : ValueFunction(org.apache.sysml.runtime.functionobjects.ValueFunction) SimpleOperator(org.apache.sysml.runtime.matrix.operators.SimpleOperator) UnaryOperator(org.apache.sysml.runtime.matrix.operators.UnaryOperator)

Example 10 with SimpleOperator

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

the class BuiltinMultipleCPInstruction method parseInstruction.

public static BuiltinMultipleCPInstruction parseInstruction(String str) throws DMLRuntimeException {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    String outputString = parts[parts.length - 1];
    CPOperand outputOperand = new CPOperand(outputString);
    String[] inputStrings = null;
    CPOperand[] inputOperands = null;
    if (parts.length > 2) {
        inputStrings = Arrays.copyOfRange(parts, 1, parts.length - 1);
        inputOperands = new CPOperand[parts.length - 2];
        for (int i = 0; i < inputStrings.length; i++) {
            inputOperands[i] = new CPOperand(inputStrings[i]);
        }
    }
    if (MultipleCP.OperationType.PRINTF.toString().equalsIgnoreCase(opcode)) {
        ValueFunction func = Builtin.getBuiltinFnObject(opcode);
        return new ScalarBuiltinMultipleCPInstruction(new SimpleOperator(func), opcode, str, outputOperand, inputOperands);
    }
    throw new DMLRuntimeException("Opcode (" + opcode + ") not recognized in BuiltinMultipleCPInstruction");
}
Also used : ValueFunction(org.apache.sysml.runtime.functionobjects.ValueFunction) SimpleOperator(org.apache.sysml.runtime.matrix.operators.SimpleOperator) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Aggregations

SimpleOperator (org.apache.sysml.runtime.matrix.operators.SimpleOperator)17 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)12 CPOperand (org.apache.sysml.runtime.instructions.cp.CPOperand)6 ValueFunction (org.apache.sysml.runtime.functionobjects.ValueFunction)5 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 JobReturn (org.apache.sysml.runtime.matrix.JobReturn)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