`torch` support indexing with negative step

Open
#144 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python, pytorch
Domain
api

Research direction

The issue names the array_api_compat.torch entry point and reproduces the failure with torch.arange(10) and x[::-1]. Start by locating the torch indexing implementation and existing slice tests, then compare its behavior with the Array API standard. Done means negative-step slicing works while preserving the documented flip workaround behavior.

Written by the indexing model from the issue text.

Description

blocked by upstream Medium Priority

The array API standard seems to support negative step.

The basic slice syntax is i:j:k where i is the starting index, j is the stopping index, and k is the step (k != 0).

But array-api-compat.torch tensors do not:

from array_api_compat import torch
x = torch.arange(10)
x[::-1]  # ValueError: step must be greater than zero

Adding support for negative step would be appreciated! (In the meantime, I can use flip.) Thanks for considering it.

Dominant language
Python
Stars
131
Forks
49
Avg merge
2d 8h
Merged PRs (30d)
6

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from data-apis/array-api-compat

All issues in data-apis/array-api-compat

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.