Code GenerationΒΆ

Conversion of sympy expressions to loopyΒΆ

class sumpy.codegen.SympyToPymbolicMapper[source]ΒΆ
sumpy.codegen.to_loopy_insns(assignments: Iterable[tuple[str, Basic]], vector_names: AbstractSet[str] | None = None, pymbolic_expr_maps: Sequence[Callable[[Expression], Expression]] = (), complex_dtype: DTypeLike | None = None, retain_names: AbstractSet[str] | None = None) Sequence[Assignment | CallInstruction][source]ΒΆ

Manipulating batches of assignmentsΒΆ

class sumpy.assignment_collection.SymbolicAssignmentCollection(assignments: dict[str, Basic] | None = 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.

assignments: dict[str, Basic]ΒΆ

A mapping from var_name to expressions.

add_assignment(name: str, expr: Basic, root_name: str | None = None, retain_name: bool = True) str[source]ΒΆ
assign_unique(name_base: str, expr: Basic) str[source]ΒΆ

Assign expr to a new variable whose name is based on name_base. Return the new variable name.

assign_temp(name_base: str, expr: Basic) str[source]ΒΆ

If expr is mapped to a existing variable, then return the existing variable or assign expr to a new variable whose name is based on name_base. Return the variable name expr is mapped to in either case.

run_global_cse(extra_exprs: None = None) Self[source]ΒΆ
run_global_cse(extra_exprs: Sequence[Expr]) tuple[Self, Sequence[Basic]]

Common subexpression eliminationΒΆ

sumpy.cse.OptimizationCallableΒΆ

alias of Callable[[sym.Basic], sym.Basic]

sumpy.cse.OptimizationPairΒΆ

alias of tuple[OptimizationCallable, OptimizationCallable]

sumpy.cse.cse(exprs: Basic | Sequence[Basic], symbols: Iterator[Symbol] | None = None, optimizations: Sequence[OptimizationPair] | None = None) tuple[Sequence[tuple[Symbol, Basic]], Sequence[Basic]][source]ΒΆ

Perform common subexpression elimination on an expression.

Parameters:
  • 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.

Returns:

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.

ReferencesΒΆ

This is only here because Sphinx (the documentation tool) fails to resolve these references properly.

class lp.TranslationUnitΒΆ

See loopy.TranslationUnit.

class sp.ExprΒΆ

See sympy.core.expr.Expr.

class np.ndarrayΒΆ

See numpy.ndarray.