xp.eye(..., device=device) has not effect when xp is cupy

Open
#337 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

Start by running the provided CuPy and PyTorch reproducer with the listed versions, then trace array_api_compat.array_namespace(x) and the xp.eye call to compare device handling. Done means the CuPy namespace honors device=1 like the PyTorch case, with a regression test covering the behavior.

Written by the indexing model from the issue text.

Description

blocked by upstream

Dear all,

I run the following command when xp is cupy

# cupy
x = cupy.asarray([1.0] * 3)
xp = array_api_compat.array_namespace(x)
E = xp.eye(3, 3, k=0, dtype='float64', device=1)
print(E.device)
with xp.cuda.Device(1):
    E = xp.eye(3, 3, k=0, dtype='float64', device=1)
    print(E.device)
# torch
x = torch.as_tensor([1.0] * 3)
xp = array_api_compat.array_namespace(x)
E = xp.eye(3, 3, k=0, dtype=torch.float64, device='cuda:1')
print(E.device)

and I get the result:

<CUDA Device 0>
<CUDA Device 1>
cuda:1

It seems that device argument of xp.eye has no effect here when xp is cupy.
It seems to work well when xp is torch.
Did I miss something?

Thank you.

array-api-compat 1.12.0
cupy-cuda12x 13.4.1

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.