Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.9/dist-packages/numpy/lib/introspect.py: 15%
20 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-09 06:12 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-09 06:12 +0000
1"""
2Introspection helper functions.
3"""
4import re
6__all__ = ['opt_func_info']
9def opt_func_info(func_name=None, signature=None):
10 """
11 Returns a dictionary containing the currently supported CPU dispatched
12 features for all optimized functions.
14 Parameters
15 ----------
16 func_name : str (optional)
17 Regular expression to filter by function name.
19 signature : str (optional)
20 Regular expression to filter by data type.
22 Returns
23 -------
24 dict
25 A dictionary where keys are optimized function names and values are
26 nested dictionaries indicating supported targets based on data types.
28 Examples
29 --------
30 Retrieve dispatch information for functions named 'add' or 'sub' and
31 data types 'float64' or 'float32':
33 >>> dict = np.lib.introspect.opt_func_info(
34 ... func_name="add|abs", signature="float64|complex64"
35 ... )
36 >>> import json
37 >>> print(json.dumps(dict, indent=2))
38 {
39 "absolute": {
40 "dd": {
41 "current": "SSE41",
42 "available": "SSE41 baseline(SSE SSE2 SSE3)"
43 },
44 "Ff": {
45 "current": "FMA3__AVX2",
46 "available": "AVX512F FMA3__AVX2 baseline(SSE SSE2 SSE3)"
47 },
48 "Dd": {
49 "current": "FMA3__AVX2",
50 "available": "AVX512F FMA3__AVX2 baseline(SSE SSE2 SSE3)"
51 }
52 },
53 "add": {
54 "ddd": {
55 "current": "FMA3__AVX2",
56 "available": "FMA3__AVX2 baseline(SSE SSE2 SSE3)"
57 },
58 "FFF": {
59 "current": "FMA3__AVX2",
60 "available": "FMA3__AVX2 baseline(SSE SSE2 SSE3)"
61 }
62 }
63 }
65 """
66 from numpy._core._multiarray_umath import (
67 __cpu_targets_info__ as targets, dtype
68 )
70 if func_name is not None:
71 func_pattern = re.compile(func_name)
72 matching_funcs = {
73 k: v for k, v in targets.items()
74 if func_pattern.search(k)
75 }
76 else:
77 matching_funcs = targets
79 if signature is not None:
80 sig_pattern = re.compile(signature)
81 matching_sigs = {}
82 for k, v in matching_funcs.items():
83 matching_chars = {}
84 for chars, targets in v.items():
85 if any([
86 sig_pattern.search(c) or
87 sig_pattern.search(dtype(c).name)
88 for c in chars
89 ]):
90 matching_chars[chars] = targets
91 if matching_chars:
92 matching_sigs[k] = matching_chars
93 else:
94 matching_sigs = matching_funcs
95 return matching_sigs