TensorDictBase.type#
- TensorDictBase.type(dst_type: dtype, *, cast_filter: Callable | None = None) Self#
Returns a tensordict whose tensor leaves are cast to
dst_type.Each leaf is cast with
torch.Tensor.type().Unlike
int(),float()andto(dtype), it returns an unlocked tensordict for a locked one, with aFutureWarning. Starting with TensorDict 0.17, the default will change to a locked result, as these casts return.- Parameters:
dst_type (dtype or str) – the dtype, or the name of a tensor type such as
"torch.IntTensor".- Keyword Arguments:
cast_filter (Callable, optional) – a predicate
fn(key, value) -> boolthat selects the tensor leaves to cast, as into(). Defaults toNone, which casts every tensor leaf (a tensorclass uses its owncast_filter, if it declares one).
Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.