torch.empty_permuted
- torch.empty_permuted(size, physical_layout, *, dtype=None, layout=None, device=None, requires_grad=False,
Creates an uninitialized, non-overlapping and dense tensor with the
specified size, with physical_layout specifying how the
dimensions are physically laid out in memory (each logical dimension is listed
from outermost to innermost). physical_layout is a generalization
of NCHW/NHWC notation: if each dimension is assigned a number according to
what order they occur in size (N=0, C=1, H=2, W=3), then NCHW is (0, 1, 2, 3)
while NHWC is (0, 2, 3, 1). Equivalently, the strides of the output
tensor t are such that t.stride(physical_layout[i]) == contiguous_strides[i]
(notably, this function is not equivalent to torch.empty(size).permute(physical_layout)).
Unlike torch.empty_strided(), this is guaranteed to produce a dense
tensor with no overlaps. If possible, prefer using this function over
torch.empty_strided() or manual use of torch.as_strided().
dtype (torch.dtype, optional) – the desired data type of returned tensor.
Default: if , uses a global default (see ).
>>> torch.empty((2, 3, 5, 7)).stride()
(105, 35, 7, 1)
>>> torch.empty_permuted((2, 3, 5, 7), (0, 1, 2
layout (torch.layout, optional) – the desired layout of returned Tensor.
Default: torch.strided.
device (torch.device, optional) – the desired device of returned tensor.
Default: if None, uses the current device for the default tensor type
(see torch.set_default_device()). device will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional) – If autograd should record operations on the
returned tensor. Default: False.
pin_memory (bool, optional) – If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: False.