pymbolic.primitives.
disable_subscript_by_getitem
()¶In prior versions of pymbolic
, directly subscripting an Expression
subclass generated a Subscript
. For various reasons, this was a
very bad idea. For example, the following code snippet would result in an
infinite loop:
for el in expr:
print(el)
numpy
does similar things under the hodd, leading to hard-to-debug
infinite loops. As a result, this behavior is being deprecated. In Pymbolic
2016.x, it will disappear entirely. It can also be disabled by this
function. Once disabled, it cannot be reenabled.
See also Expression.index()
.
New in version 2014.3.
pymbolic.primitives.
Expression
¶Superclass for parts of a mathematical expression. Overrides operators
to implicitly construct Sum
, Product
and other expressions.
Expression objects are immutable.
attr
¶mapper_method
¶The pymbolic.mapper.Mapper
method called for objects of
this type.
__getitem__
()¶Deprecated, see disable_subscript_by_getitem()
. Use index()
instead.
index
(subscript)¶Return an expression representing self[subscript]
.
New in version 2014.3.
stringifier
()¶Return a pymbolic.mapper.Mapper
class used to yield
a human-readable representation of self. Usually a subclass
of pymbolic.mapper.stringifier.StringifyMapper
.
__eq__
(other)¶Provides equality testing with quick positive and negative paths
based on id()
and __hash__()
.
Subclasses should generally not override this method, but instead
provide an implementation of is_equal()
.
__hash__
()¶Provides caching for hash values.
Subclasses should generally not override this method, but instead
provide an implementation of get_hash()
.
__str__
()¶Use the stringifier()
to return a human-readable
string representation of self.
pymbolic.primitives.
Call
(function, parameters)¶A function invocation.
function
¶A Expression
that evaluates to a function.
parameters
¶A tuple
of positional paramters, each element
of which is a Expression
or a constant.
mapper_method
= 'map_call'¶pymbolic.primitives.
CallWithKwargs
(function, parameters, kw_parameters)¶A function invocation with keyword arguments.
function
¶A Expression
that evaluates to a function.
parameters
¶A tuple
of positional paramters, each element
of which is a Expression
or a constant.
kw_parameters
¶A dictionary mapping names to arguments, , each
of which is a Expression
or a constant,
or an equivalent value accepted by the dict
constructor.
mapper_method
= 'map_call_with_kwargs'¶pymbolic.primitives.
Subscript
(aggregate, index)¶An array subscript.
aggregate
¶index
¶mapper_method
= 'map_subscript'¶pymbolic.primitives.
Lookup
(aggregate, name)¶Access to an attribute of an aggregate, such as an attribute of a class.
mapper_method
= 'map_lookup'¶pymbolic.primitives.
Quotient
(numerator, denominator=1)¶numerator
¶denominator
¶mapper_method
= 'map_quotient'¶pymbolic.primitives.
FloorDiv
(numerator, denominator=1)¶numerator
¶denominator
¶mapper_method
= 'map_floor_div'¶pymbolic.primitives.
Comparison
(left, operator, right)¶left
¶operator
¶right
¶Note
Unlike other expressions, comparisons are not implicitly constructed by
comparing Expression
objects.
Parameters: | operator – One of [">", ">=", "==", "!=", "<", "<="] . |
---|
mapper_method
= 'map_comparison'¶pymbolic.primitives.
CommonSubexpression
(child, prefix=None, scope=None)¶A helper for code generation and caching. Denotes a subexpression that
should only be evaluated once. If, in code generation, it is assigned to
a variable, a name starting with prefix
should be used.
child
¶prefix
¶See pymbolic.mapper.c_code.CCodeMapper
for an example.
Parameters: | scope – Defaults to cse_scope.EVALUATION if given as None. |
---|
mapper_method
= 'map_common_subexpression'¶pymbolic.primitives.
cse_scope
¶Determines the lifetime for the saved value of a CommonSubexpression
.
EVALUATION
¶The evaluated result lives for the duration of the evaluation of the current expression and is discarded thereafter.
EXPRESSION
¶The evaluated result lives for the lifetime of the current expression (across multiple evaluations with multiple parameters) and is discarded when the expression is.
GLOBAL
¶The evaluated result lives until the execution context dies.
pymbolic.primitives.
make_common_subexpression
(field, prefix=None, scope=None)¶Wrap field in a CommonSubexpression
with
prefix. If field is a numpy
object array,
each individual entry is instead wrapped. If field is a
pymbolic.geometric_algebra.MultiVector
, each
coefficient is individually wrapped.
See CommonSubexpression
for the meaning of prefix
and scope.
pymbolic.primitives.
is_zero
(value)¶pymbolic.primitives.
is_constant
(value)¶pymbolic.primitives.
register_constant_class
(class_)¶pymbolic.primitives.
unregister_constant_class
(class_)¶pymbolic.primitives.
variables
(s)¶Return a list of variables for each (space-delimited) identifier in s.