devito.ir.equations package¶

devito.ir.equations.algorithms module¶

devito.ir.equations.algorithms.dimension_sort(expr)[source]

Topologically sort the Dimensions in expr, based on the order in which they appear within :class:Indexeds.

devito.ir.equations.equation module¶

class devito.ir.equations.equation.LoweredEq(sympy.Eq)[source]

Bases: sympy.core.relational.Equality, devito.ir.equations.equation.IREq

LoweredEq(devito.LoweredEq, **kwargs) LoweredEq(lhs, rhs, **kwargs)

A SymPy equation with associated IterationSpace and DataSpace.

When created as LoweredEq(sympy.Eq), the iteration and data spaces are automatically derived from analysis of expr.

When created as LoweredEq(devito.LoweredEq, **kwargs), the keyword arguments can be anything that appears in LoweredEq._state (i.e., ispace, dspace, …).

When created as LoweredEq(lhs, rhs, **kwargs), all keywords in LoweredEq._state must appear in kwargs.

default_assumptions = {}
func(*args)[source]

The top-level function in an expression.

The following should hold for all objects:

>> x == x.func(*x.args)

>>> from sympy.abc import x
>>> a = 2*x
>>> a.func
<class 'sympy.core.mul.Mul'>
>>> a.args
(2, x)
>>> a.func(*a.args)
2*x
>>> a == a.func(*a.args)
True

reads
writes
xreplace(rules)[source]

Replace occurrences of objects within the expression.

rule : dict-like
Expresses a replacement rule

xreplace : the result of the replacement

>>> from sympy import symbols, pi, exp
>>> x, y, z = symbols('x y z')
>>> (1 + x*y).xreplace({x: pi})
pi*y + 1
>>> (1 + x*y).xreplace({x: pi, y: 2})
1 + 2*pi


Replacements occur only if an entire node in the expression tree is matched:

>>> (x*y + z).xreplace({x*y: pi})
z + pi
>>> (x*y*z).xreplace({x*y: pi})
x*y*z
>>> (2*x).xreplace({2*x: y, x: z})
y
>>> (2*2*x).xreplace({2*x: y, x: z})
4*z
>>> (x + y + 2).xreplace({x + y: 2})
x + y + 2
>>> (x + 2 + exp(x + 2)).xreplace({x + 2: y})
x + exp(y) + 2


xreplace doesn’t differentiate between free and bound symbols. In the following, subs(x, y) would not change x since it is a bound symbol, but xreplace does:

>>> from sympy import Integral
>>> Integral(x, (x, 1, 2*x)).xreplace({x: y})
Integral(y, (y, 1, 2*y))


Trying to replace x with an expression raises an error:

>>> Integral(x, (x, 1, 2*x)).xreplace({x: 2*y})
ValueError: Invalid limits given: ((2*y, 1, 4*y),)

replace: replacement capable of doing wildcard-like matching,
parsing of match, and conditional replacements
subs: substitution of subexpressions as defined by the objects
themselves.
class devito.ir.equations.equation.ClusterizedEq(devito.IREq, **kwargs)[source]

Bases: sympy.core.relational.Equality, devito.ir.equations.equation.IREq, devito.symbolics.extended_sympy.FrozenExpr, devito.tools.abc.Pickable

ClusterizedEq(lhs, rhs, **kwargs)

A SymPy equation with associated IterationSpace and DataSpace.

There are two main differences between a LoweredEq and a ClusterizedEq:

* In a ClusterizedEq, the iteration and data spaces must *always*
be provided by the caller.
* A ClusterizedEq is "frozen", meaning that any call to xreplace
will not trigger re-evaluation (e.g., mathematical simplification)
of the expression.


These two properties make a ClusterizedEq suitable for use in a Cluster.

default_assumptions = {}
func(*args, **kwargs)[source]

The top-level function in an expression.

The following should hold for all objects:

>> x == x.func(*x.args)

>>> from sympy.abc import x
>>> a = 2*x
>>> a.func
<class 'sympy.core.mul.Mul'>
>>> a.args
(2, x)
>>> a.func(*a.args)
2*x
>>> a == a.func(*a.args)
True

class devito.ir.equations.equation.DummyEq(expr)[source]

DummyEq(lhs, rhs)

A special ClusterizedEq that tracks no iteration or data spaces.

default_assumptions = {}