View source: R/gen-namespace.R
torch_einsum | R Documentation |
Einsum
torch_einsum(equation, tensors)
equation |
(string) The equation is given in terms of lower case letters (indices) to be associated with each dimension of the operands and result. The left hand side lists the operands dimensions, separated by commas. There should be one index letter per tensor dimension. The right hand side follows after |
tensors |
(Tensor) The operands to compute the Einstein sum of. |
This function provides a way of computing multilinear expressions (i.e. sums of products) using the Einstein summation convention.
if (torch_is_installed()) { x = torch_randn(c(5)) y = torch_randn(c(4)) torch_einsum('i,j->ij', list(x, y)) # outer product A = torch_randn(c(3,5,4)) l = torch_randn(c(2,5)) r = torch_randn(c(2,4)) torch_einsum('bn,anm,bm->ba', list(l, A, r)) # compare torch_nn$functional$bilinear As = torch_randn(c(3,2,5)) Bs = torch_randn(c(3,5,4)) torch_einsum('bij,bjk->bik', list(As, Bs)) # batch matrix multiplication A = torch_randn(c(3, 3)) torch_einsum('ii->i', list(A)) # diagonal A = torch_randn(c(4, 3, 3)) torch_einsum('...ii->...i', list(A)) # batch diagonal A = torch_randn(c(2, 3, 4, 5)) torch_einsum('...ij->...ji', list(A))$shape # batch permute }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.