TensorDictBase.new_tensor#
- TensorDictBase.new_tensor(data: Tensor | TensorCollection, *, dtype: dtype = None, device: device | str | int = NO_DEFAULT, requires_grad: bool = False, pin_memory: bool | None = None) Self#
Returns a new TensorDict with data as the tensor
data.By default, the returned TensorDict values have the same
torch.dtypeandtorch.deviceas this tensor.The
datacan also be a tensor collection (TensorDictortensorclass), in which case thenew_tensormethod iterates over the tensor pairs ofselfanddata.- Parameters:
data (Tensor or TensorDictBase) – the data to be copied.
- Keyword Arguments:
dtype (dtype, optional) – the desired type of returned tensordict. Default: if
None, the torch.dtype will be unchanged.device (device, optional) – the desired device of returned tensordict. Default: if
None, thetorch.devicewill be unchanged.requires_grad (bool, optional) – If autograd should record operations on the returned tensors. Default:
False.pin_memory (bool, optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default:
False.
Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.