Skip to content
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

mpmath doesn't work with python2.4 #89

Closed
certik opened this issue Jul 6, 2008 · 7 comments
Closed

mpmath doesn't work with python2.4 #89

certik opened this issue Jul 6, 2008 · 7 comments
Labels
bug an unexpected problem or unintended behavior imported Priority-High

Comments

@certik
Copy link
Contributor

certik commented Jul 6, 2008

ondra@fuji:~/ext/mpmath-svn$ python2.4
Python 2.4.5 (#2, Jun 25 2008, 14:11:58) 
[GCC 4.3.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.

> > > import mpmath
> > > Traceback (most recent call last):
> > >   File "<stdin>", line 1, in ?
> > >   File "mpmath/**init**.py", line 5, in ?
> > >     from mptypes import *
> > >   File "mpmath/mptypes.py", line 18, in ?
> > >     from libmpc import *
> > >   File "mpmath/libmpc.py", line 342, in ?
> > >     alpha_crossover = from_float(1.5)
> > >   File "mpmath/lib.py", line 458, in from_float
> > >     return from_man_exp(int(m*(1<<53)), e-53, prec, rnd)
> > >   File "mpmath/lib.py", line 387, in from_man_exp
> > >     return normalize(sign, man, exp, bc, prec, rnd)
> > >   File "mpmath/lib.py", line 282, in _normalize
> > >     t = trailtable[man & 255]
> > > TypeError: list indices must be integers

Original issue for #89: http://code.google.com/p/mpmath/issues/detail?id=49

Original author: https://code.google.com/u/104039945248245758823/

Original owner: https://code.google.com/u/casevh/

@certik
Copy link
Contributor Author

certik commented Jul 5, 2008

This is when 

man & 255 

is a gmpy's mpz. So it may as well be a bug in gmpy. Here is a fix that works:

# Index: mpmath/lib.py

--- mpmath/lib.py   ( revision 518 )
+++ mpmath/lib.py   (working copy)
@@ -279,13 +279,13 @@
         bc = prec
     # Strip trailing bits
     if not man & 1:
-        t = trailtable[man & 255]
-        t = trailtable[int(man & 255)]
       if not t:
           while not man & 255:
               man >>= 8
               exp += 8
               bc -= 8
-            t = trailtable[man & 255]
-            t = trailtable[int(man & 255)]
       man >>= t
       exp += t
       bc -= t
  @@ -373,7 +373,7 @@
       sign = 1
       man = -man
   if man < 1024:
-        bc = bctable[man]
-        bc = bctable[int(man)]
   else:
       bc = bitcount(man)
   if not prec:

**Status:** Started  

Original comment: http://code.google.com/p/mpmath/issues/detail?id=49#c1

Original author: https://code.google.com/u/104039945248245758823/

@fredrik-johansson
Copy link
Collaborator

I'd like to know how much slowdown this causes. An option would be to replace
trailtable and bctable by dicts if pyversion < 2.5 and gmpy-mode is used.

Original comment: http://code.google.com/p/mpmath/issues/detail?id=49#c2

Original author: https://code.google.com/u/111502149103757882156/

@certik
Copy link
Contributor Author

certik commented Jul 5, 2008

Or just use this patch only for python < 2.5.  Slow mpmath is better than no mpmath.

Original comment: http://code.google.com/p/mpmath/issues/detail?id=49#c3

Original author: https://code.google.com/u/104039945248245758823/

@casevh
Copy link
Contributor

casevh commented Jul 6, 2008

The difference between Python 2.4 and 2.5 is that Python 2.5 uses the **index**
method when indexing a list. The **index** method was added in gmpy 1.02.

I used int() when I was testing the gmpy patches because I was using gmpy 1.01
originally. I inadvertently removed when I started testing with gmpy 1.03. 

I don't think using int() creates much of a slowdown.

Sorry about not testing under Python 2.4.

Original comment: http://code.google.com/p/mpmath/issues/detail?id=49#c4

Original author: https://code.google.com/u/casevh/

@casevh
Copy link
Contributor

casevh commented Jul 6, 2008

I'm working on a patch but it's not as easy as it seems. It wasn't difficult to add
int() to all the occurrences of bctable and trailtable. But while testing I've
encountered another subtle issue.

I've been assuming that the types of the components of an mpf are (int, MP_BASE, int,
int). But I've found at least one location where exp has type MP_BASE and a couple
other places where bc or exp is type long. I fixed the occurrence where exp has type
MP_BASE. I allowed bc and exp to become type long since I didn't think it was worth
the overhead.

I updated the test in -strict mode. It's easy to edit the tests to catch when bc and
exp are type long.

Original comment: http://code.google.com/p/mpmath/issues/detail?id=49#c5

Original author: https://code.google.com/u/casevh/

@certik
Copy link
Contributor Author

certik commented Jul 6, 2008

Thanks for your work, now it works indeed. I'll update the mpmath in sympy.

Original comment: http://code.google.com/p/mpmath/issues/detail?id=49#c6

Original author: https://code.google.com/u/104039945248245758823/

@casevh
Copy link
Contributor

casevh commented Sep 16, 2008

Just closing the issue since Ondrej reports the problem is fixed.

**Status:** Fixed  
**Owner:** casevh  

Original comment: http://code.google.com/p/mpmath/issues/detail?id=49#c7

Original author: https://code.google.com/u/casevh/

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior imported Priority-High
Projects
None yet
Development

No branches or pull requests

3 participants