nalgebra icon indicating copy to clipboard operation
nalgebra copied to clipboard

ExactSizeIterator for matrix types?

Open Makogan opened this issue 1 year ago • 7 comments

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.

Makogan avatar Jun 08 '23 18:06 Makogan

Agreed, that would be a good addition.

sebcrozet avatar Jun 18 '23 10:06 sebcrozet

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?

spoloxs avatar Jun 25 '23 08:06 spoloxs

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?

geo-ant avatar Sep 13 '23 16:09 geo-ant

Is this not already done here? Happy to help as well, but could use a little more specificity on the expected implementation.

mnickrogers avatar Oct 04 '23 14:10 mnickrogers

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 avatar Oct 07 '23 22:10 Makogan

@Makogan are you still looking for a solution implementing exact size for outer type DMatrix problem so you can use STL methods on DMatrix?

camdenmcgath avatar Oct 19 '23 16:10 camdenmcgath

@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.

Makogan avatar Oct 22 '23 20:10 Makogan

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.

L00tkek avatar Aug 11 '24 17:08 L00tkek

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.

Ralith avatar Aug 11 '24 20:08 Ralith