Expression Template

template <typename T, typename Derived>

Represents a mathematical expression in a type. Active data types, such as AReal and FReal, 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.

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>

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

static const bool isLiteral

True if type is an elementary AD type (e.g. AReal)

type nested_type

The underlying double type of the expression, e.g. double for AReal<double>, or AReal<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 for AReal<double>, and FReal<double> for AReal<FReal<double>> .

Last update: September 2022