Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions thinc/backends/numpy_ops.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,20 @@ class NumpyOps(Ops):

def asarray(self, data, dtype=None):
if isinstance(data, self.xp.ndarray):
if dtype is not None:
return self.xp.asarray(data, dtype=dtype)
else:
return self.xp.asarray(data)
array = data
elif hasattr(data, 'numpy'):
# Handles PyTorch Tensor
return data.numpy()
array = data.numpy()
elif hasattr(data, "get"):
return data.get()
elif dtype is not None:
return self.xp.array(data, dtype=dtype)
array = data.get()
else:
return self.xp.array(data)
array = self.xp.array(data)

if dtype is not None:
array = array.astype(dtype=dtype, copy=False)

return array


def alloc(self, shape: Shape, *, dtype: Optional[DTypes] = "float32", zeros: bool = True) -> ArrayXd:
if zeros:
Expand Down