Fast gradient evaluation in C++ based on Expression Templates.
C++ C Makefile Shell
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
tests Update to Copyright headers. Apr 28, 2017
.travis.yml Travis ci update. Mar 24, 2016
Doxyfile Updated version to 1.4.1. Sep 26, 2017


CoDiPack (Code Differentiation Package) is a tool for gradient evaluation in computer programs. It supports the features:

  • Forward mode of Algorithmic Differentiation(AD)
  • Reverse mode of Algorithmic Differentiation(AD)
  • Different tape implementations
  • An AdjointMPI interface
  • External functions
  • Higher order derivatives

The design principle for CoDiPack is that it is easy to use. However, it also gives experienced AD developers the full access to all the data structures.

The Scientific Computing Group at the TU Kaiserslautern develops CoDiPack and will enhance and extend CoDiPack in the future. There is a newsletter available at and if you want to contact us please write a mail to

Build Status


CoDiPack is a header only library. The only file the user needs to include is codi.hpp. The only other requirement is a c++11 compliant compiler where one usually needs to specify '--std=c++11' in the compiler arguments. CoDiPack is tested with gcc and the intel compiler.

The file codi.hpp defines the datatypes RealForward, RealReverse, RealReverseUnchecked and several others. The RealForward type implements the forward mode of AD and the RealReverse type implements the reverse mode of AD. The third type is also an implementation of the reverse mode of AD but it should only be used by experienced users. For each type there is also a type with single precession e.g. RealForwardFloat.

For further details please visit our CoDiPack web page.

Miscellaneous information

Debugging with gdb

The ActiveReal type contains the tape as a static member. GDB prints the information of these members in its default settings, which makes the output quite verbose. We recommend to disable the output of the static class members. This can be done with

set print static-members off

Intel compiler options

Because CoDiPack relies on inlining of the compiler the performance can drop if it is not done or ignored. Therefore we recomend to force inlining of CoDiPack with the option


Hello World Example

A very small and simple example for the use of the RealForward type is the code:

    #include <codi.hpp>
    #include <iostream>

    int main(int nargs, char** args) {
      codi::RealForward x = 4.0;

      codi::RealForward y = x * x;

      std::cout << "f(4.0) = " << y << std::endl;
      std::cout << "df/dx(4.0) = " << y.getGradient() << std::endl;

      return 0;

It is compiled with

  g++  -I<path to codi>/include --std=c++11 -g -o forward forward.cpp

for the gcc compiler or with

  icpc  -I<path to codi>/include --std=c++11 -g -o forward forward.cpp

for the intel compiler.

Please visit the tutorial page for further information.


If you use CoDiPack in one of your applications and write a paper it would be nice if you could cite the paper High-Performance Derivative Computations using CoDiPack (submitted to ACM TOMS).

  title={{High-Performance Derivative Computations using CoDiPack}},
  author={Sagebaum, Max and Albring, Tim and Gauger, Nicolas R.},
  journal={arXiv preprint arXiv:1709.07229},