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());
}
}
}
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);
}
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;
}
Aggregations