Skip to content

Commit d95e5b2

Browse files
committed
FIX: Fix try_append_array when appending empty arrays
Fix a problem with appending empty arrays (found by ndarray-rand's quickcheck thank you). The try_append_array method was returning a tad too early in this case.
1 parent 61cea3f commit d95e5b2

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/impl_owned_array.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,21 @@ impl<A, D> Array<A, D>
203203
}
204204

205205
let len_to_append = array.len();
206-
if len_to_append == 0 {
207-
return Ok(());
208-
}
209206

210207
let array_shape = array.raw_dim();
211208
let mut res_dim = self.raw_dim();
212209
res_dim[axis.index()] += array_shape[axis.index()];
213210
let new_len = dimension::size_of_shape_checked(&res_dim)?;
214211

212+
if len_to_append == 0 {
213+
// There are no elements to append and shapes are compatible:
214+
// either the dimension increment is zero, or there is an existing
215+
// zero in another axis in self.
216+
debug_assert_eq!(self.len(), new_len);
217+
self.dim = res_dim;
218+
return Ok(());
219+
}
220+
215221
let self_is_empty = self.is_empty();
216222

217223
// array must be empty or have `axis` as the outermost (longest stride) axis

0 commit comments

Comments
 (0)