You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In numpy 1.13.3, it was possible to execute the following snippet without errors, while in 1.14.0 this happens:
In [1]: importnumpyasnpIn [2]: a=np.ones((10,2))
In [3]: b=np.ones((1,2))
In [4]: np.einsum('t...i,ti->t...', a, b)
Traceback (mostrecentcalllast):
File"<ipython-input-4-fa62d1d882f9>", line1, in<module>np.einsum('t...i,ti->t...', a, b)
File"/usr/local/lib/python2.7/dist-packages/numpy/core/einsumfunc.py", line1087, ineinsumeinsum_call=True)
File"/usr/local/lib/python2.7/dist-packages/numpy/core/einsumfunc.py", line710, ineinsum_path"not match previous terms.", char, tnum)
ValueError: ("Size of label '%s' for operand %d does not match previous terms.", 't', 1)
However optimize=False solves the problem:
In [5]: np.einsum('t...i,ti->t...', a, b, optimize=False)
Out[5]: array([2., 2., 2., 2., 2., 2., 2., 2., 2., 2.])
Is this intended behavior and the user is now responsible to explicitly disable optimization or is this a bug?
The fix in #10352 seems correct. Note also that the current optimization choice makes no sense: for 2 argument, optimization should not be attempted; see #10357.
A very simple fix for the slowdown is in #10359 - I think we should consider reverting the change in default of optimize, though. In the end, einsum is very likely used mostly with small numbers of arrays, for which the additional cost is not worth it. It seems more likely that users with long expressions will read the docstring and realize there is an optimize keyword than that users with short ones will realize the default is bad for their case.
@charris - this issue is biting lots of astropy users now (astropy/astropy#7051 (comment)) as it screws up one of our coordinate transformations. Those are all with 3x3 matrices, so pending not just a solution but also a better understanding of impacts of performance, I would indeed suggest to revert the default for 1.14.1. Obviously, we also need #10352 and especially its tests so this doesn't recur! (We missed it in astropy in part because for python3 our transformations use matmul -- guess we should test our last python2 version also with numpy-dev...)
Activity
charris commentedon Jan 8, 2018
Both?
optimize=Truewas made the default, but it shouldn't be causing errors.@dgasmith Another one ;)
eric-wieser commentedon Jan 8, 2018
Seems we failed to format the error message correctly either
mhvk commentedon Jan 8, 2018
This hit at least one user of astropy (though not our tests, annoyingly!). The following breaks (but works with
optimize=False):mhvk commentedon Jan 10, 2018
The fix in #10352 seems correct. Note also that the current optimization choice makes no sense: for 2 argument, optimization should not be attempted; see #10357.
mhvk commentedon Jan 10, 2018
A very simple fix for the slowdown is in #10359 - I think we should consider reverting the change in default of
optimize, though. In the end,einsumis very likely used mostly with small numbers of arrays, for which the additional cost is not worth it. It seems more likely that users with long expressions will read the docstring and realize there is anoptimizekeyword than that users with short ones will realize the default is bad for their case.exclude numpy 1.14.0
disable einsum optimization
disable einsum optimization
disable einsum optimization
mhvk commentedon Jan 14, 2018
@charris - this issue is biting lots of astropy users now (astropy/astropy#7051 (comment)) as it screws up one of our coordinate transformations. Those are all with 3x3 matrices, so pending not just a solution but also a better understanding of impacts of performance, I would indeed suggest to revert the default for 1.14.1. Obviously, we also need #10352 and especially its tests so this doesn't recur! (We missed it in astropy in part because for python3 our transformations use
matmul-- guess we should test our last python2 version also withnumpy-dev...)BUG: Make the einsum optimize default to `False`.
charris commentedon Jan 14, 2018
@mhvk See #10403.
mhvk commentedon Jan 14, 2018
OK, good, that gives more time.
use einsum optimize=False to avoid upstream numpy bug
disable einsum optimization
downgrade numpy (waiting on numpy/numpy#10343)
use einsum optimize=False to avoid upstream numpy bug