I am currently exploring boost as autodiff framework for my
application. I would like to calculate the derivative of a
vector->scalar function. However I could not find a way to evaluate
the same, rather I always get total gradient.
Example: How to get the following program yield output equivalent to JAX fwd?
#include
#include <iostream>
#include<vector>
template <typename T>
T power_sum(double p, std::vector<T> &z){
T y=0.0;
for (int i=0; i<6;i++){
y += pow(z[i], p);
}
return y;
}
int main() {
using namespace boost::math::differentiation;
constexpr unsigned Order = 2;
std::vector<double> z_v = {1.,2.,3.,4.,5.,6.};
std::vector > z;
for (int i=0; i<6;i++){
z.push_back(make_fvar(z_v[i]));
}
auto y = power_sum(2.0,z);
std::cout<