>>> new_blockdim(100, [20, 10, 20, 10, 40], slice(0, 90, 2)) [10, 5, 10, 5, 15] >>> new_blockdim(100, [20, 10, 20, 10, 40], [5, 1, 30, 22]) [4] >>> new_blockdim(100, [20, 10, 20, 10, 40], slice(90, 10, -2)) [16, 5, 10, 5, 4]
(dim_shape, lengths, index)
| 714 | |
| 715 | |
| 716 | def new_blockdim(dim_shape, lengths, index): |
| 717 | """ |
| 718 | |
| 719 | >>> new_blockdim(100, [20, 10, 20, 10, 40], slice(0, 90, 2)) |
| 720 | [10, 5, 10, 5, 15] |
| 721 | |
| 722 | >>> new_blockdim(100, [20, 10, 20, 10, 40], [5, 1, 30, 22]) |
| 723 | [4] |
| 724 | |
| 725 | >>> new_blockdim(100, [20, 10, 20, 10, 40], slice(90, 10, -2)) |
| 726 | [16, 5, 10, 5, 4] |
| 727 | """ |
| 728 | if index == slice(None, None, None): |
| 729 | return lengths |
| 730 | if isinstance(index, list): |
| 731 | return [len(index)] |
| 732 | assert not isinstance(index, Integral) |
| 733 | pairs = sorted(_slice_1d(dim_shape, lengths, index).items(), key=itemgetter(0)) |
| 734 | slices = [ |
| 735 | slice(0, lengths[i], 1) if slc == slice(None, None, None) else slc |
| 736 | for i, slc in pairs |
| 737 | ] |
| 738 | if isinstance(index, slice) and index.step and index.step < 0: |
| 739 | slices.reverse() |
| 740 | return [int(math.ceil((1.0 * slc.stop - slc.start) / slc.step)) for slc in slices] |
| 741 | |
| 742 | |
| 743 | def replace_ellipsis(n, index): |