Search in sources :

Example 1 with FunctionParameter

use of org.apache.sysml.udf.FunctionParameter in project incubator-systemml by apache.

the class ExternalFunctionProgramBlock method getInputObjects.

/**
	 * Method to convert string representation of input into function input
	 * object.
	 * 
	 * @param inputs list of inputs
	 * @param variableMapping local variable map
	 * @return list of function parameters
	 */
protected ArrayList<FunctionParameter> getInputObjects(ArrayList<String> inputs, LocalVariableMap variableMapping) {
    ArrayList<FunctionParameter> inputObjects = new ArrayList<FunctionParameter>();
    for (int i = 0; i < inputs.size(); i++) {
        ArrayList<String> tokens = new ArrayList<String>();
        StringTokenizer tk = new StringTokenizer(inputs.get(i), ":");
        while (tk.hasMoreTokens()) {
            tokens.add(tk.nextToken());
        }
        if (tokens.get(0).equals("Matrix")) {
            String varName = tokens.get(1);
            MatrixObject mobj = (MatrixObject) variableMapping.get(varName);
            MatrixCharacteristics mc = mobj.getMatrixCharacteristics();
            Matrix m = new Matrix(mobj.getFileName(), mc.getRows(), mc.getCols(), getMatrixValueType(tokens.get(2)));
            modifyInputMatrix(m, mobj);
            inputObjects.add(m);
        }
        if (tokens.get(0).equals("Scalar")) {
            String varName = tokens.get(1);
            ScalarObject so = (ScalarObject) variableMapping.get(varName);
            Scalar s = new Scalar(getScalarValueType(tokens.get(2)), so.getStringValue());
            inputObjects.add(s);
        }
        if (tokens.get(0).equals("Object")) {
            String varName = tokens.get(1);
            Object o = variableMapping.get(varName);
            BinaryObject obj = new BinaryObject(o);
            inputObjects.add(obj);
        }
    }
    return inputObjects;
}
Also used : MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) ArrayList(java.util.ArrayList) MatrixCharacteristics(org.apache.sysml.runtime.matrix.MatrixCharacteristics) Scalar(org.apache.sysml.udf.Scalar) ScalarObject(org.apache.sysml.runtime.instructions.cp.ScalarObject) StringTokenizer(java.util.StringTokenizer) Matrix(org.apache.sysml.udf.Matrix) BinaryObject(org.apache.sysml.udf.BinaryObject) BooleanObject(org.apache.sysml.runtime.instructions.cp.BooleanObject) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) IntObject(org.apache.sysml.runtime.instructions.cp.IntObject) BinaryObject(org.apache.sysml.udf.BinaryObject) ScalarObject(org.apache.sysml.runtime.instructions.cp.ScalarObject) DoubleObject(org.apache.sysml.runtime.instructions.cp.DoubleObject) StringObject(org.apache.sysml.runtime.instructions.cp.StringObject) FunctionParameter(org.apache.sysml.udf.FunctionParameter)

Aggregations

ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)1 BooleanObject (org.apache.sysml.runtime.instructions.cp.BooleanObject)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 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)1 BinaryObject (org.apache.sysml.udf.BinaryObject)1 FunctionParameter (org.apache.sysml.udf.FunctionParameter)1 Matrix (org.apache.sysml.udf.Matrix)1 Scalar (org.apache.sysml.udf.Scalar)1