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
This is a recursion problem. The longdouble add calls the ufunc add which (because everything is upcast to object arrays and because object arrays ask their elements how to add themselves, it calls back to the scalar add which continues the recursion.
When I investigated the problem yesterday, I realised that there must be a recursive call, given a traceback of several hundreds of lines! What is the best way to address this?
The core reason behind this problem is that longdouble's are the only data-types (along with clong_double) that returns their corresponding numpy scalars when getitem is called.
All of the numpy scalars implement their math by using the corresponding ufuncs. The ufuncs for "object" arrays use the math defined by the corresponding objects. This causes the recursion because adding to "None" upcasts everything to an object before attempting the ufunc calls. In the case of long doubles this creates an array of numpy long double scalars. As object arrays, the ufunc refers to the objects in the array to complete the math (which in this case calls back to the same ufunc which started it).
The right fix to the cycle is to break it by either
defining math separately for longdouble and clongdouble scalars or
returning a different object for the getitem call of longdouble and clongdouble arrays.
Since float64(None), I think this problem will be fixed if the None is cast to a float64. So a special test for none in the code that picks the output type should do the trick.
Activity
numpy-gitbot commentedon Oct 19, 2012
@stefanv wrote on 2008-03-18
Verified with SVN on OSX.
numpy-gitbot commentedon Oct 19, 2012
@teoliphant wrote on 2008-03-19
This is a recursion problem. The longdouble add calls the ufunc add which (because everything is upcast to object arrays and because object arrays ask their elements how to add themselves, it calls back to the scalar add which continues the recursion.
numpy-gitbot commentedon Oct 19, 2012
@stefanv wrote on 2008-03-19
When I investigated the problem yesterday, I realised that there must be a recursive call, given a traceback of several hundreds of lines! What is the best way to address this?
numpy-gitbot commentedon Oct 19, 2012
@teoliphant wrote on 2008-03-19
The core reason behind this problem is that longdouble's are the only data-types (along with clong_double) that returns their corresponding numpy scalars when getitem is called.
numpy-gitbot commentedon Oct 19, 2012
@stefanv wrote on 2008-03-20
Is that the reason for this problem, or for the intp problem? If for this problem, could you expand a bit?
numpy-gitbot commentedon Oct 19, 2012
@teoliphant wrote on 2008-03-21
All of the numpy scalars implement their math by using the corresponding ufuncs. The ufuncs for "object" arrays use the math defined by the corresponding objects. This causes the recursion because adding to "None" upcasts everything to an object before attempting the ufunc calls. In the case of long doubles this creates an array of numpy long double scalars. As object arrays, the ufunc refers to the objects in the array to complete the math (which in this case calls back to the same ufunc which started it).
The right fix to the cycle is to break it by either
A quick fix would be to special-case somehow.
numpy-gitbot commentedon Oct 19, 2012
@charris wrote on 2008-03-22
So the numpy scalars are objects? What does getitem return when called on, say float64?
numpy-gitbot commentedon Oct 19, 2012
@charris wrote on 2008-04-25
Since float64(None), I think this problem will be fixed if the None is cast to a float64. So a special test for none in the code that picks the output type should do the trick.
numpy-gitbot commentedon Oct 19, 2012
@charris wrote on 2008-04-25
Make that: Since float96(None) is nan.
numpy-gitbot commentedon Oct 19, 2012
Milestone changed to
1.1.0by @jarrodmillman on 2008-05-15numpy-gitbot commentedon Oct 19, 2012
@cournape wrote on 2008-08-23
Solved in r5680 and backported to 1.1.x. Thanks Travis !
BUG: longdouble op None could cause infinite recursion
BUG: longdouble op None could cause infinite recursion