def _extract_time_invariants(self, cluster, template, with_cse=True, costmodel=None, **kwargs): """ Extract time-invariant subexpressions, and assign them to temporaries. """ make = lambda: Scalar(name=template(), dtype=cluster.dtype).indexify() rule = iq_timeinvariant(cluster.trace) costmodel = costmodel or (lambda e: estimate_cost(e) > 0) processed, found = xreplace_constrained(cluster.exprs, make, rule, costmodel) if with_cse: leaves = [i for i in processed if i not in found] # Search for common sub-expressions amongst them (and only them) found = common_subexprs_elimination(found, make) # Some temporaries may be droppable at this point processed = compact_temporaries(found, leaves) return cluster.rebuild(processed)
def _extract_time_invariants(self, cluster, template, with_cse=True, **kwargs): """ Extract time-invariant subexpressions, and assign them to temporaries. """ make = lambda: Scalar(name=template(), dtype=cluster.dtype).indexify() rule = iq_timeinvariant(cluster.trace) costmodel = lambda e: estimate_cost(e) > 0 processed, found = xreplace_constrained(cluster.exprs, make, rule, costmodel) if with_cse: leaves = [i for i in processed if i not in found] # Search for common sub-expressions amongst them (and only them) found = common_subexprs_elimination(found, make) # Some temporaries may be droppable at this point processed = compact_temporaries(found, leaves) return cluster.rebuild(processed)