Search code examples
multidimensional-arrayslicesparse-matrixhpcchapel

Sparse Slicing of Sparse Arrays in Chapel


Given some A: [sps] over a sparse subdomain of a dom: domain(2), a slice A[A.domain.dim(1), k] yields the k​th​​ column as a dense 1D-array. How do I retrieve the k​th​​ n−1 dimensional slice of a sparse nD-array as a sparse (n-1)D-array?

var nv: int = 8,
    D: domain(2) = {1..nv, 1..nv},
    SD: sparse subdomain(D),
    X: [SD] real;

SD += (1,2); X[1,2] = 1;
SD += (2,3); X[2,3] = 1;
SD += (3,1); X[3,1] = 1;
SD += (3,4); X[3,4] = 1;
SD += (4,5); X[4,5] = 1;
SD += (3,6); X[3,6] = 1;
SD += (6,8); X[6,8] = 1;

writeln(X);
writeln(X[X.domain.dim(1),2]);

returns

1.0
1.0
1.0 1.0 1.0
1.0
1.0

1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0

The expectation in the case that I succeed in sparse slicing would be a single 1.0 returned with the ability to retrieve this position of that entry by calling writeln() on slice.domain.


Solution

  • I think that, unfortunately, you are doing the right sort of thing and that you're just running afoul of the current (as of Chapel 1.16) limitations with respect to slicing sparse domains.