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
I have the following code that I don't feel is doing the right
--- In Boost-Users@yahoogroups.com, "David Johnson"
make some mistake or is the Multi-array code buggy?
There are several mistakes in this code snippet: The ranges passed to the extents parameter are half open. This means that the length of the range is the second number minus the first number. For example: range(1,nrows) // where nrows = 2 specifies a range of 1 ( == nrows-1). Your example is constructing an array of shape 1 x 5. To avoid this problem, I would probably rewrite your construction sequence as the following: B(extents[nrows][aSize]),fortran_storage_order()); B.reindex(1); It also appears that you are indexing the array backwards. The lines where you index as B[1][2] ... B[6][2] should be B[2][1] ... B[2][6]. I suspect that these indices are reversed because you are interfacing with fortran. The fortran_storage_order parameter to the array makes this reversal unnecessary. Cheers, ron
typedef array_type::extent_range range; array_type
B(boost::extents[range(1,nrows)][range(1,aSize)],b oost::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]); ...
participants (2)
-
David Johnson
-
rgarcia1771