Adjoint Mode Type
template <typename T>
class AReal : public Expression<T, AReal<T>>¶
Defines and active data type version of the underlying type T that tracks derivatives on a tape for adjoint computation.
Derivatives will only be tracked on tape if the variable has been registered or is dependent on other registered variables. Hence creating and using variables without an active tape is not problematic.
- type tape_type¶
The type of the tape that is used to store operations on this class.
- type slot_type¶
The type used for storing this instance’s slot in the tape. This type is useful for checkpointing, where the slot of the inputs and outputs needs to be stored in the checkpoint in order to retrieve or increment their derivatives during adjoint computation.
Construct, Destruct, and Assign¶
- AReal(const T &val = T())¶
Constructs a new instance of this class, given its initial passive value.
Ensure that there is an active tape instance for the current thread, otherwise creating instances of this class results in undefined behaviour. This error condition is only checked in debug builds, where it throws an
NoTapeException. Release builds do not perform this check.
- AReal(const AReal &val)¶
- AReal(const Expression<T, Expr> &expr)¶
Construct from an expression. This constructor gets called from statements like this, where the right-hand side involves and active data type:
AReal<double> y = x + x*sin(x);
- AReal &operator=(const T &val)¶
Assign from a passive value.
- AReal &operator=(const AReal &val)¶
Assign from another AReal object.
- AReal &operator=(AReal &&val)¶
- AReal &operator=(const Expression<T, Expr> &expr)¶
Assign an expression
Values and Derivatives¶
- T getValue() const¶
Get the value of this object, as the underlying type.
The value of this object
- const T &value() const¶
Get a const reference to the value of this object.
The value of this object
- T &value()¶
Get a reference to the value of this object, i.e. it is assignable
Reference to the value of this object
- T getDerivative() const¶
Get the stored derivative of this object.
The derivative (adjoint) of this object
- const T &derivative() const¶
Get a const reference to the stored derivative of this object.
- T &derivative()¶
Get a reference to the stored derivative of this object, i.e., it is assignable.
A reference to the derivative (adjoint) of this object
- void setDerivative(const T &a)¶
Sets the derivative of this object. This is the same as calling
derivative() = a.
- bool shouldRecord() const¶
Checks if the variable has been registered with a tape and should therefore be recorded.
AReal supports all other mathematical arithmetic operations,
operator+= and friends.
AReal is an
all free math functions defined for expressions also work on instances of this class.