From 0f66403cbbe9eeac15cedd8a906c0d6a3d8841f2 Mon Sep 17 00:00:00 2001 From: Jack Wrenn Date: Wed, 5 Dec 2018 16:46:17 -0500 Subject: [PATCH] Rename `MatrixVec` to `VecStorage`. See #470. --- src/base/alias.rs | 6 +-- src/base/conversion.rs | 10 ++--- src/base/default_allocator.rs | 44 +++++++++---------- src/base/mod.rs | 4 +- src/base/storage.rs | 2 +- src/base/{matrix_vec.rs => vec_storage.rs} | 50 ++++++++++++---------- 6 files changed, 60 insertions(+), 56 deletions(-) rename src/base/{matrix_vec.rs => vec_storage.rs} (80%) diff --git a/src/base/alias.rs b/src/base/alias.rs index 3942b94e..f7ca2b34 100644 --- a/src/base/alias.rs +++ b/src/base/alias.rs @@ -2,7 +2,7 @@ use base::dimension::Dynamic; use base::dimension::{U1, U2, U3, U4, U5, U6}; #[cfg(any(feature = "std", feature = "alloc"))] -use base::matrix_vec::MatrixVec; +use base::vec_storage::VecStorage; use base::storage::Owned; use base::Matrix; @@ -119,7 +119,7 @@ pub type Matrix6x5 = MatrixMN; */ /// A dynamically sized column vector. #[cfg(any(feature = "std", feature = "alloc"))] -pub type DVector = Matrix>; +pub type DVector = Matrix>; /// A statically sized D-dimensional column vector. pub type VectorN = MatrixMN; @@ -146,7 +146,7 @@ pub type Vector6 = VectorN; */ /// A dynamically sized row vector. #[cfg(any(feature = "std", feature = "alloc"))] -pub type RowDVector = Matrix>; +pub type RowDVector = Matrix>; /// A statically sized D-dimensional row vector. pub type RowVectorN = MatrixMN; diff --git a/src/base/conversion.rs b/src/base/conversion.rs index d2130a5d..b9acd66b 100644 --- a/src/base/conversion.rs +++ b/src/base/conversion.rs @@ -17,7 +17,7 @@ use base::dimension::{ use base::iter::{MatrixIter, MatrixIterMut}; use base::storage::{ContiguousStorage, ContiguousStorageMut, Storage, StorageMut}; #[cfg(any(feature = "std", feature = "alloc"))] -use base::MatrixVec; +use base::VecStorage; use base::{DefaultAllocator, Matrix, ArrayStorage, MatrixMN, MatrixSlice, MatrixSliceMut, Scalar}; // FIXME: too bad this won't work allo slice conversions. @@ -353,7 +353,7 @@ where #[cfg(any(feature = "std", feature = "alloc"))] impl<'a, N, C, RStride, CStride> From> - for Matrix> + for Matrix> where N: Scalar, C: Dim, @@ -367,7 +367,7 @@ where #[cfg(any(feature = "std", feature = "alloc"))] impl<'a, N, R, RStride, CStride> From> - for Matrix> + for Matrix> where N: Scalar, R: DimName, @@ -397,7 +397,7 @@ where #[cfg(any(feature = "std", feature = "alloc"))] impl<'a, N, C, RStride, CStride> From> - for Matrix> + for Matrix> where N: Scalar, C: Dim, @@ -411,7 +411,7 @@ where #[cfg(any(feature = "std", feature = "alloc"))] impl<'a, N, R, RStride, CStride> From> - for Matrix> + for Matrix> where N: Scalar, R: DimName, diff --git a/src/base/default_allocator.rs b/src/base/default_allocator.rs index 49cd1d1d..5926f39d 100644 --- a/src/base/default_allocator.rs +++ b/src/base/default_allocator.rs @@ -20,7 +20,7 @@ use base::dimension::Dynamic; use base::dimension::{Dim, DimName}; use base::array_storage::ArrayStorage; #[cfg(any(feature = "std", feature = "alloc"))] -use base::matrix_vec::MatrixVec; +use base::vec_storage::VecStorage; use base::storage::{Storage, StorageMut}; use base::Scalar; @@ -29,7 +29,7 @@ use base::Scalar; * Allocator. * */ -/// An allocator based on `GenericArray` and `MatrixVec` for statically-sized and dynamically-sized +/// An allocator based on `GenericArray` and `VecStorage` for statically-sized and dynamically-sized /// matrices respectively. pub struct DefaultAllocator; @@ -77,7 +77,7 @@ where // Dynamic - Dynamic #[cfg(any(feature = "std", feature = "alloc"))] impl Allocator for DefaultAllocator { - type Buffer = MatrixVec; + type Buffer = VecStorage; #[inline] unsafe fn allocate_uninitialized(nrows: Dynamic, ncols: C) -> Self::Buffer { @@ -86,7 +86,7 @@ impl Allocator for DefaultAllocator { res.reserve_exact(length); res.set_len(length); - MatrixVec::new(nrows, ncols, res) + VecStorage::new(nrows, ncols, res) } #[inline] @@ -101,14 +101,14 @@ impl Allocator for DefaultAllocator { assert!(res.len() == nrows.value() * ncols.value(), "Allocation from iterator error: the iterator did not yield the correct number of elements."); - MatrixVec::new(nrows, ncols, res) + VecStorage::new(nrows, ncols, res) } } // Static - Dynamic #[cfg(any(feature = "std", feature = "alloc"))] impl Allocator for DefaultAllocator { - type Buffer = MatrixVec; + type Buffer = VecStorage; #[inline] unsafe fn allocate_uninitialized(nrows: R, ncols: Dynamic) -> Self::Buffer { @@ -117,7 +117,7 @@ impl Allocator for DefaultAllocator { res.reserve_exact(length); res.set_len(length); - MatrixVec::new(nrows, ncols, res) + VecStorage::new(nrows, ncols, res) } #[inline] @@ -132,7 +132,7 @@ impl Allocator for DefaultAllocator { assert!(res.len() == nrows.value() * ncols.value(), "Allocation from iterator error: the iterator did not yield the correct number of elements."); - MatrixVec::new(nrows, ncols, res) + VecStorage::new(nrows, ncols, res) } } @@ -186,7 +186,7 @@ where rto: Dynamic, cto: CTo, buf: ArrayStorage, - ) -> MatrixVec + ) -> VecStorage { let mut res = >::allocate_uninitialized(rto, cto); @@ -215,7 +215,7 @@ where rto: RTo, cto: Dynamic, buf: ArrayStorage, - ) -> MatrixVec + ) -> VecStorage { let mut res = >::allocate_uninitialized(rto, cto); @@ -238,11 +238,11 @@ impl Reallocator, - ) -> MatrixVec + buf: VecStorage, + ) -> VecStorage { let new_buf = buf.resize(rto.value() * cto.value()); - MatrixVec::new(rto, cto, new_buf) + VecStorage::new(rto, cto, new_buf) } } @@ -254,11 +254,11 @@ impl Reallocator, - ) -> MatrixVec + buf: VecStorage, + ) -> VecStorage { let new_buf = buf.resize(rto.value() * cto.value()); - MatrixVec::new(rto, cto, new_buf) + VecStorage::new(rto, cto, new_buf) } } @@ -270,11 +270,11 @@ impl Reallocator, - ) -> MatrixVec + buf: VecStorage, + ) -> VecStorage { let new_buf = buf.resize(rto.value() * cto.value()); - MatrixVec::new(rto, cto, new_buf) + VecStorage::new(rto, cto, new_buf) } } @@ -286,10 +286,10 @@ impl Reallocator, - ) -> MatrixVec + buf: VecStorage, + ) -> VecStorage { let new_buf = buf.resize(rto.value() * cto.value()); - MatrixVec::new(rto, cto, new_buf) + VecStorage::new(rto, cto, new_buf) } } diff --git a/src/base/mod.rs b/src/base/mod.rs index fca573c4..65a86032 100644 --- a/src/base/mod.rs +++ b/src/base/mod.rs @@ -23,7 +23,7 @@ mod matrix_alga; mod array_storage; mod matrix_slice; #[cfg(any(feature = "std", feature = "alloc"))] -mod matrix_vec; +mod vec_storage; mod properties; mod scalar; mod swizzle; @@ -44,4 +44,4 @@ pub use self::alias_slice::*; pub use self::array_storage::*; pub use self::matrix_slice::*; #[cfg(any(feature = "std", feature = "alloc"))] -pub use self::matrix_vec::*; +pub use self::vec_storage::*; diff --git a/src/base/storage.rs b/src/base/storage.rs index b96f69d0..0a07713b 100644 --- a/src/base/storage.rs +++ b/src/base/storage.rs @@ -34,7 +34,7 @@ pub type CStride = /// Note that `Self` must always have a number of elements compatible with the matrix length (given /// by `R` and `C` if they are known at compile-time). For example, implementors of this trait /// should **not** allow the user to modify the size of the underlying buffer with safe methods -/// (for example the `MatrixVec::data_mut` method is unsafe because the user could change the +/// (for example the `VecStorage::data_mut` method is unsafe because the user could change the /// vector's size so that it no longer contains enough elements: this will lead to UB. pub unsafe trait Storage: Debug + Sized { /// The static stride of this storage's rows. diff --git a/src/base/matrix_vec.rs b/src/base/vec_storage.rs similarity index 80% rename from src/base/matrix_vec.rs rename to src/base/vec_storage.rs index 8f4a5881..b5005c0c 100644 --- a/src/base/matrix_vec.rs +++ b/src/base/vec_storage.rs @@ -24,21 +24,25 @@ use abomonation::Abomonation; #[repr(C)] #[derive(Eq, Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] -pub struct MatrixVec { +pub struct VecStorage { data: Vec, nrows: R, ncols: C, } -impl MatrixVec { +#[deprecated(note="renamed to `VecStorage`")] +/// Renamed to [VecStorage]. +pub type MatrixVec = VecStorage; + +impl VecStorage { /// Creates a new dynamic matrix data storage from the given vector and shape. #[inline] - pub fn new(nrows: R, ncols: C, data: Vec) -> MatrixVec { + pub fn new(nrows: R, ncols: C, data: Vec) -> VecStorage { assert!( nrows.value() * ncols.value() == data.len(), "Data storage buffer dimension mismatch." ); - MatrixVec { + VecStorage { data: data, nrows: nrows, ncols: ncols, @@ -79,7 +83,7 @@ impl MatrixVec { } } -impl Deref for MatrixVec { +impl Deref for VecStorage { type Target = Vec; #[inline] @@ -88,7 +92,7 @@ impl Deref for MatrixVec { } } -impl Into> for MatrixVec +impl Into> for VecStorage { fn into(self) -> Vec { self.data @@ -101,7 +105,7 @@ impl Into> for MatrixVec * Dynamic − Dynamic * */ -unsafe impl Storage for MatrixVec +unsafe impl Storage for VecStorage where DefaultAllocator: Allocator { type RStride = U1; @@ -145,7 +149,7 @@ where DefaultAllocator: Allocator } } -unsafe impl Storage for MatrixVec +unsafe impl Storage for VecStorage where DefaultAllocator: Allocator { type RStride = U1; @@ -194,7 +198,7 @@ where DefaultAllocator: Allocator * StorageMut, ContiguousStorage. * */ -unsafe impl StorageMut for MatrixVec +unsafe impl StorageMut for VecStorage where DefaultAllocator: Allocator { #[inline] @@ -208,13 +212,13 @@ where DefaultAllocator: Allocator } } -unsafe impl ContiguousStorage for MatrixVec where DefaultAllocator: Allocator +unsafe impl ContiguousStorage for VecStorage where DefaultAllocator: Allocator {} -unsafe impl ContiguousStorageMut for MatrixVec where DefaultAllocator: Allocator +unsafe impl ContiguousStorageMut for VecStorage where DefaultAllocator: Allocator {} -unsafe impl StorageMut for MatrixVec +unsafe impl StorageMut for VecStorage where DefaultAllocator: Allocator { #[inline] @@ -229,7 +233,7 @@ where DefaultAllocator: Allocator } #[cfg(feature = "abomonation-serialize")] -impl Abomonation for MatrixVec { +impl Abomonation for VecStorage { unsafe fn entomb(&self, writer: &mut W) -> IOResult<()> { self.data.entomb(writer) } @@ -243,21 +247,21 @@ impl Abomonation for MatrixVec { } } -unsafe impl ContiguousStorage for MatrixVec where DefaultAllocator: Allocator +unsafe impl ContiguousStorage for VecStorage where DefaultAllocator: Allocator {} -unsafe impl ContiguousStorageMut for MatrixVec where DefaultAllocator: Allocator +unsafe impl ContiguousStorageMut for VecStorage where DefaultAllocator: Allocator {} -impl Extend for MatrixVec +impl Extend for VecStorage { - /// Extends the number of columns of the `MatrixVec` with elements + /// Extends the number of columns of the `VecStorage` with elements /// from the given iterator. /// /// # Panics /// This function panics if the number of elements yielded by the /// given iterator is not a multiple of the number of rows of the - /// `MatrixVec`. + /// `VecStorage`. fn extend>(&mut self, iter: I) { self.data.extend(iter); @@ -267,7 +271,7 @@ impl Extend for MatrixVec } } -impl Extend> for MatrixVec +impl Extend> for VecStorage where N: Scalar, R: Dim, @@ -275,13 +279,13 @@ where SV: Storage, ShapeConstraint: SameNumberOfRows, { - /// Extends the number of columns of the `MatrixVec` with vectors + /// Extends the number of columns of the `VecStorage` with vectors /// from the given iterator. /// /// # Panics /// This function panics if the number of rows of each `Vector` /// yielded by the iterator is not equal to the number of rows - /// of this `MatrixVec`. + /// of this `VecStorage`. fn extend>>(&mut self, iter: I) { let nrows = self.nrows.value(); @@ -296,9 +300,9 @@ where } } -impl Extend for MatrixVec +impl Extend for VecStorage { - /// Extends the number of rows of the `MatrixVec` with elements + /// Extends the number of rows of the `VecStorage` with elements /// from the given iterator. fn extend>(&mut self, iter: I) {