66# LICENSE file in the root directory of this source tree)
77#######################################################################
88
9+ import numpy as np
910import pytest
1011
1112import blosc2
1213
13- import numpy as np
14-
1514###### General expressions
1615
1716# Define the parameters
1817test_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 )
2431def 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+
3240def 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
3645def 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
3949def 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+
6172def 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+
8193def 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
8598def 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
88102def 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+
96111def 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+
112128def 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 [...])
0 commit comments