Skip to content

Commit

Permalink
Improve raise TypeError by providing exception message
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
oleksandr-pavlyk committed Oct 28, 2023
1 parent 02e7714 commit c957526
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion dpctl/tensor/_copy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

def _copy_to_numpy(ary):
if not isinstance(ary, dpt.usm_ndarray):
raise TypeError
raise TypeError(f"Expected dpctl.tensor.usm_ndarray, got {type(ary)}")
nb = ary.usm_data.nbytes
hh = dpm.MemoryUSMHost(nb, queue=ary.sycl_queue)
hh.copy_from_device(ary.usm_data)
Expand Down

0 comments on commit c957526

Please sign in to comment.