CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
codi::DerivativeAccess< T_Type > Struct Template Reference

A helper class for the access of the various derivatives in higher order AD types. More...

#include <derivativeAccess.hpp>

Public Types

template<bool constant, size_t selectionDepth, size_t order, size_t l>
using SelectCompileTime = DerivativeAccessImpl::SelectCompileTime< Type, constant, selectionDepth, order, l >
 Helper for the compile time selection of derivatives.
 
template<bool constant, size_t selectionDepth>
using SelectRunTime = DerivativeAccessImpl::SelectRunTime< Type, constant, selectionDepth >
 Helper for the run time selection of derivatives.
 
using Type = T_Type
 See DerivativeAccess.
 

Static Public Member Functions

template<size_t order, size_t l, size_t selectionDepth = RealTraits::MaxDerivativeOrder<Type>()>
static SelectCompileTime< false, selectionDepth, order, l >::RType & derivative (Type &v)
 
template<size_t selectionDepth = RealTraits::MaxDerivativeOrder<Type>()>
static SelectRunTime< false, selectionDepth >::RType & derivative (Type &v, size_t order, size_t l)
 
template<size_t order, size_t l, size_t selectionDepth = RealTraits::MaxDerivativeOrder<Type>()>
static SelectCompileTime< true, selectionDepth, order, l >::RType const & derivative (Type const &v)
 
template<size_t selectionDepth = RealTraits::MaxDerivativeOrder<Type>()>
static SelectRunTime< true, selectionDepth >::RType const & derivative (Type const &v, size_t order, size_t l)
 
template<size_t order, typename Derivative , size_t selectionDepth = RealTraits::MaxDerivativeOrder<Type>()>
static void setAllDerivatives (Type &v, Derivative const &d)
 Compile time set of all derivatives of the same order. $order \in \{0, ..., selectionDepth\}$.
 
template<typename Derivative , size_t selectionDepth = RealTraits::MaxDerivativeOrder<Type>()>
static void setAllDerivatives (Type &v, size_t order, Derivative const &d)
 Run time set of all derivatives of the same order. $order \in \{0, ..., selectionDepth\}$.
 
template<size_t order, typename Derivative , size_t selectionDepth = RealTraits::MaxDerivativeOrder<Type>()>
static void setAllDerivativesForward (Type &v, Derivative const &d)
 
template<typename Derivative , size_t selectionDepth = RealTraits::MaxDerivativeOrder<Type>()>
static void setAllDerivativesForward (Type &v, size_t order, Derivative const &d)
 
template<size_t order, typename Derivative , size_t selectionDepth = RealTraits::MaxDerivativeOrder<Type>()>
static void setAllDerivativesReverse (Type &v, Derivative const &d)
 
template<typename Derivative , size_t selectionDepth = RealTraits::MaxDerivativeOrder<Type>()>
static void setAllDerivativesReverse (Type &v, size_t order, Derivative const &d)
 

Detailed Description

template<typename T_Type>
struct codi::DerivativeAccess< T_Type >

A helper class for the access of the various derivatives in higher order AD types.

A higher order derivative that is combined via the CoDiPack types has $2^n$ possible derivative values (including the primal value) where $n$ is the number of types that are nested. If a second and third order type are constructed via

Represents a concrete lvalue in the CoDiPack expression tree.
Definition: activeType.hpp:52

then the second order type t2s has 4 possible values $(n = 2)$ and the third order type has 8 possible values $(n = 3)$. The number of derivatives per derivative order can be computed via the binomial coefficient $\binom{n}{k}$ where $k$ is the derivative order. For a second order type this yields 1 derivative of order zero (the primal value), two derivatives of first order, and one derivative of second order. For a third order type this is 0:1, 1:3, 2:3, 3:1 (order:number).

Given the derivative order $k$ and the index of the derivative within that order $l\in\{0, ..., \binom{n}{k} - 1\}$, the algorithm in this class selects the corresponding derivative value.

The class provides methods for the run time selection of the derivatives. If these methods are used, then the AD types need to be defined such that all primal and derivative values have the same type. If this is not the case, then the compiler will show errors that it cannot convert a value.

The class provides methods for the compile time selection of the derivatives, too. These methods do not have the restriction that all the primal and derivative types need to have the same type. On the other hand, the usual compile time restrictions apply to the parameters of the templates, that is, they must be compile time constants. Also, the setDerivatives method which sets all derivatives of one order may not be used if different primal and gradient types are used. The provided objects must be convertible into all possible types that are used at the leaf points of the recursion.

The selection algorithm walks along the nodes in the nested classes. From the specified order and the derivative number $l$ the algorithm checks if the derivative $l$ is in the lower (value) or upper (gradient) branch of the nested classes. The value is compared against the number of derivatives of that order in the lower branch. If smaller, the lower branch is taken. If larger or equal, the upper branch is taken. For a third order type, the graph looks as follows.

