8000 Merge pull request #4874 from juliantaylor/masked-sort-memory · numpy/numpy@b583637 · GitHub
[go: up one dir, main page]

Skip to content

Commit b583637

Browse files
committed
Merge pull request #4874 from juliantaylor/masked-sort-memory
ENH: avoid meshgrid and fancy indexing for 1d masked sort, for 1.9
2 parents 029662b + acc3369 commit b583637

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

numpy/ma/core.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5074,10 +5074,16 @@ def sort(self, axis= -1, kind='quicksort', order=None,
50745074
filler = maximum_fill_value(self)
50755075
else:
50765076
filler = fill_value
5077-
idx = np.meshgrid(*[np.arange(x) for x in self.shape], sparse=True,
5078-
indexing='ij')
5079-
idx[axis] = self.filled(filler).argsort(axis=axis, kind=kind,
5080-
order=order)
5077+
5078+
sidx = self.filled(filler).argsort(axis=axis, kind=kind,
5079+
order=order)
5080+
# save meshgrid memory for 1d arrays
5081+
if self.ndim == 1:
5082+
idx = sidx
5083+
else:
5084+
idx = np.meshgrid(*[np.arange(x) for x in self.shape], sparse=True,
5085+
indexing='ij')
5086+
idx[axis] = sidx
50815087
tmp_mask = self._mask[idx].flat
50825088
tmp_data = self._data[idx].flat
50835089
self._data.flat = tmp_data
@@ -6178,10 +6184,16 @@ def sort(a, axis= -1, kind='quicksort', order=None, endwith=True, fill_value=Non
61786184
filler = maximum_fill_value(a)
61796185
else:
61806186
filler = fill_value
6181-
# return
6182-
indx = np.meshgrid(*[np.arange(x) for x in a.shape], sparse=True,
6183-
indexing='ij')
6184-
indx[axis] = filled(a, filler).argsort(axis=axis, kind=kind, order=order)
6187+
6188+
sindx = filled(a, filler).argsort(axis=axis, kind=kind, order=order)
6189+
6190+
# save meshgrid memory for 1d arrays
6191+
if a.ndim == 1:
6192+
indx = sindx
6193+
else:
6194+
indx = np.meshgrid(*[np.arange(x) for x in a.shape], sparse=True,
6195+
indexing='ij')
6196+
indx[axis] = sindx
61856197
return a[indx]
61866198
sort.__doc__ = MaskedArray.sort.__doc__
61876199

0 commit comments

Comments
 (0)
0