latest (dev)
Copy
Latest development documentation · Updated 2026-10-15
tensorplay.functional.empty_permuted
- tensorplay.functional.empty_permuted(size, physical_layout, *, dtype=None, layout=None, device=None, requires_grad=False, pin_memory=False) Tensor[source]
Creates an uninitialized, non-overlapping and dense tensor with the specified
size, withphysical_layoutspecifying how the dimensions are physically laid out in memory (each logical dimension is listed from outermost to innermost).physical_layoutis 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 tensortare such thatt.stride(physical_layout[i]) == contiguous_strides[i](notably, this function is not equivalent totensorplay.empty(size).permute(physical_layout)).Unlike
tensorplay.empty_strided(), this is guaranteed to produce a dense tensor with no overlaps. If possible, prefer using this function overtensorplay.empty_strided()or manual use oftensorplay.as_strided().Note
The returned storage is uninitialized, and
tensorplay.use_deterministic_algorithms()does not change that. If the contents matter, allocate withtensorplay.zeros()or fill the tensor before reading it, otherwise the output becomes a source of nondeterminism. Floating point and complex tensors are filled with NaN, and integer tensors are filled with the maximum value.- Parameters:
- Keyword Arguments:
dtype (
tensorplay.dtype, optional) – the desired data type of returned tensor. Default: ifNone, uses a global default (seetensorplay.set_default_dtype()).layout (
tensorplay.layout, optional) – the desired layout of returned Tensor. Default:tensorplay.strided.device (
tensorplay.device, optional) – the desired device of returned tensor. Default: ifNone, uses the current device for the default tensor type (seetensorplay.set_default_device()).devicewill 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.
Examples
>>> tensorplay.empty((2, 3, 5, 7)).stride() (105, 35, 7, 1) >>> tensorplay.empty_permuted((2, 3, 5, 7), (0, 1, 2, 3)).stride() (105, 35, 7, 1) >>> tensorplay.empty((2, 3, 5, 7), memory_format=tensorplay.channels_last).stride() (105, 1, 21, 3) >>> tensorplay.empty_permuted((2, 3, 5, 7), (0, 2, 3, 1)).stride() (105, 1, 21, 3) >>> tensorplay.empty_permuted((2, 3, 5, 7), (0, 2, 3, 1)).dim_order() (0, 2, 3, 1)
Help improve this page
Found an error, an unclear step, or a missing example?

