Chain_matmul
Source:R/gen-namespace-docs.R
, R/gen-namespace-examples.R
, R/gen-namespace.R
torch_chain_matmul.Rd
Chain_matmul
TEST
Returns the matrix product of the \(N\) 2-D tensors. This product is efficiently computed
using the matrix chain order algorithm which selects the order in which incurs the lowest cost in terms
of arithmetic operations ([CLRS]
_). Note that since this is a function to compute the product, \(N\)
needs to be greater than or equal to 2; if equal to 2 then a trivial matrix-matrix product is returned.
If \(N\) is 1, then this is a no-op - the original matrix is returned as is.
Examples
if (torch_is_installed()) {
a = torch_randn(c(3, 4))
b = torch_randn(c(4, 5))
c = torch_randn(c(5, 6))
d = torch_randn(c(6, 7))
torch_chain_matmul(list(a, b, c, d))
}
#> torch_tensor
#> 16.6907 16.8339 -2.7730 5.8232 -6.7935 -8.3109 -2.3422
#> 6.5107 1.9628 3.4302 -11.1368 -14.3598 -9.0426 3.6788
#> -23.4347 -28.3631 10.5032 -23.5406 0.5954 5.2780 9.0183
#> [ CPUFloatType{3,7} ]