multensor.RdPerforms a tensor multiplication like tensor(), but with named indices, keeping dimnames, and vectorized.
mul.tensor(X,i=c(),Y,j=i,by=NULL)a tensor to be multiplied
numeric or character vector specifying the dimension to be used in the multiplication for X
a tensor to be multiplied
numeric or character vector specifying the dimension to be used in the multiplication for Y
the by dimensions if present and not mentioned in i or j are
used as sequence dimensions. tensors in these dimensions are
processed in parallel. So in this dimension the product is neither
inner nor outer but parallel like a*b, rather than
a%*%b or a%o%b. Unmentioned dimensions get an
outer product. Mentioned dimensions an inner.
The tensor product of X and Y with respect to the regarding dimensions.
Say $$X_{i_1\ldots i_n h_1 \ldots h_l}$$ and $$Y_{j_1\ldots j_n k_1 \ldots k_m}$$ the the result is: $$E_{h_1\ldots h_l k_1 \ldots k_m}= \sum_{i_1,\ldots,i_n} X_{i_1\ldots i_n h_1 \ldots h_l}Y_{j_1\ldots j_n k_1 \ldots k_m}$$
This is an full outer product with i,j not given and a full inner product product of i=dim(X)
A <- to.tensor(1:20,c(A=2,B=2,C=5))
B <- to.tensor(1:20,c(D=2,B=2,E=5))
mul.tensor(A,"A",A,"B")
#> Warning: Tensor with duplicated names generated: B C A C
#> , , 1, 1
#>
#> C
#> B [,1] [,2] [,3] [,4] [,5]
#> [1,] 7 23 39 55 71
#> [2,] 15 31 47 63 79
#>
#> , , 2, 1
#>
#> C
#> B [,1] [,2] [,3] [,4] [,5]
#> [1,] 10 34 58 82 106
#> [2,] 22 46 70 94 118
#>
#> , , 1, 2
#>
#> C
#> B [,1] [,2] [,3] [,4] [,5]
#> [1,] 19 67 115 163 211
#> [2,] 43 91 139 187 235
#>
#> , , 2, 2
#>
#> C
#> B [,1] [,2] [,3] [,4] [,5]
#> [1,] 22 78 134 190 246
#> [2,] 50 106 162 218 274
#>
#> , , 1, 3
#>
#> C
#> B [,1] [,2] [,3] [,4] [,5]
#> [1,] 31 111 191 271 351
#> [2,] 71 151 231 311 391
#>
#> , , 2, 3
#>
#> C
#> B [,1] [,2] [,3] [,4] [,5]
#> [1,] 34 122 210 298 386
#> [2,] 78 166 254 342 430
#>
#> , , 1, 4
#>
#> C
#> B [,1] [,2] [,3] [,4] [,5]
#> [1,] 43 155 267 379 491
#> [2,] 99 211 323 435 547
#>
#> , , 2, 4
#>
#> C
#> B [,1] [,2] [,3] [,4] [,5]
#> [1,] 46 166 286 406 526
#> [2,] 106 226 346 466 586
#>
#> , , 1, 5
#>
#> C
#> B [,1] [,2] [,3] [,4] [,5]
#> [1,] 55 199 343 487 631
#> [2,] 127 271 415 559 703
#>
#> , , 2, 5
#>
#> C
#> B [,1] [,2] [,3] [,4] [,5]
#> [1,] 58 210 362 514 666
#> [2,] 134 286 438 590 742
#>
#> attr(,"class")
#> [1] "tensor"