Stores the Jacobian matrix for a code section. More...
#include <preaccumulationHelper.hpp>
Public Types | |
using | Gradient = typename Type::Gradient |
See LhsExpressionInterface. | |
using | Identifier = typename Type::Identifier |
See LhsExpressionInterface. | |
using | Position = typename Tape::Position |
See PositionalEvaluationTapeInterface. | |
using | Real = typename Type::Real |
See LhsExpressionInterface. | |
using | Tape = typename Type::Tape |
See LhsExpressionInterface. | |
using | Type = T_Type |
See PreaccumulationHelper. | |
Public Member Functions | |
template<typename... Inputs> | |
void | addInput (Inputs const &... inputs) |
Add multiple additional inputs. Inputs need to be of type Type . Called after start(). | |
template<typename... Outputs> | |
void | addOutput (Outputs &... outputs) |
Add multiple additional outputs. Outputs need to be of type Type . Called before finish(). | |
template<typename... Outputs> | |
void | finish (bool const storeAdjoints, Outputs &... outputs) |
template<typename... Outputs> | |
void | finishLocalAdjoints (Outputs &... outputs) |
template<typename... Outputs> | |
void | finishLocalAdjointsPreprocessTape (Outputs &... outputs) |
template<typename... Outputs> | |
void | finishLocalMappedAdjoints (Outputs &... outputs) |
PreaccumulationHelper () | |
Constructor. | |
template<typename... Inputs> | |
void | start (Inputs const &... inputs) |
Starts a preaccumulation region. Resets the internal state. See addInputs() for inputs. | |
Public Attributes | |
std::vector< Identifier > | inputData |
std::vector< Identifier > | outputData |
std::vector< Type * > | outputValues |
Protected Attributes | |
JacobianCountNonZerosRow< Real > | jacobian |
Jacobian for the preaccumulation. | |
Position | startPos |
Starting position for the region. | |
std::vector< Gradient > | storedAdjoints |
If adjoints of inputs should be stored, before the preaccumulation. | |
Stores the Jacobian matrix for a code section.
The preaccumulation of a code section corresponds to the process of replacing the recorded tape entries with the Jacobian matrix of that section. If the code part is defined by the function , then the Jacobian is computed by the Preaccumulation helper and stored on the tape.
The preaccumulation of a code part is beneficial if it is complicated to compute but has only a few inputs and outputs. If the computation requires 200 statements with a total of 600 arguments, the storage for this would be 7400 byte on a Jacobian tape. If the function has only two input arguments and two output arguments, the storage for the Jacobian matrix of this function would require 50 byte.
The procedure for the preaccumulation of a code section is as follows.
The preaccumulation helper can be used multiple times, the start routine resets the state such that multiple evaluations are possible. This improves the performance of the helper since stack allocations are only performed once.
T_Type | The CoDiPack type on which the evaluations take place. |
|
inline |
Finish the preaccumulation region and perform the preaccumulation. See addOutput()
for outputs. Not compatible with simultaneous thread-local preaccumulations with shared inputs. In this case, see finishLocalMappedAdjoints, finishLocalAdjointsPreprocessTape, and finishLocalAdjoints.
|
inline |
Finish the preaccumulation region and perform the preaccumulation. Uses local adjoints instead of adjoints from the tape. Behaves either like finishLocalMappedAdjoints or like finishLocalAdjointsPreprocessTape, depending on which is more efficient given the numbers of inputs and outputs. See addOutput()
for outputs.
|
inline |
Finish the preaccumulation region and perform the preaccumulation. Create a local adjoint vector instead of using adjoints from the tape. Edits the tape, remapping the identifiers to a contiguous range. More efficient than finishLocalMappedAdjoints if both the numbers of inputs and outputs are > 1. Behaves like finishLocalMappedAdjoints if the underlying tape does not support editing.
|
inline |
Finish the preaccumulation region and perform the preaccumulation. Creates a local map of adjoints instead of using adjoints from the tape. See addOutput()
for outputs.
std::vector<Identifier> codi::PreaccumulationHelper< T_Type, typename >::inputData |
List of input identifiers. Can be added manually after start() was called.
std::vector<Identifier> codi::PreaccumulationHelper< T_Type, typename >::outputData |
List of output identifiers. Can be added manually before finish() is called. Has to be in sync with outputValues.
std::vector<Type*> codi::PreaccumulationHelper< T_Type, typename >::outputValues |
List of output value pointers. Can be added manually before finish() is called. Has to be in sync with outputData.