Skip to content

Implement argsort and make sort numpy API compliant#2386

Open
Berkant03 wants to merge 14 commits into
mainfrom
777-Implement_argsort
Open

Implement argsort and make sort numpy API compliant#2386
Berkant03 wants to merge 14 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

@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.

Returns the indices that would sort an array. This is the distributed equivalent of `np.argsort`.
The sorting is not stable which means that equal elements in the result may have a different ordering than in the
original array.
Sorting where `axis==a.split` needs a lot of communication between the processes of MPI.

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.

Suggested change
Sorting where `axis==a.split` needs a lot of communication between the processes of MPI.
Sorting with `axis==a.split` needs a lot of communication between the processes.

kind : str, optional
Sorting algorithm. Gets ignored.
order : str, list[str], optional
Used in numpy for array with fields, which are not possible in HeAT. Gets ignored.

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.

Suggested change
Used in numpy for array with fields, which are not possible in HeAT. Gets ignored.
Used in numpy for array with fields, which are not possible in Heat. Gets ignored.

Comment thread heat/core/manipulations.py Outdated
Comment on lines +2641 to +2646
kind : str, optional
Sorting algorithm. Gets ignored.
order : str, list[str], optional
Used in numpy for array with fields, which are not possible in HeAT. Gets ignored.
stable : bool, optional
Sort stability, currenty not supported.

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.

Do we really want to allow arguments that are ignored? What's the policy on this, @ClaudiaComito?
At least, I would assert not stable and raise a warning that the parameters are ignored rather than silently ignoring them.

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.

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

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

Implement argsort

4 participants