From f4e606a379e1d14a8d1646f288291e1e3ddc9053 Mon Sep 17 00:00:00 2001 From: Mark Ryan Date: Tue, 19 Dec 2023 12:22:10 +0000 Subject: [PATCH] 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. --- numpy/core/tests/test_numeric.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py index d2d041f71ef2..e5edd3efce5a 100644 --- a/numpy/core/tests/test_numeric.py +++ b/numpy/core/tests/test_numeric.py @@ -477,7 +477,14 @@ def setup_method(self): self.signd[self.ed] *= -1. self.signf[1::6][self.ef[1::6]] = -np.inf self.signd[1::6][self.ed[1::6]] = -np.inf - self.signf[3::6][self.ef[3::6]] = -np.nan + # On RISC-V, many operations that produce NaNs, such as converting + # a -NaN from f64 to f32, return a canonical NaN. The canonical + # NaNs are always positive. See section 11.3 NaN Generation and + # Propagation of the RISC-V Unprivileged ISA for more details. + # We disable the float32 sign test on riscv64 for -np.nan as the sign + # of the NaN will be lost when it's converted to a float32. + if platform.processor() != 'riscv64': + self.signf[3::6][self.ef[3::6]] = -np.nan self.signd[3::6][self.ed[3::6]] = -np.nan self.signf[4::6][self.ef[4::6]] = -0. self.signd[4::6][self.ed[4::6]] = -0.