Rate this Page
★ ★ ★ ★ ★

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() and to(dtype), it returns an unlocked tensordict for a locked one, with a FutureWarning. 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) -> bool that selects the tensor leaves to cast, as in to(). Defaults to None, which casts every tensor leaf (a tensorclass uses its own cast_filter, if it declares one).

Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.