Goal: Restore a stored Jacobian tape
Prerequisite: Example 25 - Tape Writers
Full code:
#include <codi.hpp>
#include <iostream>
int main(int nargs, char** args) {
const std::string directory = "documentation/generated_files/";
auto reader = codi::readTapeFile<Real>(directory + "jacobian_linear_text.txt");
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;
}
The tape readers are used to restore a tape that was stored in a binary or a text format using the tape writers. The process for the Jacobian and primal value reading is slightly different.