Add support for differentiating with respect to multidimensional arrays (or pointers) in Clad

Description

In mathematics and computer algebra, automatic differentiation (AD) is a set of techniques to numerically evaluate the derivative of a function specified by a computer program. Automatic differentiation is an alternative technique to Symbolic differentiation and Numerical differentiation (the method of finite differences). Clad is based on Clang which provides the necessary facilities for code transformation. The AD library is able to differentiate non-trivial functions, to find a partial derivative for trivial cases and has good unit test coverage.

Clad currently only supports differentiation with respect to single-dimensional arrays. Support for differentiation with respect to pointers is limited as well. This project aims to add support for multi-dimensional arrays (and pointers) in Clad.

Task ideas

The project consists of the following tasks:

Technology

C/C++, Clang, LLVM

Desirable Skills

Expected results

After successful completion of the project the code snippet should work as expected:

#include <iostream>
#include "clad/Differentiator/Differentiator.h"

double fn(double arr[5][5]) {
  double res = 1 * arr[0][0] + 2 * arr[1][1] + 4 * arr[2][2];
  return res * 2;
}

int main() {
  auto d_fn = clad::gradient(fn);

  double arr[5][5] = {{1, 2, 3, 4, 5},
                      {6, 7, 8, 9, 10},
                      {11, 12, 13, 14, 15},
                      {16, 17, 18, 19, 20},
                      {21, 22, 23, 24, 25}};

  double d_arr[5][5] = {};
  d_fn.execute(arr, d_arr);
  std::cout << "Derivative of d_fn wrt arr[0][0]: " << d_arr[0][0] << "\n"; // 2
  std::cout << "Derivative of d_fn wrt arr[1][1]: " << d_arr[1][1] << "\n"; // 4
  return 0;
}

Candidate Guidelines and Evaluation

If you have interest in working on the project there is a list of things to do in order to maximize your chances to get selected:

  1. Contact the mentors and express interest in the project. Make sure you attach your CV;
  2. Download the source code of the project, build it and run the demos;
  3. Start familiarizing yourself with the codebase;
  4. If you have questions you can always contact a mentor.

The mentors are interested in working with all candidates but unfortunately the rules allow only one to be selected. There are a few tasks which give bonus points to candidate’s application:

Mentors

Compiler-Research clad clang-repl llvm clang

Additional Information

Corresponding Project

Participating Organizations