8000 TST: Fix test_numeric on riscv64 · numpy/numpy@f4e606a · GitHub
[go: up one dir, main page]

Skip to content

Commit f4e606a

Browse files
markdryancharris
authored andcommitted
TST: Fix test_numeric on riscv64
Modify test_numeric so that it passes on riscv64. The subtest TestBoolCmp::test_float currently fails on riscv64 as it assumes that the sign of -np.nan is retained when stored to and read back from an array. This is not always the case on riscv64. Many RISC-V instructions that produce NaNs return a canonical NaN, as defined by the RISC-V specification. The canonical NaNs are always positive. In this particular test the negative sign of the -np.nan is lost when it is converted from a double to a float before being stored in self.signf. We disable the float32 sign tests for -np.nan on riscv64 allowing test_numeric to pass.
1 parent aeb63c8 commit f4e606a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

numpy/core/tests/test_numeric.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,14 @@ def setup_method(self):
477477
self.signd[self.ed] *= -1.
478478
self.signf[1::6][self.ef[1::6]] = -np.inf
479479
self.signd[1::6][self.ed[1::6]] = -np.inf
480-
self.signf[3::6][self.ef[3::6]] = -np.nan
480+
# On RISC-V, many operations that produce NaNs, such as converting
481+
# a -NaN from f64 to f32, return a canonical NaN. The canonical
482+
# NaNs are always positive. See section 11.3 NaN Generation and
483+
# Propagation of the RISC-V Unprivileged ISA for more details.
484+
# We disable the float32 sign test on riscv64 for -np.nan as the sign
485+
# of the NaN will be lost when it's converted to a float32.
486+
if platform.processor() != 'riscv64':
487+
self.signf[3::6][self.ef[3::6]] = -np.nan
481488
self.signd[3::6][self.ed[3::6]] = -np.nan
482489
self.signf[4::6][self.ef[4::6]] = -0.
483490
self.signd[4::6][self.ed[4::6]] = -0.

0 commit comments

Comments
 (0)
0