Closed bradbell closed 1 year ago
Thanks for bringing this to my attention! I just updated the new README. The issue was that the expression was a vector expression so autodiff
explicitly needed a seed that was a vector as well. Only when the expression is scalar do we have a default value of 1
for the seed. The new code is:
#include <fastad>
#include <iostream>
int main()
{
using namespace ad;
Var<double, scl> x(2);
Var<double, vec> v(5);
// randomly generate values for v
v.get().setRandom();
// create AD expression bound to storage
auto expr_bound = bind(sin(x) + cos(v));
// seed to get gradient of function at index 2
Eigen::Array<double, Eigen::Dynamic, 1> seed(v.size());
seed.setZero();
seed[2] = 1;
// differentiate
auto f = autodiff(expr_bound, seed);
std::cout << x.get_adj() << std::endl;
std::cout << v.get_adj(2,0) << std::endl;
return 0;
}
Closing for now, but if you see other issues, let me know.
I am getting the following messages when I try to compile one of the FastAD examples:
Below are the steps to reproduce this:
Step 1:
Step 2:
Step 3: Create the file temp.cpp with the following contents (from one of the FastAD readme examples):
Step 4: