|
Boost Users : |
From: Server Levent Yilmaz (leventyilmaz_at_[hidden])
Date: 2007-08-23 20:48:43
On 8/22/07, chris dion <evolocity_at_[hidden]> wrote:
>
> Hi
>
> I'm having a problem with the boost/multi_array and I'm hoping someone
> here
> can help, or at least explain why the following doesn't work.
What you are trying is not possible with the views (from your code it seems
you misunderstood the way they work - take a second look at the docs
here<http://www.boost.org/libs/multi_array/doc/user.html#sec_views>).
You can solve your problem with a multi_array_ref and a different storage
ordering. Here is an example:
using namespace boost;
typedef multi_array<int,2> arr2;
typedef multi_array_ref<int,2> rarr2;
typedef array<arr2::index, 2> shape2;
//
// create and fill array
//
shape2 sh = {3,4};
arr2 foo(sh);
for (int i=0; i!=sh[0]; ++i)
for (int j=0; j!=sh[1]; ++j)
foo[i][j] = i + j*10;
//
// create a reference to transposed shape
//
shape2 shT = {4,3};
rarr2 fooT(foo.data(), shT, fortran_storage_order());
for (int i=0; i!=sh[0]; ++i)
for (int j=0; j!=sh[1]; ++j)
assert( foo[i][j] == fooT[j][i] );
hth
Levent
-- Server Levent Yilmaz Mechanical Engineering University of Pittsburgh
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