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

Perform a primal reevaluation of the tape. More...

#include <primalEvaluationTapeInterface.hpp>

Inheritance diagram for codi::PrimalEvaluationTapeInterface< T_Real, T_Identifier, T_Position >:

Public Types

using Identifier = T_Identifier
 See PrimalEvaluationTapeInterface.
 
using Position = T_Position
 See PrimalEvaluationTapeInterface.
 
using Real = T_Real
 See PrimalEvaluationTapeInterface.
 
- Public Types inherited from codi::PositionalEvaluationTapeInterface< T_Position >
using Position = T_Position
 See PositionalEvaluationTapeInterface.
 

Interface definition

static bool constexpr HasPrimalValues = false
 True if the tape has primal values.
 
static bool constexpr RequiresPrimalRestore
 True if the primal state changes during a reverse or forward evaluation.
 
void evaluatePrimal (Position const &start, Position const &end)
 Perform a partly (forward) reevaluation of the primals in the tape. It has to hold start <= end.
 
void evaluatePrimal ()
 Perform a full (forward) reevaluation of the primals in the tape.
 
void setPrimal (Identifier const &identifier, Real const &gradient)
 Set primal value.
 
Real const & getPrimal (Identifier const &identifier) const
 Get primal value.
 
Realprimal (Identifier const &identifier)
 Writable reference to primal value.
 
Real const & primal (Identifier const &identifier) const
 Read only reference to primal value.
 
void revertPrimals (Position const &pos)
 Revert the primals to the state indicated by pos.
 

Additional Inherited Members

- 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_Real, typename T_Identifier, typename T_Position>
struct codi::PrimalEvaluationTapeInterface< T_Real, T_Identifier, T_Position >

Perform a primal reevaluation of the tape.

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

Whether the tape manages primal values is indicated by the static constant HasPrimalValues.

In a primal value tape, the correctness of the primal values is very important. The tapes should be programmed such that the primal values stored in the tape are always up to date with the state of the program. Only through user interaction this sync in states can be broken, but then the user should know what he is doing.

The primal evaluation is used to reevaluate the primal values stored in the tape for different values of the registered inputs. Note that this reevaluation follows the control flow that was observed during recording. The control flow statements themselves, e.g. if constructs or loops, are not treated by CoDiPack. The user cannot expect a reevaluation to choose different branches in if constructs or different numbers of loop iterations with respect to the code that was recorded.

Here is an example for a primal reevaluation (documentation/examples/primalEvaluationTapeInterface.cpp):

using Primal = typename Real::Real;
using Identifier = typename Real::Identifier;
using Tape = typename Real::Tape;
Tape& tape = Real::getTape();
Identifier x_i;
Identifier y_i;
// Recording
{
Real x = 10.0;
tape.setActive();
tape.registerInput(x);
x_i = x.getIdentifier();
Real y = 42.0 * x * x;
tape.registerOutput(y);
y_i = y.getIdentifier();
tape.setPassive();
}
// Reverse evaluation
tape.gradient(y_i) = 1.0;
tape.evaluate();
std::cout << "Gradient of dy/dx(10.0): " << tape.gradient(x_i) << std::endl;
// Primal reevaluation and reverse evaluation
for(int i = 0; i < 20; i += 1) {
// Reset the gradietn of x
tape.gradient(x_i) = 0.0;
Primal x_v = i;
tape.primal(x_i) = x_v;
tape.evaluatePrimal();
Primal y_v = tape.primal(y_i);
tape.gradient(y_i) = 1.0;
tape.evaluate();
std::cout << "Value of f(" << x_v << ") = " << y_v << ", Gradient of df/dx(" << x_v << ") = " << tape.gradient(x_i) << std::endl;
}
Template Parameters
T_RealThe computation type of a tape, usually chosen as ActiveType::Real.
T_IdentifierThe adjoint/tangent identification of a tape, usually chosen as ActiveType::Identifier.
T_PositionGlobal tape position, usually chosen as Tape::Position.

Member Data Documentation

◆ RequiresPrimalRestore

template<typename T_Real , typename T_Identifier , typename T_Position >
bool constexpr codi::PrimalEvaluationTapeInterface< T_Real, T_Identifier, T_Position >::RequiresPrimalRestore
staticconstexpr
Initial value:
=
false

True if the primal state changes during a reverse or forward evaluation.


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