Skip to content

Commit

Permalink
Merge pull request #37 from kmjohnson3/master
Browse files Browse the repository at this point in the history
Contiguous arrays for PyTorch
  • Loading branch information
frankong committed Feb 5, 2020
2 parents 8b8a258 + c589057 commit eb0c23b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions sigpy/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def to_pytorch(array, requires_grad=True): # pragma: no cover
Args:
array (numpy/cupy array): input.
requires_grad(bool): Set .requires_grad output tensor
Returns:
PyTorch tensor.
Expand All @@ -38,7 +38,7 @@ def to_pytorch(array, requires_grad=True): # pragma: no cover
tensor = from_dlpack(array.toDlpack())

tensor.requires_grad = requires_grad
return tensor
return tensor.contiguous()


def from_pytorch(tensor, iscomplex=False): # pragma: no cover
Expand All @@ -59,11 +59,11 @@ def from_pytorch(tensor, iscomplex=False): # pragma: no cover

device = tensor.device
if device.type == 'cpu':
output = tensor.detach().numpy()
output = tensor.detach().contiguous().numpy()
else:
if config.cupy_enabled:
import cupy as cp
output = cp.fromDlpack(to_dlpack(tensor))
output = cp.fromDlpack(to_dlpack(tensor.contiguous()))
else:
raise TypeError('CuPy not installed, '
'but trying to convert GPU PyTorch Tensor.')
Expand Down

0 comments on commit eb0c23b

Please sign in to comment.