Skip to content

Fix array API test failure caused by issue reported in gh-1512 #1513

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 1 commit into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 1 addition & 5 deletions dpctl/tensor/_ctors.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,17 +632,13 @@ def asarray(
usm_type=usm_type,
order=order,
)

raise NotImplementedError(
"Converting Python sequences is not implemented"
)
if copy is False:
raise ValueError(
f"Converting {type(obj)} to usm_ndarray requires a copy"
)
# obj is a scalar, create 0d array
return _asarray_from_numpy_ndarray(
np.asarray(obj),
np.asarray(obj, dtype=dtype),
dtype=dtype,
usm_type=usm_type,
sycl_queue=sycl_queue,
Expand Down
15 changes: 15 additions & 0 deletions dpctl/tests/test_tensor_asarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,21 @@ def test_asarray_input_validation():
with pytest.raises(ValueError):
# sequence is not rectangular
dpt.asarray([[1], 2])
with pytest.raises(OverflowError):
# Python int too large for type
dpt.asarray(-9223372036854775809, dtype="i4")
with pytest.raises(ValueError):
# buffer to usm_ndarray requires a copy
dpt.asarray(memoryview(np.arange(5)), copy=False)
with pytest.raises(ValueError):
# Numpy array to usm_ndarray requires a copy
dpt.asarray(np.arange(5), copy=False)
with pytest.raises(ValueError):
# Python sequence to usm_ndarray requires a copy
dpt.asarray([1, 2, 3], copy=False)
with pytest.raises(ValueError):
# Python scalar to usm_ndarray requires a copy
dpt.asarray(5, copy=False)


def test_asarray_input_validation2():
Expand Down