Commits

Brian Kearns committed 5b62fe3

fix segfault on argsort of empty array

  • Participants
  • Parent commits 0146c76

Comments (0)

Files changed (2)

File pypy/module/micronumpy/arrayimpl/sort.py

         if w_axis is space.w_None:
             # note that it's fine ot pass None here as we're not going
             # to pass the result around (None is the link to base in slices)
-            arr = arr.reshape(space, None, [arr.get_size()])
+            if arr.get_size() > 0:
+                arr = arr.reshape(space, None, [arr.get_size()])
             axis = 0
         elif w_axis is None:
             axis = -1

File pypy/module/micronumpy/test/test_sorting.py

 
     def test_argsort_axis(self):
         from numpypy import array
+        a = array([])
+        for axis in [None, -1, 0]:
+            assert a.argsort(axis=axis).shape == (0,)
         a = array([[4, 2], [1, 3]])
         assert (a.argsort(axis=None) == [2, 1, 3, 0]).all()
         assert (a.argsort(axis=-1) == [[1, 0], [0, 1]]).all()