Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions array_api_compat/torch/_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,11 +815,20 @@ def take(x: Array, indices: Array, /, *, axis: int | None = None, **kwargs: obje
if x.ndim != 1:
raise ValueError("axis must be specified when ndim > 1")
axis = 0
return torch.index_select(x, axis, indices, **kwargs)
return torch.index_select(
x,
axis,
torch.where(indices < 0, indices + x.shape[axis], indices),
**kwargs
)


def take_along_axis(x: Array, indices: Array, /, *, axis: int = -1) -> Array:
return torch.take_along_dim(x, indices, dim=axis)
return torch.take_along_dim(
x,
torch.where(indices < 0, indices + x.shape[axis], indices),
dim=axis
)


def sign(x: Array, /) -> Array:
Expand Down
Loading