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

typedef T value_type

The value-type of this class, i.e., T.

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.

Parameters:
const T &val = T()

Value to initialize the the instance with.

const T &der = T()

Derivative to initialize with (0 if not given).

FReal(const FReal &val)

Copy-constructor

Parameters:
const FReal &val

Value to initialize the instance with.

FReal(FReal &&o)

Move-constructor

Parameters:
FReal &&o

Other object to move from

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.

Parameters:
const T &val

Value to be assigned to this object.

Returns:

A reference to this

FReal &operator=(const FReal &val)

Copy-assign from another FReal object.

Parameters:
const FReal &val

Value to be assigned to this object.

Returns:

A reference to this

FReal &operator=(FReal &&val)

Move-assignment

Parameters:
FReal &&val

Value to be moved into this object

Returns:

A reference to this

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.

Parameters:
const T &a

The value to assign to the derivative.

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.


Last update: September 2022