From 5b63f260933672b7182daf4fb15ffcd15bae68bf Mon Sep 17 00:00:00 2001 From: kumudlakara <55556183+kumudlakara@users.noreply.github.com> Date: Thu, 17 Dec 2020 23:38:22 +0530 Subject: DOC: Doc for deprecate_with_doc (#17852) * Add doc for deprecate_with_doc Co-authored-by: Bas van Beek <43369155+BvB93@users.noreply.github.com> Co-authored-by: Matti Picus --- numpy/lib/utils.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'numpy/lib/utils.py') diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index 5447608bf..f7e176cf3 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) #-------------------------------------------- -- cgit v1.2.1 From 4152443b1d268951401e0be1351eccbddd572e97 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Thu, 4 Feb 2021 18:32:54 +0100 Subject: MAINT: Avoid moveaxis overhead in median. This change speeds up taking the median of 1001 floats by ~20%, as measured by `python -mtimeit -s 'import numpy as np; x = np.random.randn(1001)' -- 'np.median(x)'` --- numpy/lib/utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'numpy/lib/utils.py') diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index f7e176cf3..8f5c6eea3 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -1026,8 +1026,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) -- cgit v1.2.1 From 3cb10bc7178b3a753d7cc1f81414a8ab94b92e64 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Tue, 9 Feb 2021 22:26:51 +0100 Subject: DOC: Fix docstring of _median_nancheck. _median_nancheck doesn't support axis being anything other than an integer (otherwise the call to moveaxis would fail). This is fine, because median goes through _ureduce for multi-axis support. --- numpy/lib/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'numpy/lib/utils.py') diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index f7e176cf3..9cf9c1e76 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -1015,8 +1015,8 @@ 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 -- cgit v1.2.1 From 0ef6508397fcdd8f2bbace2a0b91a863b1617728 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Fri, 16 Apr 2021 19:34:17 -0700 Subject: DOC: Add blank line before section. Otherwise Numpydoc does not see the section. --- numpy/lib/utils.py | 1 + 1 file changed, 1 insertion(+) (limited to 'numpy/lib/utils.py') diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index 24252c834..91e7cb8a3 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -1019,6 +1019,7 @@ def _median_nancheck(data, result, axis, out): Axis along which the median was computed. out : ndarray, optional Output array in which to place the result. + Returns ------- median : scalar or ndarray -- cgit v1.2.1 From 472b152fdaad523b451410165f126b473f6de0df Mon Sep 17 00:00:00 2001 From: Sayed Adel Date: Tue, 10 Nov 2020 16:16:50 +0000 Subject: ENH: add new function `_opt_info()` to utils provides the optimization info of NumPy build --- numpy/lib/utils.py | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) (limited to 'numpy/lib/utils.py') diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index 91e7cb8a3..12a7cacdc 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -197,20 +197,20 @@ def deprecate(*args, **kwargs): 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 + + 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` - + deprecate : Decorate a function such that it issues a `DeprecationWarning` + Parameters ---------- msg : str - Additional explanation of the deprecation. Displayed in the + Additional explanation of the deprecation. Displayed in the docstring after the warning. Returns @@ -218,7 +218,7 @@ def deprecate_with_doc(msg): obj : object """ - return _Deprecate(message=msg) + return _Deprecate(message=msg) #-------------------------------------------- @@ -1042,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 #----------------------------------------------------------------------------- -- cgit v1.2.1