Skip to content

Commit

Permalink
Added jacobian mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Ris-Bali committed Nov 29, 2023
1 parent a774665 commit 9551d16
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions docs/userDocs/source/user/tutorials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,36 @@ if we want to differentiate w.r.t to the first two elements of the array along w
write `clad::hessian(f_arr, z[0:1])`.


The Jacobian Mode

Clad can produce Jacobian of a function using its reverse mode. It returns the jacobian matrix as a flaattened vector with
elements arranged in row-major format.

.. code-block:: cpp
#include "clad/Differentiator/Differentiator.h"
#include<iostream>
void f(doubl x, double y, double z, double *output) {
output[0] = x*y;
output[1] = y * y * x;
output[2] = 6 * x * y * z;
}
int main() {
auto f_jac = clad::jacobian(f);
double jac[9] = {0};
double output[3] = {0};
f_jac.execute(3, 4, 5, output, jac);
std::cout << jac[0] << " " << jac[1] << std::endl
<< jac[2] << " " << jac[3] << std::endl
<< jac[4] << " " << jac[5] << std::endl
<< jac[6] << " " << jac[7] << std::endl
<< jac[8]<<std::endl;
}
Expand Down

0 comments on commit 9551d16

Please sign in to comment.