Search in sources :

Example 21 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 22 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 23 with SimpleOperator

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

the class AggregateUnaryCPInstruction method parseInstruction.

public static AggregateUnaryCPInstruction parseInstruction(String str) {
    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") || opcode.equalsIgnoreCase("exists")) {
        return new AggregateUnaryCPInstruction(new SimpleOperator(Builtin.getBuiltinFnObject(opcode)), in1, out, AUType.valueOf(opcode.toUpperCase()), opcode, str);
    } else {
        // DEFAULT BEHAVIOR
        AggregateUnaryOperator aggun = InstructionUtils.parseBasicAggregateUnaryOperator(opcode, Integer.parseInt(parts[3]));
        return new AggregateUnaryCPInstruction(aggun, in1, out, AUType.DEFAULT, opcode, str);
    }
}
Also used : SimpleOperator(org.apache.sysml.runtime.matrix.operators.SimpleOperator) AggregateUnaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator)

Example 24 with SimpleOperator

use of org.apache.sysml.runtime.matrix.operators.SimpleOperator in project 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") || opcode.equalsIgnoreCase("lowertri") || opcode.equalsIgnoreCase("uppertri")) {
        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)

Example 25 with SimpleOperator

use of org.apache.sysml.runtime.matrix.operators.SimpleOperator in project 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("lowertri") || opcode.equalsIgnoreCase("uppertri") || 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)

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