Impl DMatrix/DVector::from_vec_storage
These methods enable safe & const construction of DMatrix/DVector from a given VecStorage.
This commit is contained in:
parent
9142dc8f84
commit
d2c11ad797
|
@ -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<T> Extend<T> for VecStorage<T, Dynamic, U1> {
|
|||
self.nrows = Dynamic::new(self.data.len());
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> DMatrix<T>
|
||||
{
|
||||
/// Creates a new heap-allocated matrix from the given [VecStorage].
|
||||
pub const fn from_vec_storage(storage: VecStorage<T, Dynamic, Dynamic>) -> 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<T> DVector<T>
|
||||
{
|
||||
/// Creates a new heap-allocated matrix from the given [VecStorage].
|
||||
pub const fn from_vec_storage(storage: VecStorage<T, Dynamic, U1>) -> 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) }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue