MCPcopy Create free account
hub / github.com/dask/dask / _validate_normalize_axes

Function _validate_normalize_axes

dask/array/gufunc.py:62–169  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 1

apply_gufuncFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected