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.7765 -0.1350  0.8466  0.8478 -0.7594
#>   1.6370 -0.2408  0.3351  2.2860 -0.6668
#>   1.9089  0.2050 -1.6219 -2.5549  1.7960
#> 
#> (2,.,.) = 
#>  -1.8824  2.0253 -2.1206 -1.3713  0.0871
#>   2.8014 -0.8317 -0.6866 -1.2809  2.3431
#>   0.1755 -3.8833  0.2988  7.5040 -3.6713
#> 
#> (3,.,.) = 
#>   0.8480 -0.0850  1.4366  2.9513 -0.3949
#>  -0.9064 -0.8385  1.3575 -7.3166 -7.2062
#>   0.5430 -0.3684  0.4283  0.9606  2.1168
#> 
#> (4,.,.) = 
#>  -2.3839  1.7347  1.1756 -1.6514  0.6408
#>   1.6447 -1.2290  1.8483  1.1605 -3.7812
#>   1.8861  0.1105  0.4390  1.3200 -0.8549
#> 
#> (5,.,.) = 
#>   0.4684  1.1384  1.3886  1.1070 -1.7678
#>   3.1111  0.6010  1.0678 -0.0603 -2.4754
#>   1.0265 -0.3575  0.2944 -1.0106 -2.2023
#> 
#> (6,.,.) = 
#>   0.3164 -1.3392  0.5580 -1.6123  5.0994
#>   1.6859 -1.7957 -0.2757  0.7590  0.4473
#>  -0.4207  0.6214  0.0980  0.1298 -0.7558
#> 
#> ... [the output was truncated (use n=-1 to disable)]
#> [ CPUFloatType{10,3,5} ]