Find an intermediate rechunk that would split some chunks to get us nearer *new_chunks*, without violating the *graph_size_limit*.
(old_chunks, new_chunks, graph_size_limit)
| 572 | |
| 573 | |
| 574 | def find_split_rechunk(old_chunks, new_chunks, graph_size_limit): |
| 575 | """ |
| 576 | Find an intermediate rechunk that would split some chunks to |
| 577 | get us nearer *new_chunks*, without violating the *graph_size_limit*. |
| 578 | """ |
| 579 | ndim = len(old_chunks) |
| 580 | |
| 581 | chunks = list(old_chunks) |
| 582 | |
| 583 | for dim in range(ndim): |
| 584 | graph_size = estimate_graph_size(chunks, new_chunks) |
| 585 | if graph_size > graph_size_limit: |
| 586 | break |
| 587 | if len(old_chunks[dim]) > len(new_chunks[dim]): |
| 588 | # It's not interesting to split |
| 589 | continue |
| 590 | # Merge the new chunks so as to stay within the graph size budget |
| 591 | max_number = int(len(old_chunks[dim]) * graph_size_limit / graph_size) |
| 592 | c = merge_to_number(new_chunks[dim], max_number) |
| 593 | assert len(c) <= max_number |
| 594 | # Consider the merge successful if its result has a greater length |
| 595 | # and smaller max width than the old chunks |
| 596 | if len(c) >= len(old_chunks[dim]) and max(c) <= max(old_chunks[dim]): |
| 597 | chunks[dim] = c |
| 598 | |
| 599 | return tuple(chunks) |
| 600 | |
| 601 | |
| 602 | def plan_rechunk( |
no test coverage detected