Rare matrix as a field in the object of the Chapel

Following this question , I now have a class Graphthat includes a sparse matrix. Defined as

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;
  }
}

creates an error

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}

It SDdoesn't seem to be redefined. What is the correct template? In the previous post we talked about dense arrays, this is for rare ones.

I'm calling through

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
source share
1 answer

vdom 1 , (Phase 2). 1 , , vdom , {1..0, 1..0}, SD A, .

proc init(A: []) {
  this.vdom = {A.domain.dim(1), A.domain.dim(2)};
  super.init(); // insert this line here
  for ij in A.domain {
    this.SD += ij;
  }
}

: :

0.0 0.0 0.0
0.0
0.0
0.0
0.0
0.0 0.0
0.0
+5

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


All Articles