pytorch - 💡(How to fix) Fix Feedback about torch.argsort [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
pytorch/pytorch#178967Fetched 2026-04-08 02:22:11
View on GitHub
Comments
0
Participants
1
Timeline
16
Reactions
0
Participants
Timeline (top)
mentioned ×6subscribed ×6labeled ×3closed ×1
RAW_BUFFERClick to expand / collapse

There is the following issue on this page: https://docs.pytorch.org/docs/stable/generated/torch.argsort.html

The example given is incorrect. Instead of a = torch.randn(4, 4) a = tensor([[ 0.0785, 1.5267, -0.8521, 0.4065], [ 0.1598, 0.0788, -0.0745, -1.2700], [ 1.2208, 1.0722, -0.7064, 1.2564], [ 0.0669, -0.2318, -0.8229, -0.9280]]) torch.argsort(a, dim=1) tensor([[2, 0, 3, 1], [3, 2, 1, 0], [2, 1, 0, 3], [3, 2, 1, 0]])

it should be tensor([[1, 3, 0, 2], [3, 2, 1, 0], [2, 1, 0, 3], [3, 2, 1, 0]])

cc @svekars @sekyondaMeta @AlannaBurke

extent analysis

TL;DR

The example output for torch.argsort(a, dim=1) in the PyTorch documentation is incorrect and should be updated to reflect the correct sorted indices.

Guidance

  • Verify the correctness of the example by running the code snippet torch.argsort(a, dim=1) with the provided tensor a and comparing the output to the expected result.
  • Check the PyTorch version being used to ensure it is the latest stable version, as the behavior of torch.argsort may have changed in recent updates.
  • If the issue persists, consider filing a bug report or submitting a pull request to update the documentation with the correct example output.
  • Review the documentation for torch.argsort to ensure understanding of its behavior and parameters, particularly the dim argument.

Example

import torch

a = torch.tensor([[ 0.0785,  1.5267, -0.8521,  0.4065],
                  [ 0.1598,  0.0788, -0.0745, -1.2700],
                  [ 1.2208,  1.0722, -0.7064,  1.2564],
                  [ 0.0669, -0.2318, -0.8229, -0.9280]])

print(torch.argsort(a, dim=1))

Notes

The provided example output seems to be incorrect, and the correct output should be tensor([[1, 3, 0, 2], [3, 2, 1, 0], [2, 1, 0, 3], [3, 2, 1, 0]]). However, without further information about the PyTorch version being used, it is difficult to determine the root cause of the issue.

Recommendation

Apply workaround: Update the documentation with the correct example output, as the provided output seems to be incorrect.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING