From 5ad928320d6bfc2897e4b964bb78e2d06bdd99d3 Mon Sep 17 00:00:00 2001 From: mloubout Date: Wed, 23 Apr 2025 11:04:43 -0400 Subject: [PATCH 1/2] api: add retrocompat to is_imaginary for older sympy --- devito/types/basic.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/devito/types/basic.py b/devito/types/basic.py index 45446f6486..a6afb007d3 100644 --- a/devito/types/basic.py +++ b/devito/types/basic.py @@ -429,7 +429,12 @@ def _eval_is_real(self): return not self.is_imaginary def _eval_is_imaginary(self): - return np.iscomplexobj(self.dtype(0)) + try: + return np.iscomplexobj(self.dtype(0)) + except TypeError: + # Non-callabale dtype, likely non-numpy + # Assuming it's not complex + return False @property def indices(self): From 73afd4cdafe396e00436b47dab5aa8f11f475582 Mon Sep 17 00:00:00 2001 From: mloubout Date: Wed, 23 Apr 2025 11:09:38 -0400 Subject: [PATCH 2/2] tests: add test for breaking is_real --- tests/test_symbolics.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/test_symbolics.py b/tests/test_symbolics.py index 7408f917f3..e7cb5b04cc 100644 --- a/tests/test_symbolics.py +++ b/tests/test_symbolics.py @@ -15,7 +15,7 @@ INT, FieldFromComposite, IntDiv, Namespace, Rvalue, ReservedWord, ListInitializer, uxreplace, pow_to_mul, retrieve_derivatives, BaseCast, SizeOf) -from devito.tools import as_tuple +from devito.tools import as_tuple, CustomDtype from devito.types import (Array, Bundle, FIndexed, LocalObject, Object, ComponentAccess, StencilDimension, Symbol as dSymbol) from devito.types.basic import AbstractSymbol @@ -912,3 +912,15 @@ def test_print_div(): b = SizeOf(np.int64) cstr = ccode(a / b) assert cstr == 'sizeof(int)/sizeof(long)' + + +def test_customdtype_complex(): + """ + Test that `CustomDtype` doesn't brak is_imag + """ + grid = Grid(shape=(4, 4)) + + f = Function(name='f', grid=grid, dtype=CustomDtype('notnumpy')) + + assert not f.is_imaginary + assert f.is_real