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

Allows user defined vectors for the forward and adjoint evaluation. More...

#include <customAdjointVectorEvaluationTapeInterface.hpp>

Inheritance diagram for codi::CustomAdjointVectorEvaluationTapeInterface< T_Position >:

Public Types

using Position = T_Position
 See CustomAdjointVectorEvaluationTapeInterface.
 
- Public Types inherited from codi::ForwardEvaluationTapeInterface< T_Position >
using Position = T_Position
 See ForwardEvaluationTapeInterface.
 
- Public Types inherited from codi::PositionalEvaluationTapeInterface< T_Position >
using Position = T_Position
 See PositionalEvaluationTapeInterface.
 

Public Member Functions

Interface definition
template<typename Adjoint >
void evaluate (Position const &start, Position const &end, Adjoint *data)
 Perform a reverse evaluation for a part of the tape. It hast to hold start >= end.
 
template<typename Adjoint >
void evaluateForward (Position const &start, Position const &end, Adjoint *data)
 Perform a forward evaluation of a part of the tape. It has to hold start <= end.
 
- Public Member Functions inherited from codi::ForwardEvaluationTapeInterface< T_Position >
void evaluateForward (Position const &start, Position const &end, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
 Perform a forward evaluation of a part of the tape. It has to hold start <= end.
 
void evaluateForward (AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
 Perform a forward evaluation of the full tape.
 
- Public Member Functions inherited from codi::PositionalEvaluationTapeInterface< T_Position >
void evaluate (Position const &start, Position const &end, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
 Perform a reverse evaluation for a part of the tape. It hast to hold start >= end.
 
void clearAdjoints (Position const &start, Position const &end, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
 Clear all adjoints that would be set in a tape evaluation from start to end. It has to hold start >= end.
 
Position getPosition () const
 Current position of the tape.
 
Position getZeroPosition () const
 Initial position of the tape.
 
void resetTo (Position const &pos, bool resetAdjoints=true, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
 Reset the tape to the provided position.
 

Detailed Description

template<typename T_Position>
struct codi::CustomAdjointVectorEvaluationTapeInterface< T_Position >

Allows user defined vectors for the forward and adjoint evaluation.

See Tape Interface Design for a general overview of the tape interface design in CoDiPack.

The two additional evaluate methods allow for the evaluation of the tape with a custom adjoint vector. The type of the vector must support the following operators:

Here is an example for an evaluation with a custom adjoint vector (documentation/examples/customAdjointVectorEvaluationTapeInterface.cpp):

using Tape = typename Real::Tape;
Tape& tape = Real::getTape();
// Recording
Real x = 10.0;
tape.setActive();
tape.registerInput(x);
Real y1 = 42.0 * x * x;
Real y2 = 20.0 * x * x * x;
tape.registerOutput(y1);
tape.registerOutput(y2);
tape.setPassive();
// Reverse evaluation
size_t adjointSize = tape.getParameter(codi::TapeParameters::LargestIdentifier);
codi::Direction<double, 2>* adjoints = new codi::Direction<double, 2>[adjointSize + 1];
adjoints[y1.getIdentifier()] = {1.0, 0.0};
adjoints[y2.getIdentifier()] = {0.0, 1.0};
tape.evaluate(tape.getPosition(), tape.getZeroPosition(), adjoints); // Full tape evaluation
std::cout << "Gradient of dy1/dx: " << adjoints[x.getIdentifier()][0] << std::endl;
std::cout << "Gradient of dy2/dx: " << adjoints[x.getIdentifier()][1] << std::endl;
delete [] adjoints;
RealReverseGen< double > RealReverse
Definition: codi.hpp:120
@ LargestIdentifier
[A: R] Largest identifier distributed by the index manger.
Identifier & getIdentifier()
Definition: activeTypeBase.hpp:156
Represents a concrete lvalue in the CoDiPack expression tree.
Definition: activeType.hpp:52
static Tape & getTape()
Get a reference to the tape which manages this expression.
Definition: activeType.hpp:99
T_Tape Tape
See ActiveType.
Definition: activeType.hpp:55
Fixed size vector mode implementation.
Definition: direction.hpp:57
Template Parameters
T_PositionGlobal tape position, usually chosen as Tape::Position.

Member Function Documentation

◆ evaluate()

template<typename T_Position >
template<typename Adjoint >
void codi::CustomAdjointVectorEvaluationTapeInterface< T_Position >::evaluate ( Position const &  start,
Position const &  end,
Adjoint *  data 
)

Perform a reverse evaluation for a part of the tape. It hast to hold start >= end.

Automatic adjoints management involves bounds checking, resizing, and locking, see AdjointsManagement for details.

Template Parameters
AdjointSee CustomAdjointVectorEvaluationTapeInterface documentation.

◆ evaluateForward()

template<typename T_Position >
template<typename Adjoint >
void codi::CustomAdjointVectorEvaluationTapeInterface< T_Position >::evaluateForward ( Position const &  start,
Position const &  end,
Adjoint *  data 
)

Perform a forward evaluation of a part of the tape. It has to hold start <= end.

Automatic adjoints management involves bounds checking, resizing, and locking, see AdjointsManagement for details.

Template Parameters
AdjointSee CustomAdjointVectorEvaluationTapeInterface documentation.

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