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) |
Finish the preaccumulation region and perform the preaccumulation. See addOutput() for 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. |
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.