Skip to content

Commit 29732b8

Browse files
committed
BF: work around sympy handling of longcomplex
Sympy does not handle np.longcomplex correctly at the moment, and this started raising an error with Sympy 1.1, released recently. It was discarding the imaginary part before, so no real loss. See: sympy/sympy#12901 for a proposal for proper handling of np.longcomplex. In the mean time, don't use it for testing.
1 parent f4a40b6 commit 29732b8

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

nipy/core/reference/coordinate_map.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ def inverse(self, preserve_dtype=False):
641641
return None
642642
except TypeError:
643643
# Try using sympy for the inverse. This might be needed for sympy
644-
# symbols in the affine, or Float128
644+
# symbols in the affine, or Float128, or complex numbers.
645645
from sympy import Matrix, matrix2numpy
646646
sym_inv = Matrix(self.affine).inv()
647647
m_inv = matrix2numpy(sym_inv).astype(aff_dt)

nipy/core/reference/tests/test_coordinate_map.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,9 @@ def test_dtype_cmap_inverses():
941941
# CoordinateMap versions of AffineTransforms
942942
dtypes = (np.sctypes['int'] + np.sctypes['uint'] + np.sctypes['float']
943943
+ np.sctypes['complex'] + [np.object])
944+
# Sympy <= 1.1 does not handle numpy longcomplex correctly. See:
945+
# https://github.com/sympy/sympy/pull/12901
946+
dtypes.remove(np.longcomplex)
944947
arr_p1 = np.eye(4)[:, [0, 2, 1, 3]]
945948
in_list = [0, 1, 2]
946949
out_list = [0, 2, 1]
@@ -956,7 +959,10 @@ def test_dtype_cmap_inverses():
956959
else:
957960
exp_i_dt = dt
958961
# Default inverse cmap may alter coordinate types
959-
r_cmap = cmap.inverse()
962+
try:
963+
r_cmap = cmap.inverse()
964+
except:
965+
1/0
960966
res = r_cmap(out_coord)
961967
assert_array_equal(res, coord)
962968
assert_equal(res.dtype, exp_i_dt)

0 commit comments

Comments
 (0)