Skip to content

Initial implementation for argpartial_sort#342

Open
matwey wants to merge 1 commit into
masterfrom
stable_sort
Open

Initial implementation for argpartial_sort#342
matwey wants to merge 1 commit into
masterfrom
stable_sort

Conversation

@matwey

@matwey matwey commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@matwey matwey force-pushed the stable_sort branch 4 times, most recently from 4cb937e to b2720c4 Compare June 17, 2026 09:29
@matwey matwey marked this pull request as ready for review June 17, 2026 09:29
@matwey matwey requested a review from hombit as a code owner June 17, 2026 09:29
@matwey

matwey commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

@hombit I need your help with this POC. The algorithm itself is very simple.

@codspeed-hq

codspeed-hq Bot commented Jun 17, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 47 untouched benchmarks
⏩ 4 skipped benchmarks1


Comparing stable_sort (b0c8bd5) with master (39106f9)

Open in CodSpeed

Footnotes

  1. 4 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@hombit hombit left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. It would be interesting to see performance vs np.argpartition, even for a single data point, e.g. len=100_000, k=100.

Comment thread rust/src/stable_sort.rs Outdated
Comment on lines +13 to +14
let mut heap = BinaryHeap::new();
heap.reserve(pos);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we need pos + 1 here because it is what we have before we pop. It also may be simplified with the specialized constructor.

Suggested change
let mut heap = BinaryHeap::new();
heap.reserve(pos);
let mut heap = BinaryHeap::with_capacity(pos+1);

Comment thread rust/src/stable_sort.rs
@matwey matwey force-pushed the stable_sort branch 3 times, most recently from a3e3ddb to 4fe18ee Compare June 25, 2026 13:37
@matwey matwey requested a review from hombit June 25, 2026 13:39
@matwey

matwey commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

I've implemented the benchmarks. For now it works ugly for large k values. I don't know why

Comment thread tests/test_stable_sort.py
assert_equal(expected, argpartial_sort(x, 5))


@pytest.mark.benchmark(min_rounds=10, disable_gc=True, warmup=False)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our CI doesn't support these arguments, please remove

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants