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

Function recurser

numpy/core/arrayprint.py:789–885  ·  view source on GitHub ↗

By using this local function, we don't need to recurse with all the arguments. Since this function is not created recursively, the cost is not significant

(index, hanging_indent, curr_width)

Source from the content-addressed store, hash-verified

787
788 """
789 def recurser(index, hanging_indent, curr_width):
790 """
791 By using this local function, we don't need to recurse with all the
792 arguments. Since this function is not created recursively, the cost is
793 not significant
794 """
795 axis = len(index)
796 axes_left = a.ndim - axis
797
798 if axes_left == 0:
799 return format_function(a[index])
800
801 # when recursing, add a space to align with the [ added, and reduce the
802 # length of the line by 1
803 next_hanging_indent = hanging_indent + ' '
804 if legacy <= 113:
805 next_width = curr_width
806 else:
807 next_width = curr_width - len(']')
808
809 a_len = a.shape[axis]
810 show_summary = summary_insert and 2*edge_items < a_len
811 if show_summary:
812 leading_items = edge_items
813 trailing_items = edge_items
814 else:
815 leading_items = 0
816 trailing_items = a_len
817
818 # stringify the array with the hanging indent on the first line too
819 s = ''
820
821 # last axis (rows) - wrap elements if they would not fit on one line
822 if axes_left == 1:
823 # the length up until the beginning of the separator / bracket
824 if legacy <= 113:
825 elem_width = curr_width - len(separator.rstrip())
826 else:
827 elem_width = curr_width - max(len(separator.rstrip()), len(']'))
828
829 line = hanging_indent
830 for i in range(leading_items):
831 word = recurser(index + (i,), next_hanging_indent, next_width)
832 s, line = _extendLine_pretty(
833 s, line, word, elem_width, hanging_indent, legacy)
834 line += separator
835
836 if show_summary:
837 s, line = _extendLine(
838 s, line, summary_insert, elem_width, hanging_indent, legacy)
839 if legacy <= 113:
840 line += ", "
841 else:
842 line += separator
843
844 for i in range(trailing_items, 1, -1):
845 word = recurser(index + (-i,), next_hanging_indent, next_width)
846 s, line = _extendLine_pretty(

Callers 1

_formatArrayFunction · 0.85

Calls 4

_extendLine_prettyFunction · 0.85
_extendLineFunction · 0.85
rstripMethod · 0.80
maxFunction · 0.70

Tested by

no test coverage detected