Internal function for max, min, amax and amin. It computes the attribute reduce_all value based on axis.
(axis, x)
| 188 | |
| 189 | |
| 190 | def _get_reduce_axis(axis, x): |
| 191 | """ |
| 192 | Internal function for max, min, amax and amin. |
| 193 | It computes the attribute reduce_all value based on axis. |
| 194 | """ |
| 195 | if axis is not None and not isinstance(axis, list): |
| 196 | if isinstance(axis, (tuple, range)): |
| 197 | axis = list(axis) |
| 198 | elif isinstance(axis, int): |
| 199 | axis = [axis] |
| 200 | else: |
| 201 | raise TypeError( |
| 202 | f"The type of axis must be int, list or tuple, but received {type(axis)}" |
| 203 | ) |
| 204 | if axis is None: |
| 205 | axis = [] |
| 206 | if axis == [] or len(axis) == len(x.shape): |
| 207 | reduce_all = True |
| 208 | else: |
| 209 | reduce_all = False |
| 210 | return reduce_all, axis |
| 211 | |
| 212 | |
| 213 | def _get_reduce_axis_with_tensor(axis, x): |
no test coverage detected