diff --git a/src/base/vec_storage.rs b/src/base/vec_storage.rs index 29da127d..15ea9237 100644 --- a/src/base/vec_storage.rs +++ b/src/base/vec_storage.rs @@ -15,6 +15,7 @@ use crate::base::{Scalar, Vector}; #[cfg(feature = "abomonation-serialize")] use abomonation::Abomonation; +use crate::{DMatrix, DVector}; /* * @@ -410,3 +411,23 @@ impl Extend for VecStorage { self.nrows = Dynamic::new(self.data.len()); } } + +impl DMatrix +{ + /// Creates a new heap-allocated matrix from the given [VecStorage]. + pub const fn from_vec_storage(storage: VecStorage) -> Self { + // This is sound because the dimensions of the matrix and the storage are guaranteed + // to be the same + unsafe { Self::from_data_statically_unchecked(storage) } + } +} + +impl DVector +{ + /// Creates a new heap-allocated matrix from the given [VecStorage]. + pub const fn from_vec_storage(storage: VecStorage) -> Self { + // This is sound because the dimensions of the matrix and the storage are guaranteed + // to be the same + unsafe { Self::from_data_statically_unchecked(storage) } + } +}