Comment #7 on issue 1946 by mattpap: Recursion error with
SYMPY_GROUND_TYPES=sympy (caching problem)
http://code.google.com/p/sympy/issues/detail?id=1946
So yes, let's change all of those to "type(b) in (int, long)" (or would
isinstance be better there too?
Well, it's a good question:
In [1]: a = 2**17
In [2]: b = 2**65
In [3]: c = Integer(b)
In [4]: d = x**2
In [5]: type(a) in (int, long)
Out[5]: True
In [6]: type(b) in (int, long)
Out[6]: True
In [7]: type(c) in (int, long)
Out[7]: False
In [8]: type(d) in (int, long)
Out[8]: False
In [9]: %timeit type(a) in (int, long);
1000000 loops, best of 3: 613 ns per loop
In [10]: %timeit type(b) in (int, long);
1000000 loops, best of 3: 685 ns per loop
In [11]: %timeit type(c) in (int, long);
1000000 loops, best of 3: 1.39 us per loop
In [12]: %timeit type(d) in (int, long);
1000000 loops, best of 3: 1.38 us per loop
In [13]: isinstance(a, (int, long))
Out[13]: True
In [14]: isinstance(b, (int, long))
Out[14]: True
In [15]: isinstance(c, (int, long))
Out[15]: False
In [16]: isinstance(d, (int, long))
Out[16]: False
In [17]: %timeit isinstance(a, (int, long));
1000000 loops, best of 3: 596 ns per loop
In [18]: %timeit isinstance(b, (int, long));
1000000 loops, best of 3: 988 ns per loop
In [19]: %timeit isinstance(c, (int, long));
1000000 loops, best of 3: 1.39 us per loop
In [20]: %timeit isinstance(d, (int, long));
1000000 loops, best of 3: 1.36 us per loop
The only real difference is [18], rest seems to be noise (although more
experiments
are needed). So, probably using type() is better in this case, although
this way we
can't compare with classes that derive from built-in types. In any case, we
will
still have the following behavior:
In [21]: from gmpy import mpz
In [22]: Integer(123) == mpz(123)
Out[22]: False
--
You received this message because you are subscribed to the Google Groups
"sympy-issues" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy-issues?hl=en.