Skip to content

Commit 9c32763

Browse files
committed
Keep ruff happy
1 parent 9f20767 commit 9c32763

File tree

4 files changed

+54
-24
lines changed

4 files changed

+54
-24
lines changed

Diff for: examples/ndarray/jit-expr.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99
# Examples of using the jit decorator with expressions
1010
# You can find benchmarks for this example in the bench/ndarray directory
1111

12-
import blosc2
1312
import numpy as np
1413

14+
import blosc2
15+
16+
1517
# Example 1: Basic usage of the jit decorator
1618
@blosc2.jit
1719
def expr_jit(a, b, c):
1820
# This function computes a boolean array where the condition is met
19-
return ((a ** 3 + np.sin(a * 2)) < c) & (b > 0)
21+
return ((a**3 + np.sin(a * 2)) < c) & (b > 0)
22+
2023

2124
# Create some sample data
2225
a = blosc2.linspace(0, 1, 10 * 100, dtype="float32", shape=(10, 100))
@@ -25,29 +28,33 @@ def expr_jit(a, b, c):
2528

2629
# Call the function with the jit decorator
2730
result = expr_jit(a, b, c)
28-
print(result[1,:10])
31+
print(result[1, :10])
2932

3033
# Example 2: Using the jit decorator with an out parameter
3134
out = blosc2.zeros((10, 100), dtype=np.bool_)
3235

36+
3337
@blosc2.jit(out=out)
3438
def expr_jit_out(a, b, c):
3539
# This function computes a boolean array and stores the result in the 'out' array
36-
return ((a ** 3 + np.sin(a * 2)) < c) & (b > 0)
40+
return ((a**3 + np.sin(a * 2)) < c) & (b > 0)
41+
3742

3843
# Call the function with the jit decorator and out parameter
3944
result_out = expr_jit_out(a, b, c)
40-
print(result_out[1,:10])
41-
print(out[1,:10]) # The 'out' array should now contain the same result
45+
print(result_out[1, :10])
46+
print(out[1, :10]) # The 'out' array should now contain the same result
4247

4348
# Example 3: Using the jit decorator with additional keyword arguments
4449
cparams = blosc2.CParams(clevel=1, codec=blosc2.Codec.LZ4, filters=[blosc2.Filter.BITSHUFFLE])
4550

51+
4652
@blosc2.jit(cparams=cparams)
4753
def expr_jit_cparams(a, b, c):
4854
# This function computes a boolean array with custom compression parameters
49-
return ((a ** 3 + np.sin(a * 2)) < c) & (b > 0)
55+
return ((a**3 + np.sin(a * 2)) < c) & (b > 0)
56+
5057

5158
# Call the function with the jit decorator and custom parameters
5259
result_cparams = expr_jit_cparams(a, b, c)
53-
print(result_cparams[1,:10])
60+
print(result_cparams[1, :10])

Diff for: examples/ndarray/jit-reduc.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99
# Examples of using the jit decorator with reductions
1010
# You can find benchmarks for this example in the bench/ndarray directory
1111

12-
import blosc2
1312
import numpy as np
1413

14+
import blosc2
15+
16+
1517
# Example 1: Basic usage of the jit decorator with reduction
1618
@blosc2.jit
1719
def expr_jit(a, b, c):
1820
# This function computes a sum reduction along axis 1
19-
return np.sum(((a ** 3 + np.sin(a * 2)) < c) & (b > 0), axis=1)
21+
return np.sum(((a**3 + np.sin(a * 2)) < c) & (b > 0), axis=1)
22+
2023

2124
# Create some sample data
2225
a = blosc2.linspace(0, 1, 10 * 100, dtype="float32", shape=(10, 100))
@@ -30,10 +33,12 @@ def expr_jit(a, b, c):
3033
# Example 2: Using the jit decorator with an out parameter for reduction
3134
out = np.zeros((10,), dtype=np.int64)
3235

36+
3337
@blosc2.jit
3438
def expr_jit_out(a, b, c):
3539
# This function computes a sum reduction along axis 1 and stores the result in the 'out' array
36-
return np.sum(((a ** 3 + np.sin(a * 2)) < c) & (b > 0), axis=1, out=out)
40+
return np.sum(((a**3 + np.sin(a * 2)) < c) & (b > 0), axis=1, out=out)
41+
3742

3843
# Call the function with the jit decorator and out parameter
3944
result_out = expr_jit_out(a, b, c)
@@ -44,10 +49,12 @@ def expr_jit_out(a, b, c):
4449
cparams = blosc2.CParams(clevel=1, codec=blosc2.Codec.LZ4, filters=[blosc2.Filter.BITSHUFFLE])
4550
out_cparams = blosc2.zeros((10,), dtype=np.int64, cparams=cparams)
4651

52+
4753
@blosc2.jit
4854
def expr_jit_cparams(a, b, c):
4955
# This function computes a sum reduction along axis 1 with custom compression parameters
50-
return np.sum(((a ** 3 + np.sin(a * 2)) < c) & (b > 0), axis=1, out=out_cparams)
56+
return np.sum(((a**3 + np.sin(a * 2)) < c) & (b > 0), axis=1, out=out_cparams)
57+
5158

5259
# Call the function with the jit decorator and custom parameters
5360
result_cparams = expr_jit_cparams(a, b, c)

Diff for: tests/ndarray/test_jit.py

+27-11
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,27 @@
66
# LICENSE file in the root directory of this source tree)
77
#######################################################################
88

9+
import numpy as np
910
import pytest
1011

1112
import blosc2
1213

13-
import numpy as np
14-
1514
###### General expressions
1615

1716
# Define the parameters
1817
test_params = [
19-
((10, 100), (10, 100,), "float32"),
18+
(
19+
(10, 100),
20+
(
21+
10,
22+
100,
23+
),
24+
"float32",
25+
),
2026
((10, 100), (100,), "float64"), # using broadcasting
2127
]
2228

29+
2330
@pytest.fixture(params=test_params)
2431
def sample_data(request):
2532
shape, cshape, dtype = request.param
@@ -29,12 +36,15 @@ def sample_data(request):
2936
c = blosc2.linspace(-10, 10, cshape[0], dtype=dtype, shape=cshape)
3037
return a, b, c, shape, cshape, dtype
3138

39+
3240
def expr_nojit(a, b, c):
33-
return ((a ** 3 + np.sin(a * 2)) < c) & (b > 0)
41+
return ((a**3 + np.sin(a * 2)) < c) & (b > 0)
42+
3443

3544
@blosc2.jit
3645
def expr_jit(a, b, c):
37-
return ((a ** 3 + np.sin(a * 2)) < c) & (b > 0)
46+
return ((a**3 + np.sin(a * 2)) < c) & (b > 0)
47+
3848

3949
def test_expr(sample_data):
4050
a, b, c, shape, cshape, dtype = sample_data
@@ -52,12 +62,13 @@ def test_expr_out(sample_data):
5262

5363
@blosc2.jit(out=out)
5464
def expr_jit_out(a, b, c):
55-
return ((a ** 3 + np.sin(a * 2)) < c) & (b > 0)
65+
return ((a**3 + np.sin(a * 2)) < c) & (b > 0)
5666

5767
d_jit = expr_jit_out(a, b, c)
5868
np.testing.assert_equal(d_jit[...], d_nojit[...])
5969
np.testing.assert_equal(out[...], d_nojit[...])
6070

71+
6172
def test_expr_kwargs(sample_data):
6273
a, b, c, shape, cshape, dtype = sample_data
6374
d_nojit = expr_nojit(a, b, c)
@@ -67,7 +78,7 @@ def test_expr_kwargs(sample_data):
6778

6879
@blosc2.jit(**{"cparams": cparams})
6980
def expr_jit_cparams(a, b, c):
70-
return ((a ** 3 + np.sin(a * 2)) < c) & (b > 0)
81+
return ((a**3 + np.sin(a * 2)) < c) & (b > 0)
7182

7283
d_jit = expr_jit_cparams(a, b, c)
7384
np.testing.assert_equal(d_jit[...], d_nojit[...])
@@ -78,12 +89,15 @@ def expr_jit_cparams(a, b, c):
7889

7990
###### Reductions
8091

92+
8193
def reduc_nojit(a, b, c):
82-
return np.sum(((a ** 3 + np.sin(a * 2)) < c) & (b > 0), axis=1)
94+
return np.sum(((a**3 + np.sin(a * 2)) < c) & (b > 0), axis=1)
95+
8396

8497
@blosc2.jit
8598
def reduc_jit(a, b, c):
86-
return np.sum(((a ** 3 + np.sin(a * 2)) < c) & (b > 0), axis=1)
99+
return np.sum(((a**3 + np.sin(a * 2)) < c) & (b > 0), axis=1)
100+
87101

88102
def test_reduc(sample_data):
89103
a, b, c, shape, cshape, dtype = sample_data
@@ -93,6 +107,7 @@ def test_reduc(sample_data):
93107

94108
np.testing.assert_equal(d_jit[...], d_nojit[...])
95109

110+
96111
def test_reduc_out(sample_data):
97112
a, b, c, shape, cshape, dtype = sample_data
98113
d_nojit = reduc_nojit(a, b, c)
@@ -103,12 +118,13 @@ def test_reduc_out(sample_data):
103118
# Note that out does not work with reductions as the last function call
104119
@blosc2.jit
105120
def reduc_jit_out(a, b, c):
106-
return np.sum(((a ** 3 + np.sin(a * 2)) < c) & (b > 0), axis=1, out=out)
121+
return np.sum(((a**3 + np.sin(a * 2)) < c) & (b > 0), axis=1, out=out)
107122

108123
d_jit = reduc_jit_out(a, b, c)
109124
np.testing.assert_equal(d_jit[...], d_nojit[...])
110125
np.testing.assert_equal(out[...], d_nojit[...])
111126

127+
112128
def test_reduc_kwargs(sample_data):
113129
a, b, c, shape, cshape, dtype = sample_data
114130
d_nojit = reduc_nojit(a, b, c)
@@ -119,7 +135,7 @@ def test_reduc_kwargs(sample_data):
119135

120136
@blosc2.jit
121137
def reduc_jit_cparams(a, b, c):
122-
return np.sum(((a ** 3 + np.sin(a * 2)) < c) & (b > 0), axis=1, out=out)
138+
return np.sum(((a**3 + np.sin(a * 2)) < c) & (b > 0), axis=1, out=out)
123139

124140
d_jit = reduc_jit_cparams(a, b, c)
125141
np.testing.assert_equal(d_jit[...], d_nojit[...])

Diff for: tests/ndarray/test_lazyexpr_fields.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def test_where_reduction1(array_fixture):
344344
def test_where_reduction2(array_fixture):
345345
sa1, sa2, nsa1, nsa2, a1, a2, a3, a4, na1, na2, na3, na4 = array_fixture
346346
# We have to use the original names in fields here
347-
expr = sa1[f"(b * a.sum()) > 0"]
347+
expr = sa1["(b * a.sum()) > 0"]
348348
res = expr[:]
349349
nres = nsa1[(na2 * na1.sum()) > 0]
350350
# On general chunked ndim arrays, we cannot guarantee the order of the results

0 commit comments

Comments
 (0)