Skip to content

Provides a n-dimensional type - tensors - with automatic differentiation support.

Notifications You must be signed in to change notification settings

samarth015/xtensor-autodiff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Xtensor Autodiff

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.

Simple example

#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.

About

Provides a n-dimensional type - tensors - with automatic differentiation support.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published