Fix usm_ndarray ctor when shape is integral numpy scalar#1467
Merged
oleksandr-pavlyk merged 4 commits intomasterfrom Nov 8, 2023
Merged
Conversation
|
View rendered docs @ https://intelpython.github.io/dpctl/pulls/1467/index.html |
Collaborator
|
Array API standard conformance tests for dpctl=0.15.1dev1=py310ha25a700_4 ran successfully. |
ndgrigorian
reviewed
Nov 6, 2023
dpctl/tensor/_usmarray.pyx
Outdated
Comment on lines
191
to
197
| try: | ||
| <Py_ssize_t> shape | ||
| shape = [shape, ] | ||
| except Exception: | ||
| raise TypeError( | ||
| "Argument shape must be a list or a tuple." | ||
| ) |
Collaborator
There was a problem hiding this comment.
Perhaps the logic of this exception and message could be improved a bit. For instance:
In [5]: x = dpt.ones(np.prod((2, 3, 4), dtype="f4"), dtype="i8")
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
File ~/repos/dpctl/dpctl/tensor/_usmarray.pyx:192, in dpctl.tensor._usmarray.usm_ndarray.__cinit__()
191 try:
--> 192 <Py_ssize_t> shape
193 shape = [shape, ]
TypeError: 'float' object cannot be interpreted as an integer
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
Cell In[5], line 1
----> 1 x = dpt.ones(np.prod((2, 3, 4), dtype="f4"), dtype="i8")
File ~/repos/dpctl/dpctl/tensor/_ctors.py:968, in ones(shape, dtype, order, device, usm_type, sycl_queue)
966 sycl_queue = normalize_queue_device(sycl_queue=sycl_queue, device=device)
967 dtype = _get_dtype(dtype, sycl_queue)
--> 968 res = dpt.usm_ndarray(
969 shape,
970 dtype=dtype,
971 buffer=usm_type,
972 order=order,
973 buffer_ctor_kwargs={"queue": sycl_queue},
974 )
975 hev, _ = ti._full_usm_ndarray(1, res, sycl_queue)
976 hev.wait()
File ~/repos/dpctl/dpctl/tensor/_usmarray.pyx:195, in dpctl.tensor._usmarray.usm_ndarray.__cinit__()
193 shape = [shape, ]
194 except Exception:
--> 195 raise TypeError(
196 "Argument shape must be a list or a tuple."
197 )
TypeError: Argument shape must be a list or a tuple.
It seems a bit misleading at first, because it would work for np.prod((2, 3, 4)).
|
Array API standard conformance tests for dpctl=0.15.1dev1=py310ha25a700_5 ran successfully. |
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This enables
dpt.usm_ndarray(np.prod((2,3,4))).