[multi_array] Access a view's index_range
How do I access the index_range of an array_view? ie.,
typedef boost::multi_array
AMDG Robert Jones wrote:
How do I access the index_range of an array_view? ie.,
typedef boost::multi_array
Grid; Grid grid( boost::extents[9][9]); Grid::array_view<2> view = grid[indices[range(), range()]]; | for (Grid::index i = view.?????.start(); i != view.?????.finish(); ++i) {....}
where I'm expecting i to take values 0..8 inclusive.
Your code seems to have gotten a bit mangled. Can you post a small compilable example? In Christ, Steven Watanabe
On Thu, Oct 9, 2008 at 5:23 PM, Steven Watanabe
AMDG
Robert Jones wrote:
How do I access the index_range of an array_view? ie.,
typedef boost::multi_array
Grid; Grid grid( boost::extents[9][9]); Grid::array_view<2> view = grid[indices[range(), range()]]; | for (Grid::index i = view.?????.start(); i != view.?????.finish(); ++i) {....}
where I'm expecting i to take values 0..8 inclusive.
Your code seems to have gotten a bit mangled. Can you post a small compilable example?
I would if I could, but getting it to compile is exactly my problem! I don't understand what I need to write for the "?????" bits. The reference guide for multi_array describes a start() and finish() methods on the index_range type, but I can't see how to get a populated object of type index_range from a multi_array or from a multi_array_view. Thanks - Rob.
Hi Robert, The index_range object is used to create views, but it doesn't stay around. However, all of the information from an index_range is still accessible. You want to look into the following 3 MultiArray concept functions: indices(), strides(), and shape(). Based on your code, it looks like you're trying to get the valid indices for the array so you can dereference it. If you're not changing the index base (meaning your array indices always start at 0), then you want to write: typedef Grid::array_view<2>::type view_t ... for(view_t::index i = 0; i != view.size(); ++i) { ... } HTH, ron On Oct 9, 2008, at 5:40 AM, Robert Jones wrote:
How do I access the index_range of an array_view? ie.,
typedef boost::multi_array
Grid; Grid grid( boost::extents[9][9]); Grid::array_view<2> view = grid[indices[range(), range()]]; | for (Grid::index i = view.?????.start(); i != view.?????.finish(); + +i) {....}
where I'm expecting i to take values 0..8 inclusive.
On Fri, Oct 10, 2008 at 12:55 AM, Ronald Garcia
Hi Robert,
The index_range object is used to create views, but it doesn't stay around. However, all of the information from an index_range is still accessible. You want to look into the following 3 MultiArray concept functions: indices(), strides(), and shape().
Based on your code, it looks like you're trying to get the valid indices for the array so you can dereference it.
If you're not changing the index base (meaning your array indices always start at 0), then you want to write:
typedef Grid::array_view<2>::type view_t
...
for(view_t::index i = 0; i != view.size(); ++i) { ... }
Hi Ron Thanks for your help - the solution you suggest will solve my immediate problem, however I was really looking for a more general solution. Looking through the reference, AFAICS the only occurance of "indices" is as the global static index_gen<0,0> object. Had this function been present as an member of multi_array it might reasonbly return exactly the information I'm seeking. Without making the assumption that my indices are zero based I think I can generally write my loop as, (and please confirm this btw) for (view_t::index i = * view.index_bases(); i != * view.shape(); ++i ) {.....} but it seems a rather non-obvious and cumbersome expression. If view_t had an indices() method that returned a list of index_range objects then I could write for(view_t::index i = view.indices()[0].start(); i != view.indices()[0].finish(); ++i ){.....} which seems to be a more obvious syntax, and more suggestive of looping over a range. Even better would be to support this syntax for(view_t::index i=view.indices(0).start(); i != view.indices(0).finish(); ++i ) {.....} Sorry if I'm covering old ground btw, but multi_array has been around in Boost for rather longer than I have. - Rob.
Hi Rob, I mis-spoke, index_bases() is exactly what you want. Use that in place of indices() below. cheers, ron On Oct 10, 2008, at 3:02 AM, Robert Jones wrote:
Without making the assumption that my indices are zero based I think I can generally write my loop as, (and please confirm this btw)
for (view_t::index i = * view.index_bases(); i != * view.shape(); + +i ) {.....}
but it seems a rather non-obvious and cumbersome expression. If view_t had an indices() method that returned a list of index_range objects then I could write
for(view_t::index i = view.indices()[0].start(); i != view.indices() [0].finish(); ++i ){.....}
participants (3)
-
Robert Jones
-
Ronald Garcia
-
Steven Watanabe