在Chapel Matrix中查找行数或列数

时间:2017-08-16 04:57:27

标签: chapel

我创建了以下Matrix,我想确定矩阵现在具有的行数/列数:

module AswanBigMatrix {
  use LinearAlgebra;

  proc main() {
    var A = Matrix(
         [0.0, 0.8, 1.1, 0.0, 2.0]
        ,[0.8, 0.0, 1.3, 1.0, 0.0]
        ,[1.1, 1.3, 0.0, 0.5, 1.7]
        ,[0.0, 1.0, 0.5, 0.0, 1.5]
        ,[2.0, 0.0, 1.7, 1.5, 0.0]
        );
    }
   writeln(A.domain);
}

这会返回有意义的{0..4, 0..4},但我不能以A.domain[0]为例,并获得长度。

1 个答案:

答案 0 :(得分:3)

几乎就在那里:

   const                D = {1..8,1..9};
   var       Matrix_A: [D] int;
   writeln( "Matrix_A[] has a .domain() of [ ",
             Matrix_A.domain.dims(),       " ], the 1st-dimension being: ",
             Matrix_A.domain.dim(1).length()
             );
   writeln( "Matrix_A[] has a  .shape() of ( ",
             Matrix_A.shape,              " ),       ",
                                               "the 1st-dimension being: ",
             Matrix_A.shape[1]
             );

<强>输出:

Matrix_A[] has a .domain() of [ (1..8, 1..9) ], the 1st-dimension being: 8
Matrix_A[] has a  .shape() of ( (8, 9) ),       the 1st-dimension being: 8