Skip to content

Commit

Permalink
tests: Strengthen test_different_dtype
Browse files Browse the repository at this point in the history
  • Loading branch information
FabioLuporini committed Jul 3, 2024
1 parent c988fa9 commit 0851d5c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion devito/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def reinit_compiler(val):
configuration.add('safe-math', 0, [0, 1], preprocessor=bool, callback=reinit_compiler)

# Enable/disable automatic padding for allocated data
configuration.add('autopadding', False, [False, True])
configuration.add('autopadding', False, [False, True, np.float32, np.float64])

# Select target device
configuration.add('deviceid', -1, preprocessor=int, impacts_jit=False)
Expand Down
32 changes: 19 additions & 13 deletions tests/test_linearize.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import scipy.sparse

from devito import (Grid, Function, TimeFunction, SparseTimeFunction, Operator, Eq,
Inc, MatrixSparseTimeFunction, sin)
Inc, MatrixSparseTimeFunction, sin, switchconfig)
from devito.ir import Call, Callable, DummyExpr, Expression, FindNodes, SymbolRegistry
from devito.passes import Graph, linearize, generate_macros
from devito.types import Array, Bundle, DefaultDimension
Expand Down Expand Up @@ -594,21 +594,27 @@ def test_inc_w_default_dims():
assert np.all(g.data[4:] == 0)


def test_different_dtype():
space_order = 4
@pytest.mark.parametrize('autopadding', [False, True, np.float64])
def test_different_dtype(autopadding):

grid = Grid(shape=(4, 4))
@switchconfig(autopadding=autopadding)
def _test_different_dtype():
space_order = 4

f = Function(name='f', grid=grid, space_order=space_order)
b = Function(name='b', grid=grid, space_order=space_order, dtype=np.float64)
grid = Grid(shape=(4, 4))

f.data[:] = 2.1
b.data[:] = 1.3
f = Function(name='f', grid=grid, space_order=space_order)
b = Function(name='b', grid=grid, space_order=space_order, dtype=np.float64)

eq = Eq(f, b.dx + f.dy)
f.data[:] = 2.1
b.data[:] = 1.3

op1 = Operator(eq, opt=('advanced', {'linearize': True}))
eq = Eq(f, b.dx + f.dy)

op1 = Operator(eq, opt=('advanced', {'linearize': True}))

# Check generated code has different strides for different dtypes
assert "bL0(x,y) b[(x)*y_stride0 + (y)]" in str(op1)
assert "L0(x,y) f[(x)*y_stride0 + (y)]" in str(op1)

# Check generated code has different strides for different dtypes
assert "bL0(x,y) b[(x)*y_stride0 + (y)]" in str(op1)
assert "L0(x,y) f[(x)*y_stride0 + (y)]" in str(op1)
_test_different_dtype()

0 comments on commit 0851d5c

Please sign in to comment.