Skip to content

Commit

Permalink
Fix astensor(cupy.ndarray) for zero-size input
Browse files Browse the repository at this point in the history
  • Loading branch information
asi1024 committed Mar 4, 2020
1 parent 830713f commit 58a33bb
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion chainer_pytorch_migration/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ def astensor(array):
# If the array is not allocated (empty)
# we just create a new one
if array.data.ptr == 0:
return torch.empty(array.shape, dtype=to_torch_dtype(array.dtype))
return torch.empty(
array.shape,
dtype=to_torch_dtype(array.dtype),
device=array.device.id
)
return torch.as_tensor(
_ArrayWithCudaArrayInterfaceHavingStrides(array),
device=array.device.id,
Expand Down

0 comments on commit 58a33bb

Please sign in to comment.