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,.,.) =
#> -1.0575 0.3833 0.8050 0.2675 -3.0613
#> -0.8268 -1.9016 0.5779 -0.9464 -0.5882
#> -1.2584 1.6696 3.7912 0.9649 2.3607
#>
#> (2,.,.) =
#> 1.8553 0.0998 -1.4494 3.4589 0.3825
#> -2.6685 -2.1388 0.4287 -4.4304 1.9997
#> -0.7735 0.7209 -0.1729 1.4363 0.8181
#>
#> (3,.,.) =
#> 1.4887 -0.9025 -0.7918 1.3083 -0.3667
#> 0.8198 -0.0573 -1.2188 0.2597 0.8283
#> 1.0448 -1.3888 -0.1311 0.9499 -0.3950
#>
#> (4,.,.) =
#> 0.4413 -0.0992 0.2571 0.5835 -0.0214
#> 0.3096 0.0384 -0.3189 -0.6925 0.3223
#> -1.9406 -0.0256 0.2576 0.4445 0.4031
#>
#> (5,.,.) =
#> -1.4586 -0.3688 0.7870 0.7316 1.2556
#> -2.8281 0.8457 0.5333 0.2137 -1.3257
#> 3.4641 0.5589 -0.9268 -1.8236 -1.2237
#>
#> (6,.,.) =
#> 3.2891 3.3975 3.3523 1.7662 -0.1384
#> -1.0187 -1.2888 -1.0786 -0.6144 0.6090
#> -0.0876 -0.6024 -3.2239 -1.1994 0.7591
#>
#> ... [the output was truncated (use n=-1 to disable)]
#> [ CPUFloatType{10,3,5} ]