8000 ENH: avoid meshgrid and fancy indexing for 1d masked sort, for 1.9 by juliantaylor · Pull Request #4874 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: avoid meshgrid and fancy indexing for 1d masked sort, for 1.9 #4874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions numpy/ma/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5082,10 +5082,16 @@ def sort(self, axis= -1, kind='quicksort', order=None,
filler = maximum_fill_value(self)
else:
filler = fill_value
idx = np.meshgrid(*[np.arange(x) for x in self.shape], sparse=True,
indexing='ij')
idx[axis] = self.filled(filler).argsort(axis=axis, kind=kind,
order=order)

sidx = self.filled(filler).argsort(axis=axis, kind=kind,
order=order)
# save meshgrid memory for 1d arrays
if self.ndim == 1:
idx = sidx
else:
idx = np.meshgrid(*[np.arange(x) for x in self.shape], sparse=True,
indexing='ij')
idx[axis] = sidx
tmp_mask = self._mask[idx].flat
tmp_data = self._data[idx].flat
self._data.flat = tmp_data
Expand Down Expand Up @@ -6187,10 +6193,16 @@ def sort(a, axis= -1, kind='quicksort', order=None, endwith=True, fill_value=Non
filler = maximum_fill_value(a)
else:
filler = fill_value
# return
indx = np.meshgrid(*[np.arange(x) for x in a.shape], sparse=True,
indexing='ij')
indx[axis] = filled(a, filler).argsort(axis=axis, kind=kind, order=order)

sindx = filled(a, filler).argsort(axis=axis, kind=kind, order=order)

# save meshgrid memory for 1d arrays
if a.ndim == 1:
indx = sindx
else:
indx = np.meshgrid(*[np.arange(x) for x in a.shape], sparse=True,
indexing='ij')
indx[axis] = sindx
return a[indx]
sort.__doc__ = MaskedArray.sort.__doc__

Expand Down
0