vgvassilev / clad

clad -- automatic differentiation for C/C++
GNU Lesser General Public License v3.0
288 stars 122 forks source link

Allow specifying non-differentiable data members #418

Open parth-07 opened 2 years ago

parth-07 commented 2 years ago

We have recently added class type support in Clad. Currently, all fields of the class are assumed to be differentiable. Practically, there are many non-differentiable fields in the class. We may not need to create derived statements for the expressions modifying non-differentiable fields, thus if we know which fields are non-differentiable, we can ideally produce more optimal derived function code.

One way to specify non-differentiable fields is by using C++ attributes:

class Tensor {
  [[clad::non_differentiable]]
  std::size_t sz;
  double data[10];
}
MihailMihov commented 3 months ago

@vgvassilev does this issue actually want any further support for the non-differentiable attribute? maybe I'm missing something, but I think this already works in forward mode and when #916 is merged will work in reverse mode too, so maybe I should make #916 close this too?

vgvassilev commented 3 months ago

I think so. Do we have a test that explicitly tests this issue?