GithubHelp home page GithubHelp logo

einsum-experiment's People

Contributors

shawwn avatar sorenlassen avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

shawwn

einsum-experiment's Issues

Broadcast problem

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

image

The example right above it works fine:

image

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.

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.