treetensor.common.trees

BaseTreeStruct

class treetensor.common.trees.BaseTreeStruct[source]
Overview:

Base structure of all the trees in treetensor.

__repr__()

Get representation format of tree value.

Returns:

Represenation string.

Example:
>>> t = TreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}})
>>> t
<TreeValue 0x7f672fc53320>
├── 'a' --> 1
├── 'b' --> 2
└── 'x' --> <TreeValue 0x7f672fc53390>
    ├── 'c' --> 3
    └── 'd' --> 4
__str__()

Return str(self).

clsmeta

treetensor.common.trees.clsmeta(func, allow_dict: bool = False) → Type[type][source]
Overview:

Create a metaclass based on generating function.

Used in treetensor.common.Object, treetensor.torch.Tensor and treetensor.torch.Size. Can do modify onto the constructor function of the classes.

Arguments:
  • func: Generating function.

  • allow_dict (bool): Auto transform dictionary to treevalue.TreeValue class, default is False.

Returns:
  • metaclass (Type[type]): Metaclass for creating a new class.