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
iter::Sum
for DMatrix
#517
Conversation
Dynamic dimensions default to `0`. Static dimensions default to themselves.
Interpret dynamic dimensions as 0.
If the sequence is empty, a zero matrix is produced in which any dynamic dimensions default to size 0. Fixes dimforge#514
That was a really quick response, thank you very much! I have not found any test cases for the implementation of |
@grtlr That would be great! In the interest of killing two birds with one stone, perhaps implement these as doctests on the If you fork and file a PR on my |
@jswrenn I have created a PR on your branch. If you have any comments regarding the formatting, feel free to let me know. |
Add doctests for std::iter::Sum
Was literally just wanting this now. You solved it in the past. Awesome! |
Thanks @jswrenn and @grtlr and very sorry for the late answer. For a first implementation of this, we should just panic if the provided matrix iterator is empty. Indeed, this implementation of let zero = DMatrix::zero();
let m = DMatrix::from_diagonal(2, 2, 1.0);
assert_eq!(m + zero, m) |
I've opened a separate pull request implementing the panic-on-empty behavior: #552. Sorry for the slow response; I've been recovering from some medical issues. |
@jswrenn No worry. Take care! |
This is one potential way to address #514. It tackles the problem in three steps:
Default
for dimensions. Statically known dimensions default to their value (this is already the behavior of theDefault
implementation provided by typenum). TheDefault
of aDynamic
dimension is 0.DimName
requirements onMatrix
constructors that required them; any dynamic dimensions simply default to zero size.DimName
requirements on functions that used these constructors, like the implementation ofiter::Sum
.This PR only lifts the
DimName
requirement oniter::Sum
, but the approach is broadly applicable and we can use it to liftDimName
requirements in many parts of nalgebra.