4. Einsum operation by DelayedTensor

Authors: Koki Tsuyuzaki [aut, cre]
Last modified: 2024-10-30 05:24:24.255552
Compiled: Wed Oct 30 05:28:18 2024

What is einsum

einsum is an easy and intuitive way to write tensor operations.

It was originally introduced by Numpy1 package of Python but similar tools have been implemented in other languages (e.g. R, Julia) inspired by Numpy. In this vignette, we will use CRAN einsum package first.

einsum is named after Einstein summation2 introduced by Albert Einstein, which is a notational convention that implies summation over a set of indexed terms in a formula.

Here, we consider a simple example of einsum; matrix multiplication. If we naively implement the matrix multiplication, the calculation would look like the following in a for loop.

A <- matrix(runif(3*4), nrow=3, ncol=4)
B <- matrix(runif(4*5), nrow=4, ncol=5)
C <- matrix(0, nrow=3, ncol=5)

I <- nrow(A)
J <- ncol(A)
K <- ncol(B)

for(i in 1:I){
  for(j in 1:J){
    for(k in 1:K){
      C[i,k] = C[i,k] + A[i,j] * B[j,k]
    }
  }
}

Therefore, any programming language can implement this. However, when analyzing tensor data, such operations tend to be more complicated and increase the possibility of causing bugs because the order of tensors is larger or more tensors are handled simultaneously. In addition, several programming languages, especially R, are known to significantly slow down the speed of computation if the code is written in for loop.

Obviously, in the case of the R language, it should be executed using the built-in matrix multiplication function (%*%) prepared by the R, as shown below.

C <- A %*% B

However, more complex operations than matrix multiplication are not always provided by programming languages as standard.

einsum is a function that solves such a problem. To put it simply, einsum is a wrapper for the for loop above. Like the Einstein summation, it omits many notations such as for, array size (e.g. I, J, and K), brackets (e.g. {}, (), and []), and even addition operator (+) and extracts the array subscripts (e.g. i, j, and k) to concisely express the tensor operation as follows.

suppressPackageStartupMessages(library("einsum"))
C <- einsum('ij,jk->ik', A, B)

Einsum of DelayedTensor

CRAN einsum is easy to use because the syntax is almost the same as that of Numpy‘s einsum, except that it prohibits the implicit modes that do not use’->’. It is extremely fast because the internal calculation is actually performed by C++. When the input tensor is huge, however, it is not scalable because it assumes that the input is R’s standard array.

Using einsum of DelayedTensor, we can augment the CRAN einsum’s functionality; in DelayedTensor, the input DelayedArray objects are divided into multiple block tensors and the CRAN einsum is incremently applied in the block processing.

Typical operations of einsum

A surprisingly large number of tensor operations can be handled uniformly in einsum.

In more detail, einsum is capable of performing any tensor operation that can be described by a combination of the following three operations3.

  1. Multiplication: the element values of the tensors on the left side of -> are multiplied by each other
  2. Summation: when comparing the left and right sides of ->, if there is a missing subscript on the right, the summation is done in the direction of the subscript
  3. Permutation: the subscripts to the right of -> can be rearranged in any order

Some typical operations are introduced below. Here we use the arrays and DelayedArray objects below.

suppressPackageStartupMessages(library("DelayedTensor"))
suppressPackageStartupMessages(library("DelayedArray"))

arrA <- array(runif(3), dim=c(3))
arrB <- array(runif(3*3), dim=c(3,3))
arrC <- array(runif(3*4), dim=c(3,4))
arrD <- array(runif(3*3*3), dim=c(3,3,3))
arrE <- array(runif(3*4*5), dim=c(3,4,5))

darrA <- DelayedArray(arrA)
darrB <- DelayedArray(arrB)
darrC <- DelayedArray(arrC)
darrD <- DelayedArray(arrD)
darrE <- DelayedArray(arrE)

No Operation

diag

We can also extract the diagonal elements as follows.

einsum::einsum('ii->i', arrB)
## [1] 0.4287071 0.5146565 0.8847386
DelayedTensor::einsum('ii->i', darrB)
## <3> HDF5Array object of type "double":
##       [1]       [2]       [3] 
## 0.4287071 0.5146565 0.8847386
einsum::einsum('iii->i', arrD)
## [1] 0.2116278 0.5453128 0.2753056
DelayedTensor::einsum('iii->i', darrD)
## <3> HDF5Array object of type "double":
##       [1]       [2]       [3] 
## 0.2116278 0.5453128 0.2753056

Multiplication

By using multiple arrays or DelayedArray objects as input and writing “,” on the right side of ->, multiplication will be performed.

Hadamard Product

Hadamard Product can also be implemented in einsum, multiplying by the product of each element.

