WPILibC++ 2025.1.1
Loading...
Searching...
No Matches
sleipnir::detail::Expression Struct Reference

An autodiff expression node. More...

#include </home/runner/work/allwpilib/allwpilib/wpimath/src/main/native/thirdparty/sleipnir/include/sleipnir/autodiff/Expression.hpp>

Public Types

using BinaryFuncDouble = double (*)(double, double)
 Binary function taking two doubles and returning a double.
 
using TrinaryFuncDouble = double (*)(double, double, double)
 Trinary function taking three doubles and returning a double.
 
using TrinaryFuncExpr
 Trinary function taking three expressions and returning an expression.
 

Public Member Functions

constexpr Expression ()=default
 Constructs a constant expression with a value of zero.
 
constexpr Expression (double value, ExpressionType type=ExpressionType::kConstant)
 Constructs a nullary expression (an operator with no arguments).
 
constexpr Expression (ExpressionType type, BinaryFuncDouble valueFunc, TrinaryFuncDouble lhsGradientValueFunc, TrinaryFuncExpr lhsGradientFunc, ExpressionPtr lhs)
 Constructs an unary expression (an operator with one argument).
 
constexpr Expression (ExpressionType type, BinaryFuncDouble valueFunc, TrinaryFuncDouble lhsGradientValueFunc, TrinaryFuncDouble rhsGradientValueFunc, TrinaryFuncExpr lhsGradientFunc, TrinaryFuncExpr rhsGradientFunc, ExpressionPtr lhs, ExpressionPtr rhs)
 Constructs a binary expression (an operator with two arguments).
 
constexpr bool IsConstant (double constant) const
 Returns true if the expression is the given constant.
 

Public Attributes

double value = 0.0
 The value of the expression node.
 
double adjoint = 0.0
 The adjoint of the expression node used during autodiff.
 
uint32_t duplications = 0
 Tracks the number of instances of this expression yet to be encountered in an expression tree.
 
int32_t row = -1
 This expression's row in wrt for autodiff gradient, Jacobian, or Hessian.
 
ExpressionPtr adjointExpr
 The adjoint of the expression node used during gradient expression tree generation.
 
ExpressionType type = ExpressionType::kConstant
 Expression argument type.
 
uint32_t refCount = 0
 Reference count for intrusive shared pointer.
 
BinaryFuncDouble valueFunc = nullptr
 Either nullary operator with no arguments, unary operator with one argument, or binary operator with two arguments.
 
std::array< TrinaryFuncDouble, 2 > gradientValueFuncs {nullptr, nullptr}
 Functions returning double adjoints of the children expressions.
 
std::array< TrinaryFuncExpr, 2 > gradientFuncs {nullptr, nullptr}
 Functions returning Variable adjoints of the children expressions.
 
std::array< ExpressionPtr, 2 > args {nullptr, nullptr}
 Expression arguments.
 

Friends

SLEIPNIR_DLLEXPORT ExpressionPtr operator* (const ExpressionPtr &lhs, const ExpressionPtr &rhs)
 Expression-Expression multiplication operator.
 
SLEIPNIR_DLLEXPORT ExpressionPtr operator/ (const ExpressionPtr &lhs, const ExpressionPtr &rhs)
 Expression-Expression division operator.
 
SLEIPNIR_DLLEXPORT ExpressionPtr operator+ (const ExpressionPtr &lhs, const ExpressionPtr &rhs)
 Expression-Expression addition operator.
 
SLEIPNIR_DLLEXPORT ExpressionPtr operator- (const ExpressionPtr &lhs, const ExpressionPtr &rhs)
 Expression-Expression subtraction operator.
 
SLEIPNIR_DLLEXPORT ExpressionPtr operator- (const ExpressionPtr &lhs)
 Unary minus operator.
 
SLEIPNIR_DLLEXPORT ExpressionPtr operator+ (const ExpressionPtr &lhs)
 Unary plus operator.
 

Detailed Description

An autodiff expression node.

Member Typedef Documentation

◆ BinaryFuncDouble

using sleipnir::detail::Expression::BinaryFuncDouble = double (*)(double, double)

Binary function taking two doubles and returning a double.

◆ TrinaryFuncDouble

using sleipnir::detail::Expression::TrinaryFuncDouble = double (*)(double, double, double)

Trinary function taking three doubles and returning a double.

◆ TrinaryFuncExpr

Initial value:
const ExpressionPtr&,
const ExpressionPtr&)
IntrusiveSharedPtr< Expression > ExpressionPtr
Typedef for intrusive shared pointer to Expression.
Definition Expression.hpp:39

Trinary function taking three expressions and returning an expression.

Constructor & Destructor Documentation

◆ Expression() [1/4]

sleipnir::detail::Expression::Expression ( )
constexprdefault

Constructs a constant expression with a value of zero.

◆ Expression() [2/4]

sleipnir::detail::Expression::Expression ( double value,
ExpressionType type = ExpressionType::kConstant )
inlineexplicitconstexpr

Constructs a nullary expression (an operator with no arguments).

Parameters
valueThe expression value.
typeThe expression type. It should be either constant (the default) or linear.

◆ Expression() [3/4]

