Skip to content

Commit 3db985f

Browse files
committed
Add a fast path to copy to numpy.ndarray
1 parent 6f6fe50 commit 3db985f

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

dpctl/tensor/_copy_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
def _copy_to_numpy(ary):
4242
if not isinstance(ary, dpt.usm_ndarray):
4343
raise TypeError(f"Expected dpctl.tensor.usm_ndarray, got {type(ary)}")
44+
if ary.size == 0:
45+
# no data needs to be copied for zero sized array
46+
return np.ndarray(ary.shape, dtype=ary.dtype)
4447
nb = ary.usm_data.nbytes
4548
q = ary.sycl_queue
4649
hh = dpm.MemoryUSMHost(nb, queue=q)

0 commit comments

Comments
 (0)