Reputation: 885
Given an array M:[sps]
over a sps = sparse subdomain(dom)
where dom: domain(n)
, I know I can iterate densely over the kth dimension with for j in M.domain.dim(k) {...}
. How would I define an analogous loop that visits only populated locations in k such that if M.domain.dim(k) = {1..N}
, but there are only m populated indices in k, the loop only formally generates m iterations rather than N?
Would the way to do this be to iterate over the whole sparse domain with an iterand that only references one index? (i.e. for (i,j) in spsDom { var idx = i }
)
Upvotes: 3
Views: 60
Reputation: 4008
I don't have much of an answer to this question beyond my previous answer to a similar question. The quick summary is that there is an undocumented iterator, dimIter()
that can be used to iterate over the efficient dimension of a sparse domain stored with a 2D CSR/CSC format, but there is not an official interface for doing this for all sparse domains today (as of version 1.16 of Chapel).
I think the way we'd want to express this ultimately would be to support slicing of sparse domains and then iterate over that slice.
Upvotes: 1