Skip to content

Commit

Permalink
Allow for floating point error in affine tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-brett committed Oct 3, 2024
1 parent ad09805 commit 4815127
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion nipy/core/reference/coordinate_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ def __init__(self, function_domain, function_range, affine):
# Test that it is actually an affine mapping in homogeneous
# form
bottom_row = np.array([0]*self.ndims[0] + [1])
if not np.all(affine[-1] == bottom_row):
if not np.allclose(affine[-1], bottom_row):
raise ValueError('the homogeneous transform should have bottom=' + \
f'row {repr(bottom_row)}')
self.affine = affine
Expand Down
20 changes: 9 additions & 11 deletions nipy/core/reference/tests/test_coordinate_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
CS = CoordinateSystem

import pytest
from numpy.testing import assert_almost_equal, assert_array_equal
from numpy.testing import (assert_almost_equal, assert_array_equal,
assert_array_almost_equal)

# Dtypes for testing coordinate map creation / processing
_SYMPY_SAFE_DTYPES = (SCTYPES['int'] + SCTYPES['uint'] +
Expand Down Expand Up @@ -972,30 +973,27 @@ def test_dtype_cmap_inverses():
else:
exp_i_dt = dt
# Default inverse cmap may alter coordinate types
try:
r_cmap = cmap.inverse()
except:
1/0
r_cmap = cmap.inverse()
res = r_cmap(out_coord)
assert_array_equal(res, coord)
assert_array_almost_equal(res, coord)
assert res.dtype == exp_i_dt
# Default behavior is preserve_type=False
r_cmap = cmap.inverse(preserve_dtype=False)
res = r_cmap(out_coord)
assert_array_equal(res, coord)
assert_array_almost_equal(res, coord)
assert res.dtype == exp_i_dt
# Preserve_dtype=True - preserves dtype
r_cmap = cmap.inverse(preserve_dtype=True)
res = r_cmap(out_coord)
assert_array_equal(res, coord)
assert_array_almost_equal(res, coord)
assert res.dtype == dt
# Preserve_dtype=True is default for conversion to CoordinateMap
cm_cmap = _as_coordinate_map(cmap)
assert_array_equal(cm_cmap(coord), out_list)
assert_array_almost_equal(cm_cmap(coord), out_list)
rcm_cmap = cm_cmap.inverse()
assert_array_equal(rcm_cmap(coord), out_list)
assert_array_almost_equal(rcm_cmap(coord), out_list)
res = rcm_cmap(out_coord)
assert_array_equal(res, coord)
assert_array_almost_equal(res, coord)
assert res.dtype == dt
# For integer types, where there is no integer inverse, return floatey
# inverse by default, and None for inverse when preserve_dtype=True
Expand Down

0 comments on commit 4815127

Please sign in to comment.