Bmm
Note
This function does not broadcast .
For broadcasting matrix products, see torch_matmul
.
bmm(input, mat2, out=NULL) -> Tensor
Performs a batch matrix-matrix product of matrices stored in input
and mat2
.
input
and mat2
must be 3-D tensors each containing
the same number of matrices.
If input
is a \((b \times n \times m)\) tensor, mat2
is a
\((b \times m \times p)\) tensor, out
will be a
\((b \times n \times p)\) tensor.
$$ \mbox{out}_i = \mbox{input}_i \mathbin{@} \mbox{mat2}_i $$
Examples
if (torch_is_installed()) {
input = torch_randn(c(10, 3, 4))
mat2 = torch_randn(c(10, 4, 5))
res = torch_bmm(input, mat2)
res
}
#> torch_tensor
#> (1,.,.) =
#> 0.0148 -1.4289 -2.5242 -2.2315 3.9070
#> -0.7986 1.3755 -2.7284 -0.7337 -1.9157
#> -0.1249 1.6538 -1.0125 0.0827 -0.8018
#>
#> (2,.,.) =
#> -1.3355 1.2500 2.8313 0.8134 0.6959
#> 1.1807 1.5554 -3.4352 -0.1900 -0.9873
#> 0.6931 -1.5055 -0.2626 1.7171 2.9591
#>
#> (3,.,.) =
#> 0.7739 0.7454 -2.4331 3.0177 -3.8896
#> 0.2750 -2.2370 3.9531 -3.8760 3.9073
#> -1.4963 -1.7030 1.9757 -0.2618 -1.6721
#>
#> (4,.,.) =
#> -1.2911 1.2444 -0.0898 -1.1425 0.6894
#> 0.9251 1.8568 -3.3428 3.1520 -1.8815
#> -1.3344 -2.3980 1.9695 -1.4698 -0.3304
#>
#> (5,.,.) =
#> 2.9257 2.4859 -2.3270 -0.6642 -2.2189
#> -0.2291 0.7260 -0.5298 -1.2475 0.0634
#> -2.3435 0.2422 1.1344 -1.2391 2.8086
#>
#> (6,.,.) =
#> 0.5211 1.3316 -0.8732 3.6360 4.5398
#> 2.7015 0.6772 -0.0901 -1.3753 -1.0526
#> -2.1076 2.4517 -0.8346 2.1821 0.3490
#>
#> ... [the output was truncated (use n=-1 to disable)]
#> [ CPUFloatType{10,3,5} ]