Skip to content

[RF] Add a clad pushforward for MathFuncs::binNumber - #23280

Merged
guitargeek merged 1 commit into
root-project:masterfrom
guitargeek:bin_number_pushforward
Sep 7, 2026
Merged

[RF] Add a clad pushforward for MathFuncs::binNumber#23280
guitargeek merged 1 commit into
root-project:masterfrom
guitargeek:bin_number_pushforward

Conversation

@guitargeek

@guitargeek guitargeek commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

This is a spinoff from #21622

binNumber uses std::lower_bound, which clad can't differentiate. That was already handled for reverse mode by a dummy binNumber_pullback, but Hessians also run the forward pass over binNumber, and without a pushforward clad descends into std::lower_bound and warns about differentiating __builtin_constant_p and about unsupported typedef declarations, before failing outright.

Declare the forward-mode counterpart, zero-valued for the same reason as the pullback: binNumber returns an integer, so it has no derivative.

Since MathFuncs.h is compiled normally as well as parsed by cling, while clad::ValueAndPushforward only exists inside the interpreter, the type is forward-declared and the return type is kept dependent so that it is only completed when clad instantiates the template.

🤖 Done with the help of AI

binNumber uses std::lower_bound, which clad can't differentiate. That was
already handled for reverse mode by a dummy binNumber_pullback, but Hessians
also run the forward pass over binNumber, and without a pushforward clad
descends into std::lower_bound and warns about differentiating
__builtin_constant_p and about unsupported typedef declarations, before
failing outright.

Declare the forward-mode counterpart, zero-valued for the same reason as the
pullback: binNumber returns an integer, so it has no derivative.

Since MathFuncs.h is compiled normally as well as parsed by cling, while
clad::ValueAndPushforward only exists inside the interpreter, the type is
forward-declared and the return type is kept dependent so that it is only
completed when clad instantiates the template.

🤖 Done with the help of AI

@vgvassilev vgvassilev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@guitargeek
guitargeek merged commit d6fc61d into root-project:master Sep 7, 2026
32 of 36 checks passed
@guitargeek
guitargeek deleted the bin_number_pushforward branch September 7, 2026 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants