clad icon indicating copy to clipboard operation
clad copied to clipboard

Invalid (uncompilable) gradient when non-array and array declarations are mixed in one declaration statement

Open parth-07 opened this issue 1 year ago • 0 comments

Clad generates invalid and uncompilable gradient when non-array and array declarations are mixed in one declaration statement.

Reproducible example:

#include "clad/Differentiator/Differentiator.h"

double fn(double u, double v) {
    double w, x[5];
    x[0] = u;
    return x[0];
}

int main() {
    auto fn_grad = clad::gradient(fn);
}

Generated gradient:

void fn_grad(double u, double v, clad::array_ref<double> _d_u, clad::array_ref<double> _d_v) {
    double _d_w = 0, _d_x(5UL);
    double _t0;
    double w, x[5];
    _t0 = x[0];
    x[0] = u;
    goto _label0;
  _label0:
    _d_x[0] += 1;
    {
        x[0] = _t0;
        double _r_d0 = _d_x[0];
        * _d_u += _r_d0;
        _d_x[0] -= _r_d0;
        _d_x[0];
    }
}

_d_x should be an array, instead it's of double type.

parth-07 avatar Dec 09 '23 15:12 parth-07