Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion devito/symbolics/extended_sympy.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,9 @@ def _process_dtype(cls, dtype, stars):
return dtype, stars

def _hashable_content(self):
return super()._hashable_content() + (self._stars,)
return super()._hashable_content() + (
self._dtype, self._stars, self._reinterpret
)

func = Pickable._rebuild

Expand Down
26 changes: 26 additions & 0 deletions tests/test_symbolics.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,32 @@ def test_str_cast():
assert ccode(v) == '(foo**)s'


def test_cast_equality():
s = Symbol(name='s', dtype=np.float64)

c_flt = Cast(s, np.float32)
c_int = Cast(s, np.int32)
assert c_flt != c_int
assert c_flt - c_int != 0
assert len({c_flt, c_int}) == 2

c_re = Cast(s, np.int32, reinterpret=True)
assert c_int != c_re
assert INT(s) != INT(s, reinterpret=True)

assert Cast(s, 'foo*') == Cast(s, 'foo', stars='*')

grid = Grid(shape=(4,))
x = grid.dimensions[0]
u = Function(name='u', grid=grid, dtype=np.float64)
out = Function(name='out', grid=grid, dtype=np.float64)
u.data[:] = [1.25, 2.5, 3.75, 4.1]

op = Operator(Eq(out, Cast(u[x], np.float32) - Cast(u[x], np.int32)))
op.apply()
assert np.allclose(out.data, [0.25, 0.5, 0.75, 0.1])


def test_findexed():
grid = Grid(shape=(3, 3, 3))
x, y, z = grid.dimensions
Expand Down