Boost logo

Boost Users :

Subject: Re: [Boost-users] [multi-array] Extracting dimension information from a multi-array
From: Ryan McConnehey (mccorywork_at_[hidden])
Date: 2010-09-12 11:58:17


Jesse Perla wrote:
Ryan McConnehey <mccorywork <at> gmail.com> writes:

  
Do you have an example of how shape() works?  The shape method isn't
used in any of the multi-array tutorials.  Also, the reference material
says the shape method returns a list of "NumDims" but the return
signature specifies a "const size_type *" is returned.  How is "const
size_type *" a list of dimension?
    

Since it is not a container, you will need to use the ::dimensionality to see
how far to iterate this bare pointer.
e.g. to put it into a bounded ublas vector vector:

   const static std::size_t rank = ublas::multi_array<double, 3>::dimensionality;
   //Or just 3 in this case... Showing you this could work in generic code

   ublas::bounded_vector<std::size_t, rank> dims;
   std::copy(var.shape(), var.shape() + rank, dims.begin())
Since the above code works we can access a specific dimension like so.

var.shape()[1] //as long as the operator values exists within the dimension

Is this correct?

Ryan

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