t3s t2s t1s double | order index
|
,---o | 3 0
/ |
,o-----o | 2 2
/ |
/ ,---o | 2 1
/ / |
o----o-----o | 1 2
/ |
/ ,---o | 2 0
/ / |
/ ,o-----o | 1 1
/ / |
| / ,---o | 1 0
| / / |
o----o----o-----o | 0 0

The two columns at the end show the derivative order under the column 'order' and the index in that order class under the column 'index'. It can be seen that the different derivative values of the same order are not continuously ordered in the graph. For the 2nd order derivatives in the above example, the indices correspond to the following calls.

DA::derivative<2,0>(v) == v.value().gradient().gradient();
DA::derivative<2,1>(v) == v.gradient().value().gradient();
DA::derivative<2,2>(v) == v.gradient().gradient().value();
Template Parameters
T_TypeThe AD type for which the derivatives are selected. The type must implement LhsExpressionInterface.

Member Function Documentation

◆ derivative() [1/4]

template<typename T_Type >
template<size_t order, size_t l, size_t selectionDepth = RealTraits::MaxDerivativeOrder<Type>()>
static SelectCompileTime< false, selectionDepth, order, l >::RType & codi::DerivativeAccess< T_Type >::derivative ( Type v)
inlinestatic

Compile time selection of derivatives. $order \in \{0, ..., selectionDepth\}$. $l \in \{0 ...
(\binom{selectionDepth}{order} - 1)\}$.

◆ derivative() [2/4]

template<typename T_Type >
template<size_t selectionDepth = RealTraits::MaxDerivativeOrder<Type>()>
static SelectRunTime< false, selectionDepth >::RType & codi::DerivativeAccess< T_Type >::derivative ( Type v,
size_t  order,
size_t  l 
)
inlinestatic

Run time selection of derivatives. $order \in \{0, ..., selectionDepth\}$. $l \in \{0 ...
(\binom{selectionDepth}{order} - 1)\}$.

◆ derivative() [3/4]

template<typename T_Type >
template<size_t order, size_t l, size_t selectionDepth = RealTraits::MaxDerivativeOrder<Type>()>
static SelectCompileTime< true, selectionDepth, order, l >::RType const & codi::DerivativeAccess< T_Type >::derivative ( Type const &  v)
inlinestatic

Compile time selection of derivatives. $order \in \{0, ..., selectionDepth\}$. $l \in \{0 ...
(\binom{selectionDepth}{order} - 1)\}$.

◆ derivative() [4/4]

template<typename T_Type >
template<size_t selectionDepth = RealTraits::MaxDerivativeOrder<Type>()>
static SelectRunTime< true, selectionDepth >::RType const & codi::DerivativeAccess< T_Type >::derivative ( Type const &  v,
size_t  order,
size_t  l 
)
inlinestatic

Run time selection of derivatives. $order \in \{0, ..., selectionDepth\}$. $l \in \{0 ...
(\binom{selectionDepth}{order} - 1)\}$.

◆ setAllDerivativesForward() [1/2]

template<typename T_Type >
template<size_t order, typename Derivative , size_t selectionDepth = RealTraits::MaxDerivativeOrder<Type>()>
static void codi::DerivativeAccess< T_Type >::setAllDerivativesForward ( Type v,
Derivative const &  d 
)
inlinestatic

Compile time set of all derivatives in the primal value part of the same order. $order \in \{0, ..., selectionDepth\}$.

◆ setAllDerivativesForward() [2/2]

template<typename T_Type >
template<typename Derivative , size_t selectionDepth = RealTraits::MaxDerivativeOrder<Type>()>
static void codi::DerivativeAccess< T_Type >::setAllDerivativesForward ( Type v,
size_t  order,
Derivative const &  d 
)
inlinestatic

Run time set of all derivatives in the primal value part of the same order. $order \in \{0, ..., selectionDepth\}$.

◆ setAllDerivativesReverse() [1/2]

template<typename T_Type >
template<size_t order, typename Derivative , size_t selectionDepth = RealTraits::MaxDerivativeOrder<Type>()>
static void codi::DerivativeAccess< T_Type >::setAllDerivativesReverse ( Type v,
Derivative const &  d 
)
inlinestatic

Compile time set of all derivatives in the gradient part of the same order. $order \in \{0, ..., selectionDepth\}$.

◆ setAllDerivativesReverse() [2/2]

template<typename T_Type >
template<typename Derivative , size_t selectionDepth = RealTraits::MaxDerivativeOrder<Type>()>
static void codi::DerivativeAccess< T_Type >::setAllDerivativesReverse ( Type v,
size_t  order,
Derivative const &  d 
)
inlinestatic

Run time set of all derivatives in the gradient part of the same order. $order\in\{0, ..., selectionDepth\}$.


The documentation for this struct was generated from the following file: