表达式¶
表达式模板¶
表示某种类型中的数学表达式。动态数据类型,如AReal和FReal,以及所有数学表达式都继承自该类。所有数学运算都定义在此类型上,而非任何特定的派生类。
派生类通常对用户透明创建。
请注意,该类使用了CRTP模式,其中Derived是派生类本身,这样就可以使用静态多态性。
所有在C++中定义的全局算术运算都针对Expression进行了专门化处理,因此可以无缝地用XAD中的活动数据类型替换double或float。这也包括比较运算。
另请参阅
表达式特性¶
XAD还定义了表达式特征,用于在模板化上下文中查找关于表达式的信息。这通常仅在需要添加处理XAD表达式的自定义函数时才需要。
Direction 枚举类型¶
该枚举表示与类型相关的算法微分方向。
enum Direction {
DIR_NONE, // Not an algorithmic differentiation type
DIR_FORWARD, // Forward mode AD type
DIR_REVERSABLE // Reverse mode AD type
};
ExprTraits¶
这是获取AD类型信息的主要特征类:
template <typename T>
struct ExprTraits {
static const bool isExpr; // true if an expression of XAD active type
static const int numVariables; // Number of variables in an expression
static const bool isForward; // true if forward-mode AD
static const bool isReverse; // true if reverse-mode AD
static const bool isLiteral; // true if it's an elementary XAD active type
// and not an expression
static const Direction direction; // direction of the expression or type
typedef ... nested_type; // underlying type of the expression
// e.g. double for AReal<double>
typedef ... value_type; // the base active type of a more
// complex expression template
typedef ... scalar_type; // Type when unwrapping a higher order
// expression, e.g. FReal<double> for
// an expression of AReal<FReal<double>>
};