38#include "../../expressions/lhsExpressionInterface.hpp"
39#include "../../misc/exceptions.hpp"
41#include "../data/position.hpp"
42#include "../interfaces/externalFunctionTapeInterface.hpp"
43#include "../misc/vectorAccessInterface.hpp"
44#include "lowLevelFunctionEntry.hpp"
53 void* adjointInterface);
117 template<
typename T_Tape>
123 using Real =
typename Tape::Real;
169 "Calling an external function in reverse mode without providing a reverse evaluation function.");
179 "Calling an external function in forward mode without providing a forward evaluation function.");
188 CODI_EXCEPTION(
"Calling an external function in primal mode without providing a primal evaluation function.");
198 "Calling an external function for iteration of inputs without providing an iteration function.");
208 "Calling an external function for iteration of outputs without providing an iteration function.");
223 template<
typename T_Tape,
typename T_Real,
typename T_Identifier>
279 tape.pushLowLevelFunction(token,
sizeof(
ExtFunc), data);
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:469
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:97
#define CODI_T(...)
Abbreviation for CODI_TEMPLATE.
Definition macros.hpp:117
uint16_t LowLevelFunctionToken
Token type for low level functions in the tapes.
Definition config.h:108
CoDiPack - Code Differentiation Package.
Definition codi.hpp:97
inlinevoid CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:55
Definition byteDataView.hpp:51
inlineT * read(size_t size)
Read an array of length size of types T.
Definition byteDataView.hpp:98
inlineT * write(T const &data)
Write a single entry of type T.
Definition byteDataView.hpp:132
void(*)(void *id, void *userData) IterCallbackUntyped
Untyped callback function for id iteration.
Definition externalFunction.hpp:56
ExternalFunctionInternalData(CallFunctionUntyped funcReverse, CallFunctionUntyped funcForward, CallFunctionUntyped funcPrimal, DeleteFunctionUntyped funcDelete, IterateIdsFunctionUntyped funcIterIn, IterateIdsFunctionUntyped funcIterOut, void *data)
Constructor.
Definition externalFunction.hpp:84
IterateIdsFunctionUntyped funcIterIn
Iterate over inputs.
Definition externalFunction.hpp:64
void(*)(void *tape, void *data, void *adjointInterface) CallFunctionUntyped
Call function definition.
Definition externalFunction.hpp:52
ExternalFunctionInternalData()
Constructor.
Definition externalFunction.hpp:72
CallFunctionUntyped funcForward
Forward evaluation function pointer.
Definition externalFunction.hpp:61
DeleteFunctionUntyped funcDelete
User data deletion function pointer.
Definition externalFunction.hpp:63
void(*)(void *tape, void *data, IterCallbackUntyped callback, void *userData) IterateIdsFunctionUntyped
Iterate ids function definition.
Definition externalFunction.hpp:57
void * data
User data pointer.
Definition externalFunction.hpp:67
CallFunctionUntyped funcReverse
Reverse evaluation function pointer.
Definition externalFunction.hpp:60
IterateIdsFunctionUntyped funcIterOut
Iterate over outputs.
Definition externalFunction.hpp:65
CallFunctionUntyped funcPrimal
Primal evaluation function pointer.
Definition externalFunction.hpp:62
void(*)(void *tape, void *data) DeleteFunctionUntyped
Delete function definition.
Definition externalFunction.hpp:54
Low level function entry implementation for external functions.
Definition externalFunction.hpp:224
inlinestatic LowLevelFunctionEntry< Tape, Real, Identifier > create()
Create the function entry for the tape registration.
Definition externalFunction.hpp:285
T_Tape Tape
See ExternalFunctionLowLevelEntryMapper.
Definition externalFunction.hpp:225
inlinestatic void store(Tape &tape, Config::LowLevelFunctionToken token, ExtFunc const &extFunc)
Store an external function on the tape.
Definition externalFunction.hpp:277
inlinestatic void del(Tape *tape, ByteDataView &data)
Recovers the external function data and calls deleteData on it.
Definition externalFunction.hpp:255
inlinestatic void iterateInputs(Tape *tape, ByteDataView &data, IterCallback func, void *userData)
Iterate over the inputs of the external function. func is called for each input with userData.
Definition externalFunction.hpp:261
inlinestatic void forward(Tape *tape, ByteDataView &data, VectorAccess *access)
Recovers the external function data and calls evaluateForward on it.
Definition externalFunction.hpp:237
typename LowLevelFunctionEntry< T_Tape, T_Real, T_Identifier >::IterCallback IterCallback
See LowLevelFunctionEntry.
Definition externalFunction.hpp:230
T_Identifier Identifier
See ExternalFunctionLowLevelEntryMapper.
Definition externalFunction.hpp:227
inlinestatic void iterateOutputs(Tape *tape, ByteDataView &data, IterCallback func, void *userData)
Iterate over the outputs of the external function. func is called for each output with userData.
Definition externalFunction.hpp:269
ExternalFunction< Tape > ExtFunc
Definition externalFunction.hpp:232
T_Real Real
See ExternalFunctionLowLevelEntryMapper.
Definition externalFunction.hpp:226
inlinestatic void reverse(Tape *tape, ByteDataView &data, VectorAccess *access)
Recovers the external function data and calls evaluateReverse on it.
Definition externalFunction.hpp:249
inlinestatic void primal(Tape *tape, ByteDataView &data, VectorAccess *access)
Recovers the external function data and calls evaluatePrimal on it.
Definition externalFunction.hpp:243
VectorAccessInterface< Real, Identifier > VectorAccess
Shortcut for VectorAccessInterface.
Definition externalFunction.hpp:234
Add user defined functions to the tape evaluation.
Definition externalFunctionTapeInterface.hpp:76
User-defined evaluation functions for the taping process.
Definition externalFunction.hpp:118
typename Tape::Real Real
See FullTapeInterface.
Definition externalFunction.hpp:123
T_Tape Tape
See ExternalFunction.
Definition externalFunction.hpp:121
void evaluatePrimal(Tape *tape, VectorAccess *adjointInterface) const
Calls the primal function if not nullptr, otherwise throws a CODI_EXCEPTION.
Definition externalFunction.hpp:184
void deleteData(Tape *tape)
Calls the delete function if not nullptr.
Definition externalFunction.hpp:156
ExternalFunction(CallFunction funcReverse, CallFunction funcForward, CallFunction funcPrimal, void *data, DeleteFunction funcDelete, IterateIdsFunction funcIterIn, IterateIdsFunction funcIterOut)
Any arguments can be nullptr if not required.
Definition externalFunction.hpp:138
typename Tape::Identifier Identifier
See FullTapeInterface.
Definition externalFunction.hpp:124
static ExternalFunction create(CallFunction funcReverse, void *data, DeleteFunction funcDelete, CallFunction funcForward=nullptr, CallFunction funcPrimal=nullptr, IterateIdsFunction funcIterIn=nullptr, IterateIdsFunction funcIterOut=nullptr)
Helper function for the creation of an ExternalFunction object.
Definition externalFunction.hpp:148
void evaluateReverse(Tape *tape, VectorAccess *adjointInterface) const
Calls the reverse function if not nullptr, otherwise throws a CODI_EXCEPTION.
Definition externalFunction.hpp:164
void evaluateForward(Tape *tape, VectorAccess *adjointInterface) const
Calls the forward function if not nullptr, otherwise throws a CODI_EXCEPTION.
Definition externalFunction.hpp:174
VectorAccessInterface< Real, Identifier > VectorAccess
Definition externalFunction.hpp:126
void(*)(Tape *tape, void *data, IterCallback callback, void *userData) IterateIdsFunction
Iterate ids function definition.
Definition externalFunction.hpp:134
typename LowLevelFunctionEntry< Tape, Real, Identifier >::IterCallback IterCallback
Callback for iterate ids function.
Definition externalFunction.hpp:128
void iterateInputs(Tape *tape, IterCallback func, void *userData) const
Calls the iterate inputs function if not nullptr, otherwise throws a CODI_EXCEPTION.
Definition externalFunction.hpp:193
void iterateOutputs(Tape *tape, IterCallback func, void *userData) const
Calls the iterate inputs function if not nullptr, otherwise throws a CODI_EXCEPTION.
Definition externalFunction.hpp:203
void(*)(Tape *tape, void *data) DeleteFunction
Delete function definition.
Definition externalFunction.hpp:133
void(*)(Tape *tape, void *data, VectorAccess *adjointInterface) CallFunction
Call function definition.
Definition externalFunction.hpp:131
Low level function entry on the tape. See LowLevelFunctionTapeInterface for details.
Definition lowLevelFunctionEntry.hpp:69
void(*)(Identifier *id, void *userData) IterCallback
Callback function for the identifier iteration.
Definition lowLevelFunctionEntry.hpp:81
Unified access to the adjoint vector and primal vector in a tape evaluation.
Definition vectorAccessInterface.hpp:94