Skip to content

torch.argsort is not stable by default #354

@mdhaber

Description

@mdhaber

According to the standard for argsort, the default should be stable=True. So I'd expect these two argsorts to produce the same result (xp.arange(30), essentially), but they do not.

# array_api_compat version 1.12.0
from array_api_compat import torch as xp
x = xp.asarray([10]*30)

xp.argsort(x)
# tensor([15, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16,  0, 14, 13,
#         12, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1])

xp.argsort(x, stable=True)
# tensor([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17,
#         18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions