@@ -161,7 +161,20 @@ def test_sizes(self):
161161 assert "const int x_fsz0 = 11;" in str (op1 .ccode )
162162 assert "const int y_fsz0 = 11;" in str (op1 .ccode )
163163
164- # TODO: Should strides get specialized? If so, how?
164+ def test_blocking (self ):
165+ grid = Grid (shape = (11 , 11 , 11 ))
166+ f = TimeFunction (name = 'f' , grid = grid , space_order = 4 )
167+
168+ op0 = Operator (Eq (f .forward , f .laplace ))
169+
170+ block_params = [p for p in op0 .parameters if 'blk' in str (p )]
171+ mapper = {p : sympy .Integer (32 ) for p in block_params }
172+
173+ op1 = Specializer (mapper ).visit (op0 )
174+
175+ assert "blk0_size" not in str (op1 .ccode )
176+ assert "x0_blk0 += 32" in str (op1 .ccode )
177+ assert "y0_blk0 += 32" in str (op1 .ccode )
165178
166179 def test_apply_basic (self ):
167180 """
@@ -190,11 +203,6 @@ def test_apply_basic(self):
190203
191204 assert np .all (check == f .data )
192205
193- # TODO: Need a test to check that block sizes can be specialized
194- # TODO: Need to test that tile sizes can be specialized
195- # TODO: Test pickling followed by specialization
196- # TODO: Test specialized operators can be pickled
197-
198206
199207class TestApply :
200208 """Tests for specialization of operators at apply time"""
@@ -311,9 +319,9 @@ def gaussian_bump(x, y, x0=0, y0=0, sigma=1):
311319 assert np .all (np .isclose (check , u .data ))
312320
313321 if source :
314- assert np .isclose (np .linalg .norm (u .data ), 21.698477 )
322+ assert np .isclose (np .linalg .norm (u .data ), 21.698477 , atol = 1e-4 , rtol = 0 )
315323 else :
316- assert np .isclose (np .linalg .norm (u .data ), 10.793053 )
324+ assert np .isclose (np .linalg .norm (u .data ), 10.793053 , atol = 1e-4 , rtol = 0 )
317325
318326 @pytest .mark .parametrize ('specialize' ,
319327 [('x_m' ,),
@@ -374,4 +382,4 @@ def test_elastic(self, specialize):
374382 norms = (1.333946 , 0.4931774 , 1.333946 , 1.1619346 , 1.1619346 )
375383
376384 for field , norm in zip (fields , norms , strict = True ):
377- assert np .isclose (np .linalg .norm (field .data ), norm )
385+ assert np .isclose (np .linalg .norm (field .data ), norm , atol = 1e-4 , rtol = 0 )
0 commit comments