diff --git a/devito/__init__.py b/devito/__init__.py index da9044ed4f..121aa657e1 100644 --- a/devito/__init__.py +++ b/devito/__init__.py @@ -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) diff --git a/tests/test_linearize.py b/tests/test_linearize.py index 7d1abad73c..a98de5c635 100644 --- a/tests/test_linearize.py +++ b/tests/test_linearize.py @@ -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 @@ -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()