view of multiarray without knowledge of dimension

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

view of multiarray without knowledge of dimension

Brian Budge-2
Hi all -

My basic need is to step through a portion of my multiarray at runtime.  I don't know the dimension apriori, since the class I'm writing is templatized on dimension.  This means that the multiarray can serve my other purposes just fine, since the dimesion is compile time constant, but I don't know the number of [] and the nesting of loops I'll need to iterate through the valid indices in my range min to max in my multiarray.

Essentially, if I could specify a view of my multiarray, likely it shouldn't be too hard to iterate through the elements of that sub-multiarray, even without knowing the dimension at coding time.

Anyone know of a way to get a view without knowing the dimensions at coding time?

Thanks,
  Brian
Reply | Threaded
Open this post in threaded view
|

Re: view of multiarray without knowledge of dimension

François Duranleau
On Thu, 2 Feb 2006, graphicsMan69 (sent by Nabble.com) wrote:

>
> Hi all -
>
> My basic need is to step through a portion of my multiarray at runtime.
> I don't know the dimension apriori, since the class I'm writing is
> templatized on dimension.  This means that the multiarray can serve my
> other purposes just fine, since the dimesion is compile time constant,
> but I don't know the number of [] and the nesting of loops I'll need to
> iterate through the valid indices in my range min to max in my
> multiarray.
>
> Essentially, if I could specify a view of my multiarray, likely it
> shouldn't be too hard to iterate through the elements of that
> sub-multiarray, even without knowing the dimension at coding time.
>
> Anyone know of a way to get a view without knowing the dimensions at
> coding time?
I came across similar problems with boost::multi_array. I wanted to
iterate on all cells of just a portion of the whole multi_array. The way I
solved the problem was to use operator() instead of operator[], and a
multi-dimensional counting iterator (e.g.
http://www-etud.iro.umontreal.ca/~duranlef/code/multi_counting_iterator.hpp).
I am not convinced it is the most efficient way (or event elegant), but it
works very well to make an abstraction of the multi_array's dimension.

--
François Duranleau
LIGUM, Université de Montréal

"'Reality' is the temporary resultant of continuous struggles between
  rival gangs of programmers."
                           - Robert Anton Wilson, _Prometheus Rising_, 1983
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: view of multiarray without knowledge of dimension

Brian Budge-2
Thanks!  That's very similar to the idea I had, but I thought that perhaps multiarray had it somewhere hidden away.

I'll probably use yours -- no need to reinvent the wheel!

  Brian