einsum::einsum('i,i->i', arrA, arrA)
## [1] 0.01723044 0.12217954 0.80274253
DelayedTensor::einsum('i,i->i', darrA, darrA)
## <3> HDF5Array object of type "double":
##        [1]        [2]        [3] 
## 0.01723044 0.12217954 0.80274253
einsum::einsum('ij,ij->ij', arrC, arrC)
##             [,1]       [,2]       [,3]      [,4]
## [1,] 0.721213169 0.47736994 0.01786815 0.1164786
## [2,] 0.009280119 0.02197748 0.04656470 0.7679276
## [3,] 0.600834109 0.14660425 0.67047769 0.8513898
DelayedTensor::einsum('ij,ij->ij', darrC, darrC)
## <3 x 4> HDF5Matrix object of type "double":
##             [,1]        [,2]        [,3]        [,4]
## [1,] 0.721213169 0.477369940 0.017868151 0.116478580
## [2,] 0.009280119 0.021977483 0.046564698 0.767927624
## [3,] 0.600834109 0.146604254 0.670477693 0.851389755
einsum::einsum('ijk,ijk->ijk', arrE, arrE)
## , , 1
## 
##            [,1]       [,2]      [,3]        [,4]
## [1,] 0.28839588 0.75543857 0.9837170 0.062667869
## [2,] 0.64284118 0.09113171 0.4056395 0.003894097
## [3,] 0.06883429 0.36370709 0.5947163 0.619651283
## 
## , , 2
## 
##            [,1]      [,2]      [,3]       [,4]
## [1,] 0.12059887 0.5902524 0.9683614 0.84385188
## [2,] 0.06491437 0.8234500 0.7496222 0.06635262
## [3,] 0.17665178 0.9666669 0.9190282 0.56152182
## 
## , , 3
## 
##            [,1]      [,2]       [,3]       [,4]
## [1,] 0.73272604 0.8119586 0.04073608 0.29899886
## [2,] 0.09106525 0.1265789 0.14186962 0.43348142
## [3,] 0.57129835 0.2713977 0.56136512 0.04862862
## 
## , , 4
## 
##            [,1]       [,2]      [,3]       [,4]
## [1,] 0.23283056 0.08573651 0.7145328 0.18497306
## [2,] 0.78764320 0.72389293 0.6050218 0.21884421
## [3,] 0.03711502 0.42267678 0.7714854 0.01691843
## 
## , , 5
## 
##           [,1]      [,2]      [,3]       [,4]
## [1,] 0.1438317 0.1534383 0.6090906 0.15389569
## [2,] 0.4688910 0.2072616 0.3038998 0.38401703
## [3,] 0.2427070 0.5556946 0.6673499 0.01003491
DelayedTensor::einsum('ijk,ijk->ijk', darrE, darrE)
## <3 x 4 x 5> HDF5Array object of type "double":
## ,,1
##             [,1]        [,2]        [,3]        [,4]
## [1,] 0.288395878 0.755438572 0.983717038 0.062667869
## [2,] 0.642841176 0.091131715 0.405639549 0.003894097
## [3,] 0.068834289 0.363707085 0.594716261 0.619651283
## 
## ,,2
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.12059887 0.59025239 0.96836137 0.84385188
## [2,] 0.06491437 0.82345001 0.74962221 0.06635262
## [3,] 0.17665178 0.96666687 0.91902821 0.56152182
## 
## ,,3
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.73272604 0.81195859 0.04073608 0.29899886
## [2,] 0.09106525 0.12657885 0.14186962 0.43348142
## [3,] 0.57129835 0.27139775 0.56136512 0.04862862
## 
## ,,4
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.23283056 0.08573651 0.71453283 0.18497306
## [2,] 0.78764320 0.72389293 0.60502177 0.21884421
## [3,] 0.03711502 0.42267678 0.77148544 0.01691843
## 
## ,,5
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.14383174 0.15343827 0.60909057 0.15389569
## [2,] 0.46889095 0.20726161 0.30389980 0.38401703
## [3,] 0.24270695 0.55569461 0.66734990 0.01003491

Outer Product

The outer product can also be implemented in einsum, in which the subscripts in the input array are all different, and all of them are kept.

