static public Index
    offsetToIndex(long offset, long[] dimsizes)
    {
        // offset = d3*(d2*(d1*(x1))+x2)+x3
        long[] indices = new long[dimsizes.length];
        for(int i = dimsizes.length - 1; i >= 0; i--) {
            indices[i] = offset % dimsizes[i];
            offset = (offset - indices[i]) / dimsizes[i];
        }
        return new Index(indices, dimsizes);
    }
static public Index offsetToIndex ( long offset , long [ ] dimsizes ) { long [ ] indices = new long [ dimsizes . length ] ; for ( int i = dimsizes . length - 1 ; i >= 0 ; i -- ) { indices [ i ] = offset % dimsizes [ i ] ; offset = ( offset - indices [ i ] ) / dimsizes [ i ] ; } return new Index ( indices , dimsizes ) ; }
Given an offset (single index) and a set of dimensions
compute the set of dimension indices that correspond
to the offset.