CoDiPack  2.3.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
codi::TapeWriterInterface< T_Type > Struct Template Reference

The interface used by all the tape writers. The tape writers are used to generate text, binary, graphical or the math statement files from the current tape. The text and binary files can be used to restore a tape using the codi::TapeReaderInterface in a new context. The writers are supported for both Jacobian and primal value tapes. More...

#include <tapeReaderWriterInterface.hpp>

Inheritance diagram for codi::TapeWriterInterface< T_Type >:

Public Types

using EvalHandle = typename Tape::EvalHandle
 Evaluation handle used for primal value tapes.
 
using Identifier = typename Type::Identifier
 Identifier for the internal management, e.g. int.
 
using Real = typename Type::Real
 Primal computation type, e.g. double.
 
using Tape = typename Type::Tape
 The tape type that is to be written out.
 
using Type = T_Type
 The evaluation type.
 

Public Member Functions

virtual void finish ()
 After all the statements have been written, the finish method finalizes the writing process.
 
virtual void start (Tape &tape)
 Destructor.
 
virtual void writeLowLevelFunction (size_t &curLLFByteDataPos, char *dataPtr, size_t &curLLFInfoDataPos, Config::LowLevelFunctionToken *const tokenPtr, Config::LowLevelFunctionDataSize *const dataSizePtr)
 Used for statements that contain a low level function.
 
virtual void writeStatement (Identifier const &curLhsIdentifier, size_t &curJacobianPos, Real const *const rhsJacobians, Identifier const *const rhsIdentifiers, Config::ArgumentSize const &nJacobians)
 Called for each statement. The method writes the current statement to the file. This overload is used for the Jacobian writers.
 
virtual void writeStatement (WriteInfo const &info, Identifier const &curLhsIdentifier, Real const &primalValue, Config::ArgumentSize const &nPassiveValues, size_t const &curRhsIdentifiersPos, Identifier const *const rhsIdentifiers, size_t const &curPassiveValuePos, Real const *const passiveValues, size_t &curConstantPos, Real const *const constantValues, EvalHandle stmtEvalHandle)
 Called for each statement. The method writes the current statement to the file. This overload is used for the primal value writers and contains additional arguments, such as the WriteInfo.
 

Detailed Description

template<typename T_Type>
struct codi::TapeWriterInterface< T_Type >

The interface used by all the tape writers. The tape writers are used to generate text, binary, graphical or the math statement files from the current tape. The text and binary files can be used to restore a tape using the codi::TapeReaderInterface in a new context. The writers are supported for both Jacobian and primal value tapes.

The user does not access the methods of this interface directly, instead the standard steps are as follows:

1) Record the inputs and outputs of the tape in std::vectors.

2) Use the codi::createWriter() function with a fileName, the input and output vectors and the desired Codi::FileType to create an automatic writer.

3) Call the codi::ReadWriteTapeInterface::writeTape() method with the generated writer.

4) The codi::TapeWriterInterface::start() is called once, after which the relevant codi::TapeWriterInterface::writeStatement() method is called for each of the statements on the tape. After all the statements have been added, the codi::TapeWriterInterface::finish method() is called and the file has been generated.

std::vector inputs, outputs;
// **Follow the normal procedure to add statements to the tape, to register inputs and outputs, and to evaluate
// the tape.
// Generate a text writer for the current tape and call the write tape method to create the .txt file
tape.writeTape(codi::createWriter<Real>("example.txt", inputs, outputs, codi::FileType::Text));

The createWriter function does not have to be used. Writers can instead be created and managed manually. The manual writers are then passed to the writeTape method. The rest of the procedure remains the same.

std::vector inputs, outputs;
// **Follow the normal procedure to add statements to the tape, to register inputs and outputs, and to evaluate
// the tape.
// Manually create a binary writer for a Jacobian tape.
codi::JacobianBinaryWriter<Real> writerHandle{"example.dat", inputs, outputs};
// Generate a binary file for the current tape.
tape.writeTape(writerHandle);
Template Parameters
T_TypeThe CoDiPack type of the tape that is to be written out.

Member Function Documentation

◆ finish()

template<typename T_Type >
virtual void codi::TapeWriterInterface< T_Type >::finish ( )
inlinevirtual

◆ start()

template<typename T_Type >
virtual void codi::TapeWriterInterface< T_Type >::start ( Tape & tape)
inlinevirtual

Destructor.

Called once at the beginning of the tape write process. Should initialize all required data structures and files.

Reimplemented in codi::CommonTextTapeWriter< T_Type >, codi::JacobianBinaryTapeWriter< T_Type >, codi::JacobianTextTapeWriter< T_Type >, codi::PrimalBinaryTapeWriter< T_Type >, and codi::PrimalTextTapeWriter< T_Type >.

◆ writeStatement() [1/2]

template<typename T_Type >
virtual void codi::TapeWriterInterface< T_Type >::writeStatement ( Identifier const & curLhsIdentifier,
size_t & curJacobianPos,
Real const *const rhsJacobians,
Identifier const *const rhsIdentifiers,
Config::ArgumentSize const & nJacobians )
inlinevirtual

Called for each statement. The method writes the current statement to the file. This overload is used for the Jacobian writers.

Reimplemented in codi::JacobianGraphTapeWriter< T_Type >, codi::JacobianBinaryTapeWriter< T_Type >, and codi::JacobianTextTapeWriter< T_Type >.

◆ writeStatement() [2/2]

template<typename T_Type >
virtual void codi::TapeWriterInterface< T_Type >::writeStatement ( WriteInfo const & info,
Identifier const & curLhsIdentifier,
Real const & primalValue,
Config::ArgumentSize const & nPassiveValues,
size_t const & curRhsIdentifiersPos,
Identifier const *const rhsIdentifiers,
size_t const & curPassiveValuePos,
Real const *const passiveValues,
size_t & curConstantPos,
Real const *const constantValues,
EvalHandle stmtEvalHandle )
inlinevirtual

Called for each statement. The method writes the current statement to the file. This overload is used for the primal value writers and contains additional arguments, such as the WriteInfo.

Reimplemented in codi::PrimalGraphTapeWriter< T_Type >, codi::MathRepWriter< T_Type >, codi::PrimalBinaryTapeWriter< T_Type >, and codi::PrimalTextTapeWriter< T_Type >.


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