Skip to content

[CUDA] support sorting complex numbers#3286

Merged
zcbenz merged 2 commits intoml-explore:mainfrom
Lyxot:cuda-complex-sort
Mar 25, 2026
Merged

[CUDA] support sorting complex numbers#3286
zcbenz merged 2 commits intoml-explore:mainfrom
Lyxot:cuda-complex-sort

Conversation

@Lyxot
Copy link
Copy Markdown
Contributor

@Lyxot Lyxot commented Mar 20, 2026

Proposed changes

Add complex64 sort, argsort, partition, and argpartition support to the CUDA backend

Summary

Remove the complex64_t exclusion from the CUDA merge sort kernels. The current merge sort is comparison-based and already supports complex64. The guard was stale.

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works

Add complex64 sort, argsort, partition, and argpartition support to the CUDA backend
Copilot AI review requested due to automatic review settings March 20, 2026 08:48
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds CUDA backend support for sorting complex64 inputs by removing the previous complex64 exclusion in the CUDA merge-sort implementation and extending NaN-handling for complex types.

Changes:

  • Enable CUDA merge-sort kernels for complex64 by removing the complex64 guard in both single-block and multi-block paths.
  • Add NaN initialization and NaN-aware comparisons for complex64 within CUDA sort comparator logic.
  • Extend Python sort/argsort test coverage to include complex64 and add a complex NaN sort assertion.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
python/tests/test_ops.py Expands sort/argsort tests to include complex64 and adds a complex NaN sort check.
mlx/backend/cuda/sort.cu Removes the complex64 exclusion and adds complex-aware NaN init/comparison support so complex64 can be sorted on CUDA.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Lyxot
Copy link
Copy Markdown
Contributor Author

Lyxot commented Mar 20, 2026

sry I forgot to check Metal's complex support. I will fix it later.

@Lyxot
Copy link
Copy Markdown
Contributor Author

Lyxot commented Mar 20, 2026

fixed

Copy link
Copy Markdown
Collaborator

@zcbenz zcbenz left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks!

@zcbenz zcbenz merged commit f8eda2c into ml-explore:main Mar 25, 2026
16 checks passed
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.

3 participants