|
Boost Users : |
Subject: Re: [Boost-users] [MultiArray] subscript to index
From: Larry Evans (cppljevans_at_[hidden])
Date: 2010-05-04 01:16:58
On 05/03/10 22:20, Sami wrote:
>
> On Sat, May 1, 2010 at 9:08 AM, Rhys Ulerich <rhys.ulerich_at_[hidden]
> <mailto:rhys.ulerich_at_[hidden]>> wrote:
>
>
> Not as far as I know. You could accomplish this accumulating indices
> and strides relative to the origin (similar to the pseudocode for
> a(index_list) in Table 3 of
> http://www.boost.org/doc/libs/1_42_0/libs/multi_array/doc/reference.html).
>
> One other option might be &a(index_list) - a.origin().
>
>
> ... since origin() is arr [0][0]...[0], neither of these is the answer
> in general. But thanks, good pointers there! Sad there isn't a
> multi_array::offset( indices ) or something that:
>
> assert (
> &arr( index_list ) == arr.data() + arr.*offset*( index_list )
> )
>
> this kind of stuff is useful when interacting with legacy libs or other
> languages.
Hmm... I puzzled why you think Sami's method won't work.
For example, given the strides, s[ndim] and indices, i[ndim], and
a.origin(), then the distance between a.origin() and the element
at indices, i[0...ndim-1] is simply the sum of the vector product
of s prepended with 1 and i. e.g.,
For a[2][2][2], the strides would be:
s={2,4,8},
and for i={1,1,1}, then
offset (of a[1]][1][1]) = 1*i[0]+s[0]*i[1]+s[1]*i[2]
Wouldn't that work?
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