You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue is opened in advance of PR #833 getting merged so not to forget this afterwards
When we have a break stmt in a for loop, we shouldn't perform the for loop increment differentiation in the first iteration in the reverse pass (as the original stmt is also not performed in the forward pass after the break stmt). This is why we add an if stmt to check whether this is the path that the break stmt corresponds to in the reverse pass, to not perform the inc diff stmt. Examples and code found in PR #833.
When the inc diff is a compound stmt it seems that this if-check is not added when using TBR analysis, even though it is added without it:
doublefn26(double i, double j) {
double res = 0;
for (int c = 0; (res += i * j); ++c, res=7*i*j) {
if(c == 0)
break;
}
return res;
}
Produced code in PR833:
voidfn26_grad(double i, double j, double *_d_i, double *_d_j) {
int _d_c = 0;
int c = 0;
clad::tape<double> _t1 = {};
clad::tape<double> _t2 = {};
clad::tape<bool> _cond0 = {};
clad::tape<unsignedlong> _t3 = {};
double _d_res = 0.;
double res = 0;
unsignedlong _t0 = 0UL;
for (c = 0; ; clad::push(_t2, res) , (++c , res = 7 * i * j)) {
{
{
clad::push(_t1, res);
}
if (!(res += i * j))
break;
}
_t0++;
{
clad::push(_cond0, c == 0);
if (clad::back(_cond0)) {
clad::push(_t3, 1UL);
break;
}
}
clad::push(_t3, 2UL);
}
_d_res += 1;
for (;; _t0--) {
{
if (!_t0 || (clad::size(_t3) != 0 && clad::back(_t3) != 1)) {
res = clad::pop(_t1);
double _r_d0 = _d_res;
*_d_i += _r_d0 * j;
*_d_j += i * _r_d0;
}
if (!_t0)
break;
}
{
res = clad::pop(_t2);
double _r_d1 = _d_res;
_d_res = 0.;
*_d_i += 7 * _r_d1 * j;
*_d_j += 7 * i * _r_d1;
_d_c += 0;
--c;
}
switch (clad::pop(_t3)) {
case2UL:
;
{
if (clad::back(_cond0))
case1UL:
;
clad::pop(_cond0);
}
}
}
}
This issue is opened in advance of PR #833 getting merged so not to forget this afterwards
When we have a break stmt in a for loop, we shouldn't perform the for loop increment differentiation in the first iteration in the reverse pass (as the original stmt is also not performed in the forward pass after the break stmt). This is why we add an if stmt to check whether this is the path that the break stmt corresponds to in the reverse pass, to not perform the inc diff stmt. Examples and code found in PR #833.
When the inc diff is a compound stmt it seems that this if-check is not added when using TBR analysis, even though it is added without it:
Produced code in PR833:
The text was updated successfully, but these errors were encountered: