![]() |
Sleipnir C++ API
|
#include </home/runner/work/Sleipnir/Sleipnir/include/sleipnir/autodiff/expression.hpp>
Public Member Functions | |
| template<typename... Args> requires (sizeof...(Args) == NumArgs && (std::same_as<std::remove_cvref_t<Args>, ExpressionPtr<Scalar>> && ...)) | |
| constexpr | NonLeafExpression (Args &&... args) |
| void | visit_args (function_ref< void(Expression< Scalar > *arg)> func) const final |
| Scalar | value () const final |
| ExpressionType | type () const final |
| std::string_view | name () const final |
| void | accumulate_adjoints () const final |
| Accumulates the child adjoints as Scalars. | |
| void | accumulate_adjoints_expr () const final |
| Accumulates the child adjoints as Expressions. | |
Public Member Functions inherited from slp::detail::Expression< Scalar > | |
| constexpr | Expression ()=default |
| Constructs a constant expression with a value of zero. | |
| constexpr | Expression (Scalar value) |
| SLEIPNIR_FORCE_INLINE constexpr bool | is_constant (Scalar constant) const |
Public Attributes | |
| std::array< ExpressionPtr< Scalar >, NumArgs > | args |
| The arguments in visit_args() order. | |
Public Attributes inherited from slp::detail::Expression< Scalar > | |
| Scalar | val |
| The value of the expression node. | |
| Scalar | adj |
| The adjoint of the expression node, used during autodiff. | |
| ExpressionPtr< Scalar > | adj_expr |
| int32_t | scratch |
| uint32_t | ref_count |
| Reference count for intrusive shared pointer. | |
| uint32_t | is_leaf |
Additional Inherited Members | |
Public Types inherited from slp::detail::Expression< Scalar > | |
| using | Scalar = Scalar |
| Scalar type alias. | |
Base of the derived expression types of non-leaf operators.
Implements Expression's virtual functions from the derived expression type's eval(), eval_grad(), and NAME and the operator's properties.
The derived expression type computes its partial derivatives with eval_grad<Value>(g, val, a₀, a₁, ...), which writes ∂/∂aₖ to g[k] given the expression's value followed by the argument values. Value is Scalar to evaluate them, or ExpressionPtr<Scalar> to build them as expressions. It's static unless the partial derivatives depend on the expression's state. If the derived expression type doesn't define it, all partial derivatives are structurally zero.
If the derived expression type sets CONSTANT_PARTIALS to true, gradient trees evaluate the partial derivatives as Scalars instead of building them as expressions.
| Derived | Derived expression type. |
| Scalar | Scalar type. |
| NumArgs | The number of arguments. |
| Type | The expression's type. |
|
inlineexplicitconstexpr |
Constructs an expression from its arguments.
| args | The arguments in visit_args() order. |
|
inlinefinalvirtual |
Accumulates the child adjoints as Scalars.
Reimplemented from slp::detail::Expression< Scalar >.
|
inlinefinalvirtual |
Accumulates the child adjoints as Expressions.
Reimplemented from slp::detail::Expression< Scalar >.
|
inlinefinalvirtual |
Returns the name of this expression.
Implements slp::detail::Expression< Scalar >.
|
inlinefinalvirtual |
Returns the type of this expression.
Implements slp::detail::Expression< Scalar >.
|
inlinefinalvirtual |
Returns the node's value computed from its arguments's values.
Implements slp::detail::Expression< Scalar >.
|
inlinefinalvirtual |
Runs a function on each argument.
| func | The function to run. |
Reimplemented from slp::detail::Expression< Scalar >.