use of org.apache.sysml.hops.LiteralOp in project incubator-systemml by apache.
the class IPAPassInlineFunctions method rCountOperators.
private static int rCountOperators(Hop current) {
if (current.isVisited())
return 0;
int count = !(current instanceof DataOp || current instanceof LiteralOp) ? 1 : 0;
for (Hop c : current.getInput()) count += rCountOperators(c);
current.setVisited();
return count;
}
use of org.apache.sysml.hops.LiteralOp in project incubator-systemml by apache.
the class IPAPassRemoveConstantBinaryOps method rRemoveConstantBinaryOp.
private static void rRemoveConstantBinaryOp(Hop hop, HashMap<String, Hop> mOnes) {
if (hop.isVisited())
return;
if (hop instanceof BinaryOp && ((BinaryOp) hop).getOp() == OpOp2.MULT && !((BinaryOp) hop).isOuterVectorOperator() && hop.getInput().get(0).getDataType() == DataType.MATRIX && hop.getInput().get(1) instanceof DataOp && mOnes.containsKey(hop.getInput().get(1).getName())) {
// replace matrix of ones with literal 1 (later on removed by
// algebraic simplification rewrites; otherwise more complex
// recursive processing of childs and rewiring required)
HopRewriteUtils.removeChildReferenceByPos(hop, hop.getInput().get(1), 1);
HopRewriteUtils.addChildReference(hop, new LiteralOp(1), 1);
}
// recursively process child nodes
for (Hop c : hop.getInput()) rRemoveConstantBinaryOp(c, mOnes);
hop.setVisited();
}
use of org.apache.sysml.hops.LiteralOp in project incubator-systemml by apache.
the class InterProceduralAnalysis method extractExternalFunctionCallReturnStatistics.
private static void extractExternalFunctionCallReturnStatistics(ExternalFunctionStatement fstmt, FunctionOp fop, LocalVariableMap callVars) {
String className = fstmt.getOtherParams().get(ExternalFunctionStatement.CLASS_NAME);
if (className.equals(OrderWrapper.class.getName())) {
Hop input = fop.getInput().get(0);
long lnnz = className.equals(OrderWrapper.class.getName()) ? input.getNnz() : -1;
MatrixObject moOut = createOutputMatrix(input.getDim1(), input.getDim2(), lnnz);
callVars.put(fop.getOutputVariableNames()[0], moOut);
} else if (className.equals(DynamicReadMatrixCP.class.getName()) || className.equals(DynamicReadMatrixRcCP.class.getName())) {
// rows
Hop input1 = fop.getInput().get(1);
// cols
Hop input2 = fop.getInput().get(2);
if (input1 instanceof LiteralOp && input2 instanceof LiteralOp)
callVars.put(fop.getOutputVariableNames()[0], createOutputMatrix(((LiteralOp) input1).getLongValue(), ((LiteralOp) input2).getLongValue(), -1));
} else {
extractFunctionCallUnknownReturnStatistics(fstmt, fop, callVars);
}
}
use of org.apache.sysml.hops.LiteralOp in project incubator-systemml by apache.
the class LiteralReplacement method replaceLiteralValueTypeCastLiteral.
private static LiteralOp replaceLiteralValueTypeCastLiteral(Hop c, LocalVariableMap vars) {
LiteralOp ret = null;
// rewrite in same dag) - literal replacement
if (c instanceof UnaryOp && (((UnaryOp) c).getOp() == OpOp1.CAST_AS_DOUBLE || ((UnaryOp) c).getOp() == OpOp1.CAST_AS_INT || ((UnaryOp) c).getOp() == OpOp1.CAST_AS_BOOLEAN) && c.getInput().get(0) instanceof LiteralOp) {
LiteralOp sdat = (LiteralOp) c.getInput().get(0);
UnaryOp cast = (UnaryOp) c;
try {
switch(cast.getOp()) {
case CAST_AS_INT:
long ival = HopRewriteUtils.getIntValue(sdat);
ret = new LiteralOp(ival);
break;
case CAST_AS_DOUBLE:
double dval = HopRewriteUtils.getDoubleValue(sdat);
ret = new LiteralOp(dval);
break;
case CAST_AS_BOOLEAN:
boolean bval = HopRewriteUtils.getBooleanValue(sdat);
ret = new LiteralOp(bval);
break;
default:
}
} catch (HopsException ex) {
throw new DMLRuntimeException(ex);
}
}
return ret;
}
use of org.apache.sysml.hops.LiteralOp in project incubator-systemml by apache.
the class LiteralReplacement method replaceLiteralValueTypeCastScalarRead.
private static LiteralOp replaceLiteralValueTypeCastScalarRead(Hop c, LocalVariableMap vars) {
LiteralOp ret = null;
// as.double/as.integer/as.boolean over scalar read - literal replacement
if (c instanceof UnaryOp && (((UnaryOp) c).getOp() == OpOp1.CAST_AS_DOUBLE || ((UnaryOp) c).getOp() == OpOp1.CAST_AS_INT || ((UnaryOp) c).getOp() == OpOp1.CAST_AS_BOOLEAN) && c.getInput().get(0) instanceof DataOp && c.getDataType() == DataType.SCALAR) {
Data dat = vars.get(c.getInput().get(0).getName());
if (// required for selective constant propagation
dat != null) {
ScalarObject sdat = (ScalarObject) dat;
UnaryOp cast = (UnaryOp) c;
switch(cast.getOp()) {
case CAST_AS_INT:
ret = new LiteralOp(sdat.getLongValue());
break;
case CAST_AS_DOUBLE:
ret = new LiteralOp(sdat.getDoubleValue());
break;
case CAST_AS_BOOLEAN:
ret = new LiteralOp(sdat.getBooleanValue());
break;
default:
}
}
}
return ret;
}
Aggregations