diff --git a/src/dimension/ndindex.rs b/src/dimension/ndindex.rs index 718ee059b..c731d30de 100644 --- a/src/dimension/ndindex.rs +++ b/src/dimension/ndindex.rs @@ -219,22 +219,34 @@ impl<'a> IntoDimension for &'a [Ix] { } } -unsafe impl<'a> NdIndex for &'a IxDyn { +unsafe impl<'a> NdIndex for &'a [Ix] { fn index_checked(&self, dim: &IxDyn, strides: &IxDyn) -> Option { - (**self).index_checked(dim, strides) + stride_offset_checked(dim.ix(), strides.ix(), *self) } fn index_unchecked(&self, strides: &IxDyn) -> isize { - (**self).index_unchecked(strides) + zip(strides.ix(), *self) + .map(|(&s, &i)| stride_offset(i, s)) + .sum() } } -unsafe impl<'a> NdIndex for &'a [Ix] { +unsafe impl<'a, T> NdIndex for &T +where + T: NdIndex, +{ fn index_checked(&self, dim: &IxDyn, strides: &IxDyn) -> Option { - stride_offset_checked(dim.ix(), strides.ix(), *self) + (*self).index_checked(dim, strides) } fn index_unchecked(&self, strides: &IxDyn) -> isize { - zip(strides.ix(), *self) - .map(|(&s, &i)| stride_offset(i, s)) - .sum() + (*self).index_unchecked(strides) + } +} + +unsafe impl<'a> NdIndex for Vec { + fn index_checked(&self, dim: &IxDyn, strides: &IxDyn) -> Option { + (&**self).index_checked(dim, strides) + } + fn index_unchecked(&self, strides: &IxDyn) -> isize { + (&**self).index_unchecked(strides) } }