Comment #3 on issue 1946 by mattpap: Recursion error with
SYMPY_GROUND_TYPES=sympy (caching problem)
http://code.google.com/p/sympy/issues/detail?id=1946
For me, Integer.__new__ is wrong, because Integer(123) and
Integer(Integer(123))
should result in a single entry in the cache, which is currently not true.
The
following patch fixes this problem (similar to Aaron's):
diff --git a/sympy/core/numbers.py b/sympy/core/numbers.py
index 34502eb..55dfb26 100644
--- a/sympy/core/numbers.py
+++ b/sympy/core/numbers.py
@@ -810,12 +810,13 @@ def _mpmath_(self, prec, rnd):
# TODO caching with decorator, but not to degrade performance
@int_trace
def __new__(cls, i):
+ ival = int(i)
+
try:
- return _intcache[i]
+ return _intcache[ival]
except KeyError:
# We only work with well-behaved integer types. This converts,
for
# example, numpy.int32 instances.
- ival = int(i)
if ival == 0: obj = S.Zero
elif ival == 1: obj = S.One
elif ival == -1: obj = S.NegativeOne
@@ -823,7 +824,7 @@ def __new__(cls, i):
obj = Expr.__new__(cls)
obj.p = ival
- _intcache[i] = obj
+ _intcache[ival] = obj
return obj
def __getnewargs__(self):
However, it's still interesting why polys fail without this patch.
--
You received this message because you are subscribed to the Google Groups
"sympy-issues" group.
To post to this group, send email to sympy-iss...@googlegroups.com.
To unsubscribe from this group, send email to
sympy-issues+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/sympy-issues?hl=en.