Search in sources :

Example 1 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 2 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 3 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)

Example 4 with SimpleOperator

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

the class QuantileSortSPInstruction method parseInstruction.

public static QuantileSortSPInstruction parseInstruction(String str) {
    CPOperand in1 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    CPOperand in2 = null;
    CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    if (opcode.equalsIgnoreCase(SortKeys.OPCODE)) {
        if (parts.length == 3) {
            // Example: sort:mVar1:mVar2 (input=mVar1, output=mVar2)
            parseUnaryInstruction(str, in1, out);
            return new QuantileSortSPInstruction(new SimpleOperator(null), in1, out, opcode, str);
        } else if (parts.length == 4) {
            // Example: sort:mVar1:mVar2:mVar3 (input=mVar1, weights=mVar2, output=mVar3)
            in2 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
            parseUnaryInstruction(str, in1, in2, out);
            return new QuantileSortSPInstruction(new SimpleOperator(null), in1, in2, out, opcode, str);
        } else {
            throw new DMLRuntimeException("Invalid number of operands in instruction: " + str);
        }
    } else {
        throw new DMLRuntimeException("Unknown opcode while parsing a SortSPInstruction: " + str);
    }
}
Also used : SimpleOperator(org.apache.sysml.runtime.matrix.operators.SimpleOperator) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 5 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) {
    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("transformapply") || opcode.equals("transformdecode") || opcode.equals("transformcolmap") || 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)

Aggregations

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