PyTorch torch.Tensor.untyped_storage() Method

The torch.Tensor.untyped_storage() method returns the underlying torch.UntypedStorage of a tensor, which is a contiguous, one-dimensional array of bytes. It is different from torch.Tensor.storage, which returns a torch.TypedStorage that has a specific data type. The torch.TypedStorage is deprecated and will be removed in the future.

Syntax

Tensor.untyped_storage()

Example

import torch

# create a tensor of shape (2, 3) with random values
x = torch.rand(2, 3)
print(x)

# get the untyped storage of the tensor
s = x.untyped_storage()
print(s)

# get the size and type of the storage
print(s.size())
print(s.type())

Output

PyTorch torch.Tensor.untyped_storage() Method

That’s it!

Leave a Comment