sorenlassen / einsum-experiment Goto Github PK
View Code? Open in Web Editor NEWExperimental implementation of torch/onnx einsum
License: MIT License
Experimental implementation of torch/onnx einsum
License: MIT License
I was testing the examples at https://www.tensorflow.org/api_docs/python/tf/einsum and noticed an interesting failure case (search for "Einsum will broadcast over axes covered by the ellipsis" on that page):
import tensorflow as tf
import einsum
s = tf.random.normal(shape=[11, 1, 5, 3])
t = tf.random.normal(shape=[1, 7, 3, 2])
e = tf.einsum('...ij,...jk->...ik', s, t)
print(e.shape)
e2 = einsum.einsum('...ij,...jk->...ik', s.numpy(), t.numpy())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/shawn/ml/einsum/src/einsum/lib.py", line 228, in einsum
return einsum_execute(spec, list(tensors))
File "/Users/shawn/ml/einsum/src/einsum/lib.py", line 223, in einsum_execute
return einsum_tensor_frompos(fn, spec.output.shape)
File "/Users/shawn/ml/einsum/src/einsum/lib.py", line 31, in einsum_tensor_frompos
return einsum_tensor(recurse([], shape))
File "/Users/shawn/ml/einsum/src/einsum/lib.py", line 29, in recurse
return [ recurse(pos + [i], remainder) for i in range(shape[0]) ]
File "/Users/shawn/ml/einsum/src/einsum/lib.py", line 29, in <listcomp>
return [ recurse(pos + [i], remainder) for i in range(shape[0]) ]
File "/Users/shawn/ml/einsum/src/einsum/lib.py", line 29, in recurse
return [ recurse(pos + [i], remainder) for i in range(shape[0]) ]
File "/Users/shawn/ml/einsum/src/einsum/lib.py", line 29, in <listcomp>
return [ recurse(pos + [i], remainder) for i in range(shape[0]) ]
File "/Users/shawn/ml/einsum/src/einsum/lib.py", line 29, in recurse
return [ recurse(pos + [i], remainder) for i in range(shape[0]) ]
File "/Users/shawn/ml/einsum/src/einsum/lib.py", line 29, in <listcomp>
return [ recurse(pos + [i], remainder) for i in range(shape[0]) ]
File "/Users/shawn/ml/einsum/src/einsum/lib.py", line 29, in recurse
return [ recurse(pos + [i], remainder) for i in range(shape[0]) ]
File "/Users/shawn/ml/einsum/src/einsum/lib.py", line 29, in <listcomp>
return [ recurse(pos + [i], remainder) for i in range(shape[0]) ]
File "/Users/shawn/ml/einsum/src/einsum/lib.py", line 26, in recurse
return fn(*pos)
File "/Users/shawn/ml/einsum/src/einsum/lib.py", line 221, in fn
return recurse(in_only_idxs)
File "/Users/shawn/ml/einsum/src/einsum/lib.py", line 218, in recurse
acc += recurse(tail)
File "/Users/shawn/ml/einsum/src/einsum/lib.py", line 210, in recurse
prod *= tensor.item(*pos)
IndexError: index 1 is out of bounds for axis 1 with size 1
The example right above it works fine:
import tensorflow as tf
import einsum
import numpy as np
s = tf.random.normal(shape=[11, 7, 5, 3])
t = tf.random.normal(shape=[11, 7, 3, 2])
e = tf.einsum('...ij,...jk->...ik', s, t)
print(e.shape)
e2 = einsum.einsum('...ij,...jk->...ik', s.numpy(), t.numpy())
np.allclose(e, e2) # True
So the problem seems related to broadcasting axes covered by ellipses.
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.