index

Documentation

class treetensor.torch.Size(data, *args, **kwargs)[source]
index(value, *args, **kwargs) → treetensor.common.object.Object[source]

Example:

>>> import torch
>>> import treetensor.numpy as ttorch
>>> ttorch.Size({
...     'a': [1, 2],
...     'b': {'x': [3, 2, 4]},
...     'c': [3, 5],
... }).index(2)
<Object 0x7fb412780e80>
├── a --> 1
├── b --> <Object 0x7fb412780eb8>
│   └── x --> 1
└── c --> None

Note

This method’s behaviour is different from the torch.Size.index(). No ValueError will be raised unless the value can not be found in any of the sizes, instead there will be nones returned in the tree.

Torch Version Related

This documentation is based on torch.Size.index in torch v1.10.0+cu102. Its arguments’ arrangements depend on the version of pytorch you installed.

If some arguments listed here are not working properly, please check your pytorch’s version with the following command and find its documentation.

1
python -c 'import torch;print(torch.__version__)'

The arguments and keyword arguments supported in torch v1.10.0+cu102 is listed below.

Description From Torch v1.10.0+cu102

class torch.Size(iterable=(), /)
index(value, start=0, stop=9223372036854775807, /)

Return first index of value.

Raises ValueError if the value is not present.