Skip to content
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

Fix usm_ndarray ctor when shape is integral numpy scalar #1467

Conversation

oleksandr-pavlyk
Copy link
Collaborator

This enables dpt.usm_ndarray(np.prod((2,3,4))).

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • If this PR is a work in progress, are you opening the PR as a draft?

Copy link

github-actions bot commented Nov 6, 2023

@coveralls
Copy link
Collaborator

coveralls commented Nov 6, 2023

Coverage Status

coverage: 85.783% (-0.002%) from 85.785%
when pulling da59476 on fix-usm-ndarray-ctor-when-shape-is-integral-numpy-scalar
into 9018745 on master.

Copy link

github-actions bot commented Nov 6, 2023

Array API standard conformance tests for dpctl=0.15.1dev1=py310ha25a700_4 ran successfully.
Passed: 935
Failed: 65
Skipped: 119

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."
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)).

Copy link

github-actions bot commented Nov 8, 2023

Array API standard conformance tests for dpctl=0.15.1dev1=py310ha25a700_5 ran successfully.
Passed: 935
Failed: 65
Skipped: 119

Copy link
Collaborator

@ndgrigorian ndgrigorian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@oleksandr-pavlyk oleksandr-pavlyk merged commit f686102 into master Nov 8, 2023
37 of 39 checks passed
@oleksandr-pavlyk oleksandr-pavlyk deleted the fix-usm-ndarray-ctor-when-shape-is-integral-numpy-scalar branch November 8, 2023 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants