Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

`array_api_compat.torch.take` with 0-d `indices`?

Open
#460 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
python, pytorch
Domain
data

Research direction

Start at the array_api_compat.torch.take entry point and compare its 0-d indices behavior with torch.take and the Array API take specification, including data-apis/array-api#1010. Done means the behavior is resolved and consistent with the chosen interpretation.

Written by the indexing model from the issue text.

Description

array_api_compat.torch.take with 0-d indices produces a result with the same number of dimensions as the input.

from array_api_compat import torch as xp
x = xp.asarray([1])
xp.take(x, xp.asarray(0))
# tensor([1])

For non-wrapped torch.take (and all other array libraries) the output has one fewer dimension than the input.

import torch
x = torch.tensor([1])
torch.take(x, torch.asarray(0))
tensor(1)

from array_api_compat import numpy as xp
x = xp.asarray([1])
xp.take(x, xp.asarray(0))
# np.int64(1)

Technically, the standard of take requires indices to have exactly one dimension.
However, it also says:

Conceptually, take(x, indices, axis=3) is equivalent to x[:,:,:,indices,...];...

This is up for discussion in data-apis/array-api#1010.

But I'd think that either all libraries should follow the letter of the standard as closely as possible in this situation ("The output array must have the same rank (i.e., number of dimensions) as x") or array_api_compat.torch.take should be consistent with torch.take.

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.