Skip to content
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

std::iter::Sum for DVector and DMatrix #514

Closed
grtlr opened this issue Dec 28, 2018 · 0 comments
Closed

std::iter::Sum for DVector and DMatrix #514

grtlr opened this issue Dec 28, 2018 · 0 comments
Labels

Comments

@grtlr
Copy link
Contributor

grtlr commented Dec 28, 2018

Currently, there is no way to use std::iter::Sum with an iterator over matrices (or vectors). I believe the reason for this is that #264 implements the trait in terms of DimName and not the more general Dim type.

This makes a lot of sense because then the dimensions of the resulting matrix are known in advance. For dynamic matrices, we would have to check (or make the assumption) that all elements have the correct dimensions. A straightforward approach would be to have the first element determine the size of the allocation. The problem with this approach is that there might not be a first element (the sequence is empty):

let mut it = seq.iter();
let x = it.next().unwrap().clone();
let res = it.fold(x, |acc, v| acc + v);

Do you see a way to make std::iter::Sum work with the dynamic types?

@sebcrozet sebcrozet added enhancement P-medium Medium priority labels Dec 28, 2018
jswrenn added a commit to jswrenn/nalgebra that referenced this issue Dec 29, 2018
If the sequence is empty, a zero matrix is produced in which any dynamic dimensions default to size 0.

Fixes dimforge#514
jswrenn added a commit to jswrenn/nalgebra that referenced this issue Feb 19, 2019
sebcrozet pushed a commit that referenced this issue Feb 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants