use of org.apache.sysml.lops.BinaryM.VectorType in project incubator-systemml by apache.
the class RelationalBinarySPInstruction method parseInstruction.
public static RelationalBinarySPInstruction parseInstruction(String str) throws DMLRuntimeException {
CPOperand in1 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
CPOperand in2 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
String opcode = null;
boolean isBroadcast = false;
VectorType vtype = null;
if (str.startsWith("SPARK" + Lop.OPERAND_DELIMITOR + "map")) {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
InstructionUtils.checkNumFields(parts, 5);
opcode = parts[0];
in1.split(parts[1]);
in2.split(parts[2]);
out.split(parts[3]);
vtype = VectorType.valueOf(parts[5]);
isBroadcast = true;
} else {
InstructionUtils.checkNumFields(str, 3);
opcode = parseBinaryInstruction(str, in1, in2, out);
}
DataType dt1 = in1.getDataType();
DataType dt2 = in2.getDataType();
Operator operator = (dt1 != dt2) ? InstructionUtils.parseScalarBinaryOperator(opcode, (dt1 == DataType.SCALAR)) : InstructionUtils.parseExtendedBinaryOperator(opcode);
if (dt1 == DataType.MATRIX || dt2 == DataType.MATRIX) {
if (dt1 == DataType.MATRIX && dt2 == DataType.MATRIX) {
if (isBroadcast)
return new MatrixBVectorRelationalSPInstruction(operator, in1, in2, out, vtype, opcode, str);
else
return new MatrixMatrixRelationalSPInstruction(operator, in1, in2, out, opcode, str);
} else
return new MatrixScalarRelationalSPInstruction(operator, in1, in2, out, opcode, str);
}
return null;
}
use of org.apache.sysml.lops.BinaryM.VectorType in project incubator-systemml by apache.
the class BuiltinBinarySPInstruction method parseInstruction.
public static BuiltinBinarySPInstruction parseInstruction(String str) throws DMLRuntimeException {
CPOperand in1 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
CPOperand in2 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
String opcode = null;
boolean isBroadcast = false;
VectorType vtype = null;
ValueFunction func = null;
if (//map builtin function
str.startsWith("SPARK" + Lop.OPERAND_DELIMITOR + "map")) {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
InstructionUtils.checkNumFields(parts, 5);
opcode = parts[0];
in1.split(parts[1]);
in2.split(parts[2]);
out.split(parts[3]);
func = Builtin.getBuiltinFnObject(opcode.substring(3));
vtype = VectorType.valueOf(parts[5]);
isBroadcast = true;
} else //default builtin function
{
opcode = parseBinaryInstruction(str, in1, in2, out);
func = Builtin.getBuiltinFnObject(opcode);
}
//sanity check value function
if (func == null)
throw new DMLRuntimeException("Failed to create builtin value function for opcode: " + opcode);
// Determine appropriate Function Object based on opcode
if (//MATRIX-SCALAR
in1.getDataType() != in2.getDataType()) {
return new MatrixScalarBuiltinSPInstruction(new RightScalarOperator(func, 0), in1, in2, out, opcode, str);
} else //MATRIX-MATRIX
{
if (isBroadcast)
return new MatrixBVectorBuiltinSPInstruction(new BinaryOperator(func), in1, in2, out, vtype, opcode, str);
else
return new MatrixMatrixBuiltinSPInstruction(new BinaryOperator(func), in1, in2, out, opcode, str);
}
}
use of org.apache.sysml.lops.BinaryM.VectorType in project incubator-systemml by apache.
the class ArithmeticBinarySPInstruction method parseInstruction.
public static ArithmeticBinarySPInstruction parseInstruction(String str) throws DMLRuntimeException {
CPOperand in1 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
CPOperand in2 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
String opcode = null;
boolean isBroadcast = false;
VectorType vtype = null;
if (str.startsWith("SPARK" + Lop.OPERAND_DELIMITOR + "map")) {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
InstructionUtils.checkNumFields(parts, 5);
opcode = parts[0];
in1.split(parts[1]);
in2.split(parts[2]);
out.split(parts[3]);
vtype = VectorType.valueOf(parts[5]);
isBroadcast = true;
} else {
opcode = parseBinaryInstruction(str, in1, in2, out);
}
// Arithmetic operations must be performed on DOUBLE or INT
DataType dt1 = in1.getDataType();
DataType dt2 = in2.getDataType();
Operator operator = (dt1 != dt2) ? InstructionUtils.parseScalarBinaryOperator(opcode, (dt1 == DataType.SCALAR)) : InstructionUtils.parseExtendedBinaryOperator(opcode);
if (dt1 == DataType.MATRIX || dt2 == DataType.MATRIX) {
if (dt1 == DataType.MATRIX && dt2 == DataType.MATRIX) {
if (isBroadcast)
return new MatrixBVectorArithmeticSPInstruction(operator, in1, in2, out, vtype, opcode, str);
else
return new MatrixMatrixArithmeticSPInstruction(operator, in1, in2, out, opcode, str);
} else
return new MatrixScalarArithmeticSPInstruction(operator, in1, in2, out, opcode, str);
}
return null;
}
use of org.apache.sysml.lops.BinaryM.VectorType in project incubator-systemml by apache.
the class BinaryMInstruction method parseInstruction.
public static BinaryMInstruction parseInstruction(String str) throws DMLRuntimeException {
InstructionUtils.checkNumFields(str, 5);
String[] parts = InstructionUtils.getInstructionParts(str);
byte in1, in2, out;
String opcode = parts[0];
in1 = Byte.parseByte(parts[1]);
in2 = Byte.parseByte(parts[2]);
out = Byte.parseByte(parts[3]);
CacheType ctype = CacheType.valueOf(parts[4]);
VectorType vtype = VectorType.valueOf(parts[5]);
BinaryOperator bop = InstructionUtils.parseExtendedBinaryOperator(opcode);
return new BinaryMInstruction(bop, in1, in2, ctype, vtype, out, str);
}
Aggregations