Introduces a from_vec constructor for MatrixMN.

Addresses #378.

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.
This commit is contained in:
Jack Wrenn 2018-11-06 19:46:28 -05:00 committed by Sébastien Crozet
parent c370564dba
commit ff4e44a8ed

View File

@ -257,6 +257,13 @@ where DefaultAllocator: Allocator<N, R, C>
{ {
Self::from_fn_generic(nrows, ncols, |_, _| distribution.sample(rng)) 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> impl<N, D: Dim> MatrixN<N, D>