From 9551d16411a94ef343cbc1985e705c6b0858dadd Mon Sep 17 00:00:00 2001 From: Rishabh Bali Date: Thu, 30 Nov 2023 01:41:26 +0530 Subject: [PATCH] Added jacobian mode --- docs/userDocs/source/user/tutorials.rst | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/userDocs/source/user/tutorials.rst b/docs/userDocs/source/user/tutorials.rst index 8ccaf7bf5..df427c1c1 100644 --- a/docs/userDocs/source/user/tutorials.rst +++ b/docs/userDocs/source/user/tutorials.rst @@ -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 + + 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]<