2

I created the following Matrix, and I want to determine the number of rows/columns the matrix now has:

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

This returns {0..4, 0..4} which makes sense, but I can't take A.domain[0] for instance and get the length.

Brian Dolan
  • 3,086
  • 2
  • 24
  • 35

1 Answers1

3

Almost there:

   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]
             );

Outputs:

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
user3666197
  • 1
  • 6
  • 50
  • 92
  • 1
    The relevant documentation is http://chapel.cray.com/docs/latest/builtins/internal/ChapelArray.html - and there are some other functions and methods in there that can solve the problem differently, such as domain.low and domain.high. – mppf Aug 17 '17 at 10:34
  • 1
    Sure, many domain tricks are available, the point is, that user-centric views are missing & it takes some time before one can build her/his own imagination, how the things work - it takes some time. Your team has spent more than a decade in polishing the language-core concepts ( domain tricks being for sure one of such point-of-interest ), but other users have each one's own pace, at which the language is being learnt & best understood as to how/where use all tools available. Always good to share alternative views, but let people the freedom to experiment. This works best for any innovation. – user3666197 Aug 17 '17 at 10:49