Forward Mode Type
FReal defines an active data type for forward mode for the underlying type
T which tracks derivatives without tape. It is designed to behave exactly like the built-in type
double, with all mathematical operations defined for this custom type.
It consists of a value and a derivative, both of which are tracked through operations on this class. The derivative of at least one independent variable should be set to 1 before the computation starts to ensure derivative propagation to the outputs.
The value-type of this class, i.e.,
Constructors and Destructors¶
The constructors create new instances of this class.
(1) creates an instance from a value, as well as optionally sets its derivativ.
(3) copy or move from other values.
(4) creates a value from an expression template, evaluating the expression and recording both the result and the derivative of the right hand side expression. It gets triggered for example by expressions like this:
x is an instance of
(5) destroys the object.
These assignment operators for
FReal behave similar to the equivalent constructors above.
Values and Derivatives¶
T getValue() const returns the value as the underlying type (without tape information).
T getDerivative() const returns the derivative.
void setDerivative(const T& a) sets the derivative in the object. Typically this is called on independent variables before the operation is started (if not already initialised using the constructor).
T& value() and
const T& value() const return a reference to the underlying passive type value. This can be used to assign a value to the variable without affecting the derivative, as
x.value() = 1.2.
T& derivative() and
const T& derivative() const return a reference to the derivative value. This can be used to assign a value to it as well, as
x.derivative() = 1.0, which is equivalent to
setDerivative. It can also be used as a replacement for
FReal instances support all other mathematical arithmetic operations, such as
operator+= and friends. Also, since
FReal is an
Expression, all math functions defined for expressions also work on instances of this class.