An automatic differentiation extension for xtensor. Implemented as a thin wrapper around xt::xarray template class. The interface is the same as xt::xarray except that the operations on the tensors are recorded and the results can differentiated with respect to the operands by simply calling the backwards() method.
A multivariate linear regression model has also been implemented by utilizing this extension.
#include "xtad/tensor_autograd.cpp"
using namespace std;
using tensor = xtad::xarray<double>;
int main(){
tensor p = {5};
tensor q = {10};
tensor r = {11};
tensor s = {17};
tensor z = xtad::pow(p, 3) * 4 + q * r * p + 20 * s;
z.backward(); // Calculating the derivative
cout << p << q << r << s << z;
}
value : {{ 5.}} grad : {{ 410.}}
value : {{ 10.}} grad : {{ 55.}}
value : {{ 11.}} grad : {{ 50.}}
value : {{ 17.}} grad : {{ 20.}}
value : {{ 1390.}} grad : 1.