__init__¶
Documentation¶
-
class
treetensor.torch.
Tensor
(data, *args, **kwargs)[source]¶ -
__init__
(data, *args, **kwargs)[source]¶ In
treetensor.torch.Tensor
, it’s similar but a little bit different with the originaltorch.Tensor
.Examples:
>>> import torch >>> import treetensor.torch as ttorch >>> pytorch.Tensor([1, 2, 3]) # in torch.Tensor, default type is float32 tensor([1., 2., 3.]) >>> ttorch.Tensor([1, 2, 3]) # a native Tensor object, its type is auto detected with torch.tensor tensor([1, 2, 3]) >>> ttorch.Tensor([1, 2, 3], dtype=pytorch.float32) # with float32 type tensor([1., 2., 3.]) >>> ttorch.Tensor({ ... 'a': [1, 2, 3], ... 'b': {'x': [4.0, 5, 6]}, ... 'c': [[True, ], [False, ]], ... }) # a tree-based Tensor object <Tensor 0x7f537bb9a880> ├── a --> tensor([1, 2, 3]) ├── b --> <Tensor 0x7f537bb9a0d0> │ └── x --> tensor([4., 5., 6.]) └── c --> tensor([[ True], [False]])
-