nalgebra
nalgebra copied to clipboard
ExactSizeIterator for matrix types?
I think the matrix types would benefit from implementing the core trait ExactSizeIterator, it would provide a generic way of determining the dimensions that would also be compatible with vectors from the stl and slices and other common list type containers.
Agreed, that would be a good addition.
Can I get a little elaboration about this ? From my understanding you want a function to know the dimension of a matrix that would be compatible for operations, like addition, multiplication etc., with a given matrix? Is this correct?
I'll gladly work on this but I also don't quite understand what is missing from the codebase. The row, column, and elementwise iterators all implement the ExactSizeIterator
trait. What am I missing?
Is this not already done here? Happy to help as well, but could use a little more specificity on the expected implementation.
Sorry for the delay. This was a while ago and I am trying to remember what the issue was. First @mnickrogers that link is about the inner storage type implementing exact size, not the outer matrix type like DMatrix.
The context for the request is, I was writing some generic code and needed to get the total number of elements as len. iirc I was trying to use one of the methods of the STL on a DMatrix.
@Makogan are you still looking for a solution implementing exact size for outer type DMatrix problem so you can use STL methods on DMatrix?
@Makogan are you still looking for a solution implementing exact size for outer type DMatrix problem so you can use STL methods on DMatrix?
I have found a work around for what I was doing and so I don't need it immediately atm. But I still think it would be nice to have.
I'm not sure if I'm understanding correctly, but it looks like this issue has been fixed since the last comment. The generic Matrix
type has an iter
method (see here) returning a MatrixIter
, which implements ExactSizeIterator
. You'd have to call matrix.iter().len()
instead of just matrix.len()
, but unless I'm not properly understanding the use case for implementing this trait, the current implementation does what we want it to.
ExactSizeIterator
indeed already exists for matrix iterators, and iterator traits don't make sense for types that aren't iterators. Not clear which this issue is intended to be about, but in either case I don't think this is actionable.