Expressions¶
Expression Template¶
-
template <typename T, typename Derived>
class Expression¶ Represents a mathematical expression in a type. Active data types, such as
AReal
andFReal
, as well as all mathematical expressions inherit from this class. Therefore all mathematical operations are defined on this type, rather than any specific derived class.The derived classes are typically created transparently to the user.
Note that this class uses the CRTP pattern, where
Derived
is the derived class itself, so that static polymorphism can be used.
All global arithmetic operations defined in C++ are specialized
for Expression
,
so that double
or float
can be replaced seamlessly with a XAD data type.
This also includes comparisons.
See also
Expression Traits¶
XAD also defines expression traits to find out information about expressions in a templated context. This is typically only needed when custom functions dealing with the XAD expressions are added.
- enum Direction¶
Enum to indicate the direction of algorithmic differentiation associated with a type.
- enumerator DIR_NONE¶
Not an algorithmic differentiation type
- enumerator DIR_FORWARD¶
Forward mode AD type
- enumerator DIR_REVERSE¶
Reverse mode AD type
-
template <typename T>
class ExprTraits¶ Main traits class to find out information about an expression type.
- static const bool isExpr¶
True if the type is in fact an expression (or any XAD active variable)
- static const int numVariables¶
Number of variables that are port of the expression
- static const bool isForward¶
Boolean to represent if forward-mode AD
- static const bool isReverse¶
Boolean to represent if adjoint mode AD
- type nested_type¶
The underlying double type of the expression, e.g.
double
forAReal<double>
, orAReal<FReal<double>>
(unwrapping all layers)
- type value_type¶
The underlying active type of the expression, e.g.
AReal<double>
for a complex expression involving reverse mode active variables.
- type scalar_type¶
The scalar type of the expression, unwrapping one layer in case of higher-order derivatives. For example, returns
double
forAReal<double>
, andFReal<double>
forAReal<FReal<double>>
.