use of org.apache.sysml.runtime.matrix.operators.Operator 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.runtime.matrix.operators.Operator in project incubator-systemml by apache.
the class RandSPInstruction method parseInstruction.
public static RandSPInstruction parseInstruction(String str) throws DMLRuntimeException {
String[] s = InstructionUtils.getInstructionPartsWithValueType(str);
String opcode = s[0];
DataGenMethod method = DataGenMethod.INVALID;
if (opcode.equalsIgnoreCase(DataGen.RAND_OPCODE)) {
method = DataGenMethod.RAND;
InstructionUtils.checkNumFields(str, 12);
} else if (opcode.equalsIgnoreCase(DataGen.SEQ_OPCODE)) {
method = DataGenMethod.SEQ;
// 8 operands: rows, cols, rpb, cpb, from, to, incr, outvar
InstructionUtils.checkNumFields(str, 8);
} else if (opcode.equalsIgnoreCase(DataGen.SAMPLE_OPCODE)) {
method = DataGenMethod.SAMPLE;
// 7 operands: range, size, replace, seed, rpb, cpb, outvar
InstructionUtils.checkNumFields(str, 7);
}
Operator op = null;
// output is specified by the last operand
CPOperand out = new CPOperand(s[s.length - 1]);
if (method == DataGenMethod.RAND) {
long rows = -1, cols = -1;
if (!s[1].contains(Lop.VARIABLE_NAME_PLACEHOLDER)) {
rows = Double.valueOf(s[1]).longValue();
}
if (!s[2].contains(Lop.VARIABLE_NAME_PLACEHOLDER)) {
cols = Double.valueOf(s[2]).longValue();
}
int rpb = Integer.parseInt(s[3]);
int cpb = Integer.parseInt(s[4]);
double minValue = -1, maxValue = -1;
if (!s[5].contains(Lop.VARIABLE_NAME_PLACEHOLDER)) {
minValue = Double.valueOf(s[5]).doubleValue();
}
if (!s[6].contains(Lop.VARIABLE_NAME_PLACEHOLDER)) {
maxValue = Double.valueOf(s[6]).doubleValue();
}
double sparsity = -1;
if (!s[7].contains(Lop.VARIABLE_NAME_PLACEHOLDER)) {
sparsity = Double.valueOf(s[7]);
}
long seed = DataGenOp.UNSPECIFIED_SEED;
if (!s[8].contains(Lop.VARIABLE_NAME_PLACEHOLDER)) {
seed = Long.parseLong(s[8]);
}
String dir = s[9];
String pdf = s[10];
String pdfParams = s[11];
return new RandSPInstruction(op, method, null, out, rows, cols, rpb, cpb, minValue, maxValue, sparsity, seed, dir, pdf, pdfParams, opcode, str);
} else if (method == DataGenMethod.SEQ) {
// Example Instruction: CP:seq:11:1:1000:1000:1:0:-0.1:scratch_space/_p7932_192.168.1.120//_t0/:mVar1
long rows = Double.valueOf(s[1]).longValue();
long cols = Double.valueOf(s[2]).longValue();
int rpb = Integer.parseInt(s[3]);
int cpb = Integer.parseInt(s[4]);
double from, to, incr;
from = to = incr = Double.NaN;
if (!s[5].contains(Lop.VARIABLE_NAME_PLACEHOLDER)) {
from = Double.valueOf(s[5]);
}
if (!s[6].contains(Lop.VARIABLE_NAME_PLACEHOLDER)) {
to = Double.valueOf(s[6]);
}
if (!s[7].contains(Lop.VARIABLE_NAME_PLACEHOLDER)) {
incr = Double.valueOf(s[7]);
}
CPOperand in = null;
return new RandSPInstruction(op, method, in, out, rows, cols, rpb, cpb, from, to, incr, opcode, str);
} else if (method == DataGenMethod.SAMPLE) {
// Example Instruction: SPARK:sample:10:100:false:1000:1000:_mVar2·MATRIX·DOUBLE
double max = 0;
long rows = 0, cols;
boolean replace = false;
if (!s[1].contains(Lop.VARIABLE_NAME_PLACEHOLDER))
max = Double.valueOf(s[1]);
if (!s[2].contains(Lop.VARIABLE_NAME_PLACEHOLDER))
rows = Double.valueOf(s[2]).longValue();
cols = 1;
if (!s[3].contains(Lop.VARIABLE_NAME_PLACEHOLDER))
replace = Boolean.valueOf(s[3]);
long seed = Long.parseLong(s[4]);
int rpb = Integer.parseInt(s[5]);
int cpb = Integer.parseInt(s[6]);
return new RandSPInstruction(op, method, null, out, rows, cols, rpb, cpb, max, replace, seed, opcode, str);
} else
throw new DMLRuntimeException("Unrecognized data generation method: " + method);
}
use of org.apache.sysml.runtime.matrix.operators.Operator in project incubator-systemml by apache.
the class CSVReblockInstruction method parseInstruction.
public static CSVReblockInstruction parseInstruction(String str) {
Operator op = null;
byte input, output;
String[] s = str.split(Instruction.OPERAND_DELIM);
String[] in1f = s[2].split(Instruction.DATATYPE_PREFIX);
input = Byte.parseByte(in1f[0]);
String[] outf = s[3].split(Instruction.DATATYPE_PREFIX);
output = Byte.parseByte(outf[0]);
int brlen = Integer.parseInt(s[4]);
int bclen = Integer.parseInt(s[5]);
boolean hasHeader = Boolean.parseBoolean(s[6]);
String delim = s[7];
boolean fill = Boolean.parseBoolean(s[8]);
double missingValue = Double.parseDouble(s[9]);
return new CSVReblockInstruction(op, input, output, brlen, bclen, hasHeader, delim, fill, missingValue, str);
}
use of org.apache.sysml.runtime.matrix.operators.Operator in project incubator-systemml by apache.
the class CSVWriteInstruction method parseInstruction.
public static CSVWriteInstruction parseInstruction(String str) {
Operator op = null;
byte input, output;
String[] s = str.split(Instruction.OPERAND_DELIM);
String[] in1f = s[2].split(Instruction.DATATYPE_PREFIX);
input = Byte.parseByte(in1f[0]);
String[] outf = s[3].split(Instruction.DATATYPE_PREFIX);
output = Byte.parseByte(outf[0]);
String header = s[4];
String delim = s[5];
boolean sparse = Boolean.parseBoolean(s[6]);
return new CSVWriteInstruction(op, input, output, delim, header, sparse, str);
}
use of org.apache.sysml.runtime.matrix.operators.Operator in project incubator-systemml by apache.
the class PMMJMRInstruction method parseInstruction.
public static PMMJMRInstruction parseInstruction(String str) throws DMLRuntimeException {
InstructionUtils.checkNumFields(str, 6);
String[] parts = InstructionUtils.getInstructionParts(str);
String opcode = parts[0];
byte in1 = Byte.parseByte(parts[1]);
byte in2 = Byte.parseByte(parts[2]);
long nrow = UtilFunctions.toLong(Double.parseDouble(parts[3]));
byte out = Byte.parseByte(parts[4]);
CacheType ctype = CacheType.valueOf(parts[5]);
boolean outputEmpty = Boolean.parseBoolean(parts[6]);
if (!opcode.equalsIgnoreCase("pmm"))
throw new DMLRuntimeException("Unknown opcode while parsing an PmmMRInstruction: " + str);
return new PMMJMRInstruction(new Operator(true), in1, in2, out, nrow, ctype, outputEmpty, str);
}
Aggregations