Skip to content

Commit

Permalink
Merge pull request numpy#3767 from juliantaylor/mom5-improve
Browse files Browse the repository at this point in the history
Mom5 selection improvements
  • Loading branch information
charris committed Sep 22, 2013
2 parents fffeee6 + eb8991e commit 0b96b2d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
8 changes: 2 additions & 6 deletions numpy/core/src/npysort/selection.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,8 @@ static npy_intp @name@median5_@suff@(
}
}
else {
if (@TYPE@_LT(v[IDX(2)], v[IDX(1)])) {
return 1;
}
else {
return 2;
}
/* v[1] and v[2] swapped into order above */
return 2;
}
}

Expand Down
11 changes: 11 additions & 0 deletions numpy/core/tests/test_multiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,17 @@ def test_partition(self):
assert_array_equal(d[np.argpartition(d, -6, kind=k)],
np.partition(d, 41, kind=k))

# median of 3 killer, O(n^2) on pure median 3 pivot quickselect
# exercises the median of median of 5 code used to keep O(n)
d = np.arange(1000000)
x = np.roll(d, d.size // 2)
mid = x.size // 2 + 1
assert_equal(np.partition(x, mid)[mid], mid)
d = np.arange(1000001)
x = np.roll(d, d.size // 2 + 1)
mid = x.size // 2 + 1
assert_equal(np.partition(x, mid)[mid], mid)

# equal elements
d = np.arange((47)) % 7
tgt = np.sort(np.arange((47)) % 7)
Expand Down

0 comments on commit 0b96b2d

Please sign in to comment.