Sleipnir C++ API
Loading...
Searching...
No Matches
slp::detail::NonLeafExpression< Derived, Scalar, NumArgs, Type > Struct Template Reference

#include </home/runner/work/Sleipnir/Sleipnir/include/sleipnir/autodiff/expression.hpp>

Inheritance diagram for slp::detail::NonLeafExpression< Derived, Scalar, NumArgs, Type >:
slp::detail::Expression< Scalar >

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
 

Static Public Attributes

static constexpr size_t NUM_ARGS = NumArgs
 The number of arguments.
 
static constexpr bool CONSTANT_PARTIALS = false
 Whether the partial derivatives are the same at every argument value.
 

Additional Inherited Members

- Public Types inherited from slp::detail::Expression< Scalar >
using Scalar = Scalar
 Scalar type alias.
 

Detailed Description

template<typename Derived, typename Scalar, size_t NumArgs, ExpressionType Type = ExpressionType::NONLINEAR>
struct slp::detail::NonLeafExpression< Derived, Scalar, NumArgs, Type >

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.

Template Parameters
DerivedDerived expression type.
ScalarScalar type.
NumArgsThe number of arguments.
TypeThe expression's type.

Constructor & Destructor Documentation

◆ NonLeafExpression()

template<typename Derived , typename Scalar , size_t NumArgs, ExpressionType Type = ExpressionType::NONLINEAR>
template<typename... Args>
requires (sizeof...(Args) == NumArgs && (std::same_as<std::remove_cvref_t<Args>, ExpressionPtr<Scalar>> && ...))
constexpr slp::detail::NonLeafExpression< Derived, Scalar, NumArgs, Type >::NonLeafExpression ( Args &&...  args)
inlineexplicitconstexpr

Constructs an expression from its arguments.

Parameters
argsThe arguments in visit_args() order.

Member Function Documentation

◆ accumulate_adjoints()

template<typename Derived , typename Scalar , size_t NumArgs, ExpressionType Type = ExpressionType::NONLINEAR>
void slp::detail::NonLeafExpression< Derived, Scalar, NumArgs, Type >::accumulate_adjoints ( ) const
inlinefinalvirtual

Accumulates the child adjoints as Scalars.

Reimplemented from slp::detail::Expression< Scalar >.

◆ accumulate_adjoints_expr()

template<typename Derived , typename Scalar , size_t NumArgs, ExpressionType Type = ExpressionType::NONLINEAR>
void slp::detail::NonLeafExpression< Derived, Scalar, NumArgs, Type >::accumulate_adjoints_expr ( ) const
inlinefinalvirtual

Accumulates the child adjoints as Expressions.

Reimplemented from slp::detail::Expression< Scalar >.

◆ name()

template<typename Derived , typename Scalar , size_t NumArgs, ExpressionType Type = ExpressionType::NONLINEAR>
std::string_view slp::detail::NonLeafExpression< Derived, Scalar, NumArgs, Type >::name ( ) const
inlinefinalvirtual

Returns the name of this expression.

Returns
The name of this expression.

Implements slp::detail::Expression< Scalar >.

◆ type()

template<typename Derived , typename Scalar , size_t NumArgs, ExpressionType Type = ExpressionType::NONLINEAR>
ExpressionType slp::detail::NonLeafExpression< Derived, Scalar, NumArgs, Type >::type ( ) const
inlinefinalvirtual

Returns the type of this expression.

Returns
The type of this expression.

Implements slp::detail::Expression< Scalar >.

◆ value()

template<typename Derived , typename Scalar , size_t NumArgs, ExpressionType Type = ExpressionType::NONLINEAR>
Scalar slp::detail::NonLeafExpression< Derived, Scalar, NumArgs, Type >::value ( ) const
inlinefinalvirtual

Returns the node's value computed from its arguments's values.

Returns
The node's value.

Implements slp::detail::Expression< Scalar >.

◆ visit_args()

template<typename Derived , typename Scalar , size_t NumArgs, ExpressionType Type = ExpressionType::NONLINEAR>
void slp::detail::NonLeafExpression< Derived, Scalar, NumArgs, Type >::visit_args ( function_ref< void(Expression< Scalar > *arg)>  func) const
inlinefinalvirtual

Runs a function on each argument.

Parameters
funcThe function to run.

Reimplemented from slp::detail::Expression< Scalar >.


The documentation for this struct was generated from the following file: