Skip to contents

Bmm

Usage

torch_bmm(self, mat2)

Arguments

self

(Tensor) the first batch of matrices to be multiplied

mat2

(Tensor) the second batch of matrices to be multiplied

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.8230  2.7546 -0.7542 -0.5477 -0.5813
#>  -0.8730  1.1366 -0.2849 -0.3910  0.6125
#>  -1.0591 -3.1156 -1.0358 -1.0026  2.9087
#> 
#> (2,.,.) = 
#>  -0.4602 -0.6427  0.3519 -0.4196  1.6671
#>   2.6385  4.2276  0.4918  5.0359 -1.5627
#>   1.6185  2.1022  1.1907  1.8916  2.9136
#> 
#> (3,.,.) = 
#>  -4.1540  0.8625  3.4507 -2.0780 -0.5078
#>  -4.0225  1.2436  3.7782 -1.9630 -1.1487
#>   1.7938 -0.5523 -1.6895  1.8270  0.3934
#> 
#> (4,.,.) = 
#>   0.5838 -3.4571 -0.4144 -1.1646  1.4206
#>  -1.1833  0.9444  0.8237 -0.0151  0.5557
#>  -0.5864  0.3695  1.3914 -0.3322 -1.6807
#> 
#> (5,.,.) = 
#>   0.4701 -0.4790  1.4412  1.5492 -0.8058
#>   1.6003  0.7965  0.9348 -1.1735 -1.0550
#>   2.5328 -0.1895  0.7619  0.6687 -2.1136
#> 
#> (6,.,.) = 
#>  -1.6555  1.2987  0.2087  2.8079 -0.0744
#>  -2.9993  0.2499  0.4804  2.5207 -2.8663
#>   3.6773 -3.4674 -1.8152 -4.8830  1.1636
#> 
#> ... [the output was truncated (use n=-1 to disable)]
#> [ CPUFloatType{10,3,5} ]