Rare cutting of sparse massifs in a chapel

Given a A: [sps]sparse subdomain dom: domain(2), the slice A[A.domain.dim(1), k]gives the kth column as a dense 1D array. How to get the k-th n-1 dimensional slice of a sparse nD-array in the form of 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

Waiting in case I succeed in a sparse section will be the only one returned 1.0with the opportunity to get this position of this record by calling writeln()on slice.domain.

+4
source share
1 answer

, , , , ( 1.16) .

+2

Source: https://habr.com/ru/post/1694834/


All Articles