Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clad generates noncompilable code for operators in the reverse mode #1079

Open
gojakuch opened this issue Sep 4, 2024 · 0 comments
Open

Comments

@gojakuch
Copy link
Collaborator

gojakuch commented Sep 4, 2024

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

double fn(double x, double y) {
    std::vector<double> a;
    a.push_back(x);
    a[0] *= x;
    return a[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';
}

in the generated code for the line a[0] *= x clad uses a variable that is only created during the reverse pass later on.

the reason for this has been mentioned in #1076. this issue is related to #1066 which is the same problem, but for constructors and not operators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant