const-ae / einsum Goto Github PK
View Code? Open in Web Editor NEWEinstein Summation for Arrays in R
Home Page: https://const-ae.github.io/einsum/
License: Other
Einstein Summation for Arrays in R
Home Page: https://const-ae.github.io/einsum/
License: Other
Hi,
Thanks for the great package.
This is really useful when the data structure is complex.
Do you have a plan to submit this package to the CRAN repository?
I want to use this functionality by importing this package.
Regards,
Hi
Congrats for this package. I saw that was already available on CRAN.
I would to thank you for filling this gap in R as this function is really useful.
However, I spotted some different behavior in comparison with einsum() from numpy.
The following script (see bellow)example illustrate this discrepancy. I hope this can be helpful. However, this is maybe a total error of my part, So I'll appreciate any answer and explanation.
Kind regards
Takiy
########################################################################################
import numpy as np
mat=np.array([[1,2,3],[4,5,6],[7,8,9]])
print(mat)
##########################################
[[1 2 3]
[4 5 6]
[7 8 9]]
##########################################
np.einsum('mp,mq->mq',mat,mat)
###########################################
array([[ 6, 12, 18],
[ 60, 75, 90],
[168, 192, 216]])
###########################################
# identical to einsum() in R
###########################################
np.einsum('mp,mq->mpq',mat,mat)
###########################################
array([[[ 1, 2, 3],
[ 2, 4, 6],
[ 3, 6, 9]],
[[16, 20, 24],
[20, 25, 30],
[24, 30, 36]],
[[49, 56, 63],
[56, 64, 72],
[63, 72, 81]]])
##########################################
# not identical to einsum() in R
###########################################
library(einsum)
mat=matrix(1:9,ncol=3,byrow=T)
mat
##########################################
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6
[3,] 7 8 9
##########################################
einsum('mp,mq->mq',mat,mat)
#########################################
[,1] [,2] [,3]
[1,] 6 12 18
[2,] 60 75 90
[3,] 168 192 216
#########################################
# identical to einsum() in python
###########################################
einsum('mp,mq->mpq',mat,mat)
##########################################
, , 1
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 16 20 24
[3,] 49 56 63
, , 2
[,1] [,2] [,3]
[1,] 2 4 6
[2,] 20 25 30
[3,] 56 64 72
, , 3
[,1] [,2] [,3]
[1,] 3 6 9
[2,] 24 30 36
[3,] 63 72 81
##########################################
# not identical to einsum() in python
###########################################
########################################################################################
Hi, Constantin
I found that CRAN einsum cannot use in implicit mode without explicit indicator (->).
Lines 16 to 18 in a5e1152
It'll be fine, implicit mode is sometimes misleading.
However, CRAN einsum can actually be performed in different meaning like below.
For example, in Numpy's einsum, implicit mode just shows the whole data.
# Numpy (Python)
import numpy as np
data = np.random.rand(3, 4)
np.einsum('ij', data)
# array([[0.50142663, 0.845945 , 0.36696267, 0.00643327],
# [0.14395742, 0.73767592, 0.81586026, 0.40644605],
# [0.12538026, 0.92932431, 0.2329707 , 0.10398253]])
However, in CRAN einsum, it is interpreted as the summation over the indices i and j.
# einsum (R)
library("einsum")
data <- array(runif(3*4), dim=c(3,4))
einsum('ij', data)
# [1] 2.951262
Wouldn't it be more trouble-free to ban equation_strings containing "->"?
For example, how about including the following argument check?
if(length(grep("->", "equation_string")) == 0){
stop("Please make sure that equation_string has explicit indicator (->)")
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.