| 934 | |
| 935 | |
| 936 | def expand_pad_value(array, pad_value): |
| 937 | if isinstance(pad_value, Number) or getattr(pad_value, "ndim", None) == 0: |
| 938 | pad_value = array.ndim * ((pad_value, pad_value),) |
| 939 | elif ( |
| 940 | isinstance(pad_value, Sequence) |
| 941 | and all(isinstance(pw, Number) for pw in pad_value) |
| 942 | and len(pad_value) == 1 |
| 943 | ): |
| 944 | pad_value = array.ndim * ((pad_value[0], pad_value[0]),) |
| 945 | elif ( |
| 946 | isinstance(pad_value, Sequence) |
| 947 | and len(pad_value) == 2 |
| 948 | and all(isinstance(pw, Number) for pw in pad_value) |
| 949 | ): |
| 950 | pad_value = array.ndim * (tuple(pad_value),) |
| 951 | elif ( |
| 952 | isinstance(pad_value, Sequence) |
| 953 | and len(pad_value) == array.ndim |
| 954 | and all(isinstance(pw, Sequence) for pw in pad_value) |
| 955 | and all((len(pw) == 2) for pw in pad_value) |
| 956 | and all(all(isinstance(w, Number) for w in pw) for pw in pad_value) |
| 957 | ): |
| 958 | pad_value = tuple(tuple(pw) for pw in pad_value) |
| 959 | elif ( |
| 960 | isinstance(pad_value, Sequence) |
| 961 | and len(pad_value) == 1 |
| 962 | and isinstance(pad_value[0], Sequence) |
| 963 | and len(pad_value[0]) == 2 |
| 964 | and all(isinstance(pw, Number) for pw in pad_value[0]) |
| 965 | ): |
| 966 | pad_value = array.ndim * (tuple(pad_value[0]),) |
| 967 | else: |
| 968 | raise TypeError("`pad_value` must be composed of integral typed values.") |
| 969 | |
| 970 | return pad_value |
| 971 | |
| 972 | |
| 973 | def get_pad_shapes_chunks(array, pad_width, axes, mode): |