use of org.apache.sysml.parser.Expression.DataType 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.parser.Expression.DataType in project incubator-systemml by apache.
the class TernaryCPInstruction method findCtableOperation.
private Ternary.OperationTypes findCtableOperation() {
DataType dt1 = input1.getDataType();
DataType dt2 = input2.getDataType();
DataType dt3 = input3.getDataType();
return Ternary.findCtableOperationByInputDataTypes(dt1, dt2, dt3);
}
use of org.apache.sysml.parser.Expression.DataType in project incubator-systemml by apache.
the class BinaryOp method constructLopsAppend.
private void constructLopsAppend(ExecType et) {
DataType dt1 = getInput().get(0).getDataType();
DataType dt2 = getInput().get(1).getDataType();
ValueType vt1 = getInput().get(0).getValueType();
ValueType vt2 = getInput().get(1).getValueType();
boolean cbind = op == OpOp2.CBIND;
// sanity check for input data types
if (!((dt1 == DataType.MATRIX && dt2 == DataType.MATRIX) || (dt1 == DataType.FRAME && dt2 == DataType.FRAME) || (dt1 == DataType.SCALAR && dt2 == DataType.SCALAR && vt1 == ValueType.STRING && vt2 == ValueType.STRING))) {
throw new HopsException("Append can only apply to two matrices, two frames, or two scalar strings!");
}
Lop append = null;
if (dt1 == DataType.MATRIX || dt1 == DataType.FRAME) {
long rlen = cbind ? getInput().get(0).getDim1() : (getInput().get(0).dimsKnown() && getInput().get(1).dimsKnown()) ? getInput().get(0).getDim1() + getInput().get(1).getDim1() : -1;
long clen = cbind ? ((getInput().get(0).dimsKnown() && getInput().get(1).dimsKnown()) ? getInput().get(0).getDim2() + getInput().get(1).getDim2() : -1) : getInput().get(0).getDim2();
if (et == ExecType.MR) {
append = constructMRAppendLop(getInput().get(0), getInput().get(1), getDataType(), getValueType(), cbind, this);
} else if (et == ExecType.SPARK) {
append = constructSPAppendLop(getInput().get(0), getInput().get(1), getDataType(), getValueType(), cbind, this);
append.getOutputParameters().setDimensions(rlen, clen, getRowsInBlock(), getColsInBlock(), getNnz());
} else // CP
{
// offset 1st input
Lop offset = createOffsetLop(getInput().get(0), cbind);
append = new Append(getInput().get(0).constructLops(), getInput().get(1).constructLops(), offset, getDataType(), getValueType(), cbind, et);
append.getOutputParameters().setDimensions(rlen, clen, getRowsInBlock(), getColsInBlock(), getNnz());
}
} else // SCALAR-STRING and SCALAR-STRING (always CP)
{
append = new Append(getInput().get(0).constructLops(), getInput().get(1).constructLops(), Data.createLiteralLop(ValueType.INT, "-1"), getDataType(), getValueType(), cbind, ExecType.CP);
append.getOutputParameters().setDimensions(0, 0, -1, -1, -1);
}
setLineNumbers(append);
setLops(append);
}
use of org.apache.sysml.parser.Expression.DataType in project incubator-systemml by apache.
the class BinaryOp method refreshSizeInformation.
@Override
public void refreshSizeInformation() {
Hop input1 = getInput().get(0);
Hop input2 = getInput().get(1);
DataType dt1 = input1.getDataType();
DataType dt2 = input2.getDataType();
if (getDataType() == DataType.SCALAR) {
// do nothing always known
setDim1(0);
setDim2(0);
} else // MATRIX OUTPUT
{
// TODO quantile
if (op == OpOp2.CBIND) {
setDim1(input1.rowsKnown() ? input1.getDim1() : input2.getDim1());
// ensure both columns are known, otherwise dangerous underestimation due to +(-1)
if (input1.colsKnown() && input2.colsKnown())
setDim2(input1.getDim2() + input2.getDim2());
else
setDim2(-1);
// ensure both nnz are known, otherwise dangerous underestimation due to +(-1)
if (input1.getNnz() > 0 && input2.getNnz() > 0)
setNnz(input1.getNnz() + input2.getNnz());
else
setNnz(-1);
} else if (op == OpOp2.RBIND) {
setDim2(colsKnown() ? input1.getDim2() : input2.getDim2());
// ensure both rows are known, otherwise dangerous underestimation due to +(-1)
if (input1.rowsKnown() && input2.rowsKnown())
setDim1(input1.getDim1() + input2.getDim1());
else
setDim1(-1);
// ensure both nnz are known, otherwise dangerous underestimation due to +(-1)
if (input1.getNnz() > 0 && input2.getNnz() > 0)
setNnz(input1.getNnz() + input2.getNnz());
else
setNnz(-1);
} else if (op == OpOp2.SOLVE) {
// normally the second input would be of equal size as the output
// however, since we use qr internally, it also supports squared first inputs
setDim1(input1.getDim2());
setDim2(input2.getDim2());
} else // general case
{
long ldim1, ldim2, lnnz1 = -1;
if (dt1 == DataType.MATRIX && dt2 == DataType.SCALAR) {
ldim1 = input1.getDim1();
ldim2 = input1.getDim2();
lnnz1 = input1.getNnz();
} else if (dt1 == DataType.SCALAR && dt2 == DataType.MATRIX) {
ldim1 = input2.getDim1();
ldim2 = input2.getDim2();
} else // MATRIX - MATRIX
{
// for cols we need to be careful with regard to matrix-vector operations
if (// OUTER VECTOR OPERATION
outer) {
ldim1 = input1.getDim1();
ldim2 = input2.getDim2();
} else // GENERAL CASE
{
ldim1 = (input1.rowsKnown()) ? input1.getDim1() : ((input2.getDim1() > 1) ? input2.getDim1() : -1);
ldim2 = (input1.colsKnown()) ? input1.getDim2() : ((input2.getDim2() > 1) ? input2.getDim2() : -1);
lnnz1 = input1.getNnz();
}
}
setDim1(ldim1);
setDim2(ldim2);
// otherwise propagated via worst-case estimates
if (op == OpOp2.POW || (input2 instanceof LiteralOp && OptimizerUtils.isBinaryOpConditionalSparseSafeExact(op, (LiteralOp) input2))) {
setNnz(lnnz1);
}
}
}
}
use of org.apache.sysml.parser.Expression.DataType in project incubator-systemml by apache.
the class BinaryOp method constructLopsCentralMoment.
private void constructLopsCentralMoment(ExecType et) {
// The output data type is a SCALAR if central moment
// gets computed in CP/SPARK, and it will be MATRIX otherwise.
DataType dt = (et == ExecType.MR ? DataType.MATRIX : DataType.SCALAR);
CentralMoment cm = new CentralMoment(getInput().get(0).constructLops(), getInput().get(1).constructLops(), dt, getValueType(), et);
setLineNumbers(cm);
if (et == ExecType.MR) {
cm.getOutputParameters().setDimensions(1, 1, 0, 0, -1);
UnaryCP unary1 = new UnaryCP(cm, HopsOpOp1LopsUS.get(OpOp1.CAST_AS_SCALAR), getDataType(), getValueType());
unary1.getOutputParameters().setDimensions(0, 0, 0, 0, -1);
setLineNumbers(unary1);
setLops(unary1);
} else {
cm.getOutputParameters().setDimensions(0, 0, 0, 0, -1);
setLops(cm);
}
}
Aggregations