10000 Support negative step sizes for slicing · Issue #59786 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content
Support negative step sizes for slicing #59786
Open
@pmeier

Description

@pmeier

The array API specification stipulates that the slicing syntax needs to be equivalent to Pythons slice() syntax. That includes negative step sizes that PyTorch does not support:

import torch

t = torch.rand((3,))
t[::-1]
ValueError: step must be greater than zero

Additional context

This was already proposed in #229, but finally dismissed in #229 (comment) in favor of torch.flip(). Note that this is only a substitution for a negative step size of 1 (::-1) rather than negative step sizes in general.

cc @mruberry @rgommers @pmeier

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: python array apiIssues related to the Python Array APItriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0