Skip to content

Commit b27dc03

Browse files
committed
pre-commit-fixes
1 parent 9277f14 commit b27dc03

12 files changed

Lines changed: 152 additions & 62 deletions

benchmarks/benchmarks/_patch_setup.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import sys
1111

1212
_PATCH_MAP = [
13-
("mkl_fft", "patch_numpy_fft"),
13+
("mkl_fft", "patch_numpy_fft"),
1414
("mkl_random", "patch_numpy_random"),
15-
("mkl_umath", "patch_numpy_umath"),
15+
("mkl_umath", "patch_numpy_umath"),
1616
]
1717

1818

@@ -25,15 +25,18 @@ def _apply_patches():
2525
except ImportError as exc:
2626
raise RuntimeError(
2727
f"[mkl-patch] Cannot import {mod_name}: {exc}\n"
28-
f" Ensure the conda env contains {mod_name} from the Intel channel.\n"
29-
f" Required channels: https://software.repos.intel.com/python/conda"
28+
f" Ensure the conda env contains {mod_name} "
29+
f"from the Intel channel.\n"
30+
" Required channels: "
31+
"https://software.repos.intel.com/python/conda"
3032
) from exc
3133

3234
patch_fn = getattr(mod, patch_fn_name, None)
3335
if patch_fn is None:
3436
raise RuntimeError(
3537
f"[mkl-patch] {mod_name} has no {patch_fn_name}(). "
36-
f"Upgrade {mod_name} to a version that exposes the stock-numpy patch API."
38+
f"Upgrade {mod_name} to a version that exposes "
39+
"the stock-numpy patch API."
3740
)
3841

3942
try:
@@ -46,8 +49,9 @@ def _apply_patches():
4649
is_patched_fn = getattr(mod, "is_patched", None)
4750
if callable(is_patched_fn) and not is_patched_fn():
4851
raise RuntimeError(
49-
f"[mkl-patch] {mod_name}.is_patched() returned False after patching. "
50-
f"NumPy may have been imported before patching in a conflicting state."
52+
f"[mkl-patch] {mod_name}.is_patched() returned False "
53+
"after patching. NumPy may have been imported before "
54+
"patching in a conflicting state."
5155
)
5256

5357
patched[mod_name] = mod
@@ -56,9 +60,9 @@ def _apply_patches():
5660
import numpy as np
5761

5862
_attr_checks = {
59-
"mkl_fft": lambda: np.fft.fft.__module__,
63+
"mkl_fft": lambda: np.fft.fft.__module__,
6064
"mkl_random": lambda: np.random.random.__module__,
61-
"mkl_umath": lambda: np.exp.__module__,
65+
"mkl_umath": lambda: np.exp.__module__,
6266
}
6367
for mod_name in patched:
6468
try:
@@ -67,7 +71,9 @@ def _apply_patches():
6771
attr = "unknown"
6872
sys.stderr.write(f"[mkl-patch] {mod_name}: numpy dispatch → {attr}\n")
6973

70-
sys.stderr.write("[mkl-patch] ALL OK — mkl_fft, mkl_random, mkl_umath active\n")
74+
sys.stderr.write(
75+
"[mkl-patch] ALL OK — mkl_fft, mkl_random, mkl_umath active\n"
76+
)
7177
sys.stderr.flush()
7278

7379

benchmarks/benchmarks/npbench/bench_arc_distance.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# https://github.com/spcl/npbench/blob/main/npbench/benchmarks/pythran/arc_distance/arc_distance.py
1313
def _initialize(N):
1414
from numpy.random import default_rng
15+
1516
rng = default_rng(42)
1617
t0 = rng.random((N,))
1718
p0 = rng.random((N,))

