Skip to content

Commit a4d4bd4

Browse files
authored
Merge pull request #2591 from devitocodes/sympy-retro-imag
api: Add retrocompat to is_imaginary for older sympy
2 parents d6980b7 + 73afd4c commit a4d4bd4

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

devito/types/basic.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,12 @@ def _eval_is_real(self):
429429
return not self.is_imaginary
430430

431431
def _eval_is_imaginary(self):
432-
return np.iscomplexobj(self.dtype(0))
432+
try:
433+
return np.iscomplexobj(self.dtype(0))
434+
except TypeError:
435+
# Non-callabale dtype, likely non-numpy
436+
# Assuming it's not complex
437+
return False
433438

434439
@property
435440
def indices(self):

tests/test_symbolics.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
INT, FieldFromComposite, IntDiv, Namespace, Rvalue,
1616
ReservedWord, ListInitializer, uxreplace, pow_to_mul,
1717
retrieve_derivatives, BaseCast, SizeOf)
18-
from devito.tools import as_tuple
18+
from devito.tools import as_tuple, CustomDtype
1919
from devito.types import (Array, Bundle, FIndexed, LocalObject, Object,
2020
ComponentAccess, StencilDimension, Symbol as dSymbol)
2121
from devito.types.basic import AbstractSymbol
@@ -912,3 +912,15 @@ def test_print_div():
912912
b = SizeOf(np.int64)
913913
cstr = ccode(a / b)
914914
assert cstr == 'sizeof(int)/sizeof(long)'
915+
916+
917+
def test_customdtype_complex():
918+
"""
919+
Test that `CustomDtype` doesn't brak is_imag
920+
"""
921+
grid = Grid(shape=(4, 4))
922+
923+
f = Function(name='f', grid=grid, dtype=CustomDtype('notnumpy'))
924+
925+
assert not f.is_imaginary
926+
assert f.is_real

0 commit comments

Comments
 (0)