devito icon indicating copy to clipboard operation
devito copied to clipboard

DSE uses wrong np.dtype for some temporaries

Open FabioLuporini opened this issue 4 years ago • 0 comments

Reproducer below

import numpy as np
from devito import Grid, Function, Eq, Operator, generic_derivative


a = np.arange(64).reshape((8, 8))
grid = Grid(shape=a.shape, extent=(8, 8))

so = 3
dims = grid.dimensions
f = Function(name='f', grid=grid, space_order=so, dtype=np.int32)
f.data[:] = a

fo = Function(name='fo', grid=grid, space_order=so, dtype=np.int32)

expr = Eq(fo, f.dx)

op = Operator(expr)
op.apply()

basically the DSE generates int r0 = 1.0/h_x;, inferring int from the dtype of the searched expression. But then r0 will be 0, and so everything will be 0 at the end. We may wanna force the temporary dtype to float. Have to think about the potential side effects of doing that though

FabioLuporini avatar Sep 03 '19 14:09 FabioLuporini