vgvassilev / clad

clad -- automatic differentiation for C/C++
GNU Lesser General Public License v3.0
291 stars 122 forks source link

Use clad::zero_vector instead of 0 in the vectorized forward mode #1140

Closed PetroZarytskyi closed 19 hours ago

PetroZarytskyi commented 5 days ago

This is necessary to ensure type safety. 0 represents a zero vector but is only properly treated as a zero vector when it gets added/subtracted with a clad::array. Initializing a clad::array with 0 will create not a zero vector but an empty array (with zero elements). To fix this, we needed exceptions for all declarations. We would need to make new exceptions when passing parameters to pushforwards.

After merging this PR and #1121, #527 will be fixed automatically.

github-actions[bot] commented 5 days ago

clang-tidy review says "All clean, LGTM! :+1:"

github-actions[bot] commented 4 days ago

clang-tidy review says "All clean, LGTM! :+1:"

codecov[bot] commented 4 days ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 94.48%. Comparing base (6753511) to head (3811bbd). Report is 1 commits behind head on master.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/vgvassilev/clad/pull/1140/graphs/tree.svg?width=650&height=150&src=pr&token=9f6Q4em8hE&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Vassil+Vassilev)](https://app.codecov.io/gh/vgvassilev/clad/pull/1140?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Vassil+Vassilev) ```diff @@ Coverage Diff @@ ## master #1140 +/- ## ======================================= Coverage 94.48% 94.48% ======================================= Files 50 50 Lines 8850 8850 ======================================= Hits 8362 8362 Misses 488 488 ``` | [Files with missing lines](https://app.codecov.io/gh/vgvassilev/clad/pull/1140?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Vassil+Vassilev) | Coverage Δ | | |---|---|---| | [...clude/clad/Differentiator/BaseForwardModeVisitor.h](https://app.codecov.io/gh/vgvassilev/clad/pull/1140?src=pr&el=tree&filepath=include%2Fclad%2FDifferentiator%2FBaseForwardModeVisitor.h&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Vassil+Vassilev#diff-aW5jbHVkZS9jbGFkL0RpZmZlcmVudGlhdG9yL0Jhc2VGb3J3YXJkTW9kZVZpc2l0b3IuaA==) | `25.00% <ø> (ø)` | | | [lib/Differentiator/VectorForwardModeVisitor.cpp](https://app.codecov.io/gh/vgvassilev/clad/pull/1140?src=pr&el=tree&filepath=lib%2FDifferentiator%2FVectorForwardModeVisitor.cpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Vassil+Vassilev#diff-bGliL0RpZmZlcmVudGlhdG9yL1ZlY3RvckZvcndhcmRNb2RlVmlzaXRvci5jcHA=) | `100.00% <100.00%> (ø)` | | | [Files with missing lines](https://app.codecov.io/gh/vgvassilev/clad/pull/1140?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Vassil+Vassilev) | Coverage Δ | | |---|---|---| | [...clude/clad/Differentiator/BaseForwardModeVisitor.h](https://app.codecov.io/gh/vgvassilev/clad/pull/1140?src=pr&el=tree&filepath=include%2Fclad%2FDifferentiator%2FBaseForwardModeVisitor.h&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Vassil+Vassilev#diff-aW5jbHVkZS9jbGFkL0RpZmZlcmVudGlhdG9yL0Jhc2VGb3J3YXJkTW9kZVZpc2l0b3IuaA==) | `25.00% <ø> (ø)` | | | [lib/Differentiator/VectorForwardModeVisitor.cpp](https://app.codecov.io/gh/vgvassilev/clad/pull/1140?src=pr&el=tree&filepath=lib%2FDifferentiator%2FVectorForwardModeVisitor.cpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Vassil+Vassilev#diff-bGliL0RpZmZlcmVudGlhdG9yL1ZlY3RvckZvcndhcmRNb2RlVmlzaXRvci5jcHA=) | `100.00% <100.00%> (ø)` | |

🚨 Try these New Features:

github-actions[bot] commented 2 days ago

clang-tidy review says "All clean, LGTM! :+1:"

github-actions[bot] commented 2 days ago

clang-tidy review says "All clean, LGTM! :+1:"

vgvassilev commented 2 days ago

Now the array is uninitialized.

vgvassilev commented 1 day ago

Now the array is uninitialized.

I think I understand the issue -- can you separate this PR into two separate ones?

github-actions[bot] commented 20 hours ago

clang-tidy review says "All clean, LGTM! :+1:"