Skip to content

Commit 0ad1656

Browse files
committed
tests: Added test applying a specialized operator
1 parent 041eb4d commit 0ad1656

1 file changed

Lines changed: 43 additions & 1 deletion

File tree

tests/test_specialization.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import sympy
22
import pytest
33

4+
import numpy as np
5+
46
from devito import (Grid, Function, TimeFunction, Eq, Operator, SubDomain, Dimension,
57
ConditionalDimension)
68
from devito.ir.iet.visitors import Specializer
@@ -171,4 +173,44 @@ def test_sizes(self):
171173
assert "const int x_fsz0 = 11;" in str(op1.ccode)
172174
assert "const int y_fsz0 = 11;" in str(op1.ccode)
173175

174-
# TODO: Should strides get linearized? If so, how?
176+
# TODO: Should strides get specialized? If so, how?
177+
178+
def test_apply_basic(self):
179+
"""
180+
Test that a trivial operator runs and returns the same results when
181+
specialized.
182+
"""
183+
grid = Grid(shape=(11, 11))
184+
((x_m, x_M), (y_m, y_M)) = [d.symbolic_extrema for d in grid.dimensions]
185+
f = Function(name='f', grid=grid, dtype=np.int32)
186+
187+
op0 = Operator(Eq(f, f+1))
188+
189+
mapper = {x_m: sympy.Integer(2), x_M: sympy.Integer(7),
190+
y_m: sympy.Integer(3), y_M: sympy.Integer(8)}
191+
192+
op1 = Specializer(mapper).visit(op0)
193+
194+
assert op1.cfunction is not op0.cfunction
195+
196+
op1.apply()
197+
198+
check = np.array(f.data[:])
199+
f.data[:] = 0
200+
201+
op0.apply(x_m=2, x_M=7, y_m=3, y_M=8)
202+
203+
assert np.all(check == f.data)
204+
205+
206+
# class TestApply:
207+
# """Tests for specialization of operators at apply time"""
208+
209+
# def test_basic(self):
210+
# grid = Grid(shape=(11, 11))
211+
212+
# f = TimeFunction(name='f', grid=grid, space_order=2)
213+
214+
# op = Operator(Eq(f.forward, f + 1))
215+
216+
# op.apply(time_M=10, specialize=('x_m', 'x_M'))

0 commit comments

Comments
 (0)