Skip to content

Commit 5da98d4

Browse files
committed
Fix PR comments
1 parent b27dc03 commit 5da98d4

16 files changed

Lines changed: 96 additions & 995 deletions

benchmarks/benchmarks/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Trigger MKL patching once per ASV worker process.
2-
# ASV uses --launch-method spawn in CI, so each worker is a fresh process
3-
# and this runs exactly once before any benchmark is collected or timed.
4-
from . import _patch_setup # noqa: F401
1+
from ._patch_setup import _apply_patches
2+
3+
_apply_patches()
4+
del _apply_patches

benchmarks/benchmarks/_patch_setup.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@
33
Patches NumPy with Intel MKL implementations for fft, random, and umath.
44
Hard-fails with a descriptive RuntimeError if any package is missing or the
55
patch does not take effect, so benchmarks never silently run on stock NumPy.
6-
7-
Visible output goes to stderr; pass --show-stderr to ``asv run`` to see it.
86
"""
97

10-
import sys
11-
128
_PATCH_MAP = [
139
("mkl_fft", "patch_numpy_fft"),
1410
("mkl_random", "patch_numpy_random"),
@@ -17,6 +13,8 @@
1713

1814

1915
def _apply_patches():
16+
import numpy as np
17+
2018
patched = {}
2119

2220
for mod_name, patch_fn_name in _PATCH_MAP:
@@ -56,9 +54,6 @@ def _apply_patches():
5654

5755
patched[mod_name] = mod
5856

59-
# Verbose attribution — verify numpy-level dispatch changed hands
60-
import numpy as np
61-
6257
_attr_checks = {
6358
"mkl_fft": lambda: np.fft.fft.__module__,
6459
"mkl_random": lambda: np.random.random.__module__,
@@ -69,12 +64,6 @@ def _apply_patches():
6964
attr = _attr_checks[mod_name]()
7065
except Exception:
7166
attr = "unknown"
72-
sys.stderr.write(f"[mkl-patch] {mod_name}: numpy dispatch → {attr}\n")
73-
74-
sys.stderr.write(
75-
"[mkl-patch] ALL OK — mkl_fft, mkl_random, mkl_umath active\n"
76-
)
77-
sys.stderr.flush()
78-
67+
print(f"[mkl-patch] {mod_name}: numpy dispatch -> {attr}")
7968

80-
_apply_patches()
69+
print("[mkl-patch] ALL OK -- mkl_fft, mkl_random, mkl_umath active")

benchmarks/benchmarks/micro/bench_exp_log.py

Lines changed: 0 additions & 98 deletions
This file was deleted.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
"""Micro-benchmarks for mkl_umath unary ufuncs.
2+
3+
Times each ufunc over a Cartesian product of
4+
dtype in [float32, float64]
5+
size in [10_000, 100_000, 1_000_000]
6+
7+
Arrays are pre-allocated in setup() and reused across timing calls.
8+
Patching is applied once at package import via benchmarks._patch_setup.
9+
"""
10+
11+
import numpy as np
12+
13+
14+
_UFUNC_CONFIGS = {
15+
"exp": {"func": np.exp, "low": -10.0, "high": 10.0},
16+
"exp2": {"func": np.exp2, "low": -10.0, "high": 10.0},
17+
"expm1": {"func": np.expm1, "low": -10.0, "high": 10.0},
18+
"log": {"func": np.log, "low": 1e-3, "high": 1e3},
19+
"log2": {"func": np.log2, "low": 1e-3, "high": 1e3},
20+
"log10": {"func": np.log10, "low": 1e-3, "high": 1e3},
21+
"log1p": {"func": np.log1p, "low": 0.0, "high": 10.0},
22+
"sin": {"func": np.sin, "low": -np.pi, "high": np.pi},
23+
"cos": {"func": np.cos, "low": -np.pi, "high": np.pi},
24+
"tan": {"func": np.tan, "low": -1.4, "high": 1.4},
25+
"arcsin": {"func": np.arcsin, "low": -1.0, "high": 1.0},
26+
"arccos": {"func": np.arccos, "low": -1.0, "high": 1.0},
27+
"arctan": {"func": np.arctan, "low": -10.0, "high": 10.0},
28+
"sinh": {"func": np.sinh, "low": -5.0, "high": 5.0},
29+
"cosh": {"func": np.cosh, "low": -5.0, "high": 5.0},
30+
"tanh": {"func": np.tanh, "low": -5.0, "high": 5.0},
31+
"arcsinh": {"func": np.arcsinh, "low": -10.0, "high": 10.0},
32+
"arccosh": {"func": np.arccosh, "low": 1.0, "high": 100.0},
33+
"arctanh": {"func": np.arctanh, "low": -0.99, "high": 0.99},
34+
"sqrt": {"func": np.sqrt, "low": 0.0, "high": 100.0},
35+
"cbrt": {"func": np.cbrt, "low": -100.0, "high": 100.0},
36+
"square": {"func": np.square, "low": -10.0, "high": 10.0},
37+
"fabs": {"func": np.fabs, "low": -100.0, "high": 100.0},
38+
"absolute": {"func": np.absolute, "low": -100.0, "high": 100.0},
39+
"reciprocal": {"func": np.reciprocal, "low": 0.01, "high": 100.0},
40+
}
41+
42+
43+
class BenchMicro:
44+
params = (
45+
sorted(_UFUNC_CONFIGS.keys()),
46+
["float32", "float64"],
47+
[10_000, 100_000, 1_000_000],
48+
)
49+
param_names = ["ufunc", "dtype", "size"]
50+
51+
def setup(self, ufunc, dtype, size):
52+
cfg = _UFUNC_CONFIGS[ufunc]
53+
rng = np.random.default_rng(42)
54+
self.x = rng.uniform(cfg["low"], cfg["high"], size).astype(dtype)
55+
self._func = cfg["func"]
56+
57+
def time_micro(self, ufunc, dtype, size):
58+
self._func(self.x)
59+
60+
61+
class BenchArctan2:
62+
"""Binary ufunc arctan2"""
63+
64+
params = (["float32", "float64"], [10_000, 100_000, 1_000_000])
65+
param_names = ["dtype", "size"]
66+
67+
def setup(self, dtype, size):
68+
rng = np.random.default_rng(42)
69+
self.y = rng.uniform(-1.0, 1.0, size).astype(dtype)
70+
self.x = rng.uniform(-1.0, 1.0, size).astype(dtype)
71+
72+
def time_arctan2(self, dtype, size):
73+
np.arctan2(self.y, self.x)
74+
75+
76+
class BenchPower:
77+
"""Binary ufunc power (arbitrary exponent via MKL vdPow)"""
78+
79+
params = (["float32", "float64"], [10_000, 100_000, 1_000_000])
80+
param_names = ["dtype", "size"]
81+
82+
def setup(self, dtype, size):
83+
rng = np.random.default_rng(42)
84+
self.base = rng.uniform(0.1, 10.0, size).astype(dtype)
85+
self.exp = rng.uniform(0.5, 3.0, size).astype(dtype)
86+
87+
def time_power(self, dtype, size):
88+
np.power(self.base, self.exp)

benchmarks/benchmarks/micro/bench_sqrt_misc.py

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)