lingvo.core.symbolic module

Utilities for symbolic computation.

class lingvo.core.symbolic.Symbol(name=None, dummy_index=None, **assumptions)[source]

Bases: Dummy

dummy_index
_explicit_class_assumptions = {}
_prop_handler = {'extended_negative': <function Expr._eval_is_extended_negative>, 'extended_positive': <function Expr._eval_is_extended_positive>}
default_assumptions = {}
lingvo.core.symbolic.IsSymbol(x)[source]
lingvo.core.symbolic.IsExpr(x)[source]
class lingvo.core.symbolic._LocalSymbolToValueStack[source]

Bases: _local

A thread-local stack of symbol-to-value dicts.

class lingvo.core.symbolic.SymbolToValueMap(value_type, symbol_to_value_map)[source]

Bases: object

A symbol-to-value mapping.

Usage:

with SymbolToValueMap(‘static’, {symbol1: value1, symbol2: value2, …}):
with SymbolToValueMap(‘tensor’, {symbol1: value1, symbol2: value2, …}):

… = EvalExpr(value_type, symbolic_expr)

Multiple SymbolToValueMap context can be nested inside one another. The inner contexts take precedence over outer ones when multiple contexts provide values for the same symbol.

_local_stack = <lingvo.core.symbolic._LocalSymbolToValueStack object>
static Stack(value_type)[source]
static Get(value_type)[source]

Returns a symbol-to-value mapping merged from Stack().

lingvo.core.symbolic.EvalExpr(value_type, x)[source]

Evaluates x with symbol_to_value_map within the current context.

Parameters
  • value_type – the target value type (see VALUE_TYPE).

  • x – a sympy.Expr, an object, or a list/tuple of Exprs and objects.

Returns

Evaluation result of ‘x’.

lingvo.core.symbolic.ToStatic(expr)[source]
lingvo.core.symbolic.ToTensor(expr)[source]