Skip to content

Commit 615113e

Browse files
jturner314bluss
authored andcommitted
Add debug assertions to SliceInfo::new_unchecked
1 parent ab79d28 commit 615113e

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/slice.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,23 +403,34 @@ where
403403

404404
impl<T, Din, Dout> SliceInfo<T, Din, Dout>
405405
where
406+
T: AsRef<[AxisSliceInfo]>,
406407
Din: Dimension,
407408
Dout: Dimension,
408409
{
409410
/// Returns a new `SliceInfo` instance.
410411
///
411412
/// If you call this method, you are guaranteeing that `in_dim` and
412413
/// `out_dim` are consistent with `indices`.
414+
///
415+
/// **Note:** only unchecked for non-debug builds of `ndarray`.
413416
#[doc(hidden)]
414417
pub unsafe fn new_unchecked(
415418
indices: T,
416419
in_dim: PhantomData<Din>,
417420
out_dim: PhantomData<Dout>,
418421
) -> SliceInfo<T, Din, Dout> {
422+
if cfg!(debug_assertions) {
423+
if let Some(in_ndim) = Din::NDIM {
424+
assert_eq!(in_ndim, indices.as_ref().in_ndim());
425+
}
426+
if let Some(out_ndim) = Dout::NDIM {
427+
assert_eq!(out_ndim, indices.as_ref().out_ndim());
428+
}
429+
}
419430
SliceInfo {
420-
in_dim: in_dim,
421-
out_dim: out_dim,
422-
indices: indices,
431+
in_dim,
432+
out_dim,
433+
indices,
423434
}
424435
}
425436
}

0 commit comments

Comments
 (0)