L
Larry Evans
The expansion vector for DataCube.new(n,m) would be:There's a book:Is this an okay job of implementing a multidimensional array?
https://github.com/kedarmhaswade/datacube/blob/master/data_cube.rb
Thank you for any feedback.
-Kedar
http://web.engr.oregonstate.edu/~budd/Books/aplc/
which describes an expansion vector which is a scan of
the array sizes. IOW, for:
arr = Array.new(s0,s1,...sn)
the expansion vector for this arr is:
arr.ev = [1, s0, s0*s1, s0*s1*s3,..., s0*s1*...*sn]
[m**0,m**1,m**2,...,m**n]
IOW, the length of this expansion vector is n+1.
[snip]
However, after looking at:arr[i0,i1,..., ij, ... in]
is located:
i0*arr.ev[0]+i1*arr.ev[1]+...+in*arr.ev[n]
elements from the 1st element:
arr[0,0,...,0]
Thus, given the sizes, you can create a member variable
which is the expansion vector, then use that to access the
elements by calculating the offset from the initial element
using the dot product:
i0*arr.ev[0]+i1*arr.ev[1]+...+in*arr.ev[n]
https://github.com/kedarmhaswade/datacube/blob/master/data_cube.rb#L48
it's not clear that to_index calculates the same offset because
coefficients corresponds to one of the i0,i1,...,in-1 in the
above formulat, and coefficients is not multiplied by anything.
It's only added to mega_index*n, and mega_index*n involves
multiplication by the dimension, n, instead of ths uniform size, m.
HTH
-Larry