473,287 Members | 1,413 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

GMPY compare warning

In the program that follows, I get the following warning message:

collatz_.py:37: RuntimeWarning: tp_compare didn't return -1, 0 or 1
while b>1:

In this case, b is a gmpy.mpz number. The program operates as it should,
which I guess is why it's a warning. Is there some reason why I shouldn't
use gmpy numbers with relational operators? Is this warning something
that can safely be ignored?


import sys
import time
import gmpy

i = long(sys.argv[1])

n = 2**(i) - 1

r1 = 0
r2 = 0
t0 = time.time()

a = n

while a>1:
z = divmod(a,2)
if z[1]==0:
a = z[0]
r1 += 1
else:
a = a*3 + 1
r2 += 1

t1 = time.time()

print "r1",r1,"r2",r2,"in",t1-t0,"seconds\n"
b = gmpy.mpz(n)

r1 = 0
r2 = 0
t0 = time.time()

while b>1:
z = gmpy.scan1(b)
if z==0:
b = b*3 + 1
r2 += 1
else:
b = b/(2**z)
r1 += z

t1 = time.time()

print "r1",r1,"r2",r2,"in",t1-t0,"seconds\n"

"""
C:\Python23\user>python collatz_.py 1000
r1 7841 r2 4316 in 0.109000086784 seconds
r1 7841 r2 4316 in 0.375 seconds

C:\Python23\user>python collatz_.py 10000
r1 86278 r2 48126 in 6.42199993134 seconds
r1 86278 r2 48126 in 4.85900008678 seconds

C:\Python23\user>python collatz_.py 100000
r1 863323 r2 481603 in 604.766000032 seconds
r1 863323 r2 481603 in 121.859999895 seconds
"""


--
Mensanator
Ace of Clubs
Jul 18 '05 #1
2 1694

"Mensanator" <me********@aol.compost> wrote in message
news:20***************************@mb-m05.aol.com...
In the program that follows, I get the following warning message:

collatz_.py:37: RuntimeWarning: tp_compare didn't return -1, 0 or 1
while b>1:

In this case, b is a gmpy.mpz number. The program operates as it should,
which I guess is why it's a warning. Is there some reason why I shouldn't
use gmpy numbers with relational operators? Is this warning something
that can safely be ignored?


http://sourceforge.net/tracker/index...3&group_id=547
0&atid=305470

might help?

Duncan
Jul 18 '05 #2
>Subject: Re: GMPY compare warning
From: "Duncan Smith" bu*****@urubu.freeserve.co.uk
Date: 11/29/2003 8:50 AM Central Standard Time
Message-id: <bq**********@news8.svr.pol.co.uk>
"Mensanator" <me********@aol.compost> wrote in message
news:20***************************@mb-m05.aol.com...
In the program that follows, I get the following warning message:

collatz_.py:37: RuntimeWarning: tp_compare didn't return -1, 0 or 1
while b>1:

In this case, b is a gmpy.mpz number. The program operates as it should,
which I guess is why it's a warning. Is there some reason why I shouldn't
use gmpy numbers with relational operators? Is this warning something
that can safely be ignored?

http://sourceforge.net/tracker/index...3&group_id=547
0&atid=305470

might help?


Thanks.

Duncan

--
Mensanator
Ace of Clubs
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Jean-Pierre Andreaux | last post by:
Gmpy module was a wrapper of the GNU MP library. It seems that no evolution is done on this module since 2001. Indeed, Gmpy is not supported in Python 2.2 nor 2.3. My question is the following:...
11
by: Alex Martelli | last post by:
Thanks to David Bolen, who did the build, I have been able to make available a win32 packaging for gmpy 1.0 on python 2.4 alpha 2 (should work on any later Python 2.4 as well, but I have no way to...
3
by: mensanator | last post by:
Since the following discussion took place (unresolved), ...
22
by: Alex Martelli | last post by:
I have fixed almost all of the outstanding bugreports and feature request for gmpy: divm doesn't leak memory any more, truediv and floordiv are implemented for all types, etc -- in the current CVS...
3
by: Alex Martelli | last post by:
As things stand now (gmpy 1.01), an instance d of decimal.Decimal cannot transparently become an instance of any of gmpy.{mpz, mpq, mpf}, nor vice versa (the conversions are all possible, but a bit...
3
by: mensanator | last post by:
## Holy Mother of Pearl! ## ## >>> for i in range(10): ## for j in range(10): ## print '%4d' % (gmpy.mpz(i)*gmpy.mpz(j)), ## print ## ## ## ...
3
by: zakad | last post by:
python 2.5.2 ubuntu 8.04 LTS (1) I find that python/gmpy is about 3 times slower than c++/gmp. Is this the general experience, or am I doing something wrong? (2) I am unable to understand the...
7
by: | last post by:
Hi, I just stumbled upon the following issue (I am running Debian): $ python Python 2.5.2 (r252:60911, Sep 29 2008, 21:15:13) on linux2 Type "help", "copyright", "credits" or "license" for...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.