formatArray is designed for two modes of operation: 1. Full output 2. Summarized output
(a, format_function, line_width, next_line_prefix,
separator, edge_items, summary_insert, legacy)
| 852 | return s, line |
| 853 | |
| 854 | def _formatArray(a, format_function, line_width, next_line_prefix, |
| 855 | separator, edge_items, summary_insert, legacy): |
| 856 | """formatArray is designed for two modes of operation: |
| 857 | |
| 858 | 1. Full output |
| 859 | |
| 860 | 2. Summarized output |
| 861 | |
| 862 | """ |
| 863 | def recurser(index, hanging_indent, curr_width): |
| 864 | """ |
| 865 | By using this local function, we don't need to recurse with all the |
| 866 | arguments. Since this function is not created recursively, the cost is |
| 867 | not significant |
| 868 | """ |
| 869 | axis = len(index) |
| 870 | axes_left = a.ndim - axis |
| 871 | |
| 872 | if axes_left == 0: |
| 873 | return format_function(a[index]) |
| 874 | |
| 875 | # when recursing, add a space to align with the [ added, and reduce the |
| 876 | # length of the line by 1 |
| 877 | next_hanging_indent = hanging_indent + ' ' |
| 878 | if legacy <= 113: |
| 879 | next_width = curr_width |
| 880 | else: |
| 881 | next_width = curr_width - len(']') |
| 882 | |
| 883 | a_len = a.shape[axis] |
| 884 | show_summary = summary_insert and 2 * edge_items < a_len |
| 885 | if show_summary: |
| 886 | leading_items = edge_items |
| 887 | trailing_items = edge_items |
| 888 | else: |
| 889 | leading_items = 0 |
| 890 | trailing_items = a_len |
| 891 | |
| 892 | # stringify the array with the hanging indent on the first line too |
| 893 | s = '' |
| 894 | |
| 895 | # last axis (rows) - wrap elements if they would not fit on one line |
| 896 | if axes_left == 1: |
| 897 | # the length up until the beginning of the separator / bracket |
| 898 | if legacy <= 113: |
| 899 | elem_width = curr_width - len(separator.rstrip()) |
| 900 | else: |
| 901 | elem_width = curr_width - max( |
| 902 | len(separator.rstrip()), len(']') |
| 903 | ) |
| 904 | |
| 905 | line = hanging_indent |
| 906 | for i in range(leading_items): |
| 907 | word = recurser(index + (i,), next_hanging_indent, next_width) |
| 908 | s, line = _extendLine_pretty( |
| 909 | s, line, word, elem_width, hanging_indent, legacy) |
| 910 | line += separator |
| 911 |
no test coverage detected
searching dependent graphs…