跟进这个问题,我现在有一个Graph
包含稀疏矩阵的类。定义为
class Graph {
var vdom: domain(2),
SD: sparse subdomain(vdom),
A: [SD] real;
proc init(A: []) {
this.vdom = {A.domain.dim(1), A.domain.dim(2)};
for ij in A.domain {
this.SD += ij;
}
}
产生错误
chingon-base-test.chpl:30: error: halt reached - Sparse domain/array index out of bounds: (1, 2) (expected to be within {1..0, 1..0}
它出现SD
没有被重新定义。什么是正确的模式?在上一篇文章中,我们谈到了密集数组,这是针对稀疏的。
我通过调用它
var nv: int = 8,
D: domain(2) = {1..nv, 1..nv},
SD: sparse subdomain(D),
A: [SD] real;
SD += (1,2); A[1,2] = 1;
SD += (1,3); A[1,3] = 1;
SD += (1,4); A[1,4] = 1;
SD += (2,4); A[2,4] = 1;
SD += (3,4); A[3,4] = 1;
SD += (4,5); A[4,5] = 1;
SD += (5,6); A[5,6] = 1;
SD += (6,7); A[6,7] = 1;
SD += (6,8); A[6,8] = 1;
SD += (7,8); A[7,8] = 1;
g = new Graph(A);
writeln(g.A);