tensorclass and non-tensor data#
This page lists TensorClass, the class form of a
tensordict, and the classes for non-tensor data and unbatched entries. A
tensorclass is a class that you declare like a dataclass, with typed fields
and methods, and that has the tensor operations of a
TensorDict. For a guide to fields, auto-casting, the
class options, and static type checking, see TensorClass: a dataclass of tensors.
To declare a tensorclass, subclass TensorClass. The
tensorclass() decorator is the original way, kept for
existing code (see Legacy: the @tensorclass decorator).
A tensorclass has the methods of TensorDictBase,
listed by task in Methods by task. On a tensorclass, the
methods that return a TensorDict on a TensorDict return an
instance of the tensorclass. Examples are select, clone, to,
apply, indexing, and reshaping.
On a tensorclass, rename_keys() raises
AttributeError for a destination that is not a field, and keeps the
sub-tensordict fields that it empties.
Tensorclasses#
|
A base class for dataclass-like containers of tensors. |
|
A decorator that turns a class with annotated fields into a tensorclass. |
|
Converts a dataclass instance to a tensorclass instance, or a dataclass type to a tensorclass type. |
Non-tensor data#
A tensordict or a tensorclass can hold values that are not tensors, such
as strings or Python objects. It wraps each one in a
NonTensorData, and a stack of them in a
NonTensorStack. If you stack
MetaData entries that hold the same object, the
result is one MetaData, not a NonTensorStack.
TensorAttrs describes the device, dtype, and shape of
an entry: attrs() returns them. See
Non-tensor data and unbatched entries.
|
A base class for tensordict entries that hold a Python object instead of a tensor. |
|
A tensordict entry that holds a Python object instead of a tensor. |
|
A lazy stack of |
|
A tensordict entry that holds one Python object for the whole batch. |
|
A tensorclass that holds the device, dtype and shape of one tensor. |
Entries that ignore the batch shape#
Warning
UnbatchedTensor is experimental: its API can change in a minor release
without a deprecation cycle.
An UnbatchedTensor is a tensor that shape operations
on its tensordict (indexing, reshaping, stacking) leave unchanged.
Operations on its data, such as arithmetic or
to(), still apply to it. See
UnbatchedTensor.
|
A tensor entry that has no batch dimensions and that batch operations leave unchanged. |
See also#
TensorClass: a dataclass of tensors: declare and use a tensorclass.
Which container should I use?: tensorclass,
TypedTensorDict, orTensorDict.TypedTensorDict: the other container with typed fields.
The tutorials Using tensorclasses for datasets, Batched data loading with tensorclasses, and Simulating particles with a tensorclass.