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

Don't synthesize 0 of the ArraySubscriptExpr type in forward mode #960

Merged
merged 1 commit into from
Jun 24, 2024

Conversation

PetroZarytskyi
Copy link
Collaborator

@PetroZarytskyi PetroZarytskyi commented Jun 24, 2024

Currently, Clad can't differentiate ArraySubscriptExpr of non-numerical types. This happens because it attempts to synthesize a 0 of the same type, which is not always numerical. To avoid this error, we can use getZeroInit instead.
Here's a reproducer (it's added to the tests in this PR):

struct A {
  double mem;
  A(double p_mem = 0) : mem(p_mem) {}
};

double fn18(double i, double j) {
  A v[2] = {2, 3};
  v[0] = 9 * i;
  return v[0].mem;
}

Differentiating this in forward mode produces an error.

This bug arises when differentiating HepEmShow.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

lib/Differentiator/BaseForwardModeVisitor.cpp Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jun 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.86%. Comparing base (216201a) to head (2b02d7c).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #960      +/-   ##
==========================================
+ Coverage   93.85%   93.86%   +0.01%     
==========================================
  Files          55       55              
  Lines        7892     7892              
==========================================
+ Hits         7407     7408       +1     
+ Misses        485      484       -1     
Files Coverage Δ
lib/Differentiator/BaseForwardModeVisitor.cpp 98.95% <100.00%> (ø)

... and 1 file with indirect coverage changes

Files Coverage Δ
lib/Differentiator/BaseForwardModeVisitor.cpp 98.95% <100.00%> (ø)

... and 1 file with indirect coverage changes

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Owner

@vgvassilev vgvassilev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@vgvassilev vgvassilev merged commit 4f487e3 into vgvassilev:master Jun 24, 2024
89 checks passed
@PetroZarytskyi PetroZarytskyi deleted the hepemshow-zero branch August 15, 2024 10:28
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

Successfully merging this pull request may close these issues.

2 participants