diff --git a/src/base/allocator.rs b/src/base/allocator.rs index fcaae7cc..77c9b528 100644 --- a/src/base/allocator.rs +++ b/src/base/allocator.rs @@ -16,19 +16,12 @@ use crate::base::DefaultAllocator; /// /// Every allocator must be both static and dynamic. Though not all implementations may share the /// same `Buffer` type. -pub trait Allocator: 'static + Sized { +/// +/// If you also want to be able to create uninitizalized memory buffers, see [`Allocator`]. +pub trait InnerAllocator: 'static + Sized { /// The type of buffer this allocator can instanciate. type Buffer: ContiguousStorageMut; - /// The corresponding uninitialized buffer. - type UninitBuffer: ContiguousStorageMut, R, C>; - - /// Allocates a buffer with the given number of rows and columns without initializing its content. - fn allocate_uninitialized(nrows: R, ncols: C) -> Self::UninitBuffer; - - /// Assumes a data buffer to be initialized. This operation should be near zero-cost. - unsafe fn assume_init(uninit: Self::UninitBuffer) -> Self::Buffer; - /// Allocates a buffer initialized with the content of the given iterator. fn allocate_from_iterator>( nrows: R, @@ -37,10 +30,26 @@ pub trait Allocator: 'static + Sized { ) -> Self::Buffer; } +/// Same as the [`InnerAllocator`] trait, but also provides methods to build uninitialized buffers. +pub trait Allocator: + InnerAllocator + InnerAllocator, R, C> +{ + /// Allocates a buffer with the given number of rows and columns without initializing its content. + fn allocate_uninitialized( + nrows: R, + ncols: C, + ) -> , R, C>>::Buffer; + + /// Assumes a data buffer to be initialized. This operation should be near zero-cost. + unsafe fn assume_init( + uninit: , R, C>>::Buffer, + ) -> >::Buffer; +} + /// A matrix reallocator. Changes the size of the memory buffer that initially contains (RFrom × /// CFrom) elements to a smaller or larger size (RTo, CTo). pub trait Reallocator: - Allocator + Allocator + InnerAllocator + InnerAllocator { /// Reallocates a buffer of shape `(RTo, CTo)`, possibly reusing a previously allocated buffer /// `buf`. Data stored by `buf` are linearly copied to the output: @@ -53,8 +62,8 @@ pub trait Reallocator: unsafe fn reallocate_copy( nrows: RTo, ncols: CTo, - buf: >::Buffer, - ) -> >::Buffer; + buf: >::Buffer, + ) -> >::Buffer; } /// The number of rows of the result of a componentwise operation on two matrices. @@ -65,46 +74,36 @@ pub type SameShapeC = >:: // TODO: Bad name. /// Restricts the given number of rows and columns to be respectively the same. -pub trait SameShapeAllocator: - Allocator + Allocator, SameShapeC> +pub trait SameShapeAllocator: + InnerAllocator + InnerAllocator, SameShapeC> where - R1: Dim, - R2: Dim, - C1: Dim, - C2: Dim, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, { } -impl SameShapeAllocator for DefaultAllocator +impl SameShapeAllocator + for DefaultAllocator where - R1: Dim, - R2: Dim, - C1: Dim, - C2: Dim, - DefaultAllocator: Allocator + Allocator, SameShapeC>, + DefaultAllocator: + InnerAllocator + InnerAllocator, SameShapeC>, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, { } // XXX: Bad name. /// Restricts the given number of rows to be equal. -pub trait SameShapeVectorAllocator: - Allocator + Allocator> + SameShapeAllocator +pub trait SameShapeVectorAllocator: + InnerAllocator + + InnerAllocator> + + SameShapeAllocator where - R1: Dim, - R2: Dim, - ShapeConstraint: SameNumberOfRows, { } -impl SameShapeVectorAllocator for DefaultAllocator +impl SameShapeVectorAllocator for DefaultAllocator where - R1: Dim, - R2: Dim, - - DefaultAllocator: Allocator + Allocator>, + DefaultAllocator: InnerAllocator + InnerAllocator>, ShapeConstraint: SameNumberOfRows, { } diff --git a/src/base/array_storage.rs b/src/base/array_storage.rs index d48d4566..09ac8a4b 100644 --- a/src/base/array_storage.rs +++ b/src/base/array_storage.rs @@ -18,7 +18,7 @@ use std::mem; #[cfg(feature = "abomonation-serialize")] use abomonation::Abomonation; -use crate::base::allocator::Allocator; +use crate::allocator::InnerAllocator; use crate::base::default_allocator::DefaultAllocator; use crate::base::dimension::{Const, ToTypenum}; use crate::base::storage::{ @@ -56,7 +56,7 @@ impl Debug for ArrayStorage { unsafe impl Storage, Const> for ArrayStorage where - DefaultAllocator: Allocator, Const, Buffer = Self>, + DefaultAllocator: InnerAllocator, Const, Buffer = Self>, { type RStride = Const<1>; type CStride = Const; @@ -84,7 +84,7 @@ where #[inline] fn into_owned(self) -> Owned, Const> where - DefaultAllocator: Allocator, Const>, + DefaultAllocator: InnerAllocator, Const>, { self } @@ -93,7 +93,7 @@ where fn clone_owned(&self) -> Owned, Const> where T: Clone, - DefaultAllocator: Allocator, Const>, + DefaultAllocator: InnerAllocator, Const>, { let it = self.as_slice().iter().cloned(); DefaultAllocator::allocate_from_iterator(self.shape().0, self.shape().1, it) @@ -108,7 +108,7 @@ where unsafe impl StorageMut, Const> for ArrayStorage where - DefaultAllocator: Allocator, Const, Buffer = Self>, + DefaultAllocator:InnerAllocator, Const, Buffer = Self>, { #[inline] fn ptr_mut(&mut self) -> *mut T { @@ -124,14 +124,14 @@ where unsafe impl ContiguousStorage, Const> for ArrayStorage where - DefaultAllocator: Allocator, Const, Buffer = Self>, + DefaultAllocator:InnerAllocator, Const, Buffer = Self>, { } unsafe impl ContiguousStorageMut, Const> for ArrayStorage where - DefaultAllocator: Allocator, Const, Buffer = Self>, + DefaultAllocator:InnerAllocator, Const, Buffer = Self>, { } diff --git a/src/base/construction.rs b/src/base/construction.rs index d5f29a19..bb12cd45 100644 --- a/src/base/construction.rs +++ b/src/base/construction.rs @@ -149,7 +149,7 @@ where #[inline] pub fn identity_generic(nrows: R, ncols: C) -> Self where - T: Zero + One, + T: Zero + One + Scalar, { Self::from_diagonal_element_generic(nrows, ncols, T::one()) } @@ -161,7 +161,7 @@ where #[inline] pub fn from_diagonal_element_generic(nrows: R, ncols: C, elt: T) -> Self where - T: Zero + One+Clone, + T: Zero + One + Scalar, { let mut res = Self::zeros_generic(nrows, ncols); @@ -179,7 +179,7 @@ where #[inline] pub fn from_partial_diagonal_generic(nrows: R, ncols: C, elts: &[T]) -> Self where - T: Zero+Clone, + T: Zero + Clone, { let mut res = Self::zeros_generic(nrows, ncols); assert!( @@ -212,7 +212,8 @@ where /// ``` #[inline] pub fn from_rows(rows: &[Matrix, C, SB>]) -> Self - where T:Clone, + where + T: Clone, SB: Storage, C>, { assert!(!rows.is_empty(), "At least one row must be given."); @@ -254,7 +255,8 @@ where /// ``` #[inline] pub fn from_columns(columns: &[Vector]) -> Self - where T:Clone, + where + T: Clone, SB: Storage, { assert!(!columns.is_empty(), "At least one column must be given."); diff --git a/src/base/default_allocator.rs b/src/base/default_allocator.rs index 041d590d..7ee425ff 100644 --- a/src/base/default_allocator.rs +++ b/src/base/default_allocator.rs @@ -13,7 +13,7 @@ use std::ptr; use alloc::vec::Vec; use super::Const; -use crate::base::allocator::{Allocator, Reallocator}; +use crate::base::allocator::{Allocator, InnerAllocator, Reallocator}; use crate::base::array_storage::ArrayStorage; #[cfg(any(feature = "alloc", feature = "std"))] use crate::base::dimension::Dynamic; @@ -21,6 +21,11 @@ use crate::base::dimension::{Dim, DimName}; use crate::base::storage::{ContiguousStorageMut, Storage, StorageMut}; #[cfg(any(feature = "std", feature = "alloc"))] use crate::base::vec_storage::VecStorage; +use crate::storage::Owned; + +type DefaultBuffer = >::Buffer; +type DefaultUninitBuffer = + , R, C>>::Buffer; /* * @@ -32,21 +37,8 @@ use crate::base::vec_storage::VecStorage; pub struct DefaultAllocator; // Static - Static -impl Allocator, Const> for DefaultAllocator { +impl InnerAllocator, Const> for DefaultAllocator { type Buffer = ArrayStorage; - type UninitBuffer = ArrayStorage, R, C>; - - #[inline] - fn allocate_uninitialized(_: Const, _: Const) -> Self::UninitBuffer { - ArrayStorage([[MaybeUninit::uninit(); R]; C]) - } - - #[inline] - unsafe fn assume_init(uninit: Self::UninitBuffer) -> Self::Buffer { - // Safety: MaybeUninit has the same alignment and layout as T, and by - // extension so do arrays based on these. - mem::transmute(uninit) - } #[inline] fn allocate_from_iterator>( @@ -72,34 +64,30 @@ impl Allocator, Const> for Def } } +impl Allocator, Const> for DefaultAllocator { + #[inline] + fn allocate_uninitialized( + _: Const, + _: Const, + ) -> Owned, Const, Const> { + ArrayStorage([[MaybeUninit::uninit(); R]; C]) + } + + #[inline] + unsafe fn assume_init( + uninit: , Const, Const>>::Buffer, + ) -> Owned, Const> { + // Safety: MaybeUninit has the same alignment and layout as T, and by + // extension so do arrays based on these. + mem::transmute(uninit) + } +} + // Dynamic - Static // Dynamic - Dynamic #[cfg(any(feature = "std", feature = "alloc"))] -impl Allocator for DefaultAllocator { +impl InnerAllocator for DefaultAllocator { type Buffer = VecStorage; - type UninitBuffer = VecStorage, Dynamic, C>; - - #[inline] - fn allocate_uninitialized(nrows: Dynamic, ncols: C) -> Self::UninitBuffer { - let mut data = Vec::new(); - let length = nrows.value() * ncols.value(); - data.reserve_exact(length); - data.resize_with(length, MaybeUninit::uninit); - - VecStorage::new(nrows, ncols, data) - } - - #[inline] - unsafe fn assume_init(uninit: Self::UninitBuffer) -> Self::Buffer { - let mut data = ManuallyDrop::new(uninit.data); - - // Safety: MaybeUninit has the same alignment and layout as T. - let new_data = unsafe { - Vec::from_raw_parts(data.as_mut_ptr() as *mut T, data.len(), data.capacity()) - }; - - VecStorage::new(uninit.nrows, uninit.ncols, new_data) - } #[inline] fn allocate_from_iterator>( @@ -116,14 +104,9 @@ impl Allocator for DefaultAllocator { } } -// Static - Dynamic -#[cfg(any(feature = "std", feature = "alloc"))] -impl Allocator for DefaultAllocator { - type Buffer = VecStorage; - type UninitBuffer = VecStorage, R, Dynamic>; - +impl Allocator for DefaultAllocator { #[inline] - fn allocate_uninitialized(nrows: R, ncols: Dynamic) -> Self::UninitBuffer { + fn allocate_uninitialized(nrows: Dynamic, ncols: C) -> Owned, Dynamic, C> { let mut data = Vec::new(); let length = nrows.value() * ncols.value(); data.reserve_exact(length); @@ -133,7 +116,7 @@ impl Allocator for DefaultAllocator { } #[inline] - unsafe fn assume_init(uninit: Self::UninitBuffer) -> Self::Buffer { + unsafe fn assume_init(uninit: Owned, Dynamic, C>) -> Owned { let mut data = ManuallyDrop::new(uninit.data); // Safety: MaybeUninit has the same alignment and layout as T. @@ -143,13 +126,19 @@ impl Allocator for DefaultAllocator { VecStorage::new(uninit.nrows, uninit.ncols, new_data) } +} + +// Static - Dynamic +#[cfg(any(feature = "std", feature = "alloc"))] +impl InnerAllocator for DefaultAllocator { + type Buffer = VecStorage; #[inline] fn allocate_from_iterator>( nrows: R, ncols: Dynamic, iter: I, - ) -> Self::Buffer { + ) -> Owned { let it = iter.into_iter(); let res: Vec = it.collect(); assert!(res.len() == nrows.value() * ncols.value(), @@ -159,6 +148,30 @@ impl Allocator for DefaultAllocator { } } +impl Allocator for DefaultAllocator { + #[inline] + fn allocate_uninitialized(nrows: R, ncols: Dynamic) -> Owned, R, Dynamic> { + let mut data = Vec::new(); + let length = nrows.value() * ncols.value(); + data.reserve_exact(length); + data.resize_with(length, MaybeUninit::uninit); + + VecStorage::new(nrows, ncols, data) + } + + #[inline] + unsafe fn assume_init(uninit: Owned, R, Dynamic>) -> Owned { + let mut data = ManuallyDrop::new(uninit.data); + + // Safety: MaybeUninit has the same alignment and layout as T. + let new_data = unsafe { + Vec::from_raw_parts(data.as_mut_ptr() as *mut T, data.len(), data.capacity()) + }; + + VecStorage::new(uninit.nrows, uninit.ncols, new_data) + } +} + /* * * Reallocator. @@ -176,10 +189,10 @@ where unsafe fn reallocate_copy( rto: Const, cto: Const, - buf: >::Buffer, + buf: Owned, ) -> ArrayStorage { let mut res = - , Const>>::allocate_uninitialized(rto, cto); + , Const>>::allocate_uninitialized(rto, cto); let (rfrom, cfrom) = buf.shape(); @@ -192,7 +205,7 @@ where ); // Safety: TODO - , Const>>::assume_init(res) + >::assume_init(res) } } diff --git a/src/base/matrix.rs b/src/base/matrix.rs index 90f030fc..90668044 100644 --- a/src/base/matrix.rs +++ b/src/base/matrix.rs @@ -34,10 +34,6 @@ use crate::{ArrayStorage, SMatrix, SimdComplexField}; #[cfg(any(feature = "std", feature = "alloc"))] use crate::{DMatrix, DVector, Dynamic, VecStorage}; -/// An uninitialized matrix. -pub type UninitMatrix = - Matrix, R, C, >::UninitBuffer>; - /// A square matrix. pub type SquareMatrix = Matrix; @@ -351,8 +347,7 @@ impl Matrix { } } -impl - Matrix, R, C, >::UninitBuffer> +impl OMatrix, R, C> where DefaultAllocator: Allocator, { @@ -368,16 +363,13 @@ where } } -impl - Matrix, R, C, >::UninitBuffer> +impl OMatrix, R, C> where DefaultAllocator: Allocator, { /// Assumes a matrix's entries to be initialized. This operation should be near zero-cost. - pub unsafe fn assume_init( - self, - ) -> Matrix>::Buffer> { - Matrix { + pub unsafe fn assume_init(self) -> OMatrix { + OMatrix { data: >::assume_init(self.data), _phantoms: PhantomData, } @@ -791,19 +783,19 @@ impl> Matrix { { let (nrows, ncols) = self.data.shape(); - let mut res: OMatrix = - unsafe { crate::unimplemented_or_uninitialized_generic!(nrows, ncols) }; + let mut res = OMatrix::new_uninitialized_generic(nrows, ncols); for j in 0..ncols.value() { for i in 0..nrows.value() { unsafe { let a = self.data.get_unchecked(i, j).clone(); - *res.data.get_unchecked_mut(i, j) = f(i, j, a) + *res.data.get_unchecked_mut(i, j) = MaybeUninit::new(f(i, j, a)); } } } - res + // Safety: all entries have been initialized. + unsafe { res.assume_init() } } /// Returns a matrix containing the result of `f` applied to each entries of `self` and diff --git a/src/base/ops.rs b/src/base/ops.rs index 852f6490..b52eb741 100644 --- a/src/base/ops.rs +++ b/src/base/ops.rs @@ -1,11 +1,13 @@ use num::{One, Zero}; use std::iter; +use std::mem::MaybeUninit; use std::ops::{ Add, AddAssign, Div, DivAssign, Index, IndexMut, Mul, MulAssign, Neg, Sub, SubAssign, }; use simba::scalar::{ClosedAdd, ClosedDiv, ClosedMul, ClosedNeg, ClosedSub}; +use crate::allocator::InnerAllocator; use crate::base::allocator::{Allocator, SameShapeAllocator, SameShapeC, SameShapeR}; use crate::base::constraint::{ AreMultipliable, DimEq, SameNumberOfColumns, SameNumberOfRows, ShapeConstraint, @@ -14,6 +16,7 @@ use crate::base::dimension::{Dim, DimMul, DimName, DimProd, Dynamic}; use crate::base::storage::{ContiguousStorageMut, Storage, StorageMut}; use crate::base::{DefaultAllocator, Matrix, MatrixSum, OMatrix, Scalar, VectorSlice}; use crate::SimdComplexField; +use crate::storage::Owned; /* * @@ -147,12 +150,12 @@ macro_rules! componentwise_binop_impl( * */ #[inline] - fn $method_to_statically_unchecked(&self, - rhs: &Matrix, - out: &mut Matrix) - where SB: Storage, - SC: StorageMut { + fn $method_to_statically_unchecked( + &self, rhs: &Matrix, out: &mut Matrix, R3, C3, SC> + ) where + SB: Storage, + SC: StorageMut + StorageMut, R3, C3> + { assert_eq!(self.shape(), rhs.shape(), "Matrix addition/subtraction dimensions mismatch."); assert_eq!(self.shape(), out.shape(), "Matrix addition/subtraction output dimensions mismatch."); @@ -162,15 +165,18 @@ macro_rules! componentwise_binop_impl( if self.data.is_contiguous() && rhs.data.is_contiguous() && out.data.is_contiguous() { let arr1 = self.data.as_slice_unchecked(); let arr2 = rhs.data.as_slice_unchecked(); - let out = out.data.as_mut_slice_unchecked(); - for i in 0 .. arr1.len() { - *out.get_unchecked_mut(i) = arr1.get_unchecked(i).inlined_clone().$method(arr2.get_unchecked(i).inlined_clone()); + let out = out.data.as_mut_slice_unchecked(); + for i in 0..arr1.len() { + *out.get_unchecked_mut(i) = MaybeUninit::new( + arr1.get_unchecked(i).inlined_clone().$method(arr2.get_unchecked(i).inlined_clone() + )); } } else { - for j in 0 .. self.ncols() { - for i in 0 .. self.nrows() { - let val = self.get_unchecked((i, j)).inlined_clone().$method(rhs.get_unchecked((i, j)).inlined_clone()); - *out.get_unchecked_mut((i, j)) = val; + for j in 0..self.ncols() { + for i in 0..self.nrows() { + *out.get_unchecked_mut((i, j)) = MaybeUninit::new( + self.get_unchecked((i, j)).inlined_clone().$method(rhs.get_unchecked((i, j)).inlined_clone()) + ); } } } @@ -421,6 +427,11 @@ impl<'a, T, C: Dim> iter::Sum<&'a OMatrix> for OMatrix, + + // TODO: we should take out this trait bound, as T: Clone should suffice. + // The brute way to do it would be how it was already done: by adding this + // trait bound on the associated type itself. + Owned: Clone, { /// # Example /// ``` @@ -635,7 +646,7 @@ where SB: Storage, SA: ContiguousStorageMut + Clone, ShapeConstraint: AreMultipliable, - DefaultAllocator: Allocator, + DefaultAllocator: InnerAllocator, { #[inline] fn mul_assign(&mut self, rhs: Matrix) { @@ -653,7 +664,7 @@ where SA: ContiguousStorageMut + Clone, ShapeConstraint: AreMultipliable, // TODO: this is too restrictive. See comments for the non-ref version. - DefaultAllocator: Allocator, + DefaultAllocator: InnerAllocator, { #[inline] fn mul_assign(&mut self, rhs: &'b Matrix) { diff --git a/src/base/storage.rs b/src/base/storage.rs index cc2cb32d..518fbf71 100644 --- a/src/base/storage.rs +++ b/src/base/storage.rs @@ -2,7 +2,7 @@ use std::ptr; -use crate::base::allocator::{Allocator, SameShapeC, SameShapeR}; +use crate::base::allocator::{Allocator, InnerAllocator, SameShapeC, SameShapeR}; use crate::base::default_allocator::DefaultAllocator; use crate::base::dimension::{Dim, U1}; @@ -11,19 +11,19 @@ use crate::base::dimension::{Dim, U1}; */ /// The data storage for the sum of two matrices with dimensions `(R1, C1)` and `(R2, C2)`. pub type SameShapeStorage = - , SameShapeC>>::Buffer; + , SameShapeC>>::Buffer; // TODO: better name than Owned ? /// The owned data storage that can be allocated from `S`. -pub type Owned = >::Buffer; +pub type Owned = >::Buffer; /// The row-stride of the owned data storage for a buffer of dimension `(R, C)`. pub type RStride = - <>::Buffer as Storage>::RStride; + <>::Buffer as Storage>::RStride; /// The column-stride of the owned data storage for a buffer of dimension `(R, C)`. pub type CStride = - <>::Buffer as Storage>::CStride; + <>::Buffer as Storage>::CStride; /// The trait shared by all matrix data storage. /// diff --git a/src/base/vec_storage.rs b/src/base/vec_storage.rs index 294ae4bf..04423beb 100644 --- a/src/base/vec_storage.rs +++ b/src/base/vec_storage.rs @@ -4,14 +4,14 @@ use std::io::{Result as IOResult, Write}; #[cfg(all(feature = "alloc", not(feature = "std")))] use alloc::vec::Vec; -use crate::base::allocator::Allocator; +use crate::allocator::InnerAllocator; use crate::base::constraint::{SameNumberOfRows, ShapeConstraint}; use crate::base::default_allocator::DefaultAllocator; use crate::base::dimension::{Dim, DimName, Dynamic, U1}; use crate::base::storage::{ ContiguousStorage, ContiguousStorageMut, Owned, ReshapableStorage, Storage, StorageMut, }; -use crate::base::{ Vector}; +use crate::base::Vector; #[cfg(feature = "serde-serialize-no-std")] use serde::{ @@ -159,7 +159,7 @@ impl From> for Vec { */ unsafe impl Storage for VecStorage where - DefaultAllocator: Allocator, + DefaultAllocator: InnerAllocator, { type RStride = U1; type CStride = Dynamic; @@ -187,7 +187,7 @@ where #[inline] fn into_owned(self) -> Owned where - DefaultAllocator: Allocator, + DefaultAllocator: InnerAllocator, { self } @@ -195,7 +195,7 @@ where #[inline] fn clone_owned(&self) -> Owned where - DefaultAllocator: Allocator, + DefaultAllocator: InnerAllocator, { self.clone() } @@ -208,7 +208,7 @@ where unsafe impl Storage for VecStorage where - DefaultAllocator: Allocator, + DefaultAllocator: InnerAllocator, { type RStride = U1; type CStride = R; @@ -236,7 +236,7 @@ where #[inline] fn into_owned(self) -> Owned where - DefaultAllocator: Allocator, + DefaultAllocator: InnerAllocator, { self } @@ -244,7 +244,7 @@ where #[inline] fn clone_owned(&self) -> Owned where - DefaultAllocator: Allocator, + DefaultAllocator: InnerAllocator, { self.clone() } @@ -262,7 +262,7 @@ where */ unsafe impl StorageMut for VecStorage where - DefaultAllocator: Allocator, + DefaultAllocator: InnerAllocator, { #[inline] fn ptr_mut(&mut self) -> *mut T { @@ -276,12 +276,12 @@ where } unsafe impl ContiguousStorage for VecStorage where - DefaultAllocator: Allocator + DefaultAllocator: InnerAllocator { } unsafe impl ContiguousStorageMut for VecStorage where - DefaultAllocator: Allocator + DefaultAllocator: InnerAllocator { } @@ -317,7 +317,7 @@ impl ReshapableStorage unsafe impl StorageMut for VecStorage where - DefaultAllocator: Allocator, + DefaultAllocator: InnerAllocator, { #[inline] fn ptr_mut(&mut self) -> *mut T { @@ -376,12 +376,12 @@ impl Abomonation for VecStorage { } unsafe impl ContiguousStorage for VecStorage where - DefaultAllocator: Allocator + DefaultAllocator: InnerAllocator { } unsafe impl ContiguousStorageMut for VecStorage where - DefaultAllocator: Allocator + DefaultAllocator: InnerAllocator { } diff --git a/src/geometry/point.rs b/src/geometry/point.rs index 70a1fde7..d3e52d5e 100644 --- a/src/geometry/point.rs +++ b/src/geometry/point.rs @@ -18,6 +18,7 @@ use crate::base::allocator::Allocator; use crate::base::dimension::{DimName, DimNameAdd, DimNameSum, U1}; use crate::base::iter::{MatrixIter, MatrixIterMut}; use crate::base::{Const, DefaultAllocator, OVector, Scalar}; +use crate::storage::Owned; /// A point in an euclidean space. /// @@ -271,9 +272,7 @@ where /// assert_eq!(it.next(), Some(3.0)); /// assert_eq!(it.next(), None); #[inline] - pub fn iter( - &self, - ) -> MatrixIter, >::Buffer> { + pub fn iter(&self) -> MatrixIter, Owned> { self.coords.iter() } @@ -297,9 +296,7 @@ where /// /// assert_eq!(p, Point3::new(10.0, 20.0, 30.0)); #[inline] - pub fn iter_mut( - &mut self, - ) -> MatrixIterMut, >::Buffer> { + pub fn iter_mut(&mut self) -> MatrixIterMut, Owned> { self.coords.iter_mut() } @@ -385,7 +382,7 @@ where } } -impl PartialOrd for OPoint +impl PartialOrd for OPoint where DefaultAllocator: Allocator, { diff --git a/src/geometry/point_construction.rs b/src/geometry/point_construction.rs index 0ffbf4d8..a4da45b4 100644 --- a/src/geometry/point_construction.rs +++ b/src/geometry/point_construction.rs @@ -173,10 +173,10 @@ where } #[cfg(feature = "arbitrary")] -impl Arbitrary for OPoint +impl Arbitrary for OPoint where - >::Buffer: Send, DefaultAllocator: Allocator, + crate:: base::storage::Owned: Send, { #[inline] fn arbitrary(g: &mut Gen) -> Self { diff --git a/src/geometry/point_conversion.rs b/src/geometry/point_conversion.rs index f35a9fc6..62528641 100644 --- a/src/geometry/point_conversion.rs +++ b/src/geometry/point_conversion.rs @@ -7,6 +7,7 @@ use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; use crate::base::{Const, DefaultAllocator, Matrix, OVector, Scalar}; use crate::geometry::Point; +use crate::storage::Owned; use crate::{DimName, OPoint}; /* @@ -110,12 +111,11 @@ where } } -impl From<[Point; 2]> - for Point +impl From<[Point; 2]> for Point where T: From<[::Element; 2]>, - T::Element: Scalar + Copy, - >>::Buffer: Copy, + T::Element: Copy, + Owned>: Copy, { #[inline] fn from(arr: [Point; 2]) -> Self { @@ -123,12 +123,11 @@ where } } -impl From<[Point; 4]> - for Point +impl From<[Point; 4]> for Point where T: From<[::Element; 4]>, - T::Element: Scalar + Copy, - >>::Buffer: Copy, + T::Element: Copy, + Owned>: Copy, { #[inline] fn from(arr: [Point; 4]) -> Self { @@ -141,12 +140,11 @@ where } } -impl From<[Point; 8]> - for Point +impl From<[Point; 8]> for Point where T: From<[::Element; 8]>, - T::Element: Scalar + Copy, - >>::Buffer: Copy, + T::Element: Copy, + Owned>: Copy, { #[inline] fn from(arr: [Point; 8]) -> Self { @@ -163,12 +161,11 @@ where } } -impl From<[Point; 16]> - for Point +impl From<[Point; 16]> for Point where T: From<[::Element; 16]>, - T::Element: Scalar + Copy, - >>::Buffer: Copy, + T::Element: Copy, + Owned>: Copy, { #[inline] fn from(arr: [Point; 16]) -> Self { diff --git a/src/geometry/rotation.rs b/src/geometry/rotation.rs index 98e8fcbc..4062de0d 100755 --- a/src/geometry/rotation.rs +++ b/src/geometry/rotation.rs @@ -10,6 +10,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; #[cfg(feature = "serde-serialize-no-std")] use crate::base::storage::Owned; +use crate::storage::Owned; #[cfg(feature = "abomonation-serialize")] use abomonation::Abomonation; @@ -59,23 +60,20 @@ pub struct Rotation { matrix: SMatrix, } -impl hash::Hash for Rotation +impl hash::Hash for Rotation where - , Const>>::Buffer: hash::Hash, + Owned, Const>: hash::Hash, { fn hash(&self, state: &mut H) { self.matrix.hash(state) } } -impl Copy for Rotation where - , Const>>::Buffer: Copy -{ -} +impl Copy for Rotation where Owned, Const>: Copy {} -impl Clone for Rotation +impl Clone for Rotation where - , Const>>::Buffer: Clone, + Owned, Const>: Clone, { #[inline] fn clone(&self) -> Self { @@ -86,7 +84,6 @@ where #[cfg(feature = "abomonation-serialize")] impl Abomonation for Rotation where - T: Scalar, SMatrix: Abomonation, { unsafe fn entomb(&self, writer: &mut W) -> IOResult<()> { @@ -116,7 +113,7 @@ where } #[cfg(feature = "serde-serialize-no-std")] -impl<'a, T: Scalar, const D: usize> Deserialize<'a> for Rotation +impl<'a, T, const D: usize> Deserialize<'a> for Rotation where Owned, Const>: Deserialize<'a>, {