|
Boost Users : |
From: rgarcia1771 (garcia_at_[hidden])
Date: 2003-06-03 10:23:55
--- In Boost-Users_at_[hidden], "David Johnson"
<yg-boost-users_at_m...> wrote:
> 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?
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]);
> ...
>
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