Skip to content

Commit

Permalink
Revert skipping creation of the derivatives of local const vars
Browse files Browse the repository at this point in the history
  • Loading branch information
kchristin22 committed Nov 3, 2024
1 parent 583e80a commit c738e3d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
3 changes: 0 additions & 3 deletions lib/Differentiator/DiffPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,9 +633,6 @@ namespace clad {
}

bool DiffRequest::shouldHaveAdjoint(const VarDecl* VD) const {
if (VD->getType().isConstQualified())
return false;

if (!EnableVariedAnalysis)
return true;

Expand Down
5 changes: 4 additions & 1 deletion test/Gradient/Assignments.C
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@ double constVal(double y, const double x) {
}

//CHECK: void constVal_grad_0(double y, const double x, double *_d_y) {
//CHECK-NEXT: double _d_z = 0.;
//CHECK-NEXT: const double z = y;
//CHECK-NEXT: double _t0 = y;
//CHECK-NEXT: y *= z;
Expand All @@ -835,7 +836,9 @@ double constVal(double y, const double x) {
//CHECK-NEXT: double _r_d0 = *_d_y;
//CHECK-NEXT: *_d_y = 0.;
//CHECK-NEXT: *_d_y += _r_d0 * z;
//CHECK-NEXT: _d_z += y * _r_d0;
//CHECK-NEXT: }
//CHECK-NEXT: *_d_y += _d_z;
//CHECK-NEXT:}

double constValInput(const double x) {
Expand Down Expand Up @@ -916,7 +919,7 @@ int main() {
auto const_test = clad::gradient(constVal, "y");
double const_test_result = 0;
const_test.execute(3, 4, &const_test_result);
printf("%.2f\n", const_test_result); // CHECK-EXEC: 12.00
printf("%.2f\n", const_test_result); // CHECK-EXEC: 24.00

auto const_test_input = clad::gradient(constValInput);
double const_test_input_result = 0;
Expand Down

0 comments on commit c738e3d

Please sign in to comment.