Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ris-Bali committed Nov 29, 2023
1 parent 9551d16 commit 69fdfca
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions docs/userDocs/source/user/tutorials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tutorials
Clad is an open source clang plugin which supports automatic differentiation of mathematical functions in C++.
Currently Clad supports four modes for automatic differentiation namely forward, reverse, Hessian, Jacobian.

Lets have a look at the forward mode
**Forward mode**

.. code-block:: cpp
Expand All @@ -29,7 +29,7 @@ returns a scaler value `x*x`.
**Note : Currently it is necessary to define the function before `main()`.**
`.dump()` method is used to get a dump of generated derivative function to the standard output.

Reverse Mode
**Reverse Mode**

Clad also supports reverse mode automatic differentiation, through the `clad::gradient` API call.

Expand All @@ -55,13 +55,14 @@ argument i.e. either `x` or `y` as `clad::gradient(f, "x")` not writing any argu
differentiation of the function w.r.t to each input.


The Hessian Mode
**The Hessian Mode**

Clad can also produce an hessian matrix through the `clad::hessian` API call.
This API call is more or less similar to the reverse mode API call and differs
in case of an array type input argument.

.. code-block:: cpp
#include "clad/Differentiator/Differentiator.h"
#include <iostream>
Expand Down Expand Up @@ -89,12 +90,13 @@ 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
**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>
Expand All @@ -110,14 +112,14 @@ elements arranged in row-major format.
double jac[9] = {0};
double output[3] = {0};
f_jac.execute(3, 4, 5, output, jac);
std::cout << jac[0] << " " << jac[1] << std::endl
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 69fdfca

Please sign in to comment.