Code Monkey home page Code Monkey logo

einsum's People

Contributors

const-ae avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

rikenbit

einsum's Issues

Submission to CRAN (proposal)

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,

issue with einsum('mp,mq->mpq',mat,mat) behavior in comparison with python einsum()

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

########################################################################################

python

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]]

##########################################

1/

np.einsum('mp,mq->mq',mat,mat)
###########################################

array([[  6,  12,  18],
       [ 60,  75,  90],
       [168, 192, 216]])

###########################################
# identical to einsum() in R
###########################################

2/

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
###########################################

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

##########################################

1/

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
###########################################

2/

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
###########################################
########################################################################################

Implicit mode can be perform in different meaning

Hi, Constantin

I found that CRAN einsum cannot use in implicit mode without explicit indicator (->).

einsum/man/einsum.Rd

Lines 16 to 18 in a5e1152

Whitespace inside the \code{equation_string} is ignored. Unlike the
equivalent functions in Python, \code{einsum()} only supports the explicit
mode. This means that the \code{equation_string} must contain '->'.}

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 (->)")
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.