Skip to content

Commit 2da3136

Browse files
committed
MAINT: use tensor.view in expand_dims
1 parent 208c4a1 commit 2da3136

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

torch_np/_wrapper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,8 @@ def squeeze(a, axis=None):
437437
def expand_dims(a, axis):
438438
a = asarray(a)
439439
shape = _util.expand_shape(a.shape, axis)
440-
return a.reshape(shape)
440+
tensor = a.get().view(shape) # never copies
441+
return ndarray._from_tensor_and_base(tensor, a)
441442

442443

443444
@asarray_replacer()

0 commit comments

Comments
 (0)