# Generic interface to iterate over stored elements of array?

**URL:** <https://discourse.julialang.org/t/generic-interface-to-iterate-over-stored-elements-of-array/77867>\
**Category:** General Usage\
**Created:** [March 14, 2022, 2:01pm UTC](https://discourse.julialang.org/t/generic-interface-to-iterate-over-stored-elements-of-array/77867 "2022-03-14T14:01:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [March 14, 2022, 2:01pm UTC](https://discourse.julialang.org/t/generic-interface-to-iterate-over-stored-elements-of-array/77867/1 "2022-03-14T14:01:53Z")

</div>

I’m playing with making a [simple optimization package](https://github.com/m3g/SPGBox.jl) generic to any type of input. It is already generic to inputs in the form vectors, matrices, number types (precision), units, etc.

But I could not yet make it generic for sparse matrices as inputs, because iterators like

```julia
for i in eachindex(x)
    ...
end

```

iterate over all indexes of the matrices, stored or not.

Is there a generic iterator to iterate over stored-only elements of sparse matrices (specifically `SparseMatrixCSC` from `SparseArrays`). I have seen that some of that was discussed previously and led to the `ArrayIteration.jl` package, but it seems that it was not released?

---

<div class="post-metadata">

**Author:** ![Akatz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/akatz/32/15164_2.png) [@Akatz](https://discourse.julialang.org/u/Akatz)\
**Post date:** [March 14, 2022, 6:11pm UTC](https://discourse.julialang.org/t/generic-interface-to-iterate-over-stored-elements-of-array/77867/2 "2022-03-14T18:11:59Z")

</div>

@rayegun is working on a sparse array interface. I can’t say if it would share an API with dense arrays. There’s also the issue of distributed and GPU support, but I don’t think we have a good abstraction for all the right now

---

<div class="post-metadata">

**Author:** ![rayegun](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rayegun/32/26729_2.png) [@rayegun](https://discourse.julialang.org/u/rayegun)\
**Post date:** [March 23, 2022, 8:26pm UTC](https://discourse.julialang.org/t/generic-interface-to-iterate-over-stored-elements-of-array/77867/3 "2022-03-23T20:26:41Z")

</div>

ArrayIteration.jl may return in some form. A good sparse array interface is still some ways off, but it will include iterating over stored values.

In the upcoming release of SuiteSparseGraphBLAS.jl (v0.6) there will be a nonzeros iterator as well, although it’s not quite ready.
