def plan_rechunk(old_chunks, new_chunks, itemsize, threshold=DEFAULT_THRESHOLD, block_size_limit=DEFAULT_BLOCK_SIZE_LIMIT):
 ndim = len(new_chunks)
 steps = []
 if ((ndim <= 1) or (not all(new_chunks))):
  return (steps + [new_chunks])
 block_size_limit /= itemsize
 largest_old_block = _largest_block_size(old_chunks)
 largest_new_block = _largest_block_size(new_chunks)
 block_size_limit = max([block_size_limit, largest_old_block, largest_new_block])
 graph_size_threshold = (threshold * (_number_of_blocks(old_chunks) + _number_of_blocks(new_chunks)))
 current_chunks = old_chunks
 first_pass = True
 while True:
  graph_size = estimate_graph_size(current_chunks, new_chunks)
  if (graph_size < graph_size_threshold):
   break
  if first_pass:
   chunks = current_chunks
  else:
   chunks = find_split_rechunk(current_chunks, new_chunks, (graph_size * threshold))
  (chunks, memory_limit_hit) = find_merge_rechunk(chunks, new_chunks, block_size_limit)
  if ((chunks == current_chunks) or (chunks == new_chunks)):
   break
  steps.append(chunks)
  current_chunks = chunks
  if (not memory_limit_hit):
   break
  first_pass = False
 return (steps + [new_chunks])

def plan_rechunk ( old_chunks , new_chunks , itemsize , threshold = DEFAULT_THRESHOLD , block_size_limit = DEFAULT_BLOCK_SIZE_LIMIT ) : ndim = len ( new_chunks ) steps = [ ] if ( ( ndim <= 1 ) or ( not all ( new_chunks ) ) ) : return ( steps + [ new_chunks ] ) block_size_limit /= itemsize largest_old_block = _largest_block_size ( old_chunks ) largest_new_block = _largest_block_size ( new_chunks ) block_size_limit = max ( [ block_size_limit , largest_old_block , largest_new_block ] ) graph_size_threshold = ( threshold * ( _number_of_blocks ( old_chunks ) + _number_of_blocks ( new_chunks ) ) ) current_chunks = old_chunks first_pass = True while True : graph_size = estimate_graph_size ( current_chunks , new_chunks ) if ( graph_size < graph_size_threshold ) : break if first_pass : chunks = current_chunks else : chunks = find_split_rechunk ( current_chunks , new_chunks , ( graph_size * threshold ) ) ( chunks , memory_limit_hit ) = find_merge_rechunk ( chunks , new_chunks , block_size_limit ) if ( ( chunks == current_chunks ) or ( chunks == new_chunks ) ) : break steps . append ( chunks ) current_chunks = chunks if ( not memory_limit_hit ) : break first_pass = False return ( steps + [ new_chunks ] )
plan an iterative rechunking from *old_chunks* to *new_chunks* .