Chapel: Creating a dense array out of a sparse one

Created on 12 Jul 2019  路  10Comments  路  Source: chapel-lang/chapel

Currently there is nothing in the sparse array interface that allows creating a dense array from a sparse one. Some method that can do that can help with linear algebra routines and some others.

Libraries / Modules Design

All 10 comments

Scipy has toarray method for something like that. I am not quite fond of the name as sparse arrays are still arrays in Chapel. I am thinking toDense but it sort of implies that it converts the existing sparse array to dense, which is not what that method is going to do. I am open to suggestions in terms of the method name here. I will look around a little bit myself, as well.

Possibly interested are @wongalvis14 and @ben-albrecht

Should this method simply return the internal parentDom field? If so, this method could apply more generally to any subdomain.

We should also consider how this might generalize to other layouts, e.g. should we have similar methods for converting CSR <-> CSC <-> COO <-> Dense?

parentDom might not be dense, if it's a sparse subdomain itself..

@benharsh: As I understand it, the goal is to get an array, not a domain, but otherwise I think basing the array on the parentDom has potential merit. Something like:

var DenserArr: [parentDom] eltType;
forall ind in parentDom do
  DenserArr = dsiAccess[ind];

ought to do it? As Paul points, out this doesn't guarantee a dense array, so we might also want a "denseParentDom" method that gets the first dense domain in the parent domain links and does the similar thing.

(for that matter, doing this outside of the array implementation would be simple if we had a "denseParentDom()" query. The user should just be able to write:

var DenseArr: [SparseArr.denseParentDom()] SparseArr.eltType = SparseArr;

)

I'd tried yesterday with var DA: [DD] SA.eltType = SA;, but hit

sparse2dense.chpl:12: error: Sparse iterators can't yet be zippered with others

Oh shoot, we should really fix that. You ought to be able to assign a sparse array to a dense.

I think the workaround would be:

var DA: [DD] SA.eltType = [i in DD] SA[i];

but this is going to be much more expensive than just implementing a follower iterator on sparse arrays that knows how to yield IRVs until it hits the next nonzero.

I added issue #13452 to capture this longstanding desire to assign a sparse array to a dense one.

I am currently thinking that #13452 is a higher-priority issue. It is more generic and can potentially allow more idioms. If there is a roadblock resolving that issue then this can be an alternative stopgap measure.

Or we might consider adding a toArray one-liner only for convenience.

Was this page helpful?
0 / 5 - 0 ratings