Determine groups of aliasing expressions in
An expression A aliases an expression B if both A and B apply the same operations to the same input operands, with the possibility for indexed objects to index into locations at a fixed constant offset in each dimension.
exprs = (a[i+1] + b[i+1], a[i+1] + b[j+1], a[i] + c[i], a[i+2] - b[i+2], a[i+2] + b[i], a[i-1] + b[i-1])
The following expressions in
a[i] + b[i]:
a[i+1] + b[i+1] : same operands and operations, distance along i = 1 a[i-1] + b[i-1] : same operands and operations, distance along i = -1
Whereas the following do not:
a[i+1] + b[j+1] : because at least one index differs a[i] + c[i] : because at least one of the operands differs a[i+2] - b[i+2] : because at least one operation differs a[i+2] + b[i] : because distance along ``i`` differ (+2 and +0)
Collect terms appearing in expr, checking all levels of the expression tree.
Parameters: expr – the expression to be factorized.
common_subexprs_elimination(exprs, make, mode='default')¶
Perform common subexpressions elimination.
Note: the output is not guranteed to be topologically sorted.
- exprs – The target SymPy expression, or a collection of SymPy expressions.
- make – A function to construct symbols used for replacement.
Drop temporaries consisting of single symbols.
Perform common sub-expressions elimination across an iterable of Clusters.
Clusterobjects of SymPy expressions into M
Clusterobjects of SymPy expressions with reduced operation count, with M >= N.
- clusters – The clusters to be transformed.
- mode – drive the expression transformation
modeparameter recognises the following values:
* 'noop': Do nothing. * 'basic': Apply common sub-expressions elimination. * 'advanced': Apply all transformations that will reduce the operation count w/ minimum increase to the memory pressure, namely 'basic', factorization, CIRE for time-invariants only. * 'speculative': Like 'advanced', but apply CIRE also to time-varying sub-expressions, which might further increase the memory pressure. * 'aggressive': Like 'speculative', but apply CIRE to any non-trivial sub-expression (i.e., anything that is at least in a sum-of-product form). Further, seek and drop cross-cluster redundancies (this is the only pass that attempts to optimize *across* clusters, rather than within a cluster). The 'aggressive' mode may substantially increase the symbolic processing time; it may or may not reduce the JIT-compilation time; it may or may not improve the overall runtime performance.