4

この質問をフォローアップすると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);
4

1 に答える 1