跳至内容

AD模式接口

XAD提供了一套接口结构,可以方便地访问不同自动微分模式所需的数据类型。这些是包含成员typedef声明的特征类,能够轻松访问特定模式下的类型。

例如,它们可以用作:

using mode = xad::adj<double>;
using adouble = mode::active_type;

// use active type in functions, etc.
adouble my_function(adouble x) {...}

mode::tape_type tape;    // setup tape

模式接口类

一阶

adj

一阶伴随模式接口类,其中T表示基础标量类型(例如double)。

fwd

一阶前向模式的接口类,其中T表示基础标量类型(例如double)。

二阶

fwd_adj

二阶正向伴随模式的接口类,其中T是基础标量类型(例如double)。

fwd_fwd

二阶前向模式(forward over forward mode)的模型接口类,其中T表示基础标量类型(例如double)。

adj_fwd

用于正向模式二阶伴随的Mode接口类,其中T是基础标量类型(例如double)。

adj_adj

二阶伴随模式覆盖伴随模式的接口类,其中T表示基础标量类型(例如double)。

类型成员

上述所有模式类都具有如下所述的类型成员。

template <typename T>
struct mode {
  typedef implementation_defined active_type;   // active data type
  typedef T                      passive_type;  // fully unwrapped passive type
  typedef implementation_defined tape_type;     // tape (void for forward mode)
  typedef passive_type           value_type;    // alias for passive_type

  // for second-order only
  typedef implementation_defined inner_type;    // first-order active type
};