Thanks to visit codestin.com
Credit goes to github.com

Skip to content

einsum optimization failure and inconsistency #11308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
attack68 opened this issue Jun 11, 2018 · 1 comment
Open

einsum optimization failure and inconsistency #11308

attack68 opened this issue Jun 11, 2018 · 1 comment

Comments

@attack68
Copy link
Contributor

This issue documents two separate bugs:

  1. Failure in the optimization routine when set to True:
    import numpy as np
    a = np.arange(64).reshape(2,4,8)
    np.einsum('obk,ijk->ioj',a,a)
    array([[[ 1904,  5872,  9840, 13808],
            [ 5488, 17648, 29808, 41968]],
           [[17776, 21744, 25712, 29680],
            [54128, 66288, 78448, 90608]]])
    np.einsum('obk,ijk->ioj',a,a, optimize=True)

    Traceback (most recent call last):
  File "/anaconda3/envs/General/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2963, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-133-00a49d0e7c9d>", line 1, in <module>
    np.einsum('obk,ijk->ioj',a,a, optimize=True)
  File "/anaconda3/envs/General/lib/python3.6/site-packages/numpy/core/einsumfunc.py", line 1118, in einsum
    if any(left_dims[ind] != right_dims[ind] for ind in idx_rm):
  File "/anaconda3/envs/General/lib/python3.6/site-packages/numpy/core/einsumfunc.py", line 1118, in <genexpr>
    if any(left_dims[ind] != right_dims[ind] for ind in idx_rm):
KeyError: 'b'
  1. Inconsistent return using different optimization options:
    >>> a = np.ones(64).reshape(2,4,8)
    >>> np.einsum('ijk,ilm,njm,nlk,abc->',a,a,a,a,a, optimize='optimal')
    262144.0
    >>> np.einsum('ijk,ilm,njm,nlk,abc->',a,a,a,a,a, optimize='greedy')
    array(262144.)
    >>> np.einsum('ijk,ilm,njm,nlk,abc->',a,a,a,a,a)
    262144.0

referencing #11234 discussion and drawing @dgasmith attention.

@dgasmith
Copy link
Contributor

ForI put in a fix for 1). A fix for 2) I think should happen in tensordot as this is the function that is return an array rather than a float. An easy fix in either function.

@charris Any thoughts as to where to change this behavior? One could argue against tensordot as it might break expected functionality of this function that already exists, but seems inconsistent with the Python ecosystem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants