Search in sources :

Example 11 with Scalar

use of org.apache.sysml.udf.Scalar in project systemml by apache.

the class DynamicReadMatrixRcCP method execute.

@Override
public void execute() {
    try {
        String fname = ((Scalar) this.getFunctionInput(0)).getValue();
        Integer m = Integer.parseInt(((Scalar) this.getFunctionInput(1)).getValue());
        Integer n = Integer.parseInt(((Scalar) this.getFunctionInput(2)).getValue());
        String format = ((Scalar) this.getFunctionInput(3)).getValue();
        InputInfo ii = InputInfo.stringToInputInfo(format);
        OutputInfo oi = OutputInfo.BinaryBlockOutputInfo;
        String fnameTmp = createOutputFilePathAndName("TMP");
        _ret = new Matrix(fnameTmp, m, n, ValueType.Double);
        MatrixBlock mbTmp = DataConverter.readMatrixFromHDFS(fname, ii, m, n, ConfigurationManager.getBlocksize(), ConfigurationManager.getBlocksize());
        _ret.setMatrixDoubleArray(mbTmp, oi, ii);
        _rc = new Scalar(ScalarValueType.Integer, "0");
    // NOTE: The packagesupport wrapper creates a new MatrixObjectNew with the given
    // matrix block. This leads to a dirty state of the new object. Hence, the resulting
    // intermediate plan variable will be exported in front of MR jobs and during this export
    // the format will be changed to binary block (the contract of external functions),
    // no matter in which format the original matrix was.
    } catch (Exception e) {
        _rc = new Scalar(ScalarValueType.Integer, "1");
    // throw new PackageRuntimeException("Error executing dynamic read of matrix",e);
    }
}
Also used : OutputInfo(org.apache.sysml.runtime.matrix.data.OutputInfo) MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) InputInfo(org.apache.sysml.runtime.matrix.data.InputInfo) Matrix(org.apache.sysml.udf.Matrix) Scalar(org.apache.sysml.udf.Scalar)

Example 12 with Scalar

use of org.apache.sysml.udf.Scalar in project systemml by apache.

the class EvalFunction method execute.

@Override
public void execute(ExecutionContext ec) {
    String fname = ((Scalar) getFunctionInput(0)).getValue();
    MatrixObject in = ((Matrix) getFunctionInput(1)).getMatrixObject();
    ArrayList<String> inputs = new ArrayList<>();
    inputs.add("A");
    ArrayList<String> outputs = new ArrayList<>();
    outputs.add("B");
    ExecutionContext ec2 = ExecutionContextFactory.createContext(ec.getProgram());
    CPOperand inName = new CPOperand("TMP", org.apache.sysml.parser.Expression.ValueType.DOUBLE, DataType.MATRIX);
    ec2.setVariable("TMP", in);
    FunctionCallCPInstruction fcpi = new FunctionCallCPInstruction(null, fname, new CPOperand[] { inName }, inputs, outputs, "eval func");
    fcpi.processInstruction(ec2);
    MatrixObject out = (MatrixObject) ec2.getVariable("B");
    _ret = new Matrix(out, ValueType.Double);
}
Also used : MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) Matrix(org.apache.sysml.udf.Matrix) ExecutionContext(org.apache.sysml.runtime.controlprogram.context.ExecutionContext) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) ArrayList(java.util.ArrayList) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) Scalar(org.apache.sysml.udf.Scalar)

Example 13 with Scalar

use of org.apache.sysml.udf.Scalar in project systemml by apache.

the class TimeWrapper method execute.

@Override
public void execute() {
    long present = System.currentTimeMillis();
    _ret = new Scalar(ScalarValueType.Double, String.valueOf(present));
}
Also used : Scalar(org.apache.sysml.udf.Scalar)

Example 14 with Scalar

use of org.apache.sysml.udf.Scalar 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)

Example 15 with Scalar

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

the class EvalFunction method execute.

@Override
public void execute(ExecutionContext ec) {
    String fname = ((Scalar) getFunctionInput(0)).getValue();
    MatrixObject in = ((Matrix) getFunctionInput(1)).getMatrixObject();
    ArrayList<String> inputs = new ArrayList<>();
    inputs.add("A");
    ArrayList<String> outputs = new ArrayList<>();
    outputs.add("B");
    ExecutionContext ec2 = ExecutionContextFactory.createContext(ec.getProgram());
    CPOperand inName = new CPOperand("TMP", org.apache.sysml.parser.Expression.ValueType.DOUBLE, DataType.MATRIX);
    ec2.setVariable("TMP", in);
    FunctionCallCPInstruction fcpi = new FunctionCallCPInstruction(null, fname, new CPOperand[] { inName }, inputs, outputs, "eval func");
    fcpi.processInstruction(ec2);
    MatrixObject out = (MatrixObject) ec2.getVariable("B");
    _ret = new Matrix(out, ValueType.Double);
}
Also used : MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) Matrix(org.apache.sysml.udf.Matrix) ExecutionContext(org.apache.sysml.runtime.controlprogram.context.ExecutionContext) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) ArrayList(java.util.ArrayList) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) Scalar(org.apache.sysml.udf.Scalar)

Aggregations

Scalar (org.apache.sysml.udf.Scalar)19 Matrix (org.apache.sysml.udf.Matrix)14 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)8 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)6 OutputInfo (org.apache.sysml.runtime.matrix.data.OutputInfo)6 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 IJV (org.apache.sysml.runtime.matrix.data.IJV)4 InputInfo (org.apache.sysml.runtime.matrix.data.InputInfo)4 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)3 StringTokenizer (java.util.StringTokenizer)2 ExecutionContext (org.apache.sysml.runtime.controlprogram.context.ExecutionContext)2 BooleanObject (org.apache.sysml.runtime.instructions.cp.BooleanObject)2 CPOperand (org.apache.sysml.runtime.instructions.cp.CPOperand)2 DoubleObject (org.apache.sysml.runtime.instructions.cp.DoubleObject)2 FunctionCallCPInstruction (org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction)2 IntObject (org.apache.sysml.runtime.instructions.cp.IntObject)2 ScalarObject (org.apache.sysml.runtime.instructions.cp.ScalarObject)2 StringObject (org.apache.sysml.runtime.instructions.cp.StringObject)2