8000 ENH: Add copy and device keyword to np.asanyarray to match np.asarray by JuliaPoo · Pull Request #26580 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: Add copy and device keyword to np.asanyarray to match np.asarray #26580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

8000
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
TST: Add device keyword tests
  • Loading branch information
JuliaPoo committed Jun 4, 2024
commit 75cc0b22d94f147b42048c341a3dedbbc94ee583
18 changes: 15 additions & 3 deletions numpy/_core/tests/test_multiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -10233,10 +10233,22 @@ class TestDevice:
"""
Test arr.device attribute and arr.to_device() method.
"""
def test_device(self):
arr = np.arange(5)

@pytest.mark.parametrize("func, arg", [
(np.arange, 5),
(np.empty_like, []),
(np.zeros, 5),
(np.empty, (5,5)),
(np.asarray, []),
(np.asanyarray, []),
])
def test_device(self, func, arg):
arr = func(arg)
assert arr.device == "cpu"
arr = func(arg, device=None)
assert arr.device == "cpu"
arr = func(arg, device="cpu")
assert arr.device == "cpu"

with assert_raises_regex(
AttributeError,
r"attribute 'device' of '(numpy.|)ndarray' objects is "
Expand Down
0