Add user defined functions to the tape evaluation. More...
#include <externalFunctionTapeInterface.hpp>
Public Types | |
using | Gradient = T_Gradient |
See ExternalFunctionTapeInterface. | |
using | Identifier = T_Identifier |
See ExternalFunctionTapeInterface. | |
using | Real = T_Real |
See ExternalFunctionTapeInterface. | |
Public Member Functions | |
Interface definition | |
template<typename Lhs , typename Tape > | |
Real | registerExternalFunctionOutput (LhsExpressionInterface< Real, Gradient, Tape, Lhs > &value) |
void | pushExternalFunction (ExternalFunction< ExternalFunctionTapeInterface > const &extFunc) |
Add user defined functions to the tape evaluation.
See Tape Interface Design for a general overview of the tape interface design in CoDiPack.
External functions allow the user to evaluate custom operations during a tape evaluation. Each external function has pointers for the reverse, forward and primal evaluation of a tape. A function pointer may be null if the corresponding mode is not called on the tape. Otherwise, if the corresponding pointer is null and the corresponding mode is called on the tape, then a CODI_EXCEPTION is thrown.
What kind of operations are evaluated in the external function is up to the user. They are usually used to define derivative computations for libraries that cannot be differentiated with operator overloading.
Variables that are outputs of external functions have to be registered with registerExternalFunctionOutput. This will ensure that the variable is considered as active in CoDiPack. For primal value tapes, the return value of this function provides the old value stored under the identifier that the variable has received. This old value has to be restored with a call to adjointInterface.setPrimal() during the evaluation of the external function in reverse mode.
Here is an example (documentation/examples/externalFunctionTapeInterface.cpp):
T_Real | The computation type of a tape, usually chosen as ActiveType::Real. |
T_Gradient | The gradient type of a tape, usually chosen as ActiveType::Gradient. |
T_Identifier | The adjoint/tangent identification type of a tape, usually chosen as ActiveType::Identifier. |
void codi::ExternalFunctionTapeInterface< T_Real, T_Gradient, T_Identifier >::pushExternalFunction | ( | ExternalFunction< ExternalFunctionTapeInterface< T_Real, T_Gradient, T_Identifier > > const & | extFunc | ) |
Push an external function to the tape.
The external function class can be created via the helper ExternalFunction::create.
Real codi::ExternalFunctionTapeInterface< T_Real, T_Gradient, T_Identifier >::registerExternalFunctionOutput | ( | LhsExpressionInterface< Real, Gradient, Tape, Lhs > & | value | ) |
Register an external function output on the tape.
Lhs | Class that implements the LhsExpressionInterface. See also LhsExpressionInterface. |
Tape | Tape implementation used in the LhsExpressionInterface. See also LhsExpressionInterface. |