pynucastro.autodiff.dual module#
Forward-mode derivatives of scalar values, usable from Python and Numba.
Seed the independent variable with Dual(value, 1.0) and constants with
Dual(value, 0.0). Use this module’s math helpers in place of NumPy ufuncs
when an argument may be dual. CPU Numba overloads support scalar-left
arithmetic, value comparisons, and two-argument min/max. Compiled
min/max return a Dual if either operand is dual, with zero derivative
when a scalar bound is selected. Ties select the first operand, as in Python.
Use DerivativePair seeds to propagate two derivatives simultaneously. All dual
operands in an expression must use the same seed kind. Other branches must
likewise keep dual-valued variables consistently typed.
- class pynucastro.autodiff.dual.Dual(value, deriv=1.0)[source]#
Carry a quantity that can propagate its derivative.
A scalar seed carries one derivative; a DerivativePair seed carries two independent derivatives. Instances are immutable namedtuples, lowered by Numba to native tuple values.
- Parameters:
value (float) – Scalar value.
deriv (float or DerivativePair, optional) – Derivative seed, defaulting to one. Use the same seed kind for all dual operands in an expression.