dot¶
Documentation¶
-
treetensor.torch.
dot
(input, other, *args, **kwargs)[source]¶ In
treetensor
, you can get the dot product of 2 tree tensors withtreetensor.torch.dot()
.Examples:
>>> import torch >>> import treetensor.torch as ttorch >>> ttorch.dot(torch.tensor([1, 2]), torch.tensor([2, 3])) tensor(8) >>> ttorch.dot( ... ttorch.tensor({ ... 'a': [1, 2, 3], ... 'b': {'x': [3, 4]}, ... }), ... ttorch.tensor({ ... 'a': [5, 6, 7], ... 'b': {'x': [1, 2]}, ... }) ... ) <Tensor 0x7feac55bde50> ├── a --> tensor(38) └── b --> <Tensor 0x7feac55c9250> └── x --> tensor(11)
Torch Version Related
This documentation is based on torch.dot in torch v2.4.1+cu121. 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 v2.4.1+cu121 is listed below.
Description From Torch v2.4.1+cu121¶
-
torch.
dot
(input, other, *, out=None) → Tensor¶ Computes the dot product of two 1D tensors.
Note
Unlike NumPy’s dot, torch.dot intentionally only supports computing the dot product of two 1D tensors with the same number of elements.
- Args:
input (Tensor): first tensor in the dot product, must be 1D. other (Tensor): second tensor in the dot product, must be 1D.
- Keyword args:
out (Tensor, optional): the output tensor.
Example:
>>> torch.dot(torch.tensor([2, 3]), torch.tensor([2, 1])) tensor(7)