Description
Feature description
Feature Request: Add linspace
, regspace
, and logspace
to ROOT::VecOps
Description
Currently, ROOT::VecOps
provides Range
, which is useful for generating sequences of integers like Python’s range()
. However, no direct equivalent exists for generating evenly spaced floating-point sequences like linspace
, regspace
, or logspace
, which exist in NumPy and other numerical computing libraries like Armadillo.
Motivation
- Many scientific and data analysis workflows require generating sequences of floating-point numbers, especially for defining analysis binning, parameter sweeps, or interpolation grids.
ROOT::VecOps::Range
only works with integers, which limits its applicability in cases where floating-point precision is needed. Unlike Python’srange()
, which produces a lazy range object,ROOT::VecOps::Range
produces an actualRVec
, making it natural to extend this functionality to floating-point sequences.- Implementing
linspace
,regspace
, andlogspace
would alignROOT::VecOps
with common numerical computing conventions, improving usability and reducing the need for external workarounds.
Proposed Feature
ROOT::VecOps::linspace(start, stop, num_points)
: Generatenum_points
evenly spaced values betweenstart
andstop
(inclusive).ROOT::VecOps::regspace(start, stop, step)
: Generate values fromstart
tostop
with step sizestep
.ROOT::VecOps::logspace(start_exp, stop_exp, num_points, base=10)
: Generatenum_points
logarithmically spaced values betweenbase^start_exp
andbase^stop_exp
.
This addition would significantly improve ROOT’s numerical capabilities and enhance user experience for scientific computing.
Additional Context
Current workarounds involve using std::vector<double>
and manually populating sequences, which is inefficient and less readable compared to built-in ROOT RVec
operations. Another place where it would be useful would be for TGraph, i.e. with the range function one can simply do something like the following analogous to the numpy and matplotlib API
ROOT::VecOps::RVec<int> x = ROOT::VecOps::Range(1, 6);
ROOT::VecOps::RVec<int> y = ROOT::VecOps::Range(1, 6);
int n = x.size();
auto g = new TGraph(n, x.data(), y.data());
g->Draw("AC*");
but for floating point operations, there is no equivalent API for this convenient plotting mechanism in ROOT for C++ users, hence why it could be useful for these functions to be added.
Would it be possible to add these functionalities to ROOT::VecOps
? If so, I eagerly wish to assign this issue to myself, please 🙏 .
Alternatives considered
No response
Additional context
No response