0

I am trying to use the autodiff package.

I tried to implement their very first example. My code follows:

#include <iostream>

// autodiff include
#include <autodiff/forward/dual.hpp>
using namespace autodiff;

// The single-variable function for which derivatives are needed
dual f(dual x)
{
  return 1 + x + x*x + 1/x + log(x);
}

int main()
{
  dual x = 2.0;                                 // the input variable x
  dual u = f(x);                                // the output variable u
  
  double dudx = derivative(f, wrt(x), at(x));   // evaluate the derivative du/dx
  
  std::cout << "u = " << u << std::endl;        // print the evaluated output u
  std::cout << "du/dx = " << dudx << std::endl; // print the evaluated derivative du/dx
}

I compile it from my Ubuntu terminal using g++ autodiff2.cpp -std=c++1z, but I get the following error:

autodiff2.cpp:4:10: fatal error: autodiff/forward/dual.hpp: No such file or directory
    4 | #include <autodiff/forward/dual.hpp>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

How can I solve this?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • I don't see an autodiff package in Ubuntu, how and where did you install the library? Did you just `git clone` it from github? Then you need to point `g++` to where the headers are, with -I – Lev M. Sep 29 '21 at 23:31
  • where is `autodiff/forward/dual.hpp` located on your machine? Generally on linux, these headers are present in `/usr/include`. You can pass additional paths to look for headers with `-I` to g++ command. – brokenfoot Sep 29 '21 at 23:32
  • I installed it using ```conda install conda-forge::autodiff``` as suggested in [this link](https://autodiff.github.io/installation/). I can not find the file dual.hpp using the ```locate``` function. How do I know where the header files are? – noirritchandra Sep 29 '21 at 23:37
  • If the headers are present in your machine, you can find it with - `find / -name dual.hpp 2>/dev/null` – brokenfoot Sep 30 '21 at 00:26
  • Looks like you can find the header location using the method in [c++ - Set include-path for header only library installed with conda - Stack Overflow](https://stackoverflow.com/questions/51424230/set-include-path-for-header-only-library-installed-with-conda) – user202729 Sep 30 '21 at 01:26

0 Answers0