#NEWLINE# def multires_order( n ) : #NEWLINE# #INDENT# 'Provide order of indexes slowly detailing into the history\n\n    Often it is desirable to order investigation of events in history\n    at "multiple resolutions".  So at first we get a glimpse of the\n    history at 3 points (first, middle, last) and then get deeper by\n    making our step twice smaller at each "resolution".  So for\n    e.g. n=9 order of indexes for such inspection would be [0, 4, 8,\n    2, 6, 1, 5, 3, 7] .\n\n    It should remind (if not being identical) to traversing the binary\n    heap associated with a list of indexes: as if we first took at\n    corners and then go layer by layer including the depth.\n\n    Current procedure is a very sloppy implementation, so inefficient\n    in general but good enough for real use (e.g. 26.6ms for n=10000)\n    ' #NEWLINE# if ( isinstance ( n , list ) or isinstance ( n , tuple ) ) : #NEWLINE# #INDENT# return n . __class__ ( ( n [ i ] for i in multires_order ( len ( n ) ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( 'ndarray' in str ( type ( n ) ) ) : #NEWLINE# #INDENT# return n [ multires_order ( len ( n ) ) ] #NEWLINE# #UNINDENT# #UNINDENT# assert isinstance ( n , int ) #NEWLINE# out = [ ] #NEWLINE# seen = ( [ False ] * n ) #NEWLINE# for i in xrange ( 1 , k ) : #NEWLINE# #INDENT# step = ( float ( ( n - 1 ) ) / ( 2 * i ) ) #NEWLINE# gotnew = False #NEWLINE# for k in xrange ( int ( ceil ( ( float ( n ) / step ) ) ) ) : #NEWLINE# #INDENT# idx = int ( ( k * step ) ) #NEWLINE# if ( not seen [ idx ] ) : #NEWLINE# #INDENT# out . append ( idx ) #NEWLINE# seen [ idx ] = True #NEWLINE# gotnew = True #NEWLINE# #UNINDENT# #UNINDENT# if ( not gotnew ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# if ( len ( out ) != n ) : #NEWLINE# #INDENT# out . extend ( [ i for i in range ( n ) if ( not seen [ i ] ) ] ) #NEWLINE# #UNINDENT# assert ( set ( out ) == set ( range ( n ) ) ) #NEWLINE# return out