473,399 Members | 2,478 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,399 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 1699

"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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.