New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a method to create a matrix of vector from a Vec. #378

Open
sebcrozet opened this Issue Sep 3, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@sebcrozet
Member

sebcrozet commented Sep 3, 2018

For dynamically-sized matrices and vectors, this would be much more efficient than the current solutions (::from_row_slice and ::from_column_slice) which copy the content of a slice. See the suggestion on the 5th point of this post.

@sebcrozet

This comment has been minimized.

Member

sebcrozet commented Sep 13, 2018

Note that the current way of doing this is quite complicated: DMatrix::from_data(MatrixVec::new(Dynamic::new(nrows), Dynamic::new(ncols), vec)) where nrows, ncols, vec are the dimension of the matrix and the Vec.

@mpizenberg

This comment has been minimized.

mpizenberg commented Sep 14, 2018

Oh good to know there is a way to do it! I never looked into MatrixVec internals yet.

jswrenn added a commit to jswrenn/nalgebra that referenced this issue Nov 7, 2018

Introduces a `from_vec` constructor for `MatrixMN`.
Addresses rustsim#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 rust-lang/rust#46084 (comment)),
this is equivalent to re-using the original Vec as storage.

sebcrozet added a commit that referenced this issue Nov 8, 2018

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 rust-lang/rust#46084 (comment)),
this is equivalent to re-using the original Vec as storage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment