4. Einsum operation by DelayedTensor

Authors: Koki Tsuyuzaki [aut, cre]
Last modified: 2024-11-29 05:23:18.287735
Compiled: Fri Nov 29 05:26:50 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.87833746 0.95288189 0.04162793
DelayedTensor::einsum('ii->i', darrB)
## <3> HDF5Array object of type "double":
##        [1]        [2]        [3] 
## 0.87833746 0.95288189 0.04162793
einsum::einsum('iii->i', arrD)
## [1] 0.3723635 0.1519632 0.8433396
DelayedTensor::einsum('iii->i', darrD)
## <3> HDF5Array object of type "double":
##       [1]       [2]       [3] 
## 0.3723635 0.1519632 0.8433396

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.0143276 0.7786923 0.1993659
DelayedTensor::einsum('i,i->i', darrA, darrA)
## <3> HDF5Array object of type "double":
##       [1]       [2]       [3] 
## 0.0143276 0.7786923 0.1993659
einsum::einsum('ij,ij->ij', arrC, arrC)
##            [,1]      [,2]       [,3]       [,4]
## [1,] 0.51079342 0.1140887 0.08618225 0.11498162
## [2,] 0.05110045 0.3442338 0.79707920 0.04041005
## [3,] 0.65320146 0.2591182 0.14305669 0.93854339
DelayedTensor::einsum('ij,ij->ij', darrC, darrC)
## <3 x 4> HDF5Matrix object of type "double":
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.51079342 0.11408866 0.08618225 0.11498162
## [2,] 0.05110045 0.34423378 0.79707920 0.04041005
## [3,] 0.65320146 0.25911820 0.14305669 0.93854339
einsum::einsum('ijk,ijk->ijk', arrE, arrE)
## , , 1
## 
##             [,1]      [,2]        [,3]       [,4]
## [1,] 0.138421767 0.1876757 0.941377743 0.07448060
## [2,] 0.002113167 0.5842229 0.925962387 0.69598138
## [3,] 0.002314747 0.8319880 0.009230184 0.07501034
## 
## , , 2
## 
##           [,1]      [,2]       [,3]       [,4]
## [1,] 0.6427500 0.1489617 0.46982646 0.07162753
## [2,] 0.2150947 0.6972218 0.00549716 0.07313118
## [3,] 0.5574447 0.1419674 0.91705433 0.66760747
## 
## , , 3
## 
##            [,1]      [,2]      [,3]      [,4]
## [1,] 0.04734462 0.4161923 0.6584371 0.5829399
## [2,] 0.11718186 0.1485920 0.1050795 0.6697690
## [3,] 0.85409222 0.3934960 0.3944669 0.9140870
## 
## , , 4
## 
##            [,1]       [,2]       [,3]      [,4]
## [1,] 0.01335701 0.93999938 0.47773711 0.7388852
## [2,] 0.59419049 0.09386514 0.09641891 0.6409954
## [3,] 0.51061884 0.06649973 0.28825773 0.5869033
## 
## , , 5
## 
##             [,1]       [,2]       [,3]       [,4]
## [1,] 0.895960307 0.01478386 0.01241065 0.31816261
## [2,] 0.033600367 0.02940391 0.01692806 0.71114574
## [3,] 0.005373272 0.39129208 0.01549741 0.06351789
DelayedTensor::einsum('ijk,ijk->ijk', darrE, darrE)
## <3 x 4 x 5> HDF5Array object of type "double":
## ,,1
##             [,1]        [,2]        [,3]        [,4]
## [1,] 0.138421767 0.187675672 0.941377743 0.074480595
## [2,] 0.002113167 0.584222855 0.925962387 0.695981380
## [3,] 0.002314747 0.831988011 0.009230184 0.075010342
## 
## ,,2
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.64275002 0.14896174 0.46982646 0.07162753
## [2,] 0.21509472 0.69722175 0.00549716 0.07313118
## [3,] 0.55744467 0.14196740 0.91705433 0.66760747
## 
## ,,3
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.04734462 0.41619229 0.65843713 0.58293992
## [2,] 0.11718186 0.14859203 0.10507950 0.66976900
## [3,] 0.85409222 0.39349601 0.39446693 0.91408703
## 
## ,,4
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.01335701 0.93999938 0.47773711 0.73888520
## [2,] 0.59419049 0.09386514 0.09641891 0.64099540
## [3,] 0.51061884 0.06649973 0.28825773 0.58690329
## 
## ,,5
##             [,1]        [,2]        [,3]        [,4]
## [1,] 0.895960307 0.014783863 0.012410650 0.318162608
## [2,] 0.033600367 0.029403906 0.016928058 0.711145741
## [3,] 0.005373272 0.391292078 0.015497410 0.063517885

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.01432760 0.1056257 0.05344563
## [2,] 0.10562571 0.7786923 0.39401104
## [3,] 0.05344563 0.3940110 0.19936593
DelayedTensor::einsum('i,j->ij', darrA, darrA)
## <3 x 3> HDF5Matrix object of type "double":
##            [,1]       [,2]       [,3]
## [1,] 0.01432760 0.10562571 0.05344563
## [2,] 0.10562571 0.77869225 0.39401104
## [3,] 0.05344563 0.39401104 0.19936593
einsum::einsum('ij,klm->ijklm', arrC, arrE)
## , , 1, 1, 1
## 
##           [,1]      [,2]      [,3]       [,4]
## [1,] 0.2659040 0.1256676 0.1092222 0.12615847
## [2,] 0.0841036 0.2182875 0.3321643 0.07479058
## [3,] 0.3006947 0.1893874 0.1407201 0.36043701
## 
## , , 2, 1, 1
## 
##            [,1]       [,2]       [,3]        [,4]
## [1,] 0.03285410 0.01552702 0.01349509 0.015587667
## [2,] 0.01039152 0.02697079 0.04104097 0.009240844
## [3,] 0.03715271 0.02340000 0.01738685 0.044534244
## 
## , , 3, 1, 1
## 
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.03438543 0.01625074 0.01412410 0.01631421
## [2,] 0.01087587 0.02822790 0.04295389 0.00967156
## [3,] 0.03888440 0.02449067 0.01819726 0.04660999
## 
## , , 1, 2, 1
## 
##            [,1]      [,2]      [,3]       [,4]
## [1,] 0.30961831 0.1463273 0.1271783 0.14689878
## [2,] 0.09793014 0.2541738 0.3867717 0.08708607
## [3,] 0.35012858 0.2205225 0.1638544 0.41969246
## 
## , , 2, 2, 1
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.5462757 0.2581728 0.2243873 0.2591812
## [2,] 0.1727833 0.4484520 0.6824016 0.1536505
## [3,] 0.6177501 0.3890794 0.2890969 0.7404853
## 
## , , 3, 2, 1
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.6519003 0.3080915 0.2677734 0.3092949
## [2,] 0.2061916 0.5351620 0.8143466 0.1833594
## [3,] 0.7371945 0.4643094 0.3449949 0.8836611
## 
## , , 1, 3, 1
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.6934332 0.3277202 0.2848334 0.3290002
## [2,] 0.2193281 0.5692574 0.8662290 0.1950413
## [3,] 0.7841615 0.4938908 0.3669746 0.9399595
## 
## , , 2, 3, 1
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.6877321 0.3250259 0.2824916 0.3262953
## [2,] 0.2175249 0.5645773 0.8591073 0.1934378
## [3,] 0.7777146 0.4898303 0.3639576 0.9322317
## 
## , , 3, 3, 1
## 
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.06866380 0.03245088 0.02820422 0.03257762
## [2,] 0.02171789 0.05636791 0.08577405 0.01931301
## [3,] 0.07764773 0.04890510 0.03633785 0.09307485
## 
## , , 1, 4, 1
## 
##            [,1]      [,2]       [,3]       [,4]
## [1,] 0.19504922 0.0921813 0.08011807 0.09254134
## [2,] 0.06169272 0.1601210 0.24365331 0.05486132
## [3,] 0.22056934 0.1389218 0.10322281 0.26439227
## 
## , , 2, 4, 1
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.5962405 0.2817864 0.2449107 0.2828870
## [2,] 0.1885868 0.4894694 0.7448169 0.1677040
## [3,] 0.6742522 0.4246663 0.3155389 0.8082133
## 
## , , 3, 4, 1
## 
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.19574164 0.09250854 0.08040249 0.09286986
## [2,] 0.06191173 0.16068943 0.24451827 0.05505608
## [3,] 0.22135235 0.13941501 0.10358924 0.26533085
## 
## , , 1, 1, 2
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.5729856 0.2707960 0.2353585 0.2718537
## [2,] 0.1812314 0.4703789 0.7157672 0.1611632
## [3,] 0.6479547 0.4081032 0.3032321 0.7766909
## 
## , , 2, 1, 2
## 
##           [,1]      [,2]      [,3]       [,4]
## [1,] 0.3314649 0.1566521 0.1361519 0.15726391
## [2,] 0.1048401 0.2721082 0.4140622 0.09323084
## [3,] 0.3748335 0.2360825 0.1754159 0.44930583
## 
## , , 3, 1, 2
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.5336095 0.2521867 0.2191845 0.2531717
## [2,] 0.1687770 0.4380540 0.6665790 0.1500879
## [3,] 0.6034266 0.3800580 0.2823937 0.7233160
## 
## , , 1, 2, 2
## 
##            [,1]      [,2]      [,3]       [,4]
## [1,] 0.27584176 0.1303643 0.1133043 0.13087345
## [2,] 0.08724685 0.2264457 0.3445784 0.07758577
## [3,] 0.31193272 0.1964655 0.1459794 0.37390781
## 
## , , 2, 2, 2
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.5967716 0.2820374 0.2451288 0.2831390
## [2,] 0.1887547 0.4899054 0.7454804 0.1678534
## [3,] 0.6748528 0.4250445 0.3158199 0.8089332
## 
## , , 3, 2, 2
## 
##            [,1]      [,2]      [,3]       [,4]
## [1,] 0.26928797 0.1272669 0.1106123 0.12776400
## [2,] 0.08517393 0.2210655 0.3363915 0.07574239
## [3,] 0.30452144 0.1917976 0.1425110 0.36502406
## 
## , , 1, 3, 2
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.4898819 0.2315208 0.2012230 0.2324251
## [2,] 0.1549463 0.4021569 0.6119550 0.1377887
## [3,] 0.5539777 0.3489134 0.2592524 0.6640426
## 
## , , 2, 3, 2
## 
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.05298975 0.02504324 0.02176597 0.02514105
## [2,] 0.01676029 0.04350067 0.06619420 0.01490438
## [3,] 0.05992289 0.03774141 0.02804292 0.07182843
## 
## , , 3, 3, 2
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.6844160 0.3234587 0.2811295 0.3247220
## [2,] 0.2164761 0.5618550 0.8549649 0.1925051
## [3,] 0.7739646 0.4874684 0.3622027 0.9277366
## 
## , , 1, 4, 2
## 
##            [,1]      [,2]       [,3]       [,4]
## [1,] 0.19127695 0.0903985 0.07856858 0.09075158
## [2,] 0.06049958 0.1570243 0.23894103 0.05380030
## [3,] 0.21630351 0.1362351 0.10122647 0.25927890
## 
## , , 2, 4, 2
## 
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.19327422 0.09134242 0.07938898 0.09169919
## [2,] 0.06113131 0.15866387 0.24143600 0.05436207
## [3,] 0.21856210 0.13765762 0.10228345 0.26198623
## 
## , , 3, 4, 2
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.5839602 0.2759827 0.2398665 0.2770606
## [2,] 0.1847026 0.4793882 0.7294765 0.1642500
## [3,] 0.6603652 0.4159198 0.3090400 0.7915672
## 
## , , 1, 1, 3
## 
##           [,1]       [,2]       [,3]       [,4]
## [1,] 0.1555099 0.07349479 0.06387696 0.07378185
## [2,] 0.0491867 0.12766213 0.19426120 0.04374013
## [3,] 0.1758567 0.11076034 0.08229803 0.21079607
## 
## , , 2, 1, 3
## 
##            [,1]      [,2]      [,3]      [,4]
## [1,] 0.24465430 0.1156249 0.1004938 0.1160765
## [2,] 0.07738247 0.2008431 0.3056194 0.0688137
## [3,] 0.27666471 0.1742526 0.1294745 0.3316327
## 
## , , 3, 1, 3
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.6605034 0.3121574 0.2713072 0.3133766
## [2,] 0.2089127 0.5422245 0.8250934 0.1857792
## [3,] 0.7469232 0.4704369 0.3495477 0.8953226
## 
## , , 1, 2, 3
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.4610730 0.2179055 0.1893895 0.2187566
## [2,] 0.1458342 0.3785069 0.5759672 0.1296856
## [3,] 0.5213995 0.3283946 0.2440063 0.6249916
## 
## , , 2, 2, 3
## 
##            [,1]      [,2]      [,3]       [,4]
## [1,] 0.27549924 0.1302024 0.1131636 0.13071095
## [2,] 0.08713851 0.2261645 0.3441506 0.07748943
## [3,] 0.31154539 0.1962216 0.1457981 0.37344353
## 
## , , 3, 2, 3
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.4483249 0.2118807 0.1841531 0.2127083
## [2,] 0.1418021 0.3680416 0.5600424 0.1260999
## [3,] 0.5069834 0.3193149 0.2372599 0.6077113
## 
## , , 1, 3, 3
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.5799356 0.2740807 0.2382133 0.2751512
## [2,] 0.1834297 0.4760843 0.7244491 0.1631180
## [3,] 0.6558141 0.4130533 0.3069101 0.7861118
## 
## , , 2, 3, 3
## 
##            [,1]      [,2]       [,3]      [,4]
## [1,] 0.23167632 0.1094915 0.09516295 0.1099191
## [2,] 0.07327762 0.1901891 0.28940746 0.0651634
## [3,] 0.26198870 0.1650091 0.12260638 0.3140409
## 
## , , 3, 3, 3
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.4488776 0.2121419 0.1843802 0.2129705
## [2,] 0.1419769 0.3684954 0.5607329 0.1262554
## [3,] 0.5076085 0.3197086 0.2375524 0.6084606
## 
## , , 1, 4, 3
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.5456756 0.2578892 0.2241408 0.2588965
## [2,] 0.1725934 0.4479594 0.6816519 0.1534817
## [3,] 0.6170715 0.3886520 0.2887793 0.7396718
## 
## , , 2, 4, 3
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.5849048 0.2764291 0.2402545 0.2775088
## [2,] 0.1850014 0.4801636 0.7306565 0.1645157
## [3,] 0.6614334 0.4165925 0.3095399 0.7928476
## 
## , , 3, 4, 3
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.6833079 0.3229349 0.2806743 0.3241962
## [2,] 0.2161256 0.5609453 0.8535806 0.1921934
## [3,] 0.7727114 0.4866791 0.3616162 0.9262345
## 
## , , 1, 1, 4
## 
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.08259947 0.03903695 0.03392841 0.03918942
## [2,] 0.02612564 0.06780806 0.10318233 0.02323268
## [3,] 0.09340673 0.05883064 0.04371281 0.11196487
## 
## , , 2, 1, 4
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.5509161 0.2603659 0.2262933 0.2613828
## [2,] 0.1742510 0.4522615 0.6881983 0.1549557
## [3,] 0.6229977 0.3923845 0.2915526 0.7467754
## 
## , , 3, 1, 4
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.5107061 0.2413624 0.2097767 0.2423051
## [2,] 0.1615328 0.4192520 0.6379684 0.1436459
## [3,] 0.5775266 0.3637453 0.2702729 0.6922701
## 
## , , 1, 2, 4
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.6929253 0.3274802 0.2846248 0.3287593
## [2,] 0.2191675 0.5688405 0.8655946 0.1948985
## [3,] 0.7835872 0.4935291 0.3667059 0.9392711
## 
## , , 2, 2, 4
## 
##            [,1]      [,2]      [,3]       [,4]
## [1,] 0.21896506 0.1034840 0.0899417 0.10388824
## [2,] 0.06925714 0.1797541 0.2735287 0.06158811
## [3,] 0.24761431 0.1559557 0.1158794 0.29681056
## 
## , , 3, 2, 4
## 
##           [,1]       [,2]       [,3]       [,4]
## [1,] 0.1843031 0.08710261 0.07570401 0.08744282
## [2,] 0.0582938 0.15129922 0.23022935 0.05183877
## [3,] 0.2084172 0.13126801 0.09753580 0.24982571
## 
## , , 1, 3, 4
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.4939888 0.2334617 0.2029100 0.2343736
## [2,] 0.1562453 0.4055284 0.6170853 0.1389438
## [3,] 0.5586220 0.3518386 0.2614259 0.6696096
## 
## , , 2, 3, 4
## 
##            [,1]      [,2]      [,3]       [,4]
## [1,] 0.22192373 0.1048823 0.0911570 0.10529198
## [2,] 0.07019295 0.1821830 0.2772246 0.06242029
## [3,] 0.25096010 0.1580629 0.1174452 0.30082109
## 
## , , 3, 3, 4
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.3837188 0.1813476 0.1576157 0.1820559
## [2,] 0.1213676 0.3150048 0.4793373 0.1079283
## [3,] 0.4339244 0.2732999 0.2030694 0.5201369
## 
## , , 1, 4, 4
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.6143433 0.2903419 0.2523466 0.2914759
## [2,] 0.1943126 0.5043305 0.7674308 0.1727958
## [3,] 0.6947236 0.4375598 0.3251192 0.8327520
## 
## , , 2, 4, 4
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.5722030 0.2704262 0.2350371 0.2714824
## [2,] 0.1809839 0.4697364 0.7147895 0.1609430
## [3,] 0.6470696 0.4075458 0.3028179 0.7756301
## 
## , , 3, 4, 4
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.5475275 0.2587644 0.2249014 0.2597751
## [2,] 0.1731792 0.4494796 0.6839652 0.1540026
## [3,] 0.6191656 0.3899709 0.2897593 0.7421821
## 
## , , 1, 1, 5
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.6764988 0.3197169 0.2778775 0.3209657
## [2,] 0.2139719 0.5553556 0.8450747 0.1902782
## [3,] 0.7650115 0.4818294 0.3580127 0.9170047
## 
## , , 2, 1, 5
## 
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.13100705 0.06191463 0.05381222 0.06215645
## [2,] 0.04143663 0.10754711 0.16365254 0.03684824
## [3,] 0.14814793 0.09330845 0.06933078 0.17758210
## 
## , , 3, 1, 5
## 
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.05238924 0.02475943 0.02151931 0.02485614
## [2,] 0.01657035 0.04300769 0.06544405 0.01473547
## [3,] 0.05924381 0.03731370 0.02772512 0.07101443
## 
## , , 1, 2, 5
## 
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.08689937 0.04106910 0.03569463 0.04122951
## [2,] 0.02748567 0.07133796 0.10855372 0.02444211
## [3,] 0.09826923 0.06189320 0.04598837 0.11779345
## 
## , , 2, 2, 5
## 
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.12255334 0.05791936 0.05033979 0.05814558
## [2,] 0.03876278 0.10060724 0.15309227 0.03447047
## [3,] 0.13858815 0.08728738 0.06485696 0.16612297
## 
## , , 3, 2, 5
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.4470676 0.2112865 0.1836367 0.2121118
## [2,] 0.1414044 0.3670095 0.5584718 0.1257463
## [3,] 0.5055616 0.3184194 0.2365945 0.6060071
## 
## , , 1, 3, 5
## 
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.07961958 0.03762864 0.03270440 0.03777561
## [2,] 0.02518313 0.06536180 0.09945989 0.02239453
## [3,] 0.09003696 0.05670825 0.04213581 0.10792559
## 
## , , 2, 3, 5
## 
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.09298785 0.04394655 0.03819553 0.04411820
## [2,] 0.02941142 0.07633616 0.11615938 0.02615461
## [3,] 0.10515432 0.06622966 0.04921049 0.12604649
## 
## , , 3, 3, 5
## 
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.08897177 0.04204853 0.03654589 0.04221276
## [2,] 0.02814116 0.07303925 0.11114254 0.02502501
## [3,] 0.10061278 0.06336924 0.04708512 0.12060262
## 
## , , 1, 4, 5
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.4031319 0.1905223 0.1655898 0.1912664
## [2,] 0.1275079 0.3309416 0.5035879 0.1133886
## [3,] 0.4558775 0.2871267 0.2133431 0.5464517
## 
## , , 2, 4, 5
## 
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.6027011 0.2848397 0.2475644 0.2859522
## [2,] 0.1906302 0.4947731 0.7528874 0.1695212
## [3,] 0.6815581 0.4292678 0.3189579 0.8169707
## 
## , , 3, 4, 5
## 
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.18012362 0.08512738 0.07398726 0.08545987
## [2,] 0.05697186 0.14786819 0.22500841 0.05066321
## [3,] 0.20369088 0.12829123 0.09532397 0.24416038
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.26590398 0.12566763 0.10922225 0.12615847
## [2,] 0.08410360 0.21828753 0.33216428 0.07479058
## [3,] 0.30069469 0.18938743 0.14072015 0.36043701
## 
## ,,2,1,1
##             [,1]        [,2]        [,3]        [,4]
## [1,] 0.032854098 0.015527021 0.013495091 0.015587667
## [2,] 0.010391525 0.026970789 0.041040972 0.009240844
## [3,] 0.037152708 0.023400000 0.017386853 0.044534244
## 
## ,,3,1,1
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.03438543 0.01625074 0.01412410 0.01631421
## [2,] 0.01087587 0.02822790 0.04295389 0.00967156
## [3,] 0.03888440 0.02449067 0.01819726 0.04660999
## 
## ...
## 
## ,,1,4,5
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.4031319 0.1905223 0.1655898 0.1912664
## [2,] 0.1275079 0.3309416 0.5035879 0.1133886
## [3,] 0.4558775 0.2871267 0.2133431 0.5464517
## 
## ,,2,4,5
##           [,1]      [,2]      [,3]      [,4]
## [1,] 0.6027011 0.2848397 0.2475644 0.2859522
## [2,] 0.1906302 0.4947731 0.7528874 0.1695212
## [3,] 0.6815581 0.4292678 0.3189579 0.8169707
## 
## ,,3,4,5
##            [,1]       [,2]       [,3]       [,4]
## [1,] 0.18012362 0.08512738 0.07398726 0.08545987
## [2,] 0.05697186 0.14786819 0.22500841 0.05066321
## [3,] 0.20369088 0.12829123 0.09532397 0.24416038

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.448637
DelayedTensor::einsum('i->', darrA)
## <1> HDF5Array object of type "double":
##      [1] 
## 1.448637
einsum::einsum('ij->', arrC)
## [1] 6.255968
DelayedTensor::einsum('ij->', darrC)
## <1> HDF5Array object of type "double":
##      [1] 
## 6.255968
einsum::einsum('ijk->', arrE)
## [1] 31.3581
DelayedTensor::einsum('ijk->', darrE)
## <1> HDF5Array object of type "double":
##     [1] 
## 31.3581

Row-wise / Column-wise Summation

einsum::einsum('ij->i', arrC)
## [1] 1.685126 1.906584 2.664258
DelayedTensor::einsum('ij->i', darrC)
## <3> HDF5Array object of type "double":
##      [1]      [2]      [3] 
## 1.685126 1.906584 2.664258
einsum::einsum('ij->j', arrC)
## [1] 1.748961 1.433521 1.564589 1.508896
DelayedTensor::einsum('ij->j', darrC)
## <4> HDF5Array object of type "double":
##      [1]      [2]      [3]      [4] 
## 1.748961 1.433521 1.564589 1.508896

Mode-wise Vectorization

einsum::einsum('ijk->i', arrE)
## [1] 11.006313  9.637068 10.714714
DelayedTensor::einsum('ijk->i', darrE)
## <3> HDF5Array object of type "double":
##       [1]       [2]       [3] 
## 11.006313  9.637068 10.714714
einsum::einsum('ijk->j', arrE)
## [1] 6.766476 7.817715 7.414063 9.359842
DelayedTensor::einsum('ijk->j', darrE)
## <4> HDF5Array object of type "double":
##      [1]      [2]      [3]      [4] 
## 6.766476 7.817715 7.414063 9.359842
einsum::einsum('ijk->k', arrE)
## [1] 5.985462 6.682206 7.443622 7.099669 4.147137
DelayedTensor::einsum('ijk->k', darrE)
## <5> HDF5Array object of type "double":
##      [1]      [2]      [3]      [4]      [5] 
## 5.985462 6.682206 7.443622 7.099669 4.147137

Mode-wise Summation

These are the same as what the modeSum function does.

einsum::einsum('ijk->ij', arrE)
##          [,1]     [,2]     [,3]     [,4]
## [1,] 2.453480 2.555425 3.269715 2.727693
## [2,] 1.806212 2.462669 1.801194 3.566993
## [3,] 2.506784 2.799621 2.343154 3.065155
DelayedTensor::einsum('ijk->ij', darrE)
## <3 x 4> HDF5Matrix object of type "double":
##          [,1]     [,2]     [,3]     [,4]
## [1,] 2.453480 2.555425 3.269715 2.727693
## [2,] 1.806212 2.462669 1.801194 3.566993
## [3,] 2.506784 2.799621 2.343154 3.065155
einsum::einsum('ijk->jk', arrE)
##           [,1]     [,2]     [,3]     [,4]      [,5]
## [1,] 0.4661318 2.012122 1.484078 1.600986 1.2031584
## [2,] 2.1096940 1.597739 1.657899 1.533785 0.9185980
## [3,] 2.0285895 1.717211 1.763667 1.538596 0.3659996
## [4,] 1.3810465 1.355133 2.537978 2.426302 1.6593812
DelayedTensor::einsum('ijk->jk', darrE)
## <4 x 5> HDF5Matrix object of type "double":
##           [,1]      [,2]      [,3]      [,4]      [,5]
## [1,] 0.4661318 2.0121221 1.4840777 1.6009860 1.2031584
## [2,] 2.1096940 1.5977393 1.6578986 1.5337853 0.9185980
## [3,] 2.0285895 1.7172113 1.7636671 1.5385956 0.3659996
## [4,] 1.3810465 1.3551335 2.5379782 2.4263023 1.6593812
einsum::einsum('ijk->jk', arrE)
##           [,1]     [,2]     [,3]     [,4]      [,5]
## [1,] 0.4661318 2.012122 1.484078 1.600986 1.2031584
## [2,] 2.1096940 1.597739 1.657899 1.533785 0.9185980
## [3,] 2.0285895 1.717211 1.763667 1.538596 0.3659996
## [4,] 1.3810465 1.355133 2.537978 2.426302 1.6593812
DelayedTensor::einsum('ijk->jk', darrE)
## <4 x 5> HDF5Matrix object of type "double":
##           [,1]      [,2]      [,3]      [,4]      [,5]
## [1,] 0.4661318 2.0121221 1.4840777 1.6009860 1.2031584
## [2,] 2.1096940 1.5977393 1.6578986 1.5337853 0.9185980
## [3,] 2.0285895 1.7172113 1.7636671 1.5385956 0.3659996
## [4,] 1.3810465 1.3551335 2.5379782 2.4263023 1.6593812

Trace

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

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

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.878337464 0.2130384 0.52067172
## [2,] 0.185278674 0.9528819 0.41732610
## [3,] 0.005395071 0.2310469 0.04162793
DelayedTensor::einsum('ij->ji', darrB)
## <3 x 3> DelayedArray object of type "double":
##             [,1]        [,2]        [,3]
## [1,] 0.878337464 0.213038433 0.520671722
## [2,] 0.185278674 0.952881891 0.417326099
## [3,] 0.005395071 0.231046915 0.041627934
einsum::einsum('ijk->jki', arrD)
## , , 1
## 
##            [,1]      [,2]       [,3]
## [1,] 0.37236352 0.4841336 0.07565263
## [2,] 0.72245768 0.5532722 0.93052505
## [3,] 0.05307618 0.2398505 0.16660815
## 
## , , 2
## 
##           [,1]      [,2]      [,3]
## [1,] 0.4271631 0.1496809 0.2175493
## [2,] 0.4841257 0.1519632 0.3462851
## [3,] 0.6352684 0.1872890 0.4820649
## 
## , , 3
## 
##           [,1]      [,2]      [,3]
## [1,] 0.2864091 0.1543501 0.2691419
## [2,] 0.5465661 0.6793850 0.9268438
## [3,] 0.1355242 0.6185573 0.8433396
DelayedTensor::einsum('ijk->jki', darrD)
## <3 x 3 x 3> DelayedArray object of type "double":
## ,,1
##            [,1]       [,2]       [,3]
## [1,] 0.37236352 0.48413357 0.07565263
## [2,] 0.72245768 0.55327219 0.93052505
## [3,] 0.05307618 0.23985048 0.16660815
## 
## ,,2
##           [,1]      [,2]      [,3]
## [1,] 0.4271631 0.1496809 0.2175493
## [2,] 0.4841257 0.1519632 0.3462851
## [3,] 0.6352684 0.1872890 0.4820649
## 
## ,,3
##           [,1]      [,2]      [,3]
## [1,] 0.2864091 0.1543501 0.2691419
## [2,] 0.5465661 0.6793850 0.9268438
## [3,] 0.1355242 0.6185573 0.8433396

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.9923858
DelayedTensor::einsum('i,i->', darrA, darrA)
## <1> HDF5Array object of type "double":
##       [1] 
## 0.9923858
einsum::einsum('ij,ij->', arrC, arrC)
## [1] 4.052789
DelayedTensor::einsum('ij,ij->', darrC, darrC)
## <1> HDF5Array object of type "double":
##      [1] 
## 4.052789
einsum::einsum('ijk,ijk->', arrE, arrE)
## [1] 21.93445
DelayedTensor::einsum('ijk,ijk->', darrE, darrE)
## <1> HDF5Array object of type "double":
##      [1] 
## 21.93445

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,] 0.1428497 1.4152894 1.0186187 1.1181663 0.93493395
## [2,] 1.6038865 0.9881509 0.9582803 1.1003643 0.43547985
## [3,] 1.8765703 1.3923780 1.1579836 0.8624137 0.04483612
## [4,] 0.8454723 0.8123662 2.1667960 1.9667839 1.09282623
DelayedTensor::einsum('ijk,ijk->jk', darrE, darrE)
## <4 x 5> HDF5Matrix object of type "double":
##            [,1]       [,2]       [,3]       [,4]       [,5]
## [1,] 0.14284968 1.41528941 1.01861870 1.11816634 0.93493395
## [2,] 1.60388654 0.98815088 0.95828033 1.10036425 0.43547985
## [3,] 1.87657031 1.39237795 1.15798355 0.86241374 0.04483612
## [4,] 0.84547232 0.81236618 2.16679596 1.96678388 1.09282623

Matrix Multiplication

Matrix Multiplication is considered a contracted product.

einsum::einsum('ij,jk->ik', arrC, t(arrC))
##           [,1]      [,2]     [,3]
## [1,] 0.8260460 0.6899952 1.189103
## [2,] 0.6899952 1.2328235 1.013785
## [3,] 1.1891030 1.0137851 1.993920
DelayedTensor::einsum('ij,jk->ik', darrC, t(darrC))
## <3 x 3> HDF5Matrix object of type "double":
##           [,1]      [,2]      [,3]
## [1,] 0.8260460 0.6899952 1.1891030
## [2,] 0.6899952 1.2328235 1.0137851
## [3,] 1.1891030 1.0137851 1.9939197

Multiplication + Permutation

Some examples of combining Multiplication and Permutation are shown below.

einsum::einsum('ij,ij->ji', arrC, arrC)
##            [,1]       [,2]      [,3]
## [1,] 0.51079342 0.05110045 0.6532015
## [2,] 0.11408866 0.34423378 0.2591182
## [3,] 0.08618225 0.79707920 0.1430567
## [4,] 0.11498162 0.04041005 0.9385434
DelayedTensor::einsum('ij,ij->ji', darrC, darrC)
## <4 x 3> HDF5Matrix object of type "double":
##            [,1]       [,2]       [,3]
## [1,] 0.51079342 0.05110045 0.65320146
## [2,] 0.11408866 0.34423378 0.25911820
## [3,] 0.08618225 0.79707920 0.14305669
## [4,] 0.11498162 0.04041005 0.93854339
einsum::einsum('ijk,ijk->jki', arrE, arrE)
## , , 1
## 
##           [,1]       [,2]       [,3]       [,4]       [,5]
## [1,] 0.1384218 0.64275002 0.04734462 0.01335701 0.89596031
## [2,] 0.1876757 0.14896174 0.41619229 0.93999938 0.01478386
## [3,] 0.9413777 0.46982646 0.65843713 0.47773711 0.01241065
## [4,] 0.0744806 0.07162753 0.58293992 0.73888520 0.31816261
## 
## , , 2
## 
##             [,1]       [,2]      [,3]       [,4]       [,5]
## [1,] 0.002113167 0.21509472 0.1171819 0.59419049 0.03360037
## [2,] 0.584222855 0.69722175 0.1485920 0.09386514 0.02940391
## [3,] 0.925962387 0.00549716 0.1050795 0.09641891 0.01692806
## [4,] 0.695981380 0.07313118 0.6697690 0.64099540 0.71114574
## 
## , , 3
## 
##             [,1]      [,2]      [,3]       [,4]        [,5]
## [1,] 0.002314747 0.5574447 0.8540922 0.51061884 0.005373272
## [2,] 0.831988011 0.1419674 0.3934960 0.06649973 0.391292078
## [3,] 0.009230184 0.9170543 0.3944669 0.28825773 0.015497410
## [4,] 0.075010342 0.6676075 0.9140870 0.58690329 0.063517885
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.13842177 0.64275002 0.04734462 0.01335701 0.89596031
## [2,] 0.18767567 0.14896174 0.41619229 0.93999938 0.01478386
## [3,] 0.94137774 0.46982646 0.65843713 0.47773711 0.01241065
## [4,] 0.07448060 0.07162753 0.58293992 0.73888520 0.31816261
## 
## ,,2
##             [,1]        [,2]        [,3]        [,4]        [,5]
## [1,] 0.002113167 0.215094717 0.117181863 0.594190488 0.033600367
## [2,] 0.584222855 0.697221753 0.148592031 0.093865142 0.029403906
## [3,] 0.925962387 0.005497160 0.105079496 0.096418906 0.016928058
## [4,] 0.695981380 0.073131180 0.669769003 0.640995397 0.711145741
## 
## ,,3
##             [,1]        [,2]        [,3]        [,4]        [,5]
## [1,] 0.002314747 0.557444670 0.854092216 0.510618841 0.005373272
## [2,] 0.831988011 0.141967396 0.393496008 0.066499732 0.391292078
## [3,] 0.009230184 0.917054327 0.394466929 0.288257727 0.015497410
## [4,] 0.075010342 0.667607468 0.914087033 0.586903289 0.063517885

Summation + Permutation

Some examples of combining Summation and Permutation are shown below.

einsum::einsum('ijk->ki', arrE)
##          [,1]     [,2]     [,3]
## [1,] 2.048424 2.606838 1.330200
## [2,] 2.140745 1.643352 2.898110
## [3,] 2.437664 1.870349 3.135609
## [4,] 2.635878 2.188348 2.275444
## [5,] 1.743603 1.328182 1.075352
DelayedTensor::einsum('ijk->ki', darrE)
## <5 x 3> HDF5Matrix object of type "double":
##          [,1]     [,2]     [,3]
## [1,] 2.048424 2.606838 1.330200
## [2,] 2.140745 1.643352 2.898110
## [3,] 2.437664 1.870349 3.135609
## [4,] 2.635878 2.188348 2.275444
## [5,] 1.743603 1.328182 1.075352

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.008463235 0.0392983307 0.002894694 0.0008166598 0.0547798419
## [2,] 0.002562933 0.0020342481 0.005683596 0.0128367997 0.0002018911
## [3,] 0.009711101 0.0048466541 0.006792331 0.0049282591 0.0001280263
## [4,] 0.001025081 0.0009858143 0.008023039 0.0101693239 0.0043788922
## 
## , , 2
## 
##              [,1]        [,2]        [,3]       [,4]        [,5]
## [1,] 9.528872e-05 0.009699234 0.005284064 0.02679374 0.001515136
## [2,] 1.774659e-01 0.211790921 0.045136921 0.02851286 0.008931850
## [3,] 6.512950e-01 0.003866543 0.073909860 0.06781825 0.011906703
## [4,] 2.481818e-02 0.002607804 0.023883469 0.02285742 0.025358933
## 
## , , 3
## 
##              [,1]       [,2]       [,3]        [,4]         [,5]
## [1,] 0.0006751126 0.16258272 0.24910209 0.148925631 0.0015671531
## [2,] 0.0962588010 0.01642525 0.04552644 0.007693842 0.0452714532
## [3,] 0.0005895817 0.05857721 0.02519673 0.018412578 0.0009899033
## [4,] 0.0314340958 0.27976992 0.38306050 0.245949741 0.0266180268
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,] 0.0084632349 0.0392983307 0.0028946940 0.0008166598 0.0547798419
## [2,] 0.0025629325 0.0020342481 0.0056835963 0.0128367997 0.0002018911
## [3,] 0.0097111012 0.0048466541 0.0067923314 0.0049282591 0.0001280263
## [4,] 0.0010250812 0.0009858143 0.0080230392 0.0101693239 0.0043788922
## 
## ,,2
##              [,1]         [,2]         [,3]         [,4]         [,5]
## [1,] 9.528872e-05 9.699234e-03 5.284064e-03 2.679374e-02 1.515136e-03
## [2,] 1.774659e-01 2.117909e-01 4.513692e-02 2.851286e-02 8.931850e-03
## [3,] 6.512950e-01 3.866543e-03 7.390986e-02 6.781825e-02 1.190670e-02
## [4,] 2.481818e-02 2.607804e-03 2.388347e-02 2.285742e-02 2.535893e-02
## 
## ,,3
##              [,1]         [,2]         [,3]         [,4]         [,5]
## [1,] 0.0006751126 0.1625827183 0.2491020931 0.1489256308 0.0015671531
## [2,] 0.0962588010 0.0164252503 0.0455264420 0.0076938422 0.0452714532
## [3,] 0.0005895817 0.0585772145 0.0251967339 0.0184125784 0.0009899033
## [4,] 0.0314340958 0.2797699160 0.3830605028 0.2459497409 0.0266180268

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.2 (2024-10-31)
## 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.15.0
##  [3] HDF5Array_1.35.1          rhdf5_2.51.0             
##  [5] DelayedArray_0.33.2       SparseArray_1.7.2        
##  [7] S4Arrays_1.7.1            abind_1.4-8              
##  [9] IRanges_2.41.1            S4Vectors_0.45.2         
## [11] MatrixGenerics_1.19.0     matrixStats_1.4.1        
## [13] BiocGenerics_0.53.3       generics_0.1.3           
## [15] Matrix_1.7-1              DelayedTensor_1.13.0     
## [17] 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.2         
##  [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.47.0     
## [16] cachem_1.1.0        yaml_2.3.10         tools_4.4.2        
## [19] beachmat_2.23.2     parallel_4.4.2      BiocParallel_1.41.0
## [22] Rhdf5lib_1.29.0     rsvd_1.0.5          buildtools_1.0.0   
## [25] R6_2.5.1            lifecycle_1.0.4     zlibbioc_1.52.0    
## [28] BiocSingular_1.23.0 irlba_2.3.5.1       ScaledMatrix_1.15.0
## [31] rTensor_1.4.8       bslib_0.8.0         Rcpp_1.0.13-1      
## [34] xfun_0.49           sys_3.4.3           knitr_1.49         
## [37] rhdf5filters_1.19.0 htmltools_0.5.8.1   rmarkdown_2.29     
## [40] maketools_1.3.1     compiler_4.4.2