Skip to content

Commit 408f42b

Browse files
committed
Panic on remove_axis if length of axis is zero
Before, this would print uninitialized values: ```rust use ndarray::prelude::*; let v = ArrayView2::<i32>::from_shape((0, 2), &[]).unwrap(); println!("{:?}", v.remove_axis(Axis(0))); ``` Now, it panics.
1 parent d5224a2 commit 408f42b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/impl_methods.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1512,10 +1512,12 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
15121512
}
15131513

15141514
/// Remove array axis `axis` and return the result.
1515+
///
1516+
/// **Panics** if the axis is out of bounds or its length is zero.
15151517
pub fn remove_axis(self, axis: Axis) -> ArrayBase<S, D::Smaller>
15161518
where D: RemoveAxis,
15171519
{
1518-
assert!(self.ndim() != 0);
1520+
assert_ne!(self.len_of(axis), 0, "Length of removed axis must be nonzero.");
15191521
let d = self.dim.remove_axis(axis);
15201522
let s = self.strides.remove_axis(axis);
15211523
ArrayBase {

0 commit comments

Comments
 (0)