scipp / scipp

Multi-dimensional data arrays with labeled dimensions
https://scipp.github.io/
BSD 3-Clause "New" or "Revised" License
113 stars 16 forks source link

Add scipp.nextafter #3546

Open jl-wynen opened 1 week ago

jl-wynen commented 1 week ago

We commonly use numpy.nextafter when constructing bin edges or slicing arrays by label. It would in some cases be more convenient to just use a function directly on scipp variables.

One thing to consider is, do we have to require a unit for the second argument? That is, do we need

sc.nextafter(x, sc.scalar(np.inf, unit='m'))

for and x with x.unit == 'm'. Or can we allow

sc.nextafter(x, np.inf)

I think that requiring a unit in all cases makes this so unergonomic that it is not worth implementing. We could make infinity special and allow omitting a unit iff the second argument is +/- infinity. I'm sure a mathematical argument can be made for why that is fine if we need to go there :-)