Implement ContiguousStorage for some matrix slices.
@@ -4,9 +4,9 @@ use std::slice;
use base::allocator::Allocator;
use base::default_allocator::DefaultAllocator;
-use base::dimension::{Dim, DimName, Dynamic, U1};
+use base::dimension::{Dim, DimName, Dynamic, U1, IsNotStaticOne};
use base::iter::MatrixIter;
-use base::storage::{Owned, Storage, StorageMut};
+use base::storage::{Owned, Storage, StorageMut, ContiguousStorage, ContiguousStorageMut};
use base::{Matrix, Scalar};
macro_rules! slice_storage_impl(
@@ -147,8 +147,6 @@ macro_rules! storage_impl(
}
}
-
-
#[inline]
fn into_owned(self) -> Owned<N, R, C>
where DefaultAllocator: Allocator<N, R, C> {
@@ -200,6 +198,14 @@ unsafe impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> StorageMu
}
}
+unsafe impl<'a, N: Scalar, R: Dim, CStride: Dim> ContiguousStorage<N, R, U1> for SliceStorage<'a, N, R, U1, U1, CStride> { }
+unsafe impl<'a, N: Scalar, R: Dim, CStride: Dim> ContiguousStorage<N, R, U1> for SliceStorageMut<'a, N, R, U1, U1, CStride> { }
+unsafe impl<'a, N: Scalar, R: Dim, CStride: Dim> ContiguousStorageMut<N, R, U1> for SliceStorageMut<'a, N, R, U1, U1, CStride> { }
+
+unsafe impl<'a, N: Scalar, R: DimName, C: Dim + IsNotStaticOne> ContiguousStorage<N, R, C> for SliceStorage<'a, N, R, C, U1, R> { }
+unsafe impl<'a, N: Scalar, R: DimName, C: Dim + IsNotStaticOne> ContiguousStorage<N, R, C> for SliceStorageMut<'a, N, R, C, U1, R> { }
+unsafe impl<'a, N: Scalar, R: DimName, C: Dim + IsNotStaticOne> ContiguousStorageMut<N, R, C> for SliceStorageMut<'a, N, R, C, U1, R> { }
+
impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
#[inline]
fn assert_slice_index(
@@ -860,3 +866,25 @@ impl<N: Scalar, R: Dim, C: Dim, S: StorageMut<N, R, C>> Matrix<N, R, C, S> {
self.slice_range_mut(.., cols)
}
}
+
+
+impl<'a, N, R, C, RStride, CStride> From<MatrixSliceMut<'a, N, R, C, RStride, CStride>>
+for MatrixSlice<'a, N, R, C, RStride, CStride>
+ where
+ N: Scalar,
+ R: Dim,
+ C: Dim,
+ RStride: Dim,
+ CStride: Dim,
+{
+ fn from(slice_mut: MatrixSliceMut<'a, N, R, C, RStride, CStride>) -> Self {
+ let data = SliceStorage {
+ ptr: slice_mut.data.ptr,
+ shape: slice_mut.data.shape,
+ strides: slice_mut.data.strides,
+ _phantoms: PhantomData,
+ };
+
+ unsafe { Matrix::from_data_statically_unchecked(data) }
+ }
+}
\ No newline at end of file
