Skip to content

Add linspace, regspace, and logspace to ROOT::VecOps #17855

Open
@edfink234

Description

@edfink234

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’s range(), which produces a lazy range object, ROOT::VecOps::Range produces an actual RVec, making it natural to extend this functionality to floating-point sequences.
  • Implementing linspace, regspace, and logspace would align ROOT::VecOps with common numerical computing conventions, improving usability and reducing the need for external workarounds.

Proposed Feature

  • ROOT::VecOps::linspace(start, stop, num_points): Generate num_points evenly spaced values between start and stop (inclusive).
  • ROOT::VecOps::regspace(start, stop, step): Generate values from start to stop with step size step.
  • ROOT::VecOps::logspace(start_exp, stop_exp, num_points, base=10): Generate num_points logarithmically spaced values between base^start_exp and base^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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions