14
14
15
15
###### General expressions
16
16
17
- def expr_nojit (a , b , c ):
18
- return ((a ** 3 + np .sin (a * 2 )) < c ) & (b > 0 )
19
-
20
- @blosc2 .jit
21
- def expr_jit (a , b , c ):
22
- return ((a ** 3 + np .sin (a * 2 )) < c ) & (b > 0 )
23
-
24
17
# Define the parameters
25
18
test_params = [
26
19
((10 , 100 ), (10 , 100 ,), "float32" ),
27
20
((10 , 100 ), (100 ,), "float64" ), # using broadcasting
28
21
]
29
22
30
- @pytest .mark .parametrize ("shape, cshape, dtype" , test_params )
31
- def test_expr (shape , cshape , dtype ):
23
+ @pytest .fixture (params = test_params )
24
+ def sample_data (request ):
25
+ shape , cshape , dtype = request .param
26
+ # The jit decorator can work with any numpy or NDArray params in functions
32
27
a = blosc2 .linspace (0 , 1 , shape [0 ] * shape [1 ], dtype = dtype , shape = shape )
33
- b = blosc2 .linspace (1 , 2 , shape [0 ] * shape [1 ], dtype = dtype , shape = shape )
28
+ b = np .linspace (1 , 2 , shape [0 ] * shape [1 ], dtype = dtype ). reshape ( shape )
34
29
c = blosc2 .linspace (- 10 , 10 , cshape [0 ], dtype = dtype , shape = cshape )
30
+ return a , b , c , shape , cshape , dtype
35
31
32
+ def expr_nojit (a , b , c ):
33
+ return ((a ** 3 + np .sin (a * 2 )) < c ) & (b > 0 )
34
+
35
+ @blosc2 .jit
36
+ def expr_jit (a , b , c ):
37
+ return ((a ** 3 + np .sin (a * 2 )) < c ) & (b > 0 )
38
+
39
+ def test_expr (sample_data ):
40
+ a , b , c , shape , cshape , dtype = sample_data
36
41
d_jit = expr_jit (a , b , c )
37
42
d_nojit = expr_nojit (a , b , c )
38
-
39
43
np .testing .assert_equal (d_jit [...], d_nojit [...])
40
44
41
45
42
- @pytest .mark .parametrize ("shape, cshape, dtype" , test_params )
43
- def test_expr_out (shape , cshape , dtype ):
44
- a = blosc2 .linspace (0 , 1 , shape [0 ] * shape [1 ], dtype = dtype , shape = shape )
45
- b = blosc2 .linspace (1 , 2 , shape [0 ] * shape [1 ], dtype = dtype , shape = shape )
46
- c = blosc2 .linspace (- 10 , 10 , cshape [0 ], dtype = dtype , shape = cshape )
46
+ def test_expr_out (sample_data ):
47
+ a , b , c , shape , cshape , dtype = sample_data
47
48
d_nojit = expr_nojit (a , b , c )
48
49
49
50
# Testing jit decorator with an out param
@@ -57,11 +58,8 @@ def expr_jit_out(a, b, c):
57
58
np .testing .assert_equal (d_jit [...], d_nojit [...])
58
59
np .testing .assert_equal (out [...], d_nojit [...])
59
60
60
- @pytest .mark .parametrize ("shape, cshape, dtype" , test_params )
61
- def test_expr_kwargs (shape , cshape , dtype ):
62
- a = blosc2 .linspace (0 , 1 , shape [0 ] * shape [1 ], dtype = dtype , shape = shape )
63
- b = blosc2 .linspace (1 , 2 , shape [0 ] * shape [1 ], dtype = dtype , shape = shape )
64
- c = blosc2 .linspace (- 10 , 10 , cshape [0 ], dtype = dtype , shape = cshape )
61
+ def test_expr_kwargs (sample_data ):
62
+ a , b , c , shape , cshape , dtype = sample_data
65
63
d_nojit = expr_nojit (a , b , c )
66
64
67
65
# Testing jit decorator with kwargs
@@ -87,22 +85,16 @@ def reduc_nojit(a, b, c):
87
85
def reduc_jit (a , b , c ):
88
86
return np .sum (((a ** 3 + np .sin (a * 2 )) < c ) & (b > 0 ), axis = 1 )
89
87
90
- @pytest .mark .parametrize ("shape, cshape, dtype" , test_params )
91
- def test_reduc (shape , cshape , dtype ):
92
- a = blosc2 .linspace (0 , 1 , shape [0 ] * shape [1 ], dtype = dtype , shape = shape )
93
- b = blosc2 .linspace (1 , 2 , shape [0 ] * shape [1 ], dtype = dtype , shape = shape )
94
- c = blosc2 .linspace (- 10 , 10 , cshape [0 ], dtype = dtype , shape = cshape )
88
+ def test_reduc (sample_data ):
89
+ a , b , c , shape , cshape , dtype = sample_data
95
90
96
91
d_jit = reduc_jit (a , b , c )
97
92
d_nojit = reduc_nojit (a , b , c )
98
93
99
94
np .testing .assert_equal (d_jit [...], d_nojit [...])
100
95
101
- @pytest .mark .parametrize ("shape, cshape, dtype" , test_params )
102
- def test_reduc_out (shape , cshape , dtype ):
103
- a = blosc2 .linspace (0 , 1 , shape [0 ] * shape [1 ], dtype = dtype , shape = shape )
104
- b = blosc2 .linspace (1 , 2 , shape [0 ] * shape [1 ], dtype = dtype , shape = shape )
105
- c = blosc2 .linspace (- 10 , 10 , cshape [0 ], dtype = dtype , shape = cshape )
96
+ def test_reduc_out (sample_data ):
97
+ a , b , c , shape , cshape , dtype = sample_data
106
98
d_nojit = reduc_nojit (a , b , c )
107
99
108
100
# Testing jit decorator with an out param via the reduction function
@@ -117,11 +109,8 @@ def reduc_jit_out(a, b, c):
117
109
np .testing .assert_equal (d_jit [...], d_nojit [...])
118
110
np .testing .assert_equal (out [...], d_nojit [...])
119
111
120
- @pytest .mark .parametrize ("shape, cshape, dtype" , test_params )
121
- def test_reduc_kwargs (shape , cshape , dtype ):
122
- a = blosc2 .linspace (0 , 1 , shape [0 ] * shape [1 ], dtype = dtype , shape = shape )
123
- b = blosc2 .linspace (1 , 2 , shape [0 ] * shape [1 ], dtype = dtype , shape = shape )
124
- c = blosc2 .linspace (- 10 , 10 , cshape [0 ], dtype = dtype , shape = cshape )
112
+ def test_reduc_kwargs (sample_data ):
113
+ a , b , c , shape , cshape , dtype = sample_data
125
114
d_nojit = reduc_nojit (a , b , c )
126
115
127
116
# Testing jit decorator with kwargs via an out param in the reduction function
0 commit comments