4

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.

ben-albrecht
  • 1,785
  • 10
  • 23
Tshimanga
  • 845
  • 6
  • 16

1 Answers1

2

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.

Brad
  • 3,839
  • 7
  • 25
  • Mkay, @bencray had mentioned intending to respond to this as well so I'll wait to hear his response (just in case) before accepting this answer. Thanks Brad – Tshimanga Mar 14 '18 at 19:00
  • I think this is a reasonable answer. It would be nice to provide some kind of work-around, but I don't have one readily available currently. I will update if that changes. – ben-albrecht Mar 14 '18 at 20:13
  • Yeah, I've been trying to think of a workaround as well. If the goal is literally "I want a full-fledged 1D sparse array that aliases those same elements" then I don't think there's any easy workaround (if there were, we'd probably have already implemented the slicing itself). If instead it was something like "I want to iterate over the nonzeroes in this row and yield the (index,value) pairs," then I think we could do some things via dimIter(), e.g. (itself a workaround). – Brad Mar 15 '18 at 21:44