Validates logic of `axes`/`axis`/`keepdims` arguments and normalize them. Refer to [1]_ for details Arguments --------- axes: List of tuples axis: int keepdims: bool input_coredimss: List of Tuple of dims output_coredimss: List of Tuple of dims Returns
(axes, axis, keepdims, input_coredimss, output_coredimss)
| 61 | |
| 62 | |
| 63 | def _validate_normalize_axes(axes, axis, keepdims, input_coredimss, output_coredimss): |
| 64 | """ |
| 65 | Validates logic of `axes`/`axis`/`keepdims` arguments and normalize them. |
| 66 | Refer to [1]_ for details |
| 67 | |
| 68 | Arguments |
| 69 | --------- |
| 70 | axes: List of tuples |
| 71 | axis: int |
| 72 | keepdims: bool |
| 73 | input_coredimss: List of Tuple of dims |
| 74 | output_coredimss: List of Tuple of dims |
| 75 | |
| 76 | Returns |
| 77 | ------- |
| 78 | input_axes: List of tuple of int |
| 79 | output_axes: List of tuple of int |
| 80 | |
| 81 | References |
| 82 | ---------- |
| 83 | .. [1] https://docs.scipy.org/doc/numpy/reference/ufuncs.html#optional-keyword-arguments |
| 84 | """ |
| 85 | nin = len(input_coredimss) |
| 86 | nout = 1 if not isinstance(output_coredimss, list) else len(output_coredimss) |
| 87 | |
| 88 | if axes is not None and axis is not None: |
| 89 | raise ValueError( |
| 90 | "Only one of `axis` or `axes` keyword arguments should be given" |
| 91 | ) |
| 92 | if axes and not isinstance(axes, list): |
| 93 | raise ValueError("`axes` has to be of type list") |
| 94 | |
| 95 | output_coredimss = output_coredimss if nout > 1 else [output_coredimss] |
| 96 | filtered_core_dims = list(filter(len, input_coredimss)) |
| 97 | nr_outputs_with_coredims = len([True for x in output_coredimss if len(x) > 0]) |
| 98 | |
| 99 | if keepdims: |
| 100 | if nr_outputs_with_coredims > 0: |
| 101 | raise ValueError("`keepdims` can only be used for scalar outputs") |
| 102 | output_coredimss = len(output_coredimss) * [filtered_core_dims[0]] |
| 103 | |
| 104 | core_dims = input_coredimss + output_coredimss |
| 105 | if axis is not None: |
| 106 | if not isinstance(axis, int): |
| 107 | raise ValueError("`axis` argument has to be an integer value") |
| 108 | if filtered_core_dims: |
| 109 | cd0 = filtered_core_dims[0] |
| 110 | if len(cd0) != 1: |
| 111 | raise ValueError( |
| 112 | "`axis` can be used only, if one core dimension is present" |
| 113 | ) |
| 114 | for cd in filtered_core_dims: |
| 115 | if cd0 != cd: |
| 116 | raise ValueError( |
| 117 | "To use `axis`, all core dimensions have to be equal" |
| 118 | ) |
| 119 | |
| 120 | # Expand defaults or axis |
no outgoing calls
searching dependent graphs…