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

Product of references in different scope isn't handled correctly in reverse mode #1014

Open
ovdiiuv opened this issue Jul 29, 2024 · 0 comments

Comments

@ovdiiuv
Copy link
Collaborator

ovdiiuv commented Jul 29, 2024

double fn(double x, double y){
  double g = 0;
  {
  double &j = x;
  g += j*j;
  }
  return g;
}

generates:

void fn_grad(double x, double y, double *_d_x, double *_d_y) {
    double _d_r = 0;
    double _d_g = 0;
    double *_d_j = 0;
    double *j = {};
    double _t0;
    double r = x;
    double g = 0;
    {
        _d_j = &_d_r;
        j = &r;
        _t0 = g;
        g += *j * j;
    }
    _d_g += 1;
    {
        {
            g = _t0;
            double _r_d0 = _d_g;
            *_d_j += _r_d0 * j;
            *_d_j += *j * _r_d0;
        }
    }
    *_d_x += _d_r;
} 

Input: x=1, y=1
Expected output: dx = 2, dy=0
Output: dx = 1, dy=0

@ovdiiuv ovdiiuv changed the title reverse mode product of references isn't handled correctly Product of references in different scope isn't handled correctly in reverse mode Jul 29, 2024
ovdiiuv pushed a commit to ovdiiuv/clad that referenced this issue Aug 5, 2024
ovdiiuv pushed a commit to ovdiiuv/clad that referenced this issue Aug 6, 2024
ovdiiuv pushed a commit to ovdiiuv/clad that referenced this issue Aug 6, 2024
ovdiiuv pushed a commit to ovdiiuv/clad that referenced this issue Aug 6, 2024
ovdiiuv pushed a commit to ovdiiuv/clad that referenced this issue Aug 6, 2024
ovdiiuv pushed a commit to ovdiiuv/clad that referenced this issue Aug 7, 2024
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