Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6ac0051

Browse files
committed
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. It's best not to make any assumptions about the retention of signs for negative NaNs on RISC-V so we disable both sign tests for -np.nan on riscv64.
1 parent 0032ede commit 6ac0051

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

numpy/_core/tests/test_numeric.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -798,8 +798,15 @@ def setup_method(self):
798798
self.signd[self.ed] *= -1.
799799
self.signf[1::6][self.ef[1::6]] = -np.inf
800800
self.signd[1::6][self.ed[1::6]] = -np.inf
801-
self.signf[3::6][self.ef[3::6]] = -np.nan
802-
self.signd[3::6][self.ed[3::6]] = -np.nan
801+
# On RISC-V, many operations that produce NaNs, such as converting
802+
# a -NaN from f64 to f32, return a canonical NaN. The canonical
803+
# NaNs are always positive. See section 11.3 NaN Generation and
804+
# Propagation of the RISC-V Unprivileged ISA for more details.
805+
# We disable the sign test on riscv64 for -np.nan as we
806+
# cannot assume that its sign will be honoured in these tests.
807+
if platform.processor() != 'riscv64':
808+
self.signf[3::6][self.ef[3::6]] = -np.nan
809+
self.signd[3::6][self.ed[3::6]] = -np.nan
803810
self.signf[4::6][self.ef[4::6]] = -0.
804811
self.signd[4::6][self.ed[4::6]] = -0.
805812

0 commit comments

Comments
 (0)