mm¶
Documentation¶
-
treetensor.torch.
mm
(input, mat2, *args, **kwargs)[source]¶ In
treetensor
, you can create a matrix multiplication withtreetensor.torch.mm()
.Examples:
>>> import torch >>> import treetensor.torch as ttorch >>> ttorch.mm( ... torch.tensor([[1, 2], [3, 4]]), ... torch.tensor([[5, 6], [7, 2]]), ... ) tensor([[19, 10], [43, 26]]) >>> ttorch.mm( ... ttorch.tensor({ ... 'a': [[1, 2], [3, 4]], ... 'b': {'x': [[3, 4, 5], [6, 7, 8]]}, ... }), ... ttorch.tensor({ ... 'a': [[5, 6], [7, 2]], ... 'b': {'x': [[6, 5], [4, 3], [2, 1]]}, ... }), ... ) <Tensor 0x7f2e7489f340> ├── a --> tensor([[19, 10], │ [43, 26]]) └── b --> <Tensor 0x7f2e74896e50> └── x --> tensor([[44, 32], [80, 59]])
Torch Version Related
This documentation is based on torch.mm 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.
mm
(input, mat2, *, out=None) → Tensor¶ Performs a matrix multiplication of the matrices
input
andmat2
.If
input
is a \((n \times m)\) tensor,mat2
is a \((m \times p)\) tensor,out
will be a \((n \times p)\) tensor.Note
This function does not broadcast. For broadcasting matrix products, see
torch.matmul()
.Supports strided and sparse 2-D tensors as inputs, autograd with respect to strided inputs.
This operator supports TensorFloat32.
- Args:
input (Tensor): the first matrix to be matrix multiplied mat2 (Tensor): the second matrix to be matrix multiplied
- Keyword args:
out (Tensor, optional): the output tensor.
Example:
>>> mat1 = torch.randn(2, 3) >>> mat2 = torch.randn(3, 3) >>> torch.mm(mat1, mat2) tensor([[ 0.4851, 0.5037, -0.3633], [-0.0760, -3.6705, 2.4784]])