public static int [ ] ind2subC ( int [ ] shape , long index , long numIndices ) { long denom = numIndices ; int [ ] ret = new int [ shape . length ] ; for ( int i = 0 ; i < shape . length ; i ++ ) { denom /= shape [ i ] ; if ( index / denom >= Integer . MAX_VALUE ) throw new IllegalArgumentException ( "Dimension can not be >= Integer.MAX_VALUE" ) ; ret [ i ] = ( int ) ( index / denom ) ; index %= denom ; } return ret ; }
Convert a linear index to the equivalent nd index