Goal: Restore a stored Primal tape
Prerequisite: Example 25 - Tape Writers
Full code:
#include <codi.hpp>
#include <iostream>
#include "../generated_files/primal_reuse_text.hpp"
int main(int nargs, char** args) {
const std::string directory = "documentation/generated_files/";
std::vector<typename Tape::EvalHandle> evalHandles = primal_reuse_textCreateEvalHandles<Tape>();
auto reader = codi::readTapeFile<Real>(directory + "primal_reuse_text.txt", evalHandles);
Tape& tape = reader->getTape();
std::vector<Identifier> const& x_id = reader->getInputs();
std::vector<Identifier> const& y_id = reader->getOutputs();
tape.gradient(y_id[0]) = 1.0;
tape.evaluate();
std::cout << "df/dx[0] = " << tape.getGradient(x_id[0]) << std::endl;
std::cout << "df/dx[1] = " << tape.getGradient(x_id[1]) << std::endl;
return 0;
}
RealReversePrimalIndexGen< double > RealReversePrimalIndex
Definition codi.hpp:208
The tape readers are used to restore a tape that was stored in a binary or a text format using the tape writers. The primal readers require the generated .hpp file to be included and the evaluation handles to be passed to the reader.