Random access view in boost::multi_array

Posted by linai on Stack Overflow See other posts from Stack Overflow or by linai
Published on 2010-04-29T13:07:23Z Indexed on 2010/04/29 17:57 UTC
Read the original article Hit count: 237

Filed under:
|

Here is a boost example:

  typedef boost::multi_array<double, 1> array_type;
  typedef array_type::index index;
  array_type A(boost::extents[100]);

  for(index i = 0; i != A.size(); ++i) {
        A[i] = (double)i;
  }

  // creating view
  array_type::index_gen indices;
  typedef boost::multi_array_types::index_range range;

  array_type::array_view<1>::type myview = A[ indices[range(0,50)] ];

What this code does is creating a subarray or view mapping onto the original array. This view is continuous and covers from 0th to 50th elements of an original array.

What if I need to explicitly define elements I'd like to see in the view? How can I create a view with indices like [1, 5, 35, 23] ? Any ideas?

© Stack Overflow or respective owner

Related posts about c++

Related posts about boost