Skip to content

Commit 6c44658

Browse files
committed
BUG: only allow torch.Tensors in the ndarray constructor
1 parent ed0f10b commit 6c44658

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

torch_np/_ndarray.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,13 @@ class ndarray:
6464
def __init__(self, t=None):
6565
if t is None:
6666
self.tensor = torch.Tensor()
67+
elif isinstance(t, torch.Tensor):
68+
self.tensor = t
6769
else:
68-
self.tensor = torch.as_tensor(t)
70+
raise ValueError(
71+
"ndarray constructor is not recommended; prefer"
72+
"either array(...) or zeros/empty(...)"
73+
)
6974

7075
@property
7176
def shape(self):

0 commit comments

Comments
 (0)