use of org.apache.sysml.hops.DataGenOp in project incubator-systemml by apache.
the class RewriteAlgebraicSimplificationStatic method simplifyConstantSort.
private static Hop simplifyConstantSort(Hop parent, Hop hi, int pos) {
// order(matrix(7), indexreturn=TRUE) -> seq(1,nrow(X),1)
if (// order
hi instanceof ReorgOp && ((ReorgOp) hi).getOp() == ReOrgOp.SORT) {
Hop hi2 = hi.getInput().get(0);
if (hi2 instanceof DataGenOp && ((DataGenOp) hi2).getOp() == DataGenMethod.RAND && ((DataGenOp) hi2).hasConstantValue() && // known indexreturn
hi.getInput().get(3) instanceof LiteralOp) {
if (HopRewriteUtils.getBooleanValue((LiteralOp) hi.getInput().get(3))) {
// order(matrix(7), indexreturn=TRUE) -> seq(1,nrow(X),1)
Hop seq = HopRewriteUtils.createSeqDataGenOp(hi2);
seq.refreshSizeInformation();
HopRewriteUtils.replaceChildReference(parent, hi, seq, pos);
HopRewriteUtils.cleanupUnreferenced(hi);
hi = seq;
LOG.debug("Applied simplifyConstantSort1.");
} else {
// order(matrix(7), indexreturn=FALSE) -> matrix(7)
HopRewriteUtils.replaceChildReference(parent, hi, hi2, pos);
HopRewriteUtils.cleanupUnreferenced(hi);
hi = hi2;
LOG.debug("Applied simplifyConstantSort2.");
}
}
}
return hi;
}
Aggregations