torch.empty_strided — PyTorch 2.7 documentation (original) (raw)

torch.empty_strided(size, stride, *, dtype=None, layout=None, device=None, requires_grad=False, pin_memory=False) → Tensor

Creates a tensor with the specified size and stride and filled with undefined data.

Warning

If the constructed tensor is “overlapped” (with multiple indices referring to the same element in memory) its behavior is undefined.

Parameters

Keyword Arguments

Example:

a = torch.empty_strided((2, 3), (1, 2)) a tensor([[8.9683e-44, 4.4842e-44, 5.1239e+07], [0.0000e+00, 0.0000e+00, 3.0705e-41]]) a.stride() (1, 2) a.size() torch.Size([2, 3])