def take_sorted(outname, inname, blockdims, index, axis=0):
 sizes = blockdims[axis]
 index_lists = partition_by_size(sizes, sorted(index))
 where_index = [i for (i, il) in enumerate(index_lists) if il]
 index_lists = [il for il in index_lists if il]
 dims = [range(len(bd)) for bd in blockdims]
 indims = list(dims)
 indims[axis] = list(range(len(where_index)))
 keys = list(product([outname], *indims))
 outdims = list(dims)
 outdims[axis] = where_index
 slices = [([colon] * len(bd)) for bd in blockdims]
 slices[axis] = index_lists
 slices = list(product(*slices))
 inkeys = list(product([inname], *outdims))
 values = [(getitem, inkey, slc) for (inkey, slc) in zip(inkeys, slices)]
 blockdims2 = list(blockdims)
 blockdims2[axis] = tuple(map(len, index_lists))
 return (tuple(blockdims2), dict(zip(keys, values)))

def take_sorted ( outname , inname , blockdims , index , axis = 0 ) : sizes = blockdims [ axis ] index_lists = partition_by_size ( sizes , sorted ( index ) ) where_index = [ i for ( i , il ) in enumerate ( index_lists ) if il ] index_lists = [ il for il in index_lists if il ] dims = [ range ( len ( bd ) ) for bd in blockdims ] indims = list ( dims ) indims [ axis ] = list ( range ( len ( where_index ) ) ) keys = list ( product ( [ outname ] , * indims ) ) outdims = list ( dims ) outdims [ axis ] = where_index slices = [ ( [ colon ] * len ( bd ) ) for bd in blockdims ] slices [ axis ] = index_lists slices = list ( product ( * slices ) ) inkeys = list ( product ( [ inname ] , * outdims ) ) values = [ ( getitem , inkey , slc ) for ( inkey , slc ) in zip ( inkeys , slices ) ] blockdims2 = list ( blockdims ) blockdims2 [ axis ] = tuple ( map ( len , index_lists ) ) return ( tuple ( blockdims2 ) , dict ( zip ( keys , values ) ) )
index array with sorted list index forms a dask for the following case x[: .