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,.,.) = 
#>  -1.5200  0.8593 -1.1707  1.6902 -0.9924
#>  -0.7422 -1.4382 -0.8673 -1.8808 -4.6933
#>  -0.8345  1.2811 -1.1514  2.5961  0.3439
#> 
#> (2,.,.) = 
#>  -0.7616 -5.7221  3.8999 -1.3435  3.3716
#>  -0.0716 -2.7815  1.2658 -2.1683 -0.2960
#>   0.6019  1.4019 -2.3965 -0.7504 -2.5028
#> 
#> (3,.,.) = 
#>  -0.3227 -0.9582 -2.4072 -1.1488  0.0948
#>  -3.0888 -0.4607 -0.2627 -0.9151  0.4471
#>  -0.4101  3.0929 -1.3338 -1.6710  2.4936
#> 
#> (4,.,.) = 
#>  -0.6440 -1.1372 -0.2937  1.4547  0.7481
#>   1.0010  0.6649  2.7118 -1.2833  2.3551
#>  -1.7462 -1.6712 -1.2059 -1.7180  0.6536
#> 
#> (5,.,.) = 
#>   0.0984 -0.4216 -2.5258 -2.4128  2.9396
#>   0.7843  0.2789  2.5225  0.6975 -1.2594
#>  -2.2007 -0.1722 -1.7133 -2.9386  3.4515
#> 
#> (6,.,.) = 
#>   0.4993 -2.0282  0.0999  3.4336  2.9142
#>   0.7751  2.2512  1.6117 -3.5616  0.9717
#>  -0.8284  2.5424  0.3490 -4.6505 -5.1805
#> 
#> ... [the output was truncated (use n=-1 to disable)]
#> [ CPUFloatType{10,3,5} ]