[hist] Allow TF1 lambdas to receive ndim and npar as arguments - Issue #22071#22509
Open
medeirosdev wants to merge 4 commits into
Open
[hist] Allow TF1 lambdas to receive ndim and npar as arguments - Issue #22071#22509medeirosdev wants to merge 4 commits into
medeirosdev wants to merge 4 commits into
Conversation
Users constructing TF1 with a lambda had no safe way to do bound
checking on variables and parameters arrays, since the current API
only exposes raw pointers with no size information.
This adds support for a 4-argument lambda signature:
[](const double *x, std::size_t ndim,
const double *p, std::size_t npar) -> double
TF1Builder now detects this signature at compile time via
std::is_invocable_r_v and wraps it in an adapter that passes
fNdim and fNpar captured from the TF1 object. The existing
2-argument API is fully preserved.
Closes root-project#22071
|
Hi, thanks for the PR. Would it be possible to have |
YanzhaoW
reviewed
Jun 8, 2026
Yes! nice one Co-authored-by: Yanzhao Wang (王彦昭) <yannzhaow@gmail.com>
nice suggestions Co-authored-by: Yanzhao Wang (王彦昭) <yannzhaow@gmail.com>
Both branches set fType to kTemplScalar, so move it before the if constexpr to avoid the duplication. Also fix extra parenthesis from applied suggestion and sync the Func* specialization to use init-captures and make_unique consistently.
Author
std::span would definitely be a cleaner API, but t challenge is that it's C++20, while ROOT currently targets C++17 as the minimum. one option would be to support it as an additional signature, guarded by #ifdef __cpp_lib_span, so users on C++20 can use span while C++17 users keep the size_t version. Would that be the right direction, or would you prefer to keep this PR focused on the size_t approach and handle span in a follow-up? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Users constructing TF1 with a lambda had no safe way to do bound checking on variables and parameters arrays, since the current API only exposes raw pointers with no size information.
This adds support for a 4-argument lambda signature:
[](const double *x, std::size_t ndim,
const double *p, std::size_t npar) -> double
TF1Builder now detects this signature at compile time via std::is_invocable_r_v and wraps it in an adapter that passes fNdim and fNpar captured from the TF1 object. The existing 2-argument API is fully preserved.
Closes #22071
This Pull request:
Changes or fixes:
Checklist:
This PR fixes #