symforce.internal.symbolic module¶
- create_named_scope(scopes_list)[source]¶
Return a context manager that adds to the given list of name scopes. This is used to add scopes to symbol names for namespacing.
- epsilon()[source]¶
The default epsilon for SymForce
Library functions that require an epsilon argument should use a function signature like:
def foo(x: Scalar, epsilon: Scalar = sf.epsilon()) -> Scalar: ...
This makes it easy to configure entire expressions that make extensive use of epsilon to either use no epsilon (i.e. 0), or a symbol, or a numerical value. It also means that by setting the default to a symbol, you can confidently generate code without worrying about having forgotten to pass an epsilon argument to one of these functions.
For more information on how we use epsilon to prevent singularities, see the Epsilon Tutorial in the SymForce docs here: https://symforce.org/tutorials/epsilon_tutorial.html
For purely numerical code that just needs a good default numerical epsilon, see
symforce.symbolic.numeric_epsilon
.- Returns:
The current default epsilon. This is typically some kind of “Scalar”, like a float or a
:class:`Symbol <symforce.symbolic.Symbol>`.
- Return type:
- wrap_angle(x)[source]¶
Wrap an angle to the interval [-pi, pi). Commonly used to compute the shortest signed distance between two angles.
See also:
angle_diff()
- angle_diff(x, y)[source]¶
Return the difference x - y, but wrapped into [-pi, pi); i.e. the angle diff closest to 0 such that x = y + diff (mod 2pi).
See also:
wrap_angle()
- argmax_onehot(vals, tolerance=0.0)[source]¶
Returns a list
l
such thatl[i] = 1.0
ifi
is the smallest index such thatvals[i]
equalsMax(*vals)
.l[i] = 0.0
otherwise.- Precondition:
vals has at least one element
- argmax(vals)[source]¶
Returns
i
(as a Scalar) such thati
is the smallest index such thatvals[i]
equalsMax(*vals)
.- Precondition:
vals has at least one element
- clamp(x, min_value, max_value)[source]¶
Clamps x between min_value and max_value
Returns:
min_value if x < min_value x if min_value <= x <= max_value max_value if x > max_value
- set_eval_on_sympify(eval_on_sympy=True)[source]¶
When using the symengine backed, set whether we should eval args when converting objects to sympy.
By default, this is enabled since this is the implicit behavior with stock symengine. Disabling eval results in more slightly ops, but greatly speeds up codegen time.
- Parameters:
eval_on_sympy (bool) –
- Return type:
None
- SymPySignNoZero¶
alias of
SignNoZero
- SymPyCopysignNoZero¶
alias of
CopysignNoZero
- copysign_no_zero(x, y)[source]¶
Returns a value with the magnitude of x and sign of y
If y is zero, returns positive x.