Boost logo

Boost Users :

Subject: Re: [Boost-users] [multi_array] Slices along the N'th dimension of a multi_array in a generic function
From: jp (jesseperla_at_[hidden])
Date: 2009-06-24 14:17:14


On Jun 24, 1:54 pm, Jesse Perla <jessepe..._at_[hidden]> wrote:
> I believe the problem is that the index_gen object needs different types as
> we build the indices in parts.  The following code shows what a hardcoded
> example would look like for N = 4 and M = 3

Sorry to answer my own question, but I poked around in the code and
found that the member data is public. The following seems to solve my
problem (though I would still love suggestions on if it is the best
way to tackle this problem with multi_array):

         boost::multi_array<double, 4> vals; //...fill....

        boost::detail::multi_array::index_gen<4, 3> slice_build;
        slice_build.ranges_[0] = range(0,n_1);
        slice_build.ranges_[1] = range(0,n_2); //could loop before
        slice_build.ranges_[2] = range(1);
        slice_build.ranges_[3] = range(0,n_4); //could loop after

        auto vals_slice4 = vals[ slice_build ];
        cout << vals_slice4[0][0][0] << endl;
        cout << vals_slice4[1][1][1] << endl;


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