On Tue, May 4, 2010 at 1:16 AM, Larry Evans
<cppljevans@suddenlink.net> wrote:
On 05/03/10 22:20, Sami wrote:
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},
actually that would be {4,2,1} for default C (row-major) storage ordering.
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?
wouldn't work when any of index_bases() is non-zero. You'd need the following to make it right:
// using inner_product instead of transform/accumulate
collection index = {i,j,k}; // looking for offset of this from data()
size_t base_offset = std::inner_product(
a.index_bases(), a.index_bases()+a.num_dimensions(),
a.strides(),
0);
size_t offset = std::inner_product( index.begin(), index.end(), a.strides(), -base_offset );