Sleipnir C++ API
Loading...
Searching...
No Matches
sleipnir::detail::Expression Struct Referenceabstract

#include <sleipnir/autodiff/Expression.hpp>

Inheritance diagram for sleipnir::detail::Expression:
sleipnir::detail::AbsExpression sleipnir::detail::AcosExpression sleipnir::detail::AsinExpression sleipnir::detail::Atan2Expression sleipnir::detail::AtanExpression sleipnir::detail::BinaryMinusExpression< T > sleipnir::detail::BinaryPlusExpression< T > sleipnir::detail::ConstExpression sleipnir::detail::CosExpression sleipnir::detail::CoshExpression sleipnir::detail::DecisionVariableExpression sleipnir::detail::DivExpression< T > sleipnir::detail::ErfExpression sleipnir::detail::ExpExpression sleipnir::detail::HypotExpression sleipnir::detail::Log10Expression sleipnir::detail::LogExpression sleipnir::detail::MultExpression< T > sleipnir::detail::PowExpression< T > sleipnir::detail::SignExpression sleipnir::detail::SinExpression sleipnir::detail::SinhExpression sleipnir::detail::SqrtExpression sleipnir::detail::TanExpression sleipnir::detail::TanhExpression sleipnir::detail::UnaryMinusExpression< T >

Public Member Functions

constexpr Expression ()=default
 
constexpr Expression (double value)
 
constexpr Expression (ExpressionPtr lhs)
 
constexpr Expression (ExpressionPtr lhs, ExpressionPtr rhs)
 
virtual ~Expression ()=default
 
constexpr bool IsConstant (double constant) const
 
virtual double Value (double lhs, double rhs) const =0
 
virtual ExpressionType Type () const =0
 
virtual double GradientValueLhs (double lhs, double rhs, double parentAdjoint) const
 
virtual double GradientValueRhs (double lhs, double rhs, double parentAdjoint) const
 
virtual ExpressionPtr GradientLhs (const ExpressionPtr &lhs, const ExpressionPtr &rhs, const ExpressionPtr &parentAdjoint) const
 
virtual ExpressionPtr GradientRhs (const ExpressionPtr &lhs, const ExpressionPtr &rhs, const ExpressionPtr &parentAdjoint) const
 

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
 
int32_t row = -1
 
ExpressionPtr adjointExpr
 
uint32_t refCount = 0
 Reference count for intrusive shared pointer.
 
std::array< ExpressionPtr, 2 > args {nullptr, nullptr}
 Expression arguments.
 

Friends

ExpressionPtr operator* (const ExpressionPtr &lhs, const ExpressionPtr &rhs)
 
ExpressionPtr operator/ (const ExpressionPtr &lhs, const ExpressionPtr &rhs)
 
ExpressionPtr operator+ (const ExpressionPtr &lhs, const ExpressionPtr &rhs)
 
ExpressionPtr operator- (const ExpressionPtr &lhs, const ExpressionPtr &rhs)
 
ExpressionPtr operator- (const ExpressionPtr &lhs)
 
ExpressionPtr operator+ (const ExpressionPtr &lhs)
 

Detailed Description

An autodiff expression node.

Constructor & Destructor Documentation

◆ Expression() [1/4]

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

Constructs a constant expression with a value of zero.

◆ Expression() [2/4]

constexpr sleipnir::detail::Expression::Expression ( double  value)
inlineexplicitconstexpr

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

Parameters
valueThe expression value.

◆ Expression() [3/4]

constexpr sleipnir::detail::Expression::Expression ( ExpressionPtr  lhs)
inlineexplicitconstexpr

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

Parameters
lhsUnary operator's operand.

◆ Expression() [4/4]

constexpr sleipnir::detail::Expression::Expression ( ExpressionPtr  lhs,
ExpressionPtr  rhs 
)
inlineconstexpr

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

Parameters
lhsBinary operator's left operand.
rhsBinary operator's right operand.

◆ ~Expression()

virtual sleipnir::detail::Expression::~Expression ( )
virtualdefault

Member Function Documentation

◆ GradientLhs()

◆ GradientRhs()

virtual ExpressionPtr sleipnir::detail::Expression::GradientRhs ( const ExpressionPtr lhs,
const ExpressionPtr rhs,
const ExpressionPtr parentAdjoint 
) const
inlinevirtual

Returns Variable adjoint of the right child expression.

Parameters
lhsLeft argument to binary operator.
rhsRight argument to binary operator.
parentAdjointAdjoint of parent expression.

Reimplemented in sleipnir::detail::BinaryMinusExpression< T >, sleipnir::detail::BinaryPlusExpression< T >, sleipnir::detail::PowExpression< T >, sleipnir::detail::DivExpression< T >, sleipnir::detail::MultExpression< T >, sleipnir::detail::HypotExpression, and sleipnir::detail::Atan2Expression.

◆ GradientValueLhs()

◆ GradientValueRhs()

virtual double sleipnir::detail::Expression::GradientValueRhs ( double  lhs,
double  rhs,
double  parentAdjoint 
) const
inlinevirtual

Returns double adjoint of the right child expression.

Parameters
lhsLeft argument to binary operator.
rhsRight argument to binary operator.
parentAdjointAdjoint of parent expression.

Reimplemented in sleipnir::detail::PowExpression< T >, sleipnir::detail::DivExpression< T >, sleipnir::detail::MultExpression< T >, sleipnir::detail::HypotExpression, sleipnir::detail::Atan2Expression, sleipnir::detail::BinaryMinusExpression< T >, and sleipnir::detail::BinaryPlusExpression< T >.

◆ IsConstant()

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

Returns true if the expression is the given constant.

Parameters
constantThe constant.

◆ Type()

◆ Value()

Friends And Related Symbol Documentation

◆ operator*

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]

Unary plus operator.

Parameters
lhsOperand of unary plus.

◆ operator+ [2/2]

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]

Unary minus operator.

Parameters
lhsOperand of unary minus.

◆ operator- [2/2]

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

Expression-Expression subtraction operator.

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

◆ operator/

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.

◆ 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.

◆ value

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

The value of the expression node.


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