einsum::einsum('i,j->ij', arrA, arrA)
##            [,1]       [,2]      [,3]
## [1,] 0.01723044 0.04588253 0.1176078
## [2,] 0.04588253 0.12217954 0.3131752
## [3,] 0.11760784 0.31317521 0.8027425
DelayedTensor::einsum('i,j->ij', darrA, darrA)
## <3 x 3> HDF5Matrix object of type "double":
##            [,1]       [,2]       [,3]
## [1,] 0.01723044 0.04588253 0.11760784
## [2,] 0.04588253 0.12217954 0.31317521
## [3,] 0.11760784 0.31317521 0.80274253
einsum::einsum('ij,klm->ijklm', arrC, arrE)
## , , 1, 1, 1
## 
##            [,1]       [,2]      [,3]      [,4]
## [1,] 0.45606458 0.37104113 0.0717851 0.1832810
## [2,] 0.05173343 0.07961291 0.1158839 0.4706030
## [3,] 0.41626684 0.20562116 0.4397306 0.4955172
## 
## , , 2, 1, 1
## 
##            [,1]      [,2]      [,3]      [,4]
## [1,] 0.68090052 0.5539612 0.1071745 0.2736370
## [2,] 0.07723757 0.1188614 0.1730136 0.7026062
## [3,] 0.62148283 0.3069906 0.6565140 0.7398029
## 
## , , 3, 1, 1
## 
##           [,1]       [,2]       [,3]       [,4]
## [1,] 0.2228098 0.18127168 0.03507052 0.08954172
## [2,] 0.0252743 0.03889479 0.05661491 0.22991249
## [3,] 0.2033666 0.10045596 0.21482983 0.24208430
## 
## , , 1, 2, 1
## 
##            [,1]      [,2]      [,3]      [,4]
## [1,] 0.73812753 0.6005195 0.1161821 0.2966352
## [2,] 0.08372909 0.1288512 0.1875547 0.7616575
## [3,] 0.67371601 0.3327920 0.7116914 0.8019805
## 
## , , 2, 2, 1
## 
##            [,1]       [,2]       [,3]      [,4]
## [1,] 0.25636964 0.20857503 0.04035288 0.1030286
## [2,] 0.02908115 0.04475316 0.06514231 0.2645422
## [3,] 0.23399795 0.11558675 0.24718775 0.2785473
## 
## , , 3, 2, 1
## 
##            [,1]       [,2]       [,3]      [,4]
## [1,] 0.51216242 0.41668073 0.08061497 0.2058254
## [2,] 0.05809686 0.08940563 0.13013804 0.5284891
## [3,] 0.46746938 0.23091342 0.49381929 0.5564679
## 
## , , 1, 3, 1
## 
##            [,1]      [,2]      [,3]      [,4]
## [1,] 0.84230023 0.6852714 0.1325790 0.3384996
## [2,] 0.09554586 0.1470361 0.2140245 0.8691510
## [3,] 0.76879825 0.3797593 0.8121332 0.9151648
## 
## , , 2, 3, 1
## 
##            [,1]       [,2]       [,3]      [,4]
## [1,] 0.54088130 0.44004560 0.08513535 0.2173668
## [2,] 0.06135457 0.09441894 0.13743538 0.5581235
## [3,] 0.49368216 0.24386161 0.52150961 0.5876711
## 
## , , 3, 3, 1
## 
##            [,1]      [,2]      [,3]      [,4]
## [1,] 0.65491770 0.5328224 0.1030848 0.2631952
## [2,] 0.07429023 0.1143257 0.1664115 0.6757951
## [3,] 0.59776736 0.2952760 0.6314618 0.7115724
## 
## , , 1, 4, 1
## 
##            [,1]       [,2]       [,3]      [,4]
## [1,] 0.21259561 0.17296172 0.03346280 0.0854369
## [2,] 0.02411567 0.03711175 0.05401954 0.2193727
## [3,] 0.19404379 0.09585080 0.20498148 0.2309865
## 
## , , 2, 4, 1
## 
##             [,1]        [,2]        [,3]       [,4]
## [1,] 0.052995037 0.043115251 0.008341481 0.02129739
## [2,] 0.006011463 0.009251078 0.013465788 0.05468441
## [3,] 0.048370510 0.023893329 0.051097017 0.05757946
## 
## , , 3, 4, 1
## 
##            [,1]      [,2]      [,3]      [,4]
## [1,] 0.66850629 0.5438776 0.1052237 0.2686561
## [2,] 0.07583164 0.1166978 0.1698643 0.6898169
## [3,] 0.61017016 0.3014026 0.6445637 0.7263365
## 
## , , 1, 1, 2
## 
##            [,1]       [,2]       [,3]      [,4]
## [1,] 0.29491946 0.23993806 0.04642067 0.1185208
## [2,] 0.03345403 0.05148261 0.07493764 0.3043209
## [3,] 0.26918379 0.13296731 0.28435690 0.3204320
## 
## , , 2, 1, 2
## 
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.21637259 0.17603457 0.03405730 0.08695478
## [2,] 0.02454411 0.03777108 0.05497925 0.22327010
## [3,] 0.19749118 0.09755369 0.20862319 0.23509026
## 
## , , 3, 1, 2
## 
##            [,1]      [,2]       [,3]      [,4]
## [1,] 0.35693639 0.2903933 0.05618221 0.1434439
## [2,] 0.04048888 0.0623086 0.09069585 0.3683148
## [3,] 0.32578891 0.1609283 0.34415269 0.3878138
## 
## , , 1, 2, 2
## 
##            [,1]      [,2]      [,3]      [,4]
## [1,] 0.65245520 0.5308189 0.1026972 0.2622056
## [2,] 0.07401089 0.1138958 0.1657858 0.6732541
## [3,] 0.59551974 0.2941658 0.6290875 0.7088969
## 
## , , 2, 2, 2
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.7706380 0.6269691 0.1212993 0.3097003
## [2,] 0.0874169 0.1345264 0.1958155 0.7952044
## [3,] 0.7033895 0.3474497 0.7430376 0.8373033
## 
## , , 3, 2, 2
## 
##            [,1]      [,2]      [,3]      [,4]
## [1,] 0.83496879 0.6793068 0.1314251 0.3355533
## [2,] 0.09471422 0.1457563 0.2121616 0.8615859
## [3,] 0.76210657 0.3764538 0.8050643 0.9071991
## 
## , , 1, 3, 2
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.8357003 0.6799019 0.1315402 0.3358472
## [2,] 0.0947972 0.1458840 0.2123475 0.8623407
## [3,] 0.7627742 0.3767836 0.8057696 0.9079939
## 
## , , 2, 3, 2
## 
##            [,1]      [,2]      [,3]      [,4]
## [1,] 0.73528050 0.5982032 0.1157340 0.2954910
## [2,] 0.08340614 0.1283542 0.1868313 0.7587197
## [3,] 0.67111742 0.3315084 0.7089464 0.7988871
## 
## , , 3, 3, 2
## 
##            [,1]      [,2]      [,3]      [,4]
## [1,] 0.81413466 0.6623567 0.1281458 0.3271805
## [2,] 0.09235091 0.1421194 0.2068678 0.8400876
## [3,] 0.74309050 0.3670605 0.7849764 0.8845627
## 
## , , 1, 4, 2
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.7801263 0.6346885 0.1227928 0.3135134
## [2,] 0.0884932 0.1361827 0.1982264 0.8049951
## [3,] 0.7120499 0.3517276 0.7521861 0.8476124
## 
## , , 2, 4, 2
## 
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.21875645 0.17797401 0.03443252 0.08791279
## [2,] 0.02481452 0.03818722 0.05558498 0.22572995
## [3,] 0.19966702 0.09862848 0.21092167 0.23768034
## 
## , , 3, 4, 2
## 
##            [,1]      [,2]      [,3]      [,4]
## [1,] 0.63637798 0.5177390 0.1001666 0.2557445
## [2,] 0.07218718 0.1110893 0.1617006 0.6566644
## [3,] 0.58084547 0.2869172 0.6135861 0.6914289
## 
## , , 1, 1, 3
## 
##            [,1]      [,2]      [,3]      [,4]
## [1,] 0.72694681 0.5914232 0.1144223 0.2921419
## [2,] 0.08246081 0.1268995 0.1847137 0.7501204
## [3,] 0.66351096 0.3277511 0.7009112 0.7898325
## 
## , , 2, 1, 3
## 
##            [,1]       [,2]       [,3]      [,4]
## [1,] 0.25627614 0.20849895 0.04033817 0.1029910
## [2,] 0.02907054 0.04473684 0.06511855 0.2644457
## [3,] 0.23391261 0.11554459 0.24709759 0.2784457
## 
## , , 3, 1, 3
## 
##            [,1]      [,2]      [,3]      [,4]
## [1,] 0.64189399 0.5222266 0.1010349 0.2579613
## [2,] 0.07281289 0.1120522 0.1631022 0.6623562
## [3,] 0.58588014 0.2894042 0.6189045 0.6974221
## 
## , , 1, 2, 3
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.7652419 0.6225790 0.1204500 0.3075318
## [2,] 0.0868048 0.1335845 0.1944444 0.7896363
## [3,] 0.6984643 0.3450168 0.7378348 0.8314404
## 
## , , 2, 2, 3
## 
##            [,1]       [,2]       [,3]      [,4]
## [1,] 0.30214291 0.24581485 0.04755765 0.1214237
## [2,] 0.03427341 0.05274357 0.07677308 0.3117746
## [3,] 0.27577689 0.13622407 0.29132164 0.3282803
## 
## , , 3, 2, 3
## 
##            [,1]       [,2]       [,3]      [,4]
## [1,] 0.44242020 0.35994045 0.06963746 0.1777977
## [2,] 0.05018569 0.07723108 0.11241688 0.4565236
## [3,] 0.40381311 0.19946946 0.42657489 0.4806925
## 
## , , 1, 3, 3
## 
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.17140419 0.13944956 0.02697922 0.06888309
## [2,] 0.01944314 0.02992117 0.04355299 0.17686820
## [3,] 0.15644688 0.07727925 0.16526534 0.18623179
## 
## , , 2, 3, 3
## 
##            [,1]       [,2]       [,3]      [,4]
## [1,] 0.31987223 0.26023892 0.05034827 0.1285487
## [2,] 0.03628453 0.05583849 0.08127802 0.3300691
## [3,] 0.29195909 0.14421751 0.30841598 0.3475433
## 
## , , 3, 3, 3
## 
##            [,1]      [,2]      [,3]      [,4]
## [1,] 0.63628918 0.5176667 0.1001527 0.2557088
## [2,] 0.07217711 0.1110738 0.1616781 0.6565728
## [3,] 0.58076442 0.2868772 0.6135004 0.6913324
## 
## , , 1, 4, 3
## 
##            [,1]      [,2]       [,3]      [,4]
## [1,] 0.46437260 0.3778003 0.07309279 0.1866198
## [2,] 0.05267585 0.0810632 0.11799488 0.4791758
## [3,] 0.42384987 0.2093669 0.44774107 0.5045439
## 
## , , 2, 4, 3
## 
##            [,1]       [,2]       [,3]      [,4]
## [1,] 0.55913550 0.45489669 0.08800859 0.2247027
## [2,] 0.06342523 0.09760548 0.14207368 0.5769596
## [3,] 0.51034343 0.25209169 0.53911003 0.6075044
## 
## , , 3, 4, 3
## 
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.18727414 0.15236090 0.02947717 0.07526083
## [2,] 0.02124334 0.03269151 0.04758547 0.19324405
## [3,] 0.17093196 0.08443437 0.18056690 0.20347459
## 
## , , 1, 1, 4
## 
##            [,1]       [,2]       [,3]      [,4]
## [1,] 0.40978100 0.33338613 0.06450001 0.1646808
## [2,] 0.04648328 0.07153342 0.10412341 0.4228440
## [3,] 0.37402212 0.18475376 0.39510467 0.4452298
## 
## , , 2, 1, 4
## 
##            [,1]      [,2]      [,3]      [,4]
## [1,] 0.75369666 0.6131861 0.1186327 0.3028920
## [2,] 0.08549516 0.1315691 0.1915108 0.7777229
## [3,] 0.68792652 0.3398115 0.7267030 0.8188964
## 
## , , 3, 1, 4
## 
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.16360881 0.13310746 0.02575222 0.06575032
## [2,] 0.01855887 0.02856037 0.04157222 0.16882432
## [3,] 0.14933175 0.07376463 0.15774915 0.17776206
## 
## , , 1, 2, 4
## 
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.24866503 0.20230677 0.03914017 0.09993231
## [2,] 0.02820718 0.04340821 0.06318461 0.25659195
## [3,] 0.22696567 0.11211305 0.23975908 0.27017621
## 
## , , 2, 2, 4
## 
##            [,1]      [,2]      [,3]      [,4]
## [1,] 0.72255181 0.5878475 0.1137305 0.2903757
## [2,] 0.08196226 0.1261323 0.1835970 0.7455853
## [3,] 0.65949948 0.3257695 0.6966736 0.7850573
## 
## , , 3, 2, 4
## 
##            [,1]       [,2]       [,3]      [,4]
## [1,] 0.55212323 0.44919170 0.08690485 0.2218846
## [2,] 0.06262979 0.09638139 0.14029190 0.5697238
## [3,] 0.50394308 0.24893014 0.53234890 0.5998856
## 
## , , 1, 3, 4
## 
##            [,1]      [,2]      [,3]      [,4]
## [1,] 0.71786523 0.5840347 0.1129928 0.2884922
## [2,] 0.08143064 0.1253141 0.1824062 0.7407493
## [3,] 0.65522187 0.3236565 0.6921548 0.7799653
## 
## , , 2, 3, 4
## 
##            [,1]      [,2]      [,3]      [,4]
## [1,] 0.66056768 0.5374190 0.1039741 0.2654658
## [2,] 0.07493113 0.1153120 0.1678471 0.6816252
## [3,] 0.60292430 0.2978234 0.6369094 0.7177112
## 
## , , 3, 3, 4
## 
##            [,1]      [,2]      [,3]      [,4]
## [1,] 0.74592591 0.6068640 0.1174096 0.2997691
## [2,] 0.08461369 0.1302126 0.1895362 0.7697045
## [3,] 0.68083388 0.3363080 0.7192105 0.8104535
## 
## , , 1, 4, 4
## 
##            [,1]       [,2]       [,3]      [,4]
## [1,] 0.36524650 0.29715413 0.05749023 0.1467835
## [2,] 0.04143153 0.06375925 0.09280741 0.3768898
## [3,] 0.33337385 0.16467494 0.35216517 0.3968427
## 
## , , 2, 4, 4
## 
##            [,1]      [,2]       [,3]     [,4]
## [1,] 0.39728243 0.3232176 0.06253272 0.159658
## [2,] 0.04506551 0.0693516 0.10094758 0.409947
## [3,] 0.36261421 0.1791187 0.38305373 0.431650
## 
## , , 3, 4, 4
## 
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.11046173 0.08986852 0.01738681 0.04439183
## [2,] 0.01253017 0.01928275 0.02806780 0.11398303
## [3,] 0.10082247 0.04980275 0.10650554 0.12001741
## 
## , , 1, 1, 5
## 
##            [,1]      [,2]       [,3]      [,4]
## [1,] 0.32207662 0.2620323 0.05069524 0.1294346
## [2,] 0.03653458 0.0562233 0.08183814 0.3323438
## [3,] 0.29397112 0.1452114 0.31054142 0.3499384
## 
## , , 2, 1, 5
## 
##            [,1]      [,2]       [,3]      [,4]
## [1,] 0.58152414 0.4731115 0.09153259 0.2337001
## [2,] 0.06596487 0.1015138 0.14776253 0.6000619
## [3,] 0.53077837 0.2621858 0.56069682 0.6318298
## 
## , , 3, 1, 5
## 
##            [,1]       [,2]       [,3]      [,4]
## [1,] 0.41838194 0.34038361 0.06585381 0.1681373
## [2,] 0.04745892 0.07303484 0.10630887 0.4317191
## [3,] 0.38187251 0.18863158 0.40339757 0.4545748
## 
## , , 1, 2, 5
## 
##            [,1]       [,2]       [,3]      [,4]
## [1,] 0.33265853 0.27064149 0.05236085 0.1336872
## [2,] 0.03773494 0.05807053 0.08452696 0.3432630
## [3,] 0.30362962 0.14998234 0.32074435 0.3614357
## 
## , , 2, 2, 5
## 
##            [,1]      [,2]       [,3]      [,4]
## [1,] 0.38662618 0.3145480 0.06085542 0.1553755
## [2,] 0.04385673 0.0674914 0.09823988 0.3989510
## [3,] 0.35288787 0.1743142 0.37277914 0.4200719
## 
## , , 3, 2, 5
## 
##            [,1]      [,2]       [,3]      [,4]
## [1,] 0.63306735 0.5150455 0.09964555 0.2544141
## [2,] 0.07181164 0.1105114 0.16085942 0.6532482
## [3,] 0.57782374 0.2854246 0.61039400 0.6878319
## 
## , , 1, 3, 5
## 
##            [,1]      [,2]      [,3]      [,4]
## [1,] 0.66278514 0.5392231 0.1043232 0.2663569
## [2,] 0.07518267 0.1156991 0.1684106 0.6839134
## [3,] 0.60494825 0.2988231 0.6390474 0.7201205
## 
## , , 2, 3, 5
## 
##           [,1]       [,2]      [,3]      [,4]
## [1,] 0.4681629 0.38088401 0.0736894 0.1881431
## [2,] 0.0531058 0.08172486 0.1189580 0.4830870
## [3,] 0.4273095 0.21107582 0.4513957 0.5086621
## 
## , , 3, 3, 5
## 
##            [,1]      [,2]      [,3]      [,4]
## [1,] 0.69375899 0.5644225 0.1091985 0.2788045
## [2,] 0.07869617 0.1211060 0.1762809 0.7158746
## [3,] 0.63321922 0.3127880 0.6689120 0.7537738
## 
## , , 1, 4, 5
## 
##            [,1]       [,2]       [,3]      [,4]
## [1,] 0.33315401 0.27104460 0.05243883 0.1338863
## [2,] 0.03779114 0.05815703 0.08465286 0.3437743
## [3,] 0.30408186 0.15020573 0.32122208 0.3619740
## 
## , , 2, 4, 5
## 
##            [,1]       [,2]       [,3]      [,4]
## [1,] 0.52626813 0.42815673 0.08283522 0.2114941
## [2,] 0.05969693 0.09186799 0.13372224 0.5430445
## [3,] 0.48034418 0.23727311 0.50741980 0.5717938
## 
## , , 3, 4, 5
## 
##             [,1]       [,2]       [,3]       [,4]
## [1,] 0.085072373 0.06921246 0.01339049 0.03418848
## [2,] 0.009650137 0.01485066 0.02161649 0.08778430
## [3,] 0.077648668 0.03835571 0.08202550 0.09243170
DelayedTensor::einsum('ij,klm->ijklm', darrC, darrE)
## <3 x 4 x 3 x 4 x 5> HDF5Array object of type "double":
## ,,1,1,1
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.45606458 0.37104113 0.07178510 0.18328105
## [2,] 0.05173343 0.07961291 0.11588385 0.47060298
## [3,] 0.41626684 0.20562116 0.43973060 0.49551720
## 
## ,,2,1,1
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.68090052 0.55396124 0.10717454 0.27363704
## [2,] 0.07723757 0.11886139 0.17301360 0.70260622
## [3,] 0.62148283 0.30699064 0.65651403 0.73980294
## 
## ,,3,1,1
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.22280978 0.18127168 0.03507052 0.08954172
## [2,] 0.02527430 0.03889479 0.05661491 0.22991249
## [3,] 0.20336664 0.10045596 0.21482983 0.24208430
## 
## ...
## 
## ,,1,4,5
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.33315401 0.27104460 0.05243883 0.13388634
## [2,] 0.03779114 0.05815703 0.08465286 0.34377427
## [3,] 0.30408186 0.15020573 0.32122208 0.36197405
## 
## ,,2,4,5
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.52626813 0.42815673 0.08283522 0.21149411
## [2,] 0.05969693 0.09186799 0.13372224 0.54304446
## [3,] 0.48034418 0.23727311 0.50741980 0.57179381
## 
## ,,3,4,5
##             [,1]        [,2]        [,3]        [,4]
## [1,] 0.085072373 0.069212455 0.013390492 0.034188477
## [2,] 0.009650137 0.014850658 0.021616487 0.087784303
## [3,] 0.077648668 0.038355708 0.082025500 0.092431698

Summation

If there is a vanishing subscript on the left or right side of ->, the summation is done for that subscript.

einsum::einsum('i->', arrA)
## [1] 1.376766
DelayedTensor::einsum('i->', darrA)
## <1> HDF5Array object of type "double":
##      [1] 
## 1.376766
einsum::einsum('ij->', arrC)
## [1] 6.251368
DelayedTensor::einsum('ij->', darrC)
## <1> HDF5Array object of type "double":
##      [1] 
## 6.251368
einsum::einsum('ijk->', arrE)
## [1] 35.03107
DelayedTensor::einsum('ijk->', darrE)
## <1> HDF5Array object of type "double":
##      [1] 
## 35.03107

Row-wise / Column-wise Summation

einsum::einsum('ij->i', arrC)
## [1] 2.015124 1.336685 2.899559
DelayedTensor::einsum('ij->i', darrC)
## <3> HDF5Array object of type "double":
##      [1]      [2]      [3] 
## 2.015124 1.336685 2.899559
einsum::einsum('ij->j', arrC)
## [1] 1.720711 1.222057 1.168287 2.140312
DelayedTensor::einsum('ij->j', darrC)
## <4> HDF5Array object of type "double":
##      [1]      [2]      [3]      [4] 
## 1.720711 1.222057 1.168287 2.140312

