MCPcopy Create free account
hub / github.com/numpy/numpy / _block_info_recursion

Function _block_info_recursion

numpy/core/shape_base.py:620–670  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

618
619
620def _block_info_recursion(arrays, max_depth, result_ndim, depth=0):
621 """
622 Returns the shape of the final array, along with a list
623 of slices and a list of arrays that can be used for assignment inside the
624 new array
625
626 Parameters
627 ----------
628 arrays : nested list of arrays
629 The arrays to check
630 max_depth : list of int
631 The number of nested lists
632 result_ndim : int
633 The number of dimensions in thefinal array.
634
635 Returns
636 -------
637 shape : tuple of int
638 The shape that the final array will take on.
639 slices: list of tuple of slices
640 The slices into the full array required for assignment. These are
641 required to be prepended with ``(Ellipsis, )`` to obtain to correct
642 final index.
643 arrays: list of ndarray
644 The data to assign to each slice of the full array
645
646 """
647 if depth < max_depth:
648 shapes, slices, arrays = zip(
649 *[_block_info_recursion(arr, max_depth, result_ndim, depth+1)
650 for arr in arrays])
651
652 axis = result_ndim - max_depth + depth
653 shape, slice_prefixes = _concatenate_shapes(shapes, axis)
654
655 # Prepend the slice prefix and flatten the slices
656 slices = [slice_prefix + the_slice
657 for slice_prefix, inner_slices in zip(slice_prefixes, slices)
658 for the_slice in inner_slices]
659
660 # Flatten the array list
661 arrays = functools.reduce(operator.add, arrays)
662
663 return shape, slices, arrays
664 else:
665 # We've 'bottomed out' - arrays is either a scalar or an array
666 # type(arrays) is not list
667 # Return the slice and the array inside a list to be consistent with
668 # the recursive case.
669 arr = _atleast_nd(arrays, result_ndim)
670 return arr.shape, [()], [arr]
671
672
673def _block(arrays, max_depth, result_ndim, depth=0):

Callers 1

_block_slicingFunction · 0.85

Calls 3

_concatenate_shapesFunction · 0.85
_atleast_ndFunction · 0.85
reduceMethod · 0.45

Tested by

no test coverage detected