Fix min/max pushforwards in Hessian generation - #1885
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Return min/max pushforward results by value and retry custom derivative matching with value-typed ValueAndPushforward results only after exact const-reference matching fails. Fixes: vgvassilev#1872
8b07ee9 to
d583116
Compare
| // ValueAndPushforward<T, T> after the exact match fails. This keeps | ||
| // reference-returning custom derivatives preferred while allowing | ||
| // assignable min/max results in higher-order differentiation. | ||
| do { |
There was a problem hiding this comment.
warning: avoid do-while loops [cppcoreguidelines-avoid-do-while]
do {
^| if (Expr* overload = | ||
| utils::MatchOverloadType(S, relaxedDTy, Found, RelaxedCandidates)) | ||
| return overload; | ||
| } while (false); |
There was a problem hiding this comment.
This seems to be just a single iteration why the do-while-stmt?
There was a problem hiding this comment.
I think the do-while(false) wasn't intended to loop I intentionally used it as a breakable scope.
Because we have to fall through to the diagnostic code at the bottom on failure, using break allowed me to keep the early exit checks perfectly flat without deep nesting.
But after I noticed the code styling guide from Github actions I've now simplified the type-checking logic down to just three conditions, I've replaced it with a standard nested if in the latest push.
|
clang-tidy review says "All clean, LGTM! 👍" |
Summary
std::minandstd::maxpushforward results by valueValueAndPushforward<const T&, const T&>returns with value typesFixes: #1872
Testing
Regressions/issue-1872.cppFirstDerivative/BuiltinDerivatives.CForwardMode/STLCustomDerivatives.Cconfirms reference-returning derivatives retain exact matchingclang-format --dry-run --Werrorgit diff --checkPerformance
Exact-HEAD versus patched, 11 alternating Release compile runs after warm-up:
STLCustomDerivatives.C: 1343.6 ms -> 1390.1 ms (+3.46%, overlapping ranges)BuiltinDerivatives.C: 1307.6 ms -> 1271.4 ms (-2.77%)At
-O3, all four Hessian paths inline withoutValueAndPushforwardcall or object overhead.