rust-ndarray / ndarray

ndarray: an N-dimensional array with array views, multidimensional slicing, and efficient operations
https://docs.rs/ndarray/
Apache License 2.0
3.61k stars 306 forks source link

Inconsistent behaviour between `arr0` and `arr1` #1255

Closed nbro closed 1 year ago

nbro commented 1 year ago

To create a 0-d array with arr0, we can actually pass an array literal as follows

let a = arr0([0]);

This is ignored because arr0 does not check what is passed or whether it has the correct shape. First of all, I think this is bad. See the related issue: https://github.com/rust-ndarray/ndarray/issues/1253

As you can see, I don't need to pass a reference.

Now, if we attempt to create a 1d, 2d or 3d array with the similar functions, we need to pass the literal by reference, i.e. the following does not compile

let a = arr1([[0], [2]]);

The same happens with arr2 and arr3.

Whether we decide to solve the other issue https://github.com/rust-ndarray/ndarray/issues/1253 or not, in my view, this inconsistency should not exist.

By the way, we can also do

let a = arr0(&[0]);

This inconsistency is due to the fact that arr0 accepts A while the other functions accept &[A], and I suppose we can pass references when we accept A

bluss commented 1 year ago

0-d is always a special case, so I don't see what the action should be here. A 0-d array is very similar to a scalar, so I think its argument should be a scalar.