Should there be a method that returns different sets of elements? (allElements(), nonZeroElements(), filteredElements(Condition)). Whatever the contract, it should definitely be stated and should definitely work the same for sparse or non-sparse matrices.
The only two reasonable options that I see are: a) iteration through vector themselves is in-order, hitting all elements. A special method returns an iterator through non-zeros or through all elements not equal to some specified value or satisfying some condition. Iterating through the non-zeros should work identically for dense and sparse matrices. b) iteration through a vector is "something" and is different for all types, but generally is something that we think would be convenient. Special methods return iterators with defined semantics. Obviously from the sarcastic tone of (b), I prefer (a) In-order iteration is definitely hard to do with many implementations. I don't know of any algorithms that really require in-order traversal for sparse matrices/vectors. For dense algorithms, ordering is often important (imagine back-substitution in an LU solver). On Tue, Jun 23, 2009 at 2:10 PM, Sean Owen <sro...@gmail.com> wrote: > You bet, Vector implements Iterable<Vector.Element>! > > In the case of SparseVector it only hits the nonzero elements. > > I wonder if we can tighten up the contract of Vector in this respect: > - can it really not guarantee in-order iteration? this seems intuitive > and maybe useful > - should state it may not (will not?) hit elements that are zero? > >