Are torch.stack and cat inplace operations?

Hi all,
just wondering, are torch.stack, inplace operations? If we use the same variable name on both sides of the statement.

example .

torch_list = [torch.randn(2, 2), torch.randn(2, 2), torch.randn(2, 2)] torch_list = torch.stack(torch_list, dim=0)

print(torch_list.shape) # torch.Size([3, 2, 2])

Thanks in advance.


They are not inplace as we do not support a Tensor backed by multiple small memory storage.

When you do some_name = in python. It just assigns the returned object to that name.

1 Like