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×n×m) tensor, mat2 is a (b×m×p) tensor, out will be a (b×n×p) tensor.

outi=inputi@mat2i

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.9501 -2.1371  1.9676  3.0700  0.4077
#>  -1.4499 -1.4446  2.4942 -0.6344  2.2255
#>  -0.6433 -0.1672 -1.1785 -0.6782  0.3128
#> 
#> (2,.,.) = 
#>   2.0348 -2.2606  2.4080 -0.6820  0.3326
#>   3.0801  0.0414  2.1451 -0.1846 -0.2773
#>  -2.0642  1.0676 -1.1299 -0.0173  0.0166
#> 
#> (3,.,.) = 
#>  -1.4207  1.5816 -0.8085 -1.1405 -0.2784
#>  -1.0228  3.0545 -0.1846 -1.6912  1.4710
#>   1.0635  0.4789 -1.1840 -0.7035 -0.7093
#> 
#> (4,.,.) = 
#>   0.7499 -2.0121  1.1876 -0.4341  0.6876
#>  -1.2348  3.6392 -0.8906  2.1019 -1.4382
#>  -3.7749  5.3829 -2.3838 -0.0100 -2.8686
#> 
#> (5,.,.) = 
#>   0.2522 -1.6028  0.5622  1.0670  0.1879
#>  -0.4224 -3.3732  0.7758  2.1540 -0.8548
#>   0.3720 -4.2180  1.6636  0.1477 -1.0113
#> 
#> (6,.,.) = 
#>   5.0343 -5.1844 -0.2810  5.2303  0.6995
#>   3.2519  1.0542 -2.1754  1.2397 -0.1884
#>  -6.3572  1.7436  1.6122 -7.6951 -3.0094
#> 
#> ... [the output was truncated (use n=-1 to disable)]
#> [ CPUFloatType{10,3,5} ]