latest (dev)
Copy
Latest development documentation · Updated 2026-10-08
tensorplay.nested.as_nested_tensor
- 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:
Help improve this page
Found an error, an unclear step, or a missing example?

