Forward Mode Type FReal
¶
Overview¶
-
template <typename T>
class FReal : public Expression<T, FReal<T>>¶ Defines and active data type version of the underlying type T that tracks derivatives for forward mode differentiation (without tape)
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.
Members¶
Types¶
Construct, Destruct, and Assign¶
- FReal(const T &val = T(), const T &der = T())¶
Constructs a new instance of this class, given its initial passive value and derivative.
- FReal(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:
FReal<double> y = x + x * sin(x);
- Parameters:¶
- const Expression<T, Expr> &expr¶
The expression to construct from
- FReal &operator=(const T &val)¶
Assign from a passive value. Sets the value to
val
and the derivative to zero.
- FReal &operator=(const Expression<T, Expr> &expr)¶
Assign an expression
- Parameters:¶
- const Expression<T, Expr> &expr¶
Expression to be assigned to this object.
- Returns:¶
A reference to
this
Values and Derivatives¶
- T getValue() const¶
Get the value of this object, as the underlying type.
- Returns:¶
The value of this object
- const T &value() const¶
Get a const reference to the value of this object.
- Returns:¶
The value of this object
- T &value()¶
Get a reference to the value of this object, i.e. it is assignable
- Returns:¶
Reference to the value of this object
- T getDerivative() const¶
Get the stored derivative of this object.
- Returns:¶
The derivative stored in this object
- const T &derivative() const¶
Get a const reference to the stored derivative of this object.
- Returns:¶
The derivative stored in this object
- T &derivative()¶
Get a reference to the stored derivative of this object, i.e., it is assignable.
- Returns:¶
A reference to the derivative in this object
- void setDerivative(const T &a)¶
Sets the derivative of this object. This is the same as calling
derivative() = a
.
Other Operations¶
In addition, FReal
supports all other mathematical arithmetic operations,
such as operator+=
and friends.
Also, as FReal
is an Expression
,
all free math functions defined for expressions also work on instances of this class.
See also