vgvassilev / clad

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

Clad crashes when trying to initialise a class type declaration in the reverse mode #1082

Open gojakuch opened 4 weeks ago

gojakuch commented 4 weeks ago

reproducer:

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

double fn(double x, double y) {
    std::vector<double> v{1, 2, 3}; // this doesn't work
    return v[0];
}

int main(int argc, char* argv[]) {
    double dx, dy;
    auto df = clad::gradient(fn, "x, y");
    std::cout << fn(3, 4) << '\n';
    dx = 0; dy = 0;
    df.execute(3, 4, &dx, &dy);
    std::cout << dx << ' ' << dy << '\n';
}

same thing is happening with other types

gojakuch commented 2 weeks ago

I guess what needs to be done is that we need some support of the initializer_list in the reverse mode and then we just need to make custom pullbacks for constructors that use it.