latest (dev)
Copy
Latest development documentation · Updated 2026-10-08
tensorplay.nested API
Functions 4
as_nested_tensor
functionFull reference ↗- tensorplay.nested.as_nested_tensor(ts, dtype=None, device=None, layout=None)[source]
Constructs a nested tensor preserving autograd history from a tensor or a list / tuple of tensors.
If a nested tensor is passed, it is returned directly unless the device / dtype differ. A dense tensor of rank two or more is treated as a batch of constituents of consistent size; its storage is shared when no device / dtype conversion is requested. Constituents given as a list / tuple are always copied into one packed buffer.
- Parameters:
ts (Tensor or List[Tensor] or Tuple[Tensor]) – a tensor to treat as a nested tensor or a list / tuple of tensors with the same rank.
- Keyword Arguments:
dtype (tensorplay.dtype, optional) – desired dtype of the result. Default: the dtype of the first input.
device (tensorplay.device, optional) – desired device of the result. Default: the device of the first input.
layout – only the strided layout (
Noneor0) is supported.
- Returns:
the nested tensor.
- Return type:
nested_tensor
functionFull reference ↗- tensorplay.nested.nested_tensor(ts, *, dtype=None, device=None, requires_grad=False, layout=None, pin_memory=False)[source]
Constructs a nested tensor from a list / tuple of tensors.
Constituents must share the same rank; they are always copied into one packed buffer sized to the total element count.
- Parameters:
ts (List[Tensor] or Tuple[Tensor]) – tensors of the same rank.
- Keyword Arguments:
dtype (tensorplay.dtype, optional) – desired dtype of the result.
device (tensorplay.device, optional) – desired device of the result.
requires_grad (bool, optional) – whether the result tracks gradients.
layout – only the strided layout (
Noneor0) is supported.pin_memory (bool, optional) – whether the packed buffer is pinned.
- Returns:
the nested tensor.
- Return type:
nested_to_padded_tensor
functionFull reference ↗- tensorplay.nested.nested_to_padded_tensor()
nested_to_padded_tensor(Tensor self, float padding, int[]? output_size=None) -> Tensor
to_padded_tensor
functionFull reference ↗- tensorplay.nested.to_padded_tensor(input, padding, output_size=None)[source]
Pads a nested tensor into a regular dense tensor and returns it.
The leading entries of each output slice carry the nested data while the trailing entries are filled with
padding. Padding always copies the underlying data, since the nested and dense representations differ in memory layout.- Parameters:
- Keyword Arguments:
output_size (Tuple[int], optional) – the size of the output. If given, it must be large enough to contain all nested data; otherwise the maximum extent of the constituents along each dimension is inferred.
- Returns:
the dense padded tensor.
- Return type:
Help improve this page
Found an error, an unclear step, or a missing example?