Mode-wise Vectorization

einsum::einsum('ijk->i', arrE)
## [1] 12.16671 11.07610 11.78826
DelayedTensor::einsum('ijk->i', darrE)
## <3> HDF5Array object of type "double":
##      [1]      [2]      [3] 
## 12.16671 11.07610 11.78826
einsum::einsum('ijk->j', arrE)
## [1]  7.656456  9.597043 11.186256  6.591314
DelayedTensor::einsum('ijk->j', darrE)
## <4> HDF5Array object of type "double":
##       [1]       [2]       [3]       [4] 
##  7.656456  9.597043 11.186256  6.591314
einsum::einsum('ijk->k', arrE)
## [1] 6.875103 8.415341 6.444883 6.885871 6.409871
DelayedTensor::einsum('ijk->k', darrE)
## <5> HDF5Array object of type "double":
##      [1]      [2]      [3]      [4]      [5] 
## 6.875103 8.415341 6.444883 6.885871 6.409871

Mode-wise Summation

These are the same as what the modeSum function does.

einsum::einsum('ijk->ij', arrE)
##          [,1]     [,2]     [,3]     [,4]
## [1,] 2.602069 3.223046 3.803453 2.538138
## [2,] 2.930576 2.871180 3.208464 2.065885
## [3,] 2.123811 3.502817 4.174338 1.987291
DelayedTensor::einsum('ijk->ij', darrE)
## <3 x 4> HDF5Matrix object of type "double":
##          [,1]     [,2]     [,3]     [,4]
## [1,] 2.602069 3.223046 3.803453 2.538138
## [2,] 2.930576 2.871180 3.208464 2.065885
## [3,] 2.123811 3.502817 4.174338 1.987291
einsum::einsum('ijk->jk', arrE)
##          [,1]     [,2]     [,3]     [,4]     [,5]
## [1,] 1.601162 1.022356 1.913607 1.562670 1.556661
## [2,] 1.774121 2.658912 1.777825 1.793763 1.592421
## [3,] 2.399902 2.808520 1.327731 2.501474 2.148628
## [4,] 1.099918 1.925552 1.425720 1.027964 1.112161
DelayedTensor::einsum('ijk->jk', darrE)
## <4 x 5> HDF5Matrix object of type "double":
##          [,1]     [,2]     [,3]     [,4]     [,5]
## [1,] 1.601162 1.022356 1.913607 1.562670 1.556661
## [2,] 1.774121 2.658912 1.777825 1.793763 1.592421
## [3,] 2.399902 2.808520 1.327731 2.501474 2.148628
## [4,] 1.099918 1.925552 1.425720 1.027964 1.112161
einsum::einsum('ijk->jk', arrE)
##          [,1]     [,2]     [,3]     [,4]     [,5]
## [1,] 1.601162 1.022356 1.913607 1.562670 1.556661
## [2,] 1.774121 2.658912 1.777825 1.793763 1.592421
## [3,] 2.399902 2.808520 1.327731 2.501474 2.148628
## [4,] 1.099918 1.925552 1.425720 1.027964 1.112161
DelayedTensor::einsum('ijk->jk', darrE)
## <4 x 5> HDF5Matrix object of type "double":
##          [,1]     [,2]     [,3]     [,4]     [,5]
## [1,] 1.601162 1.022356 1.913607 1.562670 1.556661
## [2,] 1.774121 2.658912 1.777825 1.793763 1.592421
## [3,] 2.399902 2.808520 1.327731 2.501474 2.148628
## [4,] 1.099918 1.925552 1.425720 1.027964 1.112161

