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

Incorrect gradient generation #650

Closed
parth-07 opened this issue Oct 31, 2023 · 4 comments · Fixed by #733
Closed

Incorrect gradient generation #650

parth-07 opened this issue Oct 31, 2023 · 4 comments · Fixed by #733
Assignees
Milestone

Comments

@parth-07
Copy link
Collaborator

parth-07 commented Oct 31, 2023

Reproducible example:

#include "clad/Differentiator/Differentiator.h"
#include <iostream>
#define show(x) std::cout << #x << ": " << x << "\n";

double fn(double u, double v) {
    double r = (u = v = u = 0);
    return r;
}

int main() {
    auto fn_grad = clad::gradient(fn);
    double du, dv;
    du = dv = 0;
    fn_grad.execute(3, 5, &du, &dv);
    show(du);
    show(dv);
    auto d_fn_u = clad::differentiate(fn, "u");
    show(d_fn_u.execute(3, 5));
    auto d_fn_v = clad::differentiate(fn, "u");
    show(d_fn_v.execute(3, 5));
}

Output:

du: -1
dv: 0
d_fn_u.execute(3, 5): 0
d_fn_v.execute(3, 5): 0

Incorrect gradient is generated for both the current master and the TBR branch.

@vgvassilev vgvassilev modified the milestones: v1.1, v1.3 Nov 4, 2023
@devilkiller-ag
Copy link

Hi @parth-07, I superficially examined your issue. The issue seems to be with line auto d_fn_v = clad::differentiate(fn, "u");. It should be auto d_fn_v = clad::differentiate(fn, "v");. However, I am unsure if this is the real cause of the error as I haven't run the example yet.

@vgvassilev vgvassilev modified the milestones: v1.3, v1.4 Dec 1, 2023
@vaithak
Copy link
Collaborator

vaithak commented Dec 13, 2023

I am not sure in which commit, but this is fixed. The result is correct now.

@vgvassilev
Copy link
Owner

Can we add a test and close this issue?

@vaithak
Copy link
Collaborator

vaithak commented Dec 13, 2023

My bad; there was a difference in what I was testing and the snippet in this issue. The result is still wrong, as mentioned in the issue.

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

Successfully merging a pull request may close this issue.

4 participants