Code GenerationΒΆ
Conversion of sympy expressions to loopyΒΆ
- 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.
- 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.
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_symbolsgenerator 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).replacementsis 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_exprsis 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ΒΆ
- class sp.ExprΒΆ
See
sympy.core.expr.Expr.
- class np.ndarrayΒΆ
See
numpy.ndarray.