Generate adjoints for pointer-typed conditional operators #2210
clang-tidy review says "All clean, LGTM! :+1:"
clang-tidy review says "All clean, LGTM! :+1:"
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:loudspeaker: Thoughts on this report? Let us know!
This lifts a refusal that was deliberate, and nothing shows the lifted case now gives the right answer.
The case VariedAdjointInitializer.C used to pin -- double* r = c ? &p : &q -- has pointer type, so it takes this branch now and is no longer refused. I checked on master that it is refused today, and that the lambda you replaced it with still produces both the warning and the error. But the comment in that test says refusing was chosen over answering with a wrong gradient, so moving the test to a different construct leaves the conditional case untested in either direction.
That function is easy to assert on: f(x) = xx through **r, so the gradient at 3 is 6. If it comes out right, it belongs in Pointers.C next to condNewPointer; if it does not, the refusal should stay for pointer-to-pointer.
Relatedly, dropping the modifiable-lvalue re-check for pointers keeps a ResultRef that is a prvalue. That is fine where the adjoint is dereferenced, as in your test, but the comment just above says this exists for (c ? a : b) = x, and a prvalue cannot be assigned to.
One remark inline.
This review came from ai-vgvassilev.
clang-tidy review says "All clean, LGTM! :+1:"
vgvassilev
Vedant2005goyal
Currently, Clad only generated adjoints for conditional operators that were modifiable lvalues. For pointer-typed conditionals, the adjoint pointer was left uninitialized.
Example:
This led to a crash in the reverse sweep. This patch generates adjoints for pointer-typed conditionals.