Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ENH: Addsort_compare dtype slot to register new-style sorts#30415

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
MaanasArora wants to merge3 commits intonumpy:main
base:main
Choose a base branch
Loading
fromMaanasArora:enh/sort-compare

Conversation

@MaanasArora
Copy link
Contributor

@MaanasAroraMaanasArora commentedDec 11, 2025
edited
Loading

Follows#29737 and#30328 (and supersedes#29987) to implement asort_compare slot that can be used to register sorting methods using a comparison function. This functionality also existed in the ArrFuncs slots, but now we implement the new-style sorting methods, and the array method context is passed to the comparison function rather than the array itself.

I've tested this withmpfdtype on the user dtypes repo (though having a bit of an issue with installation... the slot wasn't visible there, so had to redefine just the macro). Unfortunately there don't seem to be dtypes we can write tests for within numpy itself, though I did a small experiment with the scaled float dtype. ping@seberg@mhvk@ngoldbaum if you're interested - thanks!

Copy link
Member

@ngoldbaumngoldbaum left a comment
edited
Loading

Choose a reason for hiding this comment

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

@mhvk and@charris I think had strong opinions about prior versions of this. I'd appreciate it if they could weigh in on the approach.

Overall I think this is a nice cleanup and since StringDType wanted it, I wouldn't be surprised if future DTypes do as well.

If defined, implements a comparison function for two array elements
for use in sorting and argsorting. This can be defined in place of the
custom sort functions using the ArrayMethod API (see:ref:`array-methods-sorting`)
to implement sorting for the DType.
Copy link
Member

Choose a reason for hiding this comment

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

maybe add a mention for why you'd want to do this - e.g. if comparisons have some big cost that can be amortized over the whole array

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I've added a note - a bit on the detailed side, hopefully that works, thanks!

@MaanasArora
Copy link
ContributorAuthor

Thanks for looking@ngoldbaum!

Overall I think this is a nice cleanup and since StringDType wanted it, I wouldn't be surprised if future DTypes do as well.

Agreed, the full loop implementation would probably be overkill in many cases. I think this would be necessary to expose the sorts on the user-dtypes too since they don't define full sorts now, so a good way to test the new infrastructure!

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

Reviewers

@ngoldbaumngoldbaumngoldbaum left review comments

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@MaanasArora@ngoldbaum

[8]ページ先頭

©2009-2025 Movatter.jp