how is an arbitrary dimension "reshaper" turned into a function given a linear index? i have an arbitrary "reshaping" function which, given a linear sequential array can "reshape" it to 2D or 3D.  the order in which the X-dimension, Y-dimension and Z-dimension may all be changed, as well as the size of the X, Y and Z dimensions, may all be changed, at runtime.  consequently it is not possible to use static compilers or static allocation.

here is a function that, for the full sequential range, prints out a corresponding (remapped) set of indices:

(xdim, ydim, zdim) = (3, 2, 5)
lims = [xdim, ydim, zdim]
idxs = [0,0,0]
order = [1,0,2]

for idx in range(xdim * ydim * zdim):
    new_idx = idxs[0] + idxs[1] * xdim + idxs[2] * xdim * ydim
    print new_idx,
    for i in range(3):
        idxs[order[i]] = idxs[order[i]] + 1
        if (idxs[order[i]] != lims[order[i]]):
            break
        print
    idxs[order[i]] = 0


what i actually need is a function which, when it is passed an arbitrary index, returns one (correct) remapped index.

i suppose what i could hypothetically do is have a function that sets up the full array (at startup time), and indexes it.  i would however like to see an algorithmic version of the above.
If the index of $(i,j,k)$ is $p = i + xj + xyk$ then you can compute $i,j,k$ given $p$ as follows:

i = p mod x
j = (p / x) mod y
k = (p / x) / y


Using this you can solve your problem.