summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSayed Adel <seiko@imavr.com>2020-11-10 16:16:50 +0000
committerSayed Adel <seiko@imavr.com>2021-04-22 23:58:02 +0200
commit472b152fdaad523b451410165f126b473f6de0df (patch)
treefbb184060a0cd6949c15169e9c70964cae60afb3
parentec912112407ece5f6269040ffde0a5cffc840e12 (diff)
downloadnumpy-472b152fdaad523b451410165f126b473f6de0df.tar.gz
ENH: add new function `_opt_info()` to utils provides the optimization info of NumPy build
-rw-r--r--benchmarks/benchmarks/__init__.py2
-rw-r--r--numpy/_pytesttester.py16
-rw-r--r--numpy/lib/utils.py44
3 files changed, 38 insertions, 24 deletions
diff --git a/benchmarks/benchmarks/__init__.py b/benchmarks/benchmarks/__init__.py
index 50dd0898c..7b9f1d3e6 100644
--- a/benchmarks/benchmarks/__init__.py
+++ b/benchmarks/benchmarks/__init__.py
@@ -47,7 +47,7 @@ def dirty_lock(lock_name, lock_on_count=1):
pass
return False
+
# FIXME: there's no official way to provide extra information to the test log
if not dirty_lock("print_cpu_features.lock"):
show_cpu_features()
-
diff --git a/numpy/_pytesttester.py b/numpy/_pytesttester.py
index 813e069a4..acfaa1ca5 100644
--- a/numpy/_pytesttester.py
+++ b/numpy/_pytesttester.py
@@ -35,25 +35,13 @@ __all__ = ['PytestTester']
def _show_numpy_info():
- from numpy.core._multiarray_umath import (
- __cpu_features__, __cpu_baseline__, __cpu_dispatch__
- )
import numpy as np
print("NumPy version %s" % np.__version__)
relaxed_strides = np.ones((10, 1), order="C").flags.f_contiguous
print("NumPy relaxed strides checking option:", relaxed_strides)
-
- if len(__cpu_baseline__) == 0 and len(__cpu_dispatch__) == 0:
- enabled_features = "nothing enabled"
- else:
- enabled_features = ' '.join(__cpu_baseline__)
- for feature in __cpu_dispatch__:
- if __cpu_features__[feature]:
- enabled_features += " %s*" % feature
- else:
- enabled_features += " %s?" % feature
- print("NumPy CPU features:", enabled_features)
+ info = np.lib.utils._opt_info()
+ print("NumPy CPU features: ", (info if info else 'nothing enabled'))
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
#-----------------------------------------------------------------------------