Skip to content

Commit

Permalink
Merge pull request #464 from jakirkham/numpy114_fixes
Browse files Browse the repository at this point in the history
Fixes for NumPy 1.14
  • Loading branch information
jakirkham authored Jan 11, 2018
2 parents 1f824de + 2b980b5 commit bab75d0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
20 changes: 15 additions & 5 deletions nanshe/imp/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@
from nanshe.util import prof


# Use NumPy printing style from 1.13 for doctests.
# There is no `legacy` keyword until 1.14 though.
# So catch any errors that arise and suppress them.
try:
numpy.set_printoptions(legacy="1.13")
except TypeError:
pass

# Get the loggers
trace_logger = prof.getTraceLogger(__name__)
logger = prof.logging.getLogger(__name__)
Expand Down Expand Up @@ -502,15 +510,15 @@ def translate_fourier(frame_fft, shift):
[ 4., 5., 6., 7.],
[ 8., 9., 10., 11.]])
>>> af = fft.fftn(a, axes=tuple(iters.irange(a.ndim)))
>>> numpy.around(af, decimals=10)
>>> numpy.around(af, decimals=10) # doctest: +SKIP
array([[ 66. +0.j , -6. +6.j , -6. +0.j , -6. -6.j ],
[-24.+13.85640646j, 0. +0.j , 0. +0.j , 0. +0.j ],
[-24.-13.85640646j, 0. +0.j , 0. +0.j , 0. +0.j ]])
>>> s = numpy. array([1, -1])
>>> atf = translate_fourier(af, s)
>>> numpy.around(atf, decimals=10)
>>> numpy.around(atf, decimals=10) # doctest: +SKIP
array([[ 66. +0.j , -6. -6.j , 6. -0.j , -6. +6.j ],
[ 24.+13.85640646j, 0. +0.j , 0. +0.j , -0. +0.j ],
[ 24.-13.85640646j, 0. -0.j , 0. +0.j , 0. +0.j ]])
Expand All @@ -524,7 +532,7 @@ def translate_fourier(frame_fft, shift):
>>> a = a[None]; af = af[None]; s = s[None]
>>> atf = translate_fourier(af, s)
>>> numpy.around(atf, decimals=10)
>>> numpy.around(atf, decimals=10) # doctest: +SKIP
array([[[ 66. +0.j , -6. -6.j , 6. -0.j , -6. +6.j ],
[ 24.+13.85640646j, 0. +0.j , 0. +0.j , -0. +0.j ],
[ 24.-13.85640646j, 0. -0.j , 0. +0.j , 0. +0.j ]]])
Expand Down Expand Up @@ -635,7 +643,8 @@ def find_offsets(frames2reg_fft, template_fft):
[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.]]])
>>> af = numpy.fft.fftn(a, axes=range(1, a.ndim)); af
>>> af = numpy.fft.fftn(a, axes=range(1, a.ndim))
>>> af # doctest: +SKIP
array([[[ 4.+0.j , 0.+0.j , 0.+0.j , 0.+0.j ],
[ 4.+0.j , 0.+0.j , 0.+0.j , 0.+0.j ],
[ 4.+0.j , 0.+0.j , 0.+0.j , 0.+0.j ]],
Expand All @@ -656,7 +665,8 @@ def find_offsets(frames2reg_fft, template_fft):
[ 4.+0.j , 0.+0.j , 0.+0.j , 0.+0.j ],
[ 4.+0.j , 0.+0.j , 0.+0.j , 0.+0.j ]]])
>>> tf = numpy.fft.fftn(a.mean(axis=0)); tf
>>> tf = numpy.fft.fftn(a.mean(axis=0))
>>> tf # doctest: +SKIP
array([[ 4.0+0.j , 0.0+0.j , 0.0+0.j , 0.0+0.j ],
[ 2.8+0.69282032j, 0.0+0.j , 0.0+0.j , 0.0+0.j ],
[ 2.8-0.69282032j, 0.0+0.j , 0.0+0.j , 0.0+0.j ]])
Expand Down
2 changes: 1 addition & 1 deletion nanshe/imp/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def remove_zeroed_lines(new_data,
zero_mask_i_labeled_j, dilation_structure
)

