[Metal] Support sorting complex numbers#3314
Open
Lyxot wants to merge 2 commits intoml-explore:mainfrom
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds Metal backend support for sorting complex64 values (including NaN-aware ordering) and updates Python tests to exercise complex sorting on Metal, as a follow-up to CUDA complex sorting support.
Changes:
- Instantiate Metal block and multi-block sort/partition/merge kernels for
complex64. - Add
complex64_tNaN initialization andisnan(complex64_t)support for comparisons in sort kernels. - Expand Python sort tests to include
complex64unconditionally (including NaN behavior).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| python/tests/test_ops.py | Enables complex64 coverage for sort and complex NaN sort expectations on Metal |
| mlx/backend/metal/kernels/sort.metal | Instantiates sort-related kernels for complex64 in the static Metal kernel set |
| mlx/backend/metal/kernels/sort.h | Adds complex64 init value (NaN) and enables NaN-aware comparator behavior for complex64 |
| mlx/backend/metal/kernels/complex.h | Adds isnan(complex64_t) helper used by sort comparator |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
075ee43 to
8944273
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes
Followup to #3286.
Add complex64 sort, argsort, partition, and argpartition support to the Metal backend