forked from M-Labs/nalgebra
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:
parent
c370564dba
commit
ff4e44a8ed
@ -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>
|
||||||
|
Loading…
Reference in New Issue
Block a user