rust-ndarray / ndarray

ndarray: an N-dimensional array with array views, multidimensional slicing, and efficient operations

Home Page:https://docs.rs/ndarray/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Euclidean division for signed integers

rkshthrmsh opened this issue · comments

I was dividing signed ndarrays with positivie scalars, and found that the results for negative integer elements were unexpected. It appears that the scalar division trait in ArrayBase only implements truncating division (round towards 0). While it is possible to mapv div_euclid for each element, providing an option for Euclidiean division might be helpful. Please let me know your thoughts on this.

providing an option for Euclidiean division might be helpful

Of course using div_euclid as the standard operation for / is out of the question. This is probably not what you're asking anyway.

The maintainers of ndarray don't want to add methods for simple one-liners. Otherwise we would have hundreds of methods. I mean, we would add it if almost everybody wants a specific method (like sum), but in this specific case... IMO you should stick to mapv div_euclid. It's simple, readable and as fast.

My concern was regarding performance, and since that has been answered, I will close this issue.