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 std::vector differentiation in the reverse mode #1070

Closed
gojakuch opened this issue Sep 2, 2024 · 1 comment · Fixed by #1076
Closed

Incorrect std::vector differentiation in the reverse mode #1070

gojakuch opened this issue Sep 2, 2024 · 1 comment · Fixed by #1076

Comments

@gojakuch
Copy link
Collaborator

gojakuch commented Sep 2, 2024

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

double fn(double x, double y) {
  std::vector<double> a;
  a.push_back(x);
  a.push_back(x);
  a[1] = x*x;
  return a[1];
}

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

expected output:
9
6 0
output:
9
1 0

my assumption as to why this happens is that we don't match the constructor forw and pullback properly. but I'm not sure, it could be that other things are not matched properly as well or that it's another kind of problem.

@gojakuch
Copy link
Collaborator Author

gojakuch commented Sep 2, 2024

this might be related to #1067

gojakuch added a commit to gojakuch/clad that referenced this issue Sep 3, 2024
Previously, nullptr used to be set as the derivative of a
call in the reverse mode, if there was a custom reverse_forw
function available. This issue was overlooked at first, since
it doesn't cause any trouble, unless someone decides to use nested
operators (such as expressions of the form `a[i] = x*x`).

Fixes: vgvassilev#1070
gojakuch added a commit to gojakuch/clad that referenced this issue Sep 3, 2024
Previously, nullptr used to be set as the derivative of a
call in the reverse mode, if there was a custom reverse_forw
function available. This issue was overlooked at first, since
it doesn't cause any trouble, unless someone decides to use nested
operators (such as expressions of the form `a[i] = x*x`).

Fixes: vgvassilev#1070
vgvassilev pushed a commit that referenced this issue Sep 3, 2024
Previously, nullptr used to be set as the derivative of a
call in the reverse mode, if there was a custom reverse_forw
function available. This issue was overlooked at first, since
it doesn't cause any trouble, unless someone decides to use nested
operators (such as expressions of the form `a[i] = x*x`).

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

Successfully merging a pull request may close this issue.

1 participant