sleipnir::detail::Expression::Expression ( ExpressionType type,
BinaryFuncDouble valueFunc,
TrinaryFuncDouble lhsGradientValueFunc,
TrinaryFuncExpr lhsGradientFunc,
ExpressionPtr lhs )
inlineconstexpr

Constructs an unary expression (an operator with one argument).

Parameters
typeThe expression's type.
valueFuncUnary operator that produces this expression's value.
lhsGradientValueFuncGradient with respect to the operand.
lhsGradientFuncGradient with respect to the operand.
lhsUnary operator's operand.

◆ Expression() [4/4]

sleipnir::detail::Expression::Expression ( ExpressionType type,
BinaryFuncDouble valueFunc,
TrinaryFuncDouble lhsGradientValueFunc,
TrinaryFuncDouble rhsGradientValueFunc,
TrinaryFuncExpr lhsGradientFunc,
TrinaryFuncExpr rhsGradientFunc,
ExpressionPtr lhs,
ExpressionPtr rhs )
inlineconstexpr

Constructs a binary expression (an operator with two arguments).

Parameters
typeThe expression's type.
valueFuncUnary operator that produces this expression's value.
lhsGradientValueFuncGradient with respect to the left operand.
rhsGradientValueFuncGradient with respect to the right operand.
lhsGradientFuncGradient with respect to the left operand.
rhsGradientFuncGradient with respect to the right operand.
lhsBinary operator's left operand.
rhsBinary operator's right operand.

Member Function Documentation

◆ IsConstant()

bool sleipnir::detail::Expression::IsConstant ( double constant) const
inlineconstexpr

Returns true if the expression is the given constant.

Parameters
constantThe constant.

Friends And Related Symbol Documentation

◆ operator*

SLEIPNIR_DLLEXPORT ExpressionPtr operator* ( const ExpressionPtr & lhs,
const ExpressionPtr & rhs )
friend

Expression-Expression multiplication operator.

Parameters
lhsOperator left-hand side.
rhsOperator right-hand side.

◆ operator+ [1/2]

SLEIPNIR_DLLEXPORT ExpressionPtr operator+ ( const ExpressionPtr & lhs)
friend

Unary plus operator.

Parameters
lhsOperand of unary plus.

◆ operator+ [2/2]

SLEIPNIR_DLLEXPORT ExpressionPtr operator+ ( const ExpressionPtr & lhs,
const ExpressionPtr & rhs )
friend

Expression-Expression addition operator.

Parameters
lhsOperator left-hand side.
rhsOperator right-hand side.

◆ operator- [1/2]

SLEIPNIR_DLLEXPORT ExpressionPtr operator- ( const ExpressionPtr & lhs)
friend

Unary minus operator.

Parameters
lhsOperand of unary minus.

◆ operator- [2/2]

SLEIPNIR_DLLEXPORT ExpressionPtr operator- ( const ExpressionPtr & lhs,
const ExpressionPtr & rhs )
friend

Expression-Expression subtraction operator.

Parameters
lhsOperator left-hand side.
rhsOperator right-hand side.

◆ operator/

SLEIPNIR_DLLEXPORT ExpressionPtr operator/ ( const ExpressionPtr & lhs,
const ExpressionPtr & rhs )
friend

Expression-Expression division operator.

Parameters
lhsOperator left-hand side.
rhsOperator right-hand side.

Member Data Documentation

◆ adjoint

double sleipnir::detail::Expression::adjoint = 0.0

The adjoint of the expression node used during autodiff.

◆ adjointExpr

ExpressionPtr sleipnir::detail::Expression::adjointExpr

The adjoint of the expression node used during gradient expression tree generation.

◆ args

std::array<ExpressionPtr, 2> sleipnir::detail::Expression::args {nullptr, nullptr}

Expression arguments.

◆ duplications

uint32_t sleipnir::detail::Expression::duplications = 0

Tracks the number of instances of this expression yet to be encountered in an expression tree.

◆ gradientFuncs

std::array<TrinaryFuncExpr, 2> sleipnir::detail::Expression::gradientFuncs {nullptr, nullptr}

Functions returning Variable adjoints of the children expressions.

Parameters:

  • lhs: Left argument to binary operator.
  • rhs: Right argument to binary operator.
  • parentAdjoint: Adjoint of parent expression.

◆ gradientValueFuncs

std::array<TrinaryFuncDouble, 2> sleipnir::detail::Expression::gradientValueFuncs {nullptr, nullptr}

Functions returning double adjoints of the children expressions.

Parameters:

  • lhs: Left argument to binary operator.
  • rhs: Right argument to binary operator.
  • parentAdjoint: Adjoint of parent expression.

◆ refCount

uint32_t sleipnir::detail::Expression::refCount = 0

Reference count for intrusive shared pointer.

◆ row

int32_t sleipnir::detail::Expression::row = -1

This expression's row in wrt for autodiff gradient, Jacobian, or Hessian.

This is -1 if the expression isn't in wrt.

◆ type

ExpressionType sleipnir::detail::Expression::type = ExpressionType::kConstant

Expression argument type.

◆ value

double sleipnir::detail::Expression::value = 0.0

The value of the expression node.

◆ valueFunc

BinaryFuncDouble sleipnir::detail::Expression::valueFunc = nullptr

Either nullary operator with no arguments, unary operator with one argument, or binary operator with two arguments.

This operator is used to update the node's value.


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