test sorting with NaNs
For lexsort, seems relevant?
@@ -146,6 +146,16 @@ class TestSort(unittest.TestCase):
with self.assertRaises(numpy.AxisError):
cupy.sort(a, axis=-4)
+ # Test NaN ordering
+
+ @testing.for_dtypes('efdFD')
+ @testing.numpy_cupy_allclose()
+ def test_nan(self, xp, dtype):
+ a = testing.shaped_random((10,), xp, dtype)
+ a[2] = a[6] = xp.nan
+ a.sort()
+ return a
+
@testing.gpu
class TestLexsort(unittest.TestCase):
@@ -184,6 +194,18 @@ class TestLexsort(unittest.TestCase):
a = testing.shaped_random((2, 10), xp, dtype)
return xp.lexsort(a)
+ # Test NaN ordering
+ # TODO(leofang): test two more cases after #3232 is fixed
+ # 1. a[1, 2] = a[1, 6] = xp.nan
+ # 2. a[0, 2] = a[1, 6] = xp.nan
+
+ @testing.for_dtypes('efdFD')
+ @testing.numpy_cupy_allclose()
+ def test_nan(self, xp, dtype):
+ a = testing.shaped_random((2, 10), xp, dtype)
+ a[0, 2] = a[0, 6] = xp.nan
+ return xp.lexsort(a)
+
@testing.parameterize(*testing.product({
'external': [False, True],
@@ -287,6 +309,15 @@ class TestArgsort(unittest.TestCase):
self.argsort(a)
testing.assert_allclose(a, b)
+ # Test NaN ordering
+
+ @testing.for_dtypes('efdFD')
+ @testing.numpy_cupy_allclose()
+ def test_nan(self, xp, dtype):
+ a = testing.shaped_random((10,), xp, dtype)
+ a[2] = a[6] = xp.nan
+ return xp.argsort(a)
+
@testing.gpu
class TestMsort(unittest.TestCase):
