38#include "primalBaseReaderWriter.hpp"
62 template<
typename T_Type>
65 using Tape =
typename Type::Tape;
68 using Real =
typename Type::Real;
75 std::vector<Identifier>
const& out)
80 if (Tape::TapeTypes::IsStaticIndexHandler) {
95 Real const*
const passiveValues,
Real const*
const constantValues,
119 FILE* filePrimalBin =
nullptr;
122 std::string fileNamePrimals = this->
modifyFileName(
"Primals.dat");
124 this->
openFile(filePrimalBin, fileNamePrimals,
"wb");
127 fwrite(&nPrimals,
sizeof(
size_t), 1, filePrimalBin);
128 for (
size_t indexCounter = 0; indexCounter < nPrimals; indexCounter++) {
129 Real const curPrimal = tape.getPrimal(indexCounter);
130 if (curPrimal != 0) {
131 fwrite(&indexCounter,
sizeof(
Identifier), 1, filePrimalBin);
132 fwrite(&curPrimal,
sizeof(
Real), 1, filePrimalBin);
136 fclose(filePrimalBin);
170 template<
typename T_Type>
173 using Tape =
typename Type::Tape;
175 using Real =
typename Type::Real;
180 : CommonBaseTapeReader<T_Type>(),
evalHandles(handles) {}
184 FILE* fileHandleReadBin =
nullptr;
203 if (Tape::TapeTypes::IsStaticIndexHandler) {
210 fread(lhsIdentifiers.data(),
sizeof(
Identifier), nOutputValues, fileHandleReadBin);
211 fread(primalValues.data(),
sizeof(
Real), nOutputValues, fileHandleReadBin);
220 fread(rhsIdentifiers.data(),
sizeof(
Identifier), nActiveValues, fileHandleReadBin);
221 fread(rhsPrimalValues.data(),
sizeof(
Real), nPassiveValues, fileHandleReadBin);
223 fread(constants.data(),
sizeof(
Real), nConstants, fileHandleReadBin);
226 fread(&evalHandleKey,
sizeof(
EvalHandleKey), 1, fileHandleReadBin);
227 this->
tape.createStatementManual(nOutputValues, lhsIdentifiers.data(), primalValues.data(), nActiveValues,
228 rhsIdentifiers.data(), nPassiveValues, rhsPrimalValues.data(), nConstants,
232 fclose(fileHandleReadBin);
237 FILE* filePrimalBin =
nullptr;
246 fread(&nPrimals,
sizeof(
size_t), 1, filePrimalBin);
250 while (fread(&curIdentifier,
sizeof(
Identifier), 1, filePrimalBin) == 1) {
251 fread(&curPrimal,
sizeof(
Real), 1, filePrimalBin);
252 this->
tape.setPrimal(curIdentifier, curPrimal);
#define CODI_Unlikely
Declare unlikely evaluation of an execution path.
Definition config.h:408
#define CODI_Likely
Declare likely evaluation of an execution path.
Definition config.h:406
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:96
size_t constexpr StatementLowLevelFunctionTag
Statement tag for low level functions.
Definition config.h:126
size_t constexpr MaxArgumentSize
Maximum number of arguments in a statement.
Definition config.h:120
uint8_t ArgumentSize
Type for the number of arguments in statements.
Definition config.h:117
size_t constexpr StatementInputTag
Tag for statements that are inputs. Used in linear index management context.
Definition config.h:123
CoDiPack - Code Differentiation Package.
Definition codi.hpp:94
@ PrimalSize
[A: RW] Number of primal vector entries in primal value tapes.
Definition tapeParameters.hpp:63
size_t EvalHandleKey
Key for the evalHandle lookup.
Definition tapeReaderWriterInterface.hpp:44
Tape tape
The newly resorted tape.
Definition commonReaderWriterBase.hpp:153
Identifier largestIndex
The largest index on the stored tape.
Definition commonReaderWriterBase.hpp:155
void restoreIoBinary()
Restore the IO for the binary readers.
Definition commonReaderWriterBase.hpp:180
void printIoBinary(Tape &tape)
Generate the IO file in a binary format.
Definition commonReaderWriterBase.hpp:117
std::string fileName
The base file name provided by the user.
Definition commonReaderWriterBase.hpp:51
std::string modifyFileName(std::string const &suffix)
Remove the file extension and replace it with a new suffix.
Definition commonReaderWriterBase.hpp:59
void openFile(FILE *&fileHandle, std::string const &name, std::string const &mode)
Definition commonReaderWriterBase.hpp:67
void generateHandleCreatorFile()
This method is used to generate an .hpp file which creates the necessary EvalHandles in the reading p...
Definition primalBaseReaderWriter.hpp:78
PrimalBaseTapeWriter(std::string const &name, std::vector< Identifier > const &in, std::vector< Identifier > const &out)
Constructor.
Definition primalBaseReaderWriter.hpp:68
size_t getEvalHandleIndex(EvalHandle const evalHandle, std::string const &evalStatement)
Get the index for an evalHandle.
Definition primalBaseReaderWriter.hpp:118
typename Type::Real Real
See TapeReaderInterface.
Definition primalBinaryReaderWriter.hpp:175
typename Type::Identifier Identifier
See TapeReaderInterface.
Definition primalBinaryReaderWriter.hpp:174
T_Type Type
See TapeReaderInterface.
Definition primalBinaryReaderWriter.hpp:172
typename Type::Tape Tape
See TapeReaderInterface.
Definition primalBinaryReaderWriter.hpp:173
void restorePrimals()
Read and record the primal values from the sparse primal vector stored in "filename"Primals....
Definition primalBinaryReaderWriter.hpp:236
std::vector< typename Tape::EvalHandle > evalHandles
Definition primalBinaryReaderWriter.hpp:177
void readFile(std::string const &name)
This method uses the the fileName to reproduce a valid tape.
Definition primalBinaryReaderWriter.hpp:183
PrimalBinaryTapeReader(std::vector< typename Tape::EvalHandle > const &handles)
Constructor.
Definition primalBinaryReaderWriter.hpp:179
PrimalBinaryTapeWriter(std::string const &name, std::vector< Identifier > const &in, std::vector< Identifier > const &out)
Constructor.
Definition primalBinaryReaderWriter.hpp:74
typename Type::Tape Tape
See TapeWriterInterface.
Definition primalBinaryReaderWriter.hpp:65
void printPrimals(Tape &tape)
Print the primal vector in sparse vector representation.
Definition primalBinaryReaderWriter.hpp:118
typename Type::Identifier Identifier
See TapeWriterInterface.
Definition primalBinaryReaderWriter.hpp:67
FILE * fileHandleBin
File handle.
Definition primalBinaryReaderWriter.hpp:71
T_Type Type
See TapeWriterInterface.
Definition primalBinaryReaderWriter.hpp:64
typename Type::Real Real
See TapeWriterInterface.
Definition primalBinaryReaderWriter.hpp:68
void writeStatement(WriteInfo const &info, Identifier const *lhsIdentifiers, Real const *primalValues, Config::ArgumentSize const &nPassiveValues, Identifier const *const rhsIdentifiers, Real const *const passiveValues, Real const *const constantValues, EvalHandle stmtEvalHandle)
Called for each statement. The method writes the current statement to the file. This overload is used...
Definition primalBinaryReaderWriter.hpp:93
void start(Tape &tape)
Destructor.
Definition primalBinaryReaderWriter.hpp:79
void finish()
After all the statements have been written, the finish method finalizes the writing process.
Definition primalBinaryReaderWriter.hpp:140
typename Tape::EvalHandle EvalHandle
See TapeWriterInterface.
Definition primalBinaryReaderWriter.hpp:69
This class is used during the writing process of a primal value tape. The WriteInfo is returned by St...
Definition tapeReaderWriterInterface.hpp:69
size_t numberOfActiveArguments
Number of active arguments.
Definition tapeReaderWriterInterface.hpp:71
std::string stmtExpression
Used to generate a .hpp file for reading back a primal value tape.
Definition tapeReaderWriterInterface.hpp:73
size_t numberOfOutputArguments
Number of output arguments.
Definition tapeReaderWriterInterface.hpp:70
size_t numberOfConstantArguments
Number of constant arguments.
Definition tapeReaderWriterInterface.hpp:72