treetensor.common.object

Object

class treetensor.common.Object(data, *args, constraint=None, **kwargs)[source]
Overview:

Generic object tree class, used in treetensor.numpy and treetensor.torch.

__init__(data, constraint=None)[source]

In treetensor.common.Object, object or object tree can be initialized.

Examples:

>>> from treetensor.common import Object
>>> Object(1)
1

>>> Object({'a': 1, 'b': 2, 'x': {'c': 233}})
<Object 0x7fe00b1153a0>
├── a --> 1
├── b --> 2
└── x --> <Object 0x7fe00b115ee0>
    └── c --> 233
all()[source]

The values in this tree is all true or not.

Examples:

>>> from treetensor.common import Object
>>> Object({'a': False, 'b': {'x': False}}).all()
False
>>> Object({'a': True, 'b': {'x': False}}).all()
False
>>> Object({'a': True, 'b': {'x': True}}).all()
True
any()[source]

The values in this tree is not all False or yes.

Examples:

>>> from treetensor.common import Object
>>> Object({'a': False, 'b': {'x': False}}).any()
False
>>> Object({'a': True, 'b': {'x': False}}).any()
True
>>> Object({'a': True, 'b': {'x': True}}).any()
True