benchmarks/benchmarks/npbench/bench_cholesky2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
def _initialize(N, datatype=np.float64):
2020
A = np.empty((N, N), dtype=datatype)
2121
for i in range(N):
22-
A[i, :i + 1] = np.fromfunction(
22+
A[i, : i + 1] = np.fromfunction(
2323
lambda j: (-j % N) / N + 1, (i + 1,), dtype=datatype
2424
)
25-
A[i, i + 1:] = 0.0
25+
A[i, i + 1 :] = 0.0
2626
A[i, i] = 1.0
2727
A[:] = A @ np.transpose(A)
2828
return A

benchmarks/benchmarks/npbench/bench_correlation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ def _kernel(M, float_n, data):
2929
data /= np.sqrt(float_n) * stddev
3030
corr = np.eye(M, dtype=data.dtype)
3131
for i in range(M - 1):
32-
corr[i + 1:M, i] = corr[i, i + 1:M] = data[:, i] @ data[:, i + 1:M]
32+
corr[i + 1 : M, i] = corr[i, i + 1 : M] = (
33+
data[:, i] @ data[:, i + 1 : M]
34+
)
3335
return corr
3436

3537

benchmarks/benchmarks/npbench/bench_gemm.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
"""npbench wrapper: GEMM (general matrix-matrix multiply) — mkl_umath ops: matmul.
1+
"""npbench wrapper: GEMM (general matrix-matrix multiply).
2+
3+
mkl_umath ops: matmul.
24
35
Preset sizes from npbench bench_info/gemm.json:
46
M: NI=2500, NJ=2750, NK=3000
@@ -15,10 +17,16 @@
1517
# https://github.com/spcl/npbench/blob/main/npbench/benchmarks/polybench/gemm/gemm.py
1618
def _initialize(NI, NJ, NK, datatype=np.float64):
1719
alpha = datatype(1.5)
18-
beta = datatype(1.2)
19-
C = np.fromfunction(lambda i, j: ((i * j + 1) % NI) / NI, (NI, NJ), dtype=datatype)
20-
A = np.fromfunction(lambda i, k: (i * (k + 1) % NK) / NK, (NI, NK), dtype=datatype)
21-
B = np.fromfunction(lambda k, j: (k * (j + 2) % NJ) / NJ, (NK, NJ), dtype=datatype)
20+
beta = datatype(1.2)
21+
C = np.fromfunction(
22+
lambda i, j: ((i * j + 1) % NI) / NI, (NI, NJ), dtype=datatype
23+
)
24+
A = np.fromfunction(
25+
lambda i, k: (i * (k + 1) % NK) / NK, (NI, NK), dtype=datatype
26+
)
27+
B = np.fromfunction(
28+
lambda k, j: (k * (j + 2) % NJ) / NJ, (NK, NJ), dtype=datatype
29+
)
2230
return alpha, beta, C, A, B
2331

2432

@@ -46,7 +54,7 @@ def setup_cache(self):
4654
def setup(self, cache, preset):
4755
alpha, beta, C, A, B = cache[preset]
4856
self.alpha = alpha
49-
self.beta = beta
57+
self.beta = beta
5058
self.C = C.copy() # mutated in-place
5159
self.A = A
5260
self.B = B

benchmarks/benchmarks/npbench/bench_gemver.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
"""npbench wrapper: GEMVER (vector multiplication and matrix addition) — mkl_umath ops: outer.
1+
"""npbench wrapper: GEMVER (vector multiplication and matrix addition).
2+
3+
mkl_umath ops: outer.
24
35
Preset sizes from npbench bench_info/gemver.json:
46
M: N=3_000
@@ -16,15 +18,15 @@ def _initialize(N, datatype=np.float64):
1618
alpha = datatype(1.5)
1719
beta = datatype(1.2)
1820
fn = datatype(N)
19-
A = np.fromfunction(lambda i, j: (i * j % N) / N, (N, N), dtype=datatype)
21+
A = np.fromfunction(lambda i, j: (i * j % N) / N, (N, N), dtype=datatype)
2022
u1 = np.fromfunction(lambda i: i, (N,), dtype=datatype)
2123
u2 = np.fromfunction(lambda i: ((i + 1) / fn) / 2.0, (N,), dtype=datatype)
2224
v1 = np.fromfunction(lambda i: ((i + 1) / fn) / 4.0, (N,), dtype=datatype)
2325
v2 = np.fromfunction(lambda i: ((i + 1) / fn) / 6.0, (N,), dtype=datatype)
24-
w = np.zeros((N,), dtype=datatype)
25-
x = np.zeros((N,), dtype=datatype)
26-
y = np.fromfunction(lambda i: ((i + 1) / fn) / 8.0, (N,), dtype=datatype)
27-
z = np.fromfunction(lambda i: ((i + 1) / fn) / 9.0, (N,), dtype=datatype)
26+
w = np.zeros((N,), dtype=datatype)
27+
x = np.zeros((N,), dtype=datatype)
28+
y = np.fromfunction(lambda i: ((i + 1) / fn) / 8.0, (N,), dtype=datatype)
29+
z = np.fromfunction(lambda i: ((i + 1) / fn) / 9.0, (N,), dtype=datatype)
2830
return alpha, beta, A, u1, v1, u2, v2, w, x, y, z
2931

3032

@@ -54,20 +56,28 @@ def setup_cache(self):
5456
def setup(self, cache, preset):
5557
alpha, beta, A, u1, v1, u2, v2, w, x, y, z = cache[preset]
5658
self.alpha = alpha
57-
self.beta = beta
58-
self.A = A.copy() # mutated: A += outer(u1,v1) + outer(u2,v2)
59+
self.beta = beta
60+
self.A = A.copy() # mutated: A += outer(u1,v1) + outer(u2,v2)
5961
self.u1 = u1
6062
self.v1 = v1
6163
self.u2 = u2
6264
self.v2 = v2
63-
self.w = w.copy() # mutated: w += alpha * A @ x
64-
self.x = x.copy() # mutated: x += beta * y @ A + z
65-
self.y = y
66-
self.z = z
65+
self.w = w.copy() # mutated: w += alpha * A @ x
66+
self.x = x.copy() # mutated: x += beta * y @ A + z
67+
self.y = y
68+
self.z = z
6769

6870
def time_gemver(self, cache, preset):
6971
_kernel(
70-
self.alpha, self.beta,
71-
self.A, self.u1, self.v1, self.u2, self.v2,
72-
self.w, self.x, self.y, self.z,
72+
self.alpha,
73+
self.beta,
74+
self.A,
75+
self.u1,
76+
self.v1,
77+
self.u2,
78+
self.v2,
79+
self.w,
80+
self.x,
81+
self.y,
82+
self.z,
7383
)

benchmarks/benchmarks/npbench/bench_gesummv.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
"""npbench wrapper: GESUMMV (scalar, vector and matrix multiplication) — mkl_umath ops: matmul.
1+
"""npbench wrapper: GESUMMV (scalar, vector and matrix multiplication).
2+
3+
mkl_umath ops: matmul.
24
35
Preset sizes from npbench bench_info/gesummv.json:
46
M: N=4_000
@@ -13,8 +15,12 @@
1315
def _initialize(N, datatype=np.float64):
1416
alpha = datatype(1.5)
1517
beta = datatype(1.2)
16-
A = np.fromfunction(lambda i, j: ((i * j + 1) % N) / N, (N, N), dtype=datatype)
17-
B = np.fromfunction(lambda i, j: ((i * j + 2) % N) / N, (N, N), dtype=datatype)
18+
A = np.fromfunction(
19+
lambda i, j: ((i * j + 1) % N) / N, (N, N), dtype=datatype
20+
)
21+
B = np.fromfunction(
22+
lambda i, j: ((i * j + 2) % N) / N, (N, N), dtype=datatype
23+
)
1824
x = np.fromfunction(lambda i: (i % N) / N, (N,), dtype=datatype)
1925
return alpha, beta, A, B, x
2026

benchmarks/benchmarks/npbench/bench_go_fast.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# https://github.com/spcl/npbench/blob/main/npbench/benchmarks/go_fast/go_fast.py
1717
def _initialize(N):
1818
from numpy.random import default_rng
19+
1920
rng = default_rng(42)
2021
a = rng.random((N, N))
2122
return (a,)
@@ -37,7 +38,7 @@ def _go_fast(a):
3738

3839

3940
class BenchGoFastLoop:
40-
"""Original npbench kernel — diagonal Python loop calling np.tanh per element."""
41+
"""Original npbench kernel — Python loop calling np.tanh per element."""
4142

4243
params = (["M", "L"],)
4344
param_names = ["preset"]

benchmarks/benchmarks/npbench/bench_k2mm.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,19 @@
1515
# https://github.com/spcl/npbench/blob/main/npbench/benchmarks/polybench/k2mm/k2mm.py
1616
def _initialize(NI, NJ, NK, NL, datatype=np.float64):
1717
alpha = datatype(1.5)
18-
beta = datatype(1.2)
19-
A = np.fromfunction(lambda i, j: ((i * j + 1) % NI) / NI, (NI, NK), dtype=datatype)
20-
B = np.fromfunction(lambda i, j: (i * (j + 1) % NJ) / NJ, (NK, NJ), dtype=datatype)
21-
C = np.fromfunction(lambda i, j: ((i * (j + 3) + 1) % NL) / NL, (NJ, NL), dtype=datatype)
22-
D = np.fromfunction(lambda i, j: (i * (j + 2) % NK) / NK, (NI, NL), dtype=datatype)
18+
beta = datatype(1.2)
19+
A = np.fromfunction(
20+
lambda i, j: ((i * j + 1) % NI) / NI, (NI, NK), dtype=datatype
21+
)
22+
B = np.fromfunction(
23+
lambda i, j: (i * (j + 1) % NJ) / NJ, (NK, NJ), dtype=datatype
24+
)
25+
C = np.fromfunction(
26+
lambda i, j: ((i * (j + 3) + 1) % NL) / NL, (NJ, NL), dtype=datatype
27+
)
28+
D = np.fromfunction(
29+
lambda i, j: (i * (j + 2) % NK) / NK, (NI, NL), dtype=datatype
30+
)
2331
return alpha, beta, A, B, C, D
2432

2533

@@ -47,7 +55,7 @@ def setup_cache(self):
4755
def setup(self, cache, preset):
4856
alpha, beta, A, B, C, D = cache[preset]
4957
self.alpha = alpha
50-
self.beta = beta
58+
self.beta = beta
5159
self.A = A
5260
self.B = B
5361
self.C = C

benchmarks/benchmarks/npbench/bench_k3mm.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,22 @@
1111
# Inlined from spcl/npbench @ main
1212
# https://github.com/spcl/npbench/blob/main/npbench/benchmarks/polybench/k3mm/k3mm.py
1313
def _initialize(NI, NJ, NK, NL, NM, datatype=np.float64):
14-
A = np.fromfunction(lambda i, j: ((i * j + 1) % NI) / (5 * NI), (NI, NK), dtype=datatype)
15-
B = np.fromfunction(lambda i, j: ((i * (j + 1) + 2) % NJ) / (5 * NJ), (NK, NJ), dtype=datatype)
16-
C = np.fromfunction(lambda i, j: (i * (j + 3) % NL) / (5 * NL), (NJ, NM), dtype=datatype)
17-
D = np.fromfunction(lambda i, j: ((i * (j + 2) + 2) % NK) / (5 * NK), (NM, NL), dtype=datatype)
14+
A = np.fromfunction(
15+
lambda i, j: ((i * j + 1) % NI) / (5 * NI), (NI, NK), dtype=datatype
16+
)
17+
B = np.fromfunction(
18+
lambda i, j: ((i * (j + 1) + 2) % NJ) / (5 * NJ),
19+
(NK, NJ),
20+
dtype=datatype,
21+
)
22+
C = np.fromfunction(
23+
lambda i, j: (i * (j + 3) % NL) / (5 * NL), (NJ, NM), dtype=datatype
24+
)
25+
D = np.fromfunction(
26+
lambda i, j: ((i * (j + 2) + 2) % NK) / (5 * NK),
27+
(NM, NL),
28+
dtype=datatype,
29+
)
1830
return A, B, C, D
1931

2032

0 commit comments

Comments
 (0)