Bmm

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,.,.) = #> 4.6720 2.3236 -0.6752 2.2118 7.7838 #> -2.9713 -2.8536 0.6313 -6.6923 -7.1784 #> 3.4564 1.9885 2.0401 -4.0179 -0.5031 #> #> (2,.,.) = #> 4.4642 -1.5956 -3.6263 4.6891 -2.8911 #> 2.9005 2.5687 -4.1896 -0.2603 -3.1560 #> 0.9602 3.4051 -3.2852 -1.6490 -1.0988 #> #> (3,.,.) = #> 1.5118 -4.2018 1.2013 2.8799 1.4430 #> 0.1968 1.3195 0.0796 -0.8581 0.1691 #> -0.2086 -2.7262 0.3367 1.8685 0.5879 #> #> (4,.,.) = #> -0.0630 -0.8098 -0.0536 0.4078 1.0004 #> 0.8590 6.2015 2.2468 -2.6963 -2.4054 #> 0.1005 0.4742 0.2456 0.1041 0.3470 #> #> (5,.,.) = #> -0.5578 0.2932 0.6770 1.4121 0.5700 #> -2.7177 -0.6883 -1.4968 -2.4297 -0.3376 #> 2.9007 -0.8240 -0.2019 -0.3341 1.4992 #> #> (6,.,.) = #> -3.7872 -1.1924 -0.1650 1.2402 0.6433 #> -2.9502 -0.9807 1.0816 0.5332 -0.4031 #> 2.4482 0.1315 2.2764 -1.3249 -1.8174 #> #> ... [the output was truncated (use n=-1 to disable)] #> [ CPUFloatType{10,3,5} ]