Skip to content

[Breaking Change] Implement argsort and make sort numpy API compliant - #2386

Merged
brownbaerchen merged 37 commits into
mainfrom
777-Implement_argsort
Aug 4, 2026
Merged

[Breaking Change] Implement argsort and make sort numpy API compliant#2386
brownbaerchen merged 37 commits into
mainfrom
777-Implement_argsort

Conversation

@Berkant03

Copy link
Copy Markdown
Collaborator

Due Diligence

  • General:
  • Implementation:
    • unit tests: all split configurations tested
    • unit tests: multiple dtypes tested
    • NEW unit tests: MPS tested (1 MPI process, 1 GPU)
    • benchmarks: created for new functionality
    • benchmarks: performance improved or maintained
    • documentation updated where needed

Description

argsort and sort have been changed to reflect the Numpy API, while also allowing old usage.

Issue/s resolved: #777

Type of change

  • New feature

Does this change modify the behaviour of other functions? If so, which?

yes, sort now does not give back the indices when sorting like pytorch. Instead a flag must be given to achieve same behaviour.

Comment thread tests/core/test_manipulations.py Outdated

@brownbaerchen brownbaerchen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks! I think it's a good idea to be closer to Numpy and to support argsort. However, I don't think we should silently ignore additional arguments that Numpy users are used to.

Note that the errors in the collection step in pytest happen all over the place, including in other repositories, and have nothing to do with this PR.

Comment thread heat/core/manipulations.py Outdated
Comment thread heat/core/manipulations.py Outdated
Comment thread heat/core/manipulations.py Outdated
Comment thread heat/core/manipulations.py Outdated
@github-project-automation github-project-automation Bot moved this from Todo to In Progress in Roadmap Jul 16, 2026
@brownbaerchen

Copy link
Copy Markdown
Collaborator

Excellent! If you apply something similar to argsort, this should be ready to merge.

@brownbaerchen brownbaerchen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks! I think we can clean up the tests a bit more. Otherwise, this is ready in my opinion.

Comment thread tests/core/test_manipulations.py Outdated
Comment thread tests/core/test_manipulations.py
@brownbaerchen brownbaerchen added this to the 2.0 milestone Jul 27, 2026
@brownbaerchen brownbaerchen changed the title Implement argsort and make sort numpy API compliant [Breaking Change] Implement argsort and make sort numpy API compliant Jul 27, 2026
@Berkant03

Copy link
Copy Markdown
Collaborator Author

The current tests fail, due to an API change in numpy 2.5, which added the descending keyword to argsort, but is absent in previous versions. How should we handle the cases with a lower numpy version? @brownbaerchen

@brownbaerchen

Copy link
Copy Markdown
Collaborator

The current tests fail, due to an API change in numpy 2.5, which added the descending keyword to argsort, but is absent in previous versions. How should we handle the cases with a lower numpy version? @brownbaerchen

That's annoying! I think the best we can do is to split the tests into ones with descending and without. Then you can skip tests using descending if np.lib.NumpyVersion(np.__version__) < '2.5.0'.
You can use a decorator:

class Tests(...):
    @unittest.skipif(np.lib.NumpyVersion(np.__version__) < '2.5.0', f'Numpy version {np.__version__} does not support `descending` keyword in `sort`)
    def test_sort(self):
        ...
    def test_sort_no_descending_argument(self):
        ...

Alternatively, you can use the unittest.subtest stuff within a single function and skip some subtests from there.
Neither is particularly clean.. Do use skipping infrastructure, though. This will tell you how many tests were skipped during the collection step and why and is not silent.

@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.74%. Comparing base (c26de1f) to head (e3072e3).
⚠️ Report is 6 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
heat/core/manipulations.py 45.45% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2386      +/-   ##
==========================================
- Coverage   91.81%   91.74%   -0.08%     
==========================================
  Files          87       87              
  Lines       14149    14168      +19     
==========================================
+ Hits        12991    12998       +7     
- Misses       1158     1170      +12     
Flag Coverage Δ
unit 91.74% <50.00%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@brownbaerchen brownbaerchen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sorry, I have a few more small points, but should be quick to address 🙈

Comment thread tests/core/test_sorting.py Outdated
Comment thread tests/core/test_sorting.py Outdated
Comment thread tests/core/test_sorting.py Outdated
Comment thread tests/core/test_sorting.py Outdated
Comment thread tests/core/test_sorting.py Outdated
Comment thread tests/core/test_sorting.py Outdated
Comment thread tests/core/test_sorting.py Outdated
Comment thread tests/core/test_sorting.py Outdated
Comment thread tests/core/test_sorting.py Outdated
Comment thread tests/core/test_sorting.py Outdated
Berkant03 and others added 3 commits August 3, 2026 12:44
brownbaerchen
brownbaerchen previously approved these changes Aug 3, 2026

@brownbaerchen brownbaerchen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Feel free to remove any unnecessary tests, or not. Otherwise, we can finally merge :D

@github-project-automation github-project-automation Bot moved this from In Progress to Merge queue in Roadmap Aug 3, 2026
@brownbaerchen

Copy link
Copy Markdown
Collaborator

The failures in previous pushes look unrelated to this.. No idea what's going on there... :(

@Berkant03

Copy link
Copy Markdown
Collaborator Author

@brownbaerchen, I removed the specific test. The codebase test fails due to not enough storage. If everything is fine, you can merge it.

@brownbaerchen

Copy link
Copy Markdown
Collaborator

@brownbaerchen, I removed the specific test. The codebase test fails due to not enough storage. If everything is fine, you can merge it.

Let's merge! @JuanPedroGHM, do you have some bandwidth for looking into why we are suddenly running out of disk space on codebase during installation?

@brownbaerchen
brownbaerchen merged commit 4dbf2a5 into main Aug 4, 2026
12 of 13 checks passed
@brownbaerchen
brownbaerchen deleted the 777-Implement_argsort branch August 4, 2026 11:07
@github-project-automation github-project-automation Bot moved this from Merge queue to Done in Roadmap Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Implement argsort

4 participants