Returns the shape of the final array, along with a list of slices and a list of arrays that can be used for assignment inside the new array Parameters ---------- arrays : nested list of arrays The arrays to check max_depth : list of int The number of nes
(arrays, max_depth, result_ndim, depth=0)
| 693 | |
| 694 | |
| 695 | def _block_info_recursion(arrays, max_depth, result_ndim, depth=0): |
| 696 | """ |
| 697 | Returns the shape of the final array, along with a list |
| 698 | of slices and a list of arrays that can be used for assignment inside the |
| 699 | new array |
| 700 | |
| 701 | Parameters |
| 702 | ---------- |
| 703 | arrays : nested list of arrays |
| 704 | The arrays to check |
| 705 | max_depth : list of int |
| 706 | The number of nested lists |
| 707 | result_ndim : int |
| 708 | The number of dimensions in thefinal array. |
| 709 | |
| 710 | Returns |
| 711 | ------- |
| 712 | shape : tuple of int |
| 713 | The shape that the final array will take on. |
| 714 | slices: list of tuple of slices |
| 715 | The slices into the full array required for assignment. These are |
| 716 | required to be prepended with ``(Ellipsis, )`` to obtain to correct |
| 717 | final index. |
| 718 | arrays: list of ndarray |
| 719 | The data to assign to each slice of the full array |
| 720 | |
| 721 | """ |
| 722 | if depth < max_depth: |
| 723 | shapes, slices, arrays = zip( |
| 724 | *[_block_info_recursion(arr, max_depth, result_ndim, depth + 1) |
| 725 | for arr in arrays]) |
| 726 | |
| 727 | axis = result_ndim - max_depth + depth |
| 728 | shape, slice_prefixes = _concatenate_shapes(shapes, axis) |
| 729 | |
| 730 | # Prepend the slice prefix and flatten the slices |
| 731 | slices = [slice_prefix + the_slice |
| 732 | for slice_prefix, inner_slices in zip(slice_prefixes, slices) |
| 733 | for the_slice in inner_slices] |
| 734 | |
| 735 | # Flatten the array list |
| 736 | arrays = functools.reduce(operator.add, arrays) |
| 737 | |
| 738 | return shape, slices, arrays |
| 739 | else: |
| 740 | # We've 'bottomed out' - arrays is either a scalar or an array |
| 741 | # type(arrays) is not list |
| 742 | # Return the slice and the array inside a list to be consistent with |
| 743 | # the recursive case. |
| 744 | arr = _atleast_nd(arrays, result_ndim) |
| 745 | return arr.shape, [()], [arr] |
| 746 | |
| 747 | |
| 748 | def _block(arrays, max_depth, result_ndim, depth=0): |
no test coverage detected
searching dependent graphs…