Boost logo

Boost Users :

From: David Johnson (yg-boost-users_at_[hidden])
Date: 2003-06-02 15:51:48


I have the following code that I don't feel is doing the right thing. Did I
make some mistake or is the Multi-array code buggy?

int nrows = 2;

int aSize = 6;

typedef array_type::extent_range range;
array_type
B(boost::extents[range(1,nrows)][range(1,aSize)],boost::fortran_storage_orde
r());
B[1][1] = 1.0;
printf("\n first B11 %lf %lf %lf %lf %lf
%lf",B[1][1],B[2][1],B[3][1],B[4][1],B[5][1],B[5][1]);
printf("\n first B21 %lf %lf %lf %lf %lf
%lf",B[1][2],B[2][2],B[3][2],B[4][2],B[5][2],B[6][2]);
B[2][1] = 2.0;
printf("\n first B11 %lf %lf %lf %lf %lf
%lf",B[1][1],B[2][1],B[3][1],B[4][1],B[5][1],B[5][1]);
printf("\n first B21 %lf %lf %lf %lf %lf
%lf",B[1][2],B[2][2],B[3][2],B[4][2],B[5][2],B[6][2]);
B[3][1] = 3.0;
B[4][1] = 4.0;
B[5][1] = 5.0;
B[6][1] = 6.0;
printf("\n first B11 %lf %lf %lf %lf %lf
%lf",B[1][1],B[2][1],B[3][1],B[4][1],B[5][1],B[5][1]);
printf("\n first B21 %lf %lf %lf %lf %lf
%lf",B[1][2],B[2][2],B[3][2],B[4][2],B[5][2],B[6][2]);
B[1][2] = 7.0;
printf("\n first B11 %lf %lf %lf %lf %lf
%lf",B[1][1],B[2][1],B[3][1],B[4][1],B[5][1],B[5][1]);
printf("\n first B21 %lf %lf %lf %lf %lf
%lf",B[1][2],B[2][2],B[3][2],B[4][2],B[5][2],B[6][2]);
B[2][2] = 8.0;
printf("\n first B11 %lf %lf %lf %lf %lf
%lf",B[1][1],B[2][1],B[3][1],B[4][1],B[5][1],B[5][1]);
printf("\n first B21 %lf %lf %lf %lf %lf
%lf",B[1][2],B[2][2],B[3][2],B[4][2],B[5][2],B[6][2]);
B[3][2] = 9.0;
B[4][2] = 10.0;
B[5][2] = 11.0;
B[6][2] = 12.0;
printf("\n first B11 %lf %lf %lf %lf %lf
%lf",B[1][1],B[2][1],B[3][1],B[4][1],B[5][1],B[5][1]);
printf("\n first B21 %lf %lf %lf %lf %lf
%lf",B[1][2],B[2][2],B[3][2],B[4][2],B[5][2],B[6][2]);

Which when I ran it produced:

  first B11 1.000000 0.000000 0.000000 0.000000 0.000000 0.000000
  first B21 0.000000 0.000000 0.000000 0.000000 -0.000000
-2656983832617227100000
0000000000000000000000000000000000000000000000000000000000000000000000000000
0000
0000000000000000000000000000000000000000000000000000000000000000000000000000
0000
0000000000000000000000000000000000000000000000000000000000000000000000000000
0000
000000000000000000000000000000000000000000.000000
  first B11 1.000000 2.000000 0.000000 0.000000 0.000000 0.000000
  first B21 2.000000 0.000000 0.000000 0.000000 -0.000000
-2656983832617227100000
0000000000000000000000000000000000000000000000000000000000000000000000000000
0000
0000000000000000000000000000000000000000000000000000000000000000000000000000
0000
0000000000000000000000000000000000000000000000000000000000000000000000000000
0000
000000000000000000000000000000000000000000.000000
  first B11 1.000000 2.000000 3.000000 4.000000 5.000000 5.000000
  first B21 2.000000 3.000000 4.000000 5.000000 6.000000
-26569838326172271000000
0000000000000000000000000000000000000000000000000000000000000000000000000000
0000
0000000000000000000000000000000000000000000000000000000000000000000000000000
0000
0000000000000000000000000000000000000000000000000000000000000000000000000000
0000
00000000000000000000000000000000000000000.000000
  first B11 1.000000 7.000000 3.000000 4.000000 5.000000 5.000000
  first B21 7.000000 3.000000 4.000000 5.000000 6.000000
-26569838326172271000000
0000000000000000000000000000000000000000000000000000000000000000000000000000
0000
0000000000000000000000000000000000000000000000000000000000000000000000000000
0000
0000000000000000000000000000000000000000000000000000000000000000000000000000
0000
00000000000000000000000000000000000000000.000000
  first B11 1.000000 7.000000 8.000000 4.000000 5.000000 5.000000
  first B21 7.000000 8.000000 4.000000 5.000000 6.000000
-26569838326172271000000
0000000000000000000000000000000000000000000000000000000000000000000000000000
0000
0000000000000000000000000000000000000000000000000000000000000000000000000000
0000
0000000000000000000000000000000000000000000000000000000000000000000000000000
0000
00000000000000000000000000000000000000000.000000
  first B11 1.000000 7.000000 8.000000 9.000000 10.000000 10.000000
  first B21 7.000000 8.000000 9.000000 10.000000 11.000000 12.000000

THis first thing to note is that i get 2 in two places in the output after
only inputing it once. Why is B[1][2] identical with B[2][1] ? I have also
tried referencing it as [1-6][1-2] and it still has garbage in the array(
same results after adding [1][2], as I can see the same value in [2][1]). I
also had the assignment statements as [1-2][1-6] with no change in the
output for [1][2] and [2][1]. Any help greatly appreciated on this since it
is really confusing me. I found that using the documention wasn'te much
help since it seems to contain errors. I had to look in the examples to see
that fortran_storage_order was a function that needed the parenthesis,
since the doc left them out in the text. But the examples had them.

Dave


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net