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

Improve raised TypeError by providing exception message #1460

Merged
merged 1 commit into from
Oct 31, 2023

Conversation

oleksandr-pavlyk
Copy link
Collaborator

Closes gh-1457


In [1]: import dpctl.tensor as dpt

In [2]: dpt.asnumpy([1,2,3])
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[2], line 1
----> 1 dpt.asnumpy([1,2,3])

File ~/repos/dpctl/dpctl/tensor/_copy_utils.py:185, in asnumpy(usm_ary)
    169 def asnumpy(usm_ary):
    170     """
    171     asnumpy(usm_ary)
    172
   (...)
    183             of `usm_ary`
    184     """
--> 185     return _copy_to_numpy(usm_ary)

File ~/repos/dpctl/dpctl/tensor/_copy_utils.py:40, in _copy_to_numpy(ary)
     38 def _copy_to_numpy(ary):
     39     if not isinstance(ary, dpt.usm_ndarray):
---> 40         raise TypeError(
     41             f"Expected dpctl.tensor.usm_ndarray, got {type(ary)}"
     42         )
     43     nb = ary.usm_data.nbytes
     44     hh = dpm.MemoryUSMHost(nb, queue=ary.sycl_queue)

TypeError: Expected dpctl.tensor.usm_ndarray, got <class 'list'>

In [3]: quit
  • 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?

Closes gh-1457

```

In [1]: import dpctl.tensor as dpt

In [2]: dpt.asnumpy([1,2,3])
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[2], line 1
----> 1 dpt.asnumpy([1,2,3])

File ~/repos/dpctl/dpctl/tensor/_copy_utils.py:185, in asnumpy(usm_ary)
    169 def asnumpy(usm_ary):
    170     """
    171     asnumpy(usm_ary)
    172
   (...)
    183             of `usm_ary`
    184     """
--> 185     return _copy_to_numpy(usm_ary)

File ~/repos/dpctl/dpctl/tensor/_copy_utils.py:40, in _copy_to_numpy(ary)
     38 def _copy_to_numpy(ary):
     39     if not isinstance(ary, dpt.usm_ndarray):
---> 40         raise TypeError(
     41             f"Expected dpctl.tensor.usm_ndarray, got {type(ary)}"
     42         )
     43     nb = ary.usm_data.nbytes
     44     hh = dpm.MemoryUSMHost(nb, queue=ary.sycl_queue)

TypeError: Expected dpctl.tensor.usm_ndarray, got <class 'list'>

In [3]: quit
```
@github-actions
Copy link

@coveralls
Copy link
Collaborator

Coverage Status

coverage: 85.748%. remained the same when pulling c957526 on fix-gh-1457 into 02e7714 on master.

@github-actions
Copy link

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

@ndgrigorian ndgrigorian merged commit 9131925 into master Oct 31, 2023
@ndgrigorian ndgrigorian deleted the fix-gh-1457 branch October 31, 2023 09:24
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.

Unhelpful error message when calling asnumpy with non-usm_array type
4 participants