Skip to content

Commit 1d3af58

Browse files
committed
BF: adapt best_float type test to sparc fix
Previous commit stopped sparc64 using longdouble for calculations; this commit fixes the tests to take this into account
1 parent c2531c3 commit 1d3af58

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

nibabel/tests/test_casting.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
""" Test casting utilities
22
"""
3+
from platform import machine
34

45
import numpy as np
56

@@ -201,7 +202,8 @@ def test_best_float():
201202
assert_equal(end_of_ints, end_of_ints + 1)
202203
# longdouble may have more, but not on 32 bit windows, at least
203204
end_of_ints = np.longdouble(2**53)
204-
if end_of_ints == (end_of_ints + 1): # off continuous integers
205+
if (end_of_ints == (end_of_ints + 1) or # off continuous integers
206+
machine() == 'sparc64'): # crippling slow longdouble on sparc
205207
assert_equal(best, np.float64)
206208
else:
207209
assert_equal(best, np.longdouble)

nibabel/tests/test_utils.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
shape_zoom_affine,
3333
rec2dict)
3434

35-
from ..casting import FloatingError, floor_log2, type_info, best_float
35+
from ..casting import (floor_log2, type_info, best_float, OK_FLOATS)
3636

3737
from numpy.testing import (assert_array_almost_equal,
3838
assert_array_equal)
@@ -426,17 +426,6 @@ def check_against(f1, f2):
426426
assert_equal(better_float_of('i4', 'i8', 'f8'), np.float64)
427427

428428

429-
def have_longer_double():
430-
# True if longdouble has more precision than float64, and longdouble is
431-
# something we can rely on
432-
nmant_64 = type_info(np.float64)['nmant'] # should be 52
433-
try:
434-
nmant_ld = type_info(np.longdouble)['nmant']
435-
except FloatingError:
436-
return False
437-
return nmant_ld > nmant_64
438-
439-
440429
def test_best_write_scale_ftype():
441430
# Test best write scaling type
442431
# Types return better of (default, array type) unless scale overflows.
@@ -453,7 +442,7 @@ def test_best_write_scale_ftype():
453442
better_float_of(dtt, np.float32))
454443
# Overflowing ints with scaling results in upcast
455444
best_vals = ((np.float32, np.float64),)
456-
if have_longer_double():
445+
if np.longdouble in OK_FLOATS:
457446
best_vals += ((np.float64, np.longdouble),)
458447
for lower_t, higher_t in best_vals:
459448
# Information on this float

0 commit comments

Comments
 (0)