Code Generation#

Conversion of sympy expressions to loopy#

class sumpy.codegen.SympyToPymbolicMapper[source]#
sumpy.codegen.to_loopy_insns(assignments, vector_names=frozenset({}), pymbolic_expr_maps=(), complex_dtype=None, retain_names=frozenset({}))[source]#

Manipulating batches of assignments#

class sumpy.assignment_collection.SymbolicAssignmentCollection(assignments=None)[source]#

Represents a collection of assignments:

a = 5*x
b = a**2-k

In the above, x and k are external variables, and a and b are variables managed by this object.

This is a stateful object, but the only state changes allowed are additions to assignments, and corresponding updates of its lookup tables.

Note that user code is only allowed to hold on to names generated by this class, but not expressions using names defined in this collection.

Common subexpression elimination#

sumpy.cse.cse(exprs, symbols=None, optimizations=None)[source]#

Perform common subexpression elimination on an expression.

  • exprs – A list of sympy expressions, or a single sympy expression to reduce

  • symbols – An iterator yielding unique Symbols used to label the common subexpressions which are pulled out. The numbered_symbols generator from sympy is useful. The default is a stream of symbols of the form “x0”, “x1”, etc. This must be an infinite iterator.

  • optimizations – A list of (callable, callable) pairs consisting of (preprocessor, postprocessor) pairs of external optimization functions.


This returns a pair (replacements, reduced_exprs).

  • replacements is a list of (Symbol, expression) pairs consisting of all of the common subexpressions that were replaced. Subexpressions earlier in this list might show up in subexpressions later in this list.

  • reduced_exprs is a list of sympy expressions. This contains the reduced expressions with all of the replacements above.