Trace

If we take the diagonal elements of a matrix and add them together, we get trace.

einsum::einsum('ii->', arrB)
## [1] 1.828102
DelayedTensor::einsum('ii->', darrB)
## <1> HDF5Array object of type "double":
##      [1] 
## 1.828102

Permutation

By changing the order of the indices on the left and right side of ->, we can get a sorted array or DelayedArray.

einsum::einsum('ij->ji', arrB)
##            [,1]       [,2]       [,3]
## [1,] 0.42870706 0.02663326 0.01021571
## [2,] 0.07828706 0.51465647 0.34886928
## [3,] 0.01822425 0.86612482 0.88473862
DelayedTensor::einsum('ij->ji', darrB)
## <3 x 3> DelayedArray object of type "double":
##            [,1]       [,2]       [,3]
## [1,] 0.42870706 0.02663326 0.01021571
## [2,] 0.07828706 0.51465647 0.34886928
## [3,] 0.01822425 0.86612482 0.88473862
einsum::einsum('ijk->jki', arrD)
## , , 1
## 
##           [,1]       [,2]      [,3]
## [1,] 0.2116278 0.85004260 0.6003329
## [2,] 0.4533196 0.04752356 0.2386284
## [3,] 0.9572999 0.65689551 0.8077267
## 
## , , 2
## 
##           [,1]      [,2]      [,3]
## [1,] 0.5967222 0.7574087 0.9849221
## [2,] 0.2276772 0.5453128 0.6569572
## [3,] 0.8331119 0.1829376 0.3241175
## 
## , , 3
## 
##           [,1]      [,2]       [,3]
## [1,] 0.7451280 0.1618515 0.72285918
## [2,] 0.4956204 0.7910935 0.02584717
## [3,] 0.5068867 0.5707727 0.27530558
DelayedTensor::einsum('ijk->jki', darrD)
## <3 x 3 x 3> DelayedArray object of type "double":
## ,,1
##            [,1]       [,2]       [,3]
## [1,] 0.21162784 0.85004260 0.60033285
## [2,] 0.45331960 0.04752356 0.23862838
## [3,] 0.95729987 0.65689551 0.80772667
## 
## ,,2
##           [,1]      [,2]      [,3]
## [1,] 0.5967222 0.7574087 0.9849221
## [2,] 0.2276772 0.5453128 0.6569572
## [3,] 0.8331119 0.1829376 0.3241175
## 
## ,,3
##            [,1]       [,2]       [,3]
## [1,] 0.74512799 0.16185145 0.72285918
## [2,] 0.49562043 0.79109346 0.02584717
## [3,] 0.50688670 0.57077275 0.27530558

Multiplication + Summation

Some examples of combining Multiplication and Summation are shown below.

Inner Product (Squared Frobenius Norm)

Inner Product first calculate Hadamard Product and collapses it to 0D tensor (norm).

einsum::einsum('i,i->', arrA, arrA)
## [1] 0.9421525
DelayedTensor::einsum('i,i->', darrA, darrA)
## <1> HDF5Array object of type "double":
##       [1] 
## 0.9421525
einsum::einsum('ij,ij->', arrC, arrC)
## [1] 4.447986
DelayedTensor::einsum('ij,ij->', darrC, darrC)
## <1> HDF5Array object of type "double":
##      [1] 
## 4.447986
einsum::einsum('ijk,ijk->', arrE, arrE)
## [1] 24.56379
DelayedTensor::einsum('ijk,ijk->', darrE, darrE)
## <1> HDF5Array object of type "double":
##      [1] 
## 24.56379

Contracted Product

The inner product is an operation that eliminates all subscripts, while the outer product is an operation that leaves all subscripts intact. In the middle of the two, the operation that eliminates some subscripts while keeping others by summing them is called contracted product.

