diff options
author | Aaron Meurer <asmeurer@gmail.com> | 2021-06-14 14:07:18 -0600 |
---|---|---|
committer | Aaron Meurer <asmeurer@gmail.com> | 2021-06-14 14:07:18 -0600 |
commit | 8c78b84968e580f24b3705378fb35705a434cdf1 (patch) | |
tree | c9f82beeb5a2c3f0301f7984d4b6d19539c35d23 /numpy/lib/utils.py | |
parent | 8bf3a4618f1de951c7a4ccdb8bc3e36825a1b744 (diff) | |
parent | 75f852edf94a7293e7982ad516bee314d7187c2d (diff) | |
download | numpy-8c78b84968e580f24b3705378fb35705a434cdf1.tar.gz |
Merge branch 'main' into matrix_rank-doc-fix
Diffstat (limited to 'numpy/lib/utils.py')
-rw-r--r-- | numpy/lib/utils.py | 61 |
1 files changed, 56 insertions, 5 deletions
diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index 5447608bf..12a7cacdc 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -193,7 +193,32 @@ def deprecate(*args, **kwargs): else: return _Deprecate(*args, **kwargs) -deprecate_with_doc = lambda msg: _Deprecate(message=msg) + +def deprecate_with_doc(msg): + """ + Deprecates a function and includes the deprecation in its docstring. + + This function is used as a decorator. It returns an object that can be + used to issue a DeprecationWarning, by passing the to-be decorated + function as argument, this adds warning to the to-be decorated function's + docstring and returns the new function object. + + See Also + -------- + deprecate : Decorate a function such that it issues a `DeprecationWarning` + + Parameters + ---------- + msg : str + Additional explanation of the deprecation. Displayed in the + docstring after the warning. + + Returns + ------- + obj : object + + """ + return _Deprecate(message=msg) #-------------------------------------------- @@ -990,10 +1015,11 @@ def _median_nancheck(data, result, axis, out): Input data to median function result : Array or MaskedArray Result of median function - axis : {int, sequence of int, None}, optional - Axis or axes along which the median was computed. + axis : int + Axis along which the median was computed. out : ndarray, optional Output array in which to place the result. + Returns ------- median : scalar or ndarray @@ -1001,8 +1027,7 @@ def _median_nancheck(data, result, axis, out): """ if data.size == 0: return result - data = np.moveaxis(data, axis, -1) - n = np.isnan(data[..., -1]) + n = np.isnan(data.take(-1, axis=axis)) # masked NaN values are ok if np.ma.isMaskedArray(n): n = n.filled(False) @@ -1017,4 +1042,30 @@ def _median_nancheck(data, result, axis, out): result[n] = np.nan return result +def _opt_info(): + """ + Returns a string contains the supported CPU features by the current build. + + The string format can be explained as follows: + - dispatched features that are supported by the running machine + end with `*`. + - dispatched features that are "not" supported by the running machine + end with `?`. + - remained features are representing the baseline. + """ + from numpy.core._multiarray_umath import ( + __cpu_features__, __cpu_baseline__, __cpu_dispatch__ + ) + + if len(__cpu_baseline__) == 0 and len(__cpu_dispatch__) == 0: + return '' + + enabled_features = ' '.join(__cpu_baseline__) + for feature in __cpu_dispatch__: + if __cpu_features__[feature]: + enabled_features += f" {feature}*" + else: + enabled_features += f" {feature}?" + + return enabled_features #----------------------------------------------------------------------------- |