zero_mask_i_labeled_j_outline = zero_mask_i_labeled_j_dilated - zero_mask_i_labeled_j
zero_mask_i_labeled_j_outline = zero_mask_i_labeled_j_dilated ^ zero_mask_i_labeled_j

zero_masks_dilated[i][zero_mask_i_labeled_j_dilated] = True
zero_masks_outline[i][zero_mask_i_labeled_j_outline] = True
Expand Down
24 changes: 16 additions & 8 deletions nanshe/util/xnumpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@
from nanshe.util import prof


# Use NumPy printing style from 1.13 for doctests.
# There is no `legacy` keyword until 1.14 though.
# So catch any errors that arise and suppress them.
try:
numpy.set_printoptions(legacy="1.13")
except TypeError:
pass

# Get the logger
trace_logger = prof.getTraceLogger(__name__)

Expand Down Expand Up @@ -1227,13 +1235,13 @@ def min_abs(new_array, axis=None, keepdims=False, return_indices=False):
>>> min_abs(
... numpy.array([[1+0j, 0+1j, 2+1j], [0+0j, 1+1j, 1+3j]]),
... axis=0
... )
... ) # doctest: +SKIP
array([ 0.+0.j, 0.+1.j, 2.+1.j])
>>> min_abs(
... numpy.array([[1+0j, 0+1j, 2+1j], [0+0j, 1+1j, 1+3j]]),
... axis=1
... )
... ) # doctest: +SKIP
array([ 1.+0.j, 0.+0.j])
>>> min_abs(numpy.arange(24).reshape(2,3,4), axis=(1,2))
Expand Down Expand Up @@ -1359,13 +1367,13 @@ def nanmin_abs(new_array, axis=None, keepdims=False, return_indices=False):
>>> nanmin_abs(
... numpy.array([[1+0j, 0+1j, 2+1j], [0+0j, 1+1j, 1+3j]]),
... axis=0
... )
... ) # doctest: +SKIP
array([ 0.+0.j, 0.+1.j, 2.+1.j])
>>> nanmin_abs(
... numpy.array([[1+0j, 0+1j, 2+1j], [0+0j, 1+1j, 1+3j]]),
... axis=1
... )
... ) # doctest: +SKIP
array([ 1.+0.j, 0.+0.j])
>>> nanmin_abs(numpy.arange(24).reshape(2,3,4), axis=(1,2))
Expand Down Expand Up @@ -1493,13 +1501,13 @@ def max_abs(new_array, axis=None, keepdims=False, return_indices=False):
>>> max_abs(
... numpy.array([[1+0j, 0+1j, 2+1j], [0+0j, 1+1j, 1+3j]]),
... axis=0
... )
... ) # doctest: +SKIP
array([ 1.+0.j, 1.+1.j, 1.+3.j])
>>> max_abs(
... numpy.array([[1+0j, 0+1j, 2+1j], [0+0j, 1+1j, 1+3j]]),
... axis=1
... )
... ) # doctest: +SKIP
array([ 2.+1.j, 1.+3.j])
>>> max_abs(numpy.arange(24).reshape(2,3,4), axis=(1,2))
Expand Down Expand Up @@ -1626,13 +1634,13 @@ def nanmax_abs(new_array, axis=None, keepdims=False, return_indices=False):
>>> nanmax_abs(
... numpy.array([[1+0j, 0+1j, 2+1j], [0+0j, 1+1j, 1+3j]]),
... axis=0,
... )
... ) # doctest: +SKIP
array([ 1.+0.j, 1.+1.j, 1.+3.j])
>>> nanmax_abs(
... numpy.array([[1+0j, 0+1j, 2+1j], [0+0j, 1+1j, 1+3j]]),
... axis=1,
... )
... ) # doctest: +SKIP
array([ 2.+1.j, 1.+3.j])
>>> nanmax_abs(numpy.arange(24).reshape(2,3,4), axis=(1,2))
Expand Down

0 comments on commit bab75d0

Please sign in to comment.