einsum::einsum('ijk,ijk->jk', arrE, arrE)
##           [,1]     [,2]      [,3]      [,4]      [,5]
## [1,] 1.0000713 0.362165 1.3950896 1.0575888 0.8554297
## [2,] 1.2102774 2.380369 1.2099352 1.2323062 0.9163945
## [3,] 1.9840728 2.637012 0.7439708 2.0910400 1.5803403
## [4,] 0.6862132 1.471726 0.7811089 0.4207357 0.5479476
DelayedTensor::einsum('ijk,ijk->jk', darrE, darrE)
## <4 x 5> HDF5Matrix object of type "double":
##           [,1]      [,2]      [,3]      [,4]      [,5]
## [1,] 1.0000713 0.3621650 1.3950896 1.0575888 0.8554297
## [2,] 1.2102774 2.3803693 1.2099352 1.2323062 0.9163945
## [3,] 1.9840728 2.6370118 0.7439708 2.0910400 1.5803403
## [4,] 0.6862132 1.4717263 0.7811089 0.4207357 0.5479476

Matrix Multiplication

Matrix Multiplication is considered a contracted product.

einsum::einsum('ij,jk->ik', arrC, t(arrC))
##           [,1]      [,2]     [,3]
## [1,] 1.3329298 0.5121599 1.347188
## [2,] 0.5121599 0.8457499 1.116710
## [3,] 1.3471881 1.1167100 2.269306
DelayedTensor::einsum('ij,jk->ik', darrC, t(darrC))
## <3 x 3> HDF5Matrix object of type "double":
##           [,1]      [,2]      [,3]
## [1,] 1.3329298 0.5121599 1.3471881
## [2,] 0.5121599 0.8457499 1.1167100
## [3,] 1.3471881 1.1167100 2.2693058

Multiplication + Permutation

Some examples of combining Multiplication and Permutation are shown below.

einsum::einsum('ij,ij->ji', arrC, arrC)
##            [,1]        [,2]      [,3]
## [1,] 0.72121317 0.009280119 0.6008341
## [2,] 0.47736994 0.021977483 0.1466043
## [3,] 0.01786815 0.046564698 0.6704777
## [4,] 0.11647858 0.767927624 0.8513898
DelayedTensor::einsum('ij,ij->ji', darrC, darrC)
## <4 x 3> HDF5Matrix object of type "double":
##             [,1]        [,2]        [,3]
## [1,] 0.721213169 0.009280119 0.600834109
## [2,] 0.477369940 0.021977483 0.146604254
## [3,] 0.017868151 0.046564698 0.670477693
## [4,] 0.116478580 0.767927624 0.851389755
einsum::einsum('ijk,ijk->jki', arrE, arrE)
## , , 1
## 
##            [,1]      [,2]       [,3]       [,4]      [,5]
## [1,] 0.28839588 0.1205989 0.73272604 0.23283056 0.1438317
## [2,] 0.75543857 0.5902524 0.81195859 0.08573651 0.1534383
## [3,] 0.98371704 0.9683614 0.04073608 0.71453283 0.6090906
## [4,] 0.06266787 0.8438519 0.29899886 0.18497306 0.1538957
## 
## , , 2
## 
##             [,1]       [,2]       [,3]      [,4]      [,5]
## [1,] 0.642841176 0.06491437 0.09106525 0.7876432 0.4688910
## [2,] 0.091131715 0.82345001 0.12657885 0.7238929 0.2072616
## [3,] 0.405639549 0.74962221 0.14186962 0.6050218 0.3038998
## [4,] 0.003894097 0.06635262 0.43348142 0.2188442 0.3840170
## 
## , , 3
## 
##            [,1]      [,2]       [,3]       [,4]       [,5]
## [1,] 0.06883429 0.1766518 0.57129835 0.03711502 0.24270695
## [2,] 0.36370709 0.9666669 0.27139775 0.42267678 0.55569461
## [3,] 0.59471626 0.9190282 0.56136512 0.77148544 0.66734990
## [4,] 0.61965128 0.5615218 0.04862862 0.01691843 0.01003491
DelayedTensor::einsum('ijk,ijk->jki', darrE, darrE)
## <4 x 5 x 3> HDF5Array object of type "double":
## ,,1
##            [,1]       [,2]       [,3]       [,4]       [,5]
## [1,] 0.28839588 0.12059887 0.73272604 0.23283056 0.14383174
## [2,] 0.75543857 0.59025239 0.81195859 0.08573651 0.15343827
## [3,] 0.98371704 0.96836137 0.04073608 0.71453283 0.60909057
## [4,] 0.06266787 0.84385188 0.29899886 0.18497306 0.15389569
## 
## ,,2
##             [,1]        [,2]        [,3]        [,4]        [,5]
## [1,] 0.642841176 0.064914370 0.091065250 0.787643203 0.468890952
## [2,] 0.091131715 0.823450006 0.126578854 0.723892928 0.207261612
## [3,] 0.405639549 0.749622211 0.141869625 0.605021767 0.303899802
## [4,] 0.003894097 0.066352621 0.433481417 0.218844210 0.384017031
## 
## ,,3
##            [,1]       [,2]       [,3]       [,4]       [,5]
## [1,] 0.06883429 0.17665178 0.57129835 0.03711502 0.24270695
## [2,] 0.36370709 0.96666687 0.27139775 0.42267678 0.55569461
## [3,] 0.59471626 0.91902821 0.56136512 0.77148544 0.66734990
## [4,] 0.61965128 0.56152182 0.04862862 0.01691843 0.01003491

Summation + Permutation

Some examples of combining Summation and Permutation are shown below.

einsum::einsum('ijk->ki', arrE)
##          [,1]     [,2]     [,3]
## [1,] 2.648345 1.802955 2.423802
## [2,] 3.018220 2.285622 3.111499
## [3,] 2.505721 1.692598 2.246563
## [4,] 2.050719 2.983951 1.851202
## [5,] 1.943701 2.310978 2.155192
DelayedTensor::einsum('ijk->ki', darrE)
## <5 x 3> HDF5Matrix object of type "double":
##          [,1]     [,2]     [,3]
## [1,] 2.648345 1.802955 2.423802
## [2,] 3.018220 2.285622 3.111499
## [3,] 2.505721 1.692598 2.246563
## [4,] 2.050719 2.983951 1.851202
## [5,] 1.943701 2.310978 2.155192

Multiplication + Summation + Permutation

Finally, we will show a more complex example, combining Multiplication, Summation, and Permutation.

