Product of references in different scope isn't handled correctly in reverse mode
Opened this issue · 0 comments
ovdiiuv commented
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