Search in sources :

Example 21 with ScalarObject

use of org.apache.sysml.runtime.instructions.cp.ScalarObject in project incubator-systemml by apache.

the class ExternalFunctionInvocationInstruction method verifyAndAttachOutputs.

private void verifyAndAttachOutputs(ExecutionContext ec, PackageFunction fun, CPOperand[] outputs) {
    for (int i = 0; i < outputs.length; i++) {
        CPOperand output = outputs[i];
        switch(fun.getFunctionOutput(i).getType()) {
            case Matrix:
                Matrix m = (Matrix) fun.getFunctionOutput(i);
                MatrixObject newVar = createOutputMatrixObject(m);
                ec.setVariable(output.getName(), newVar);
                break;
            case Scalar:
                Scalar s = (Scalar) fun.getFunctionOutput(i);
                ScalarObject scalarObject = null;
                switch(s.getScalarType()) {
                    case Integer:
                        scalarObject = new IntObject(Long.parseLong(s.getValue()));
                        break;
                    case Double:
                        scalarObject = new DoubleObject(Double.parseDouble(s.getValue()));
                        break;
                    case Boolean:
                        scalarObject = new BooleanObject(Boolean.parseBoolean(s.getValue()));
                        break;
                    case Text:
                        scalarObject = new StringObject(s.getValue());
                        break;
                    default:
                        throw new DMLRuntimeException("Unknown scalar value type '" + s.getScalarType() + "' of output '" + output.getName() + "'.");
                }
                ec.setVariable(output.getName(), scalarObject);
                break;
            default:
                throw new DMLRuntimeException("Unsupported data type: " + fun.getFunctionOutput(i).getType().name());
        }
    }
}
Also used : ScalarObject(org.apache.sysml.runtime.instructions.cp.ScalarObject) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) IntObject(org.apache.sysml.runtime.instructions.cp.IntObject) DoubleObject(org.apache.sysml.runtime.instructions.cp.DoubleObject) StringObject(org.apache.sysml.runtime.instructions.cp.StringObject) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) BooleanObject(org.apache.sysml.runtime.instructions.cp.BooleanObject) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 22 with ScalarObject

use of org.apache.sysml.runtime.instructions.cp.ScalarObject in project incubator-systemml by apache.

the class PlusMultSPInstruction method processInstruction.

@Override
public void processInstruction(ExecutionContext ec) throws DMLRuntimeException {
    SparkExecutionContext sec = (SparkExecutionContext) ec;
    //pass the scalar
    ScalarObject constant = (ScalarObject) ec.getScalarInput(input3.getName(), input3.getValueType(), input3.isLiteral());
    ((ValueFunctionWithConstant) ((BinaryOperator) _optr).fn).setConstant(constant.getDoubleValue());
    super.processMatrixMatrixBinaryInstruction(sec);
}
Also used : ScalarObject(org.apache.sysml.runtime.instructions.cp.ScalarObject) ValueFunctionWithConstant(org.apache.sysml.runtime.functionobjects.ValueFunctionWithConstant) SparkExecutionContext(org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext)

Example 23 with ScalarObject

use of org.apache.sysml.runtime.instructions.cp.ScalarObject 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

ScalarObject (org.apache.sysml.runtime.instructions.cp.ScalarObject)23 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)13 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)9 CPOperand (org.apache.sysml.runtime.instructions.cp.CPOperand)7 DoubleObject (org.apache.sysml.runtime.instructions.cp.DoubleObject)7 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)7 LiteralOp (org.apache.sysml.hops.LiteralOp)6 IntObject (org.apache.sysml.runtime.instructions.cp.IntObject)6 DataOp (org.apache.sysml.hops.DataOp)5 SparkExecutionContext (org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext)5 ArrayList (java.util.ArrayList)4 BooleanObject (org.apache.sysml.runtime.instructions.cp.BooleanObject)4 Data (org.apache.sysml.runtime.instructions.cp.Data)4 StringObject (org.apache.sysml.runtime.instructions.cp.StringObject)4 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)4 MatrixIndexes (org.apache.sysml.runtime.matrix.data.MatrixIndexes)4 Hop (org.apache.sysml.hops.Hop)3 UnaryOp (org.apache.sysml.hops.UnaryOp)3 MetaDataFormat (org.apache.sysml.runtime.matrix.MetaDataFormat)3 ScalarOperator (org.apache.sysml.runtime.matrix.operators.ScalarOperator)3