einsum::einsum('i,ij,ijk,ijk,ji->jki',
    arrA, arrC, arrE, arrE, t(arrC))
## , , 1
## 
##              [,1]        [,2]         [,3]        [,4]        [,5]
## [1,] 0.0273024007 0.011417079 6.936708e-02 0.022042039 0.013616533
## [2,] 0.0473371778 0.036986306 5.087883e-02 0.005372408 0.009614726
## [3,] 0.0023072674 0.002271251 9.554478e-05 0.001675907 0.001428597
## [4,] 0.0009581624 0.012902101 4.571553e-03 0.002828152 0.002352993
## 
## , , 2
## 
##              [,1]         [,2]         [,3]        [,4]        [,5]
## [1,] 0.0020852421 0.0002105686 0.0002953966 0.002554950 0.001520984
## [2,] 0.0007000785 0.0063257850 0.0009723852 0.005560982 0.001592194
## [3,] 0.0066023161 0.0122010855 0.0023091144 0.009847523 0.004946368
## [4,] 0.0010452647 0.0178105615 0.1163563288 0.058742792 0.103078956
## 
## , , 3
## 
##            [,1]       [,2]       [,3]       [,4]        [,5]
## [1,] 0.03705506 0.09509567 0.30754289 0.01997986 0.130654670
## [2,] 0.04777344 0.12697305 0.03564847 0.05551919 0.072991266
## [3,] 0.35725826 0.55207911 0.33722355 0.46344714 0.400890783
## [4,] 0.47267639 0.42833464 0.03709441 0.01290555 0.007654732
DelayedTensor::einsum('i,ij,ijk,ijk,ji->jki',
    darrA, darrC, darrE, darrE, t(darrC))
## <4 x 5 x 3> HDF5Array object of type "double":
## ,,1
##              [,1]         [,2]         [,3]         [,4]         [,5]
## [1,] 2.730240e-02 1.141708e-02 6.936708e-02 2.204204e-02 1.361653e-02
## [2,] 4.733718e-02 3.698631e-02 5.087883e-02 5.372408e-03 9.614726e-03
## [3,] 2.307267e-03 2.271251e-03 9.554478e-05 1.675907e-03 1.428597e-03
## [4,] 9.581624e-04 1.290210e-02 4.571553e-03 2.828152e-03 2.352993e-03
## 
## ,,2
##              [,1]         [,2]         [,3]         [,4]         [,5]
## [1,] 0.0020852421 0.0002105686 0.0002953966 0.0025549495 0.0015209840
## [2,] 0.0007000785 0.0063257850 0.0009723852 0.0055609824 0.0015921943
## [3,] 0.0066023161 0.0122010855 0.0023091144 0.0098475235 0.0049463682
## [4,] 0.0010452647 0.0178105615 0.1163563288 0.0587427924 0.1030789560
## 
## ,,3
##             [,1]        [,2]        [,3]        [,4]        [,5]
## [1,] 0.037055062 0.095095666 0.307542888 0.019979859 0.130654670
## [2,] 0.047773435 0.126973048 0.035648475 0.055519187 0.072991266
## [3,] 0.357258265 0.552079112 0.337223550 0.463447141 0.400890783
## [4,] 0.472676391 0.428334639 0.037094415 0.012905553 0.007654732

Create your original function by einsum

By using einsum and other DelayedTensor functions, it is possible to implement your original tensor calculation functions. It is intended to be applied to Delayed Arrays, which can scale to large-scale data since the calculation is performed internally by block processing.

For example, kronecker can be easily implmented by eimsum and other DelayedTensor functions4 (the kronecker function inside DelayedTensor has a more efficient implementation though).

darr1 <- DelayedArray(array(1:6, dim=c(2,3)))
darr2 <- DelayedArray(array(20:1, dim=c(4,5)))

mykronecker <- function(darr1, darr2){
    stopifnot((length(dim(darr1)) == 2) && (length(dim(darr2)) == 2))
    # Outer Product
    tmpdarr <- DelayedTensor::einsum('ij,kl->ikjl', darr1, darr2)
    # Reshape
    DelayedTensor::unfold(tmpdarr, row_idx=c(2,1), col_idx=c(4,3))
}

identical(as.array(DelayedTensor::kronecker(darr1, darr2)),
    as.array(mykronecker(darr1, darr2)))
## [1] TRUE

Session information

## R version 4.4.1 (2024-06-14)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.1 LTS
## 
## Matrix products: default
## BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so;  LAPACK version 3.12.0
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=C              
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## time zone: Etc/UTC
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats4    stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] einsum_0.1.2              DelayedRandomArray_1.13.1
##  [3] HDF5Array_1.33.8          rhdf5_2.49.0             
##  [5] DelayedArray_0.31.14      SparseArray_1.5.45       
##  [7] S4Arrays_1.5.11           abind_1.4-8              
##  [9] IRanges_2.39.2            S4Vectors_0.43.2         
## [11] MatrixGenerics_1.17.1     matrixStats_1.4.1        
## [13] BiocGenerics_0.53.0       Matrix_1.7-1             
## [15] DelayedTensor_1.13.0      BiocStyle_2.35.0         
## 
## loaded via a namespace (and not attached):
##  [1] dqrng_0.4.1         sass_0.4.9          lattice_0.22-6     
##  [4] digest_0.6.37       evaluate_1.0.1      grid_4.4.1         
##  [7] fastmap_1.2.0       jsonlite_1.8.9      BiocManager_1.30.25
## [10] codetools_0.2-20    jquerylib_0.1.4     cli_3.6.3          
## [13] rlang_1.1.4         crayon_1.5.3        XVector_0.45.0     
## [16] cachem_1.1.0        yaml_2.3.10         tools_4.4.1        
## [19] beachmat_2.23.0     parallel_4.4.1      BiocParallel_1.39.0
## [22] Rhdf5lib_1.27.0     rsvd_1.0.5          buildtools_1.0.0   
## [25] R6_2.5.1            lifecycle_1.0.4     zlibbioc_1.51.2    
## [28] BiocSingular_1.23.0 irlba_2.3.5.1       ScaledMatrix_1.13.0
## [31] rTensor_1.4.8       bslib_0.8.0         Rcpp_1.0.13        
## [34] xfun_0.48           sys_3.4.3           knitr_1.48         
## [37] rhdf5filters_1.17.0 htmltools_0.5.8.1   rmarkdown_2.28     
## [40] maketools_1.3.1     compiler_4.4.1