Introduces a `from_vec` constructor for `MatrixMN`.
Addresses
The implementation of `from_vec` simply wraps a call to
`from_iterator_generic`. Because the standard library's implementation
of `into_iter` is specialized for the `.into_iter().collect<Vec<_>>()`
case (see https://github.com/rust-lang/rust/issues/46084#issuecomment-345524508),
this is equivalent to re-using the original Vec as storage.
@@ -257,6 +257,13 @@ where DefaultAllocator: Allocator<N, R, C>
{
Self::from_fn_generic(nrows, ncols, |_, _| distribution.sample(rng))
}
+
+ /// Creates a matrix backed by a given vector.
+ #[inline]
+ #[cfg(feature = "std")]
+ pub fn from_vec(nrows: R, ncols: C, data: Vec<N>) -> Self {
+ Self::from_iterator_generic(nrows, ncols, data)
+ }
}
impl<N, D: Dim> MatrixN<N, D>
