library(rTorch)

Matrices

Dot product

\[dot(a,b)_{i,j,k,a,b,c} = \sum_m a_{i,j,k,m}b_{a,b,m,c}\]

torch$dot(torch$tensor(c(2, 3)), torch$tensor(c(2, 1)))
#> tensor(7.)

torch.dot() treats both a and b as 1D vectors (irrespective of their original shape) and computes their inner product.

If we perform the same dot product operation in Python, we get the same error:

# 1D tensors work fine
r = torch$dot(torch$Tensor(list(4L, 2L, 4L)), torch$Tensor(list(3L, 4L, 1L)))
r
#> tensor(24.)

Here is agood explanation: https://stackoverflow.com/a/44525687/5270873

\[(A B)^T = B^T A^T\]