Explain what you would like to see improved and how.
Original issue: root forum
Issue
The lambda used to construct the TF1 object has the following signature for the current version:
auto [](const double* variables, const double* parameters) -> double;
This API is pretty awful as it has basically no way to do bound checking inside the lambda on variables or parameters, unless I’m using a global variable to indicate the sizes, which is very error-prone.
Improvements
Runtime size information
It would be nice if the TF1 allows the lambda to have sizes as its input arguments:
auto [](const double* variables, std::size_t variable_size,
const double* parameters, std::size_t parameter_size) -> double;
Or even better using std::span:
auto [](std::span<const double> variables, std::span<const double> parameters) -> double;
Compile-time size information
Most of the time, the fitting function is fixed already during the compile time, so it makes sense to have something like:
auto [](const std::array<double, 2>& variables,
const std::array<double, 3>& parameters) -> double
{
const auto& [x, y] = variables;
const auto& [a, b, c] = parameters;
return a * x + b * y + c;
};
This looks very nice and clear, but it requires a redesign of TF1, as TF1 would have to be a class template, with the template arguments to be the number of variables and parameters. Or it at least needs two template specialization, one for dynamic sizes (old API, sizes are determined at the runtime) and another for fixed compile-time sizes.
ROOT version
6.36.04
Installation method
rpm
Operating system
Fedora 42
Additional context
No response
Explain what you would like to see improved and how.
Original issue: root forum
Issue
The lambda used to construct the TF1 object has the following signature for the current version:
This API is pretty awful as it has basically no way to do bound checking inside the lambda on variables or parameters, unless I’m using a global variable to indicate the sizes, which is very error-prone.
Improvements
Runtime size information
It would be nice if the TF1 allows the lambda to have sizes as its input arguments:
Or even better using
std::span:Compile-time size information
Most of the time, the fitting function is fixed already during the compile time, so it makes sense to have something like:
This looks very nice and clear, but it requires a redesign of TF1, as TF1 would have to be a class template, with the template arguments to be the number of variables and parameters. Or it at least needs two template specialization, one for dynamic sizes (old API, sizes are determined at the runtime) and another for fixed compile-time sizes.
ROOT version
6.36.04
Installation method
rpm
Operating system
Fedora 42
Additional context
No response