8000 Merge pull request #16601 from charris/test_ignore_nan_ulperror · numpy/numpy@a0350ed · GitHub
[go: up one dir, main page]

Skip to content

Commit a0350ed

Browse files
authored
Merge pull request #16601 from charris/test_ignore_nan_ulperror
MAINT: Move and improve ``test_ignore_nan_ulperror``.
2 parents cb98ad4 + dcf74f6 commit a0350ed

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

numpy/core/tests/test_umath_accuracy.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,3 @@ def test_validate_transcendentals(self):
5757
outval = outval[perm]
5858
maxulperr = data_subset['ulperr'].max()
5959
assert_array_max_ulp(npfunc(inval), outval, maxulperr)
60-
61-
def test_ignore_nan_ulperror(self):
62-
# Ignore ULP differences between various NAN's
63-
nan1_f32 = np.array(str_to_float('0xffffffff'), dtype=np.float32)
64-
nan2_f32 = np.array(str_to_float('0x7fddbfbf'), dtype=np.float32)
65-
assert_array_max_ulp(nan1_f32, nan2_f32, 0)

numpy/testing/tests/test_utils.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,17 @@ def test_float64_fail(self):
941941
assert_raises(AssertionError, assert_array_almost_equal_nulp,
942942
x, y, nulp)
943943

944+
def test_float64_ignore_nan(self):
945+
# Ignore ULP differences between various NAN's
946+
# Note that MIPS may reverse quiet and signaling nans
947+
# so we use the builtin version as a base.
948+
offset = np.uint64(0xffffffff)
949+
nan1_i64 = np.array(np.nan, dtype=np.float64).view(np.uint64)
950+
nan2_i64 = nan1_i64 ^ offset # nan payload on MIPS is all ones.
951+
nan1_f64 = nan1_i64.view(np.float64)
952+
nan2_f64 = nan2_i64.view(np.float64)
953+
assert_array_max_ulp(nan1_f64, nan2_f64, 0)
954+
944955
def test_float32_pass(self):
945956
nulp = 5
946957
x = np.linspace(-20, 20, 50, dtype=np.float32)
@@ -971,6 +982,17 @@ def test_float32_fail(self):
971982
assert_raises(AssertionError, assert_array_almost_equal_nulp,
972983
x, y, nulp)
973984

985+
def test_float32_ignore_nan(self):
986+
# Ignore ULP differences between various NAN's
987+
# Note that MIPS may reverse quiet and signaling nans
988+
# so we use the builtin version as a base.
989+
offset = np.uint32(0xffff)
990+
nan1_i32 = np.array(np.nan, dtype=np.float32).view(np.uint32)
991+
nan2_i32 = nan1_i32 ^ offset # nan payload on MIPS is all ones.
992+
nan1_f32 = nan1_i32.view(np.float32)
993+
nan2_f32 = nan2_i32.view(np.float32)
994+
assert_array_max_ulp(nan1_f32, nan2_f32, 0)
995+
974996
def test_float16_pass(self):
975997
nulp = 5
976998
x = np.linspace(-4, 4, 10, dtype=np.float16)
@@ -1001,6 +1023,17 @@ def test_float16_fail(self):
10011023
assert_raises(AssertionError, assert_array_almost_equal_nulp,
10021024
x, y, nulp)
10031025

1026+
def test_float16_ignore_nan(self):
1027+
# Ignore ULP differences between various NAN's
1028+
# Note that MIPS may reverse quiet and signaling nans
1029+
# so we use the builtin version as a base.
1030+
offset = np.uint16(0xff)
1031+
nan1_i16 = np.array(np.nan, dtype=np.float16).view(np.uint16)
1032+
nan2_i16 = nan1_i16 ^ offset # nan payload on MIPS is all ones.
1033+
nan1_f16 = nan1_i16.view(np.float16)
1034+
nan2_f16 = nan2_i16.view(np.float16)
1035+
assert_array_max_ulp(nan1_f16, nan2_f16, 0)
1036+
10041037
def test_complex128_pass(self):
10051038
nulp = 5
10061039
x = np.linspace(-20, 20, 50, dtype=np.float64)

0 commit comments

Comments
 (0)
0