473,662 Members | 2,376 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

gmpy and counting None

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)
[GCC 4.3.2] on linux2
Type "help", "copyright" , "credits" or "license" for more information.
>>[2, None].count(None)
1
>>from gmpy import mpz
[mpz(2), None].count(None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: coercion to gmpy.mpz type failed
>>>
Is this a bug in gmpy?

If yes is there any way to issue the bug at
http://code.google.com/p/gmpy/
without creating a gmail account?
Thanks

Martin
Oct 13 '08 #1
7 1406
On Oct 13, 2:43*pm, <mma...@gmx.net wrote:
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)
[GCC 4.3.2] on linux2
Type "help", "copyright" , "credits" or "license" for more information.>>>[2, None].count(None)
1
>from gmpy import mpz
[mpz(2), None].count(None)

Traceback (most recent call last):
* File "<stdin>", line 1, in <module>
TypeError: coercion to gmpy.mpz type failed

Is this a bug in gmpy?
Does the underlying GMP code support Nulls?
>
If yes is there any way to issue the bug athttp://code.google.com/p/gmpy/
without creating a gmail account?

Thanks

Martin
Oct 13 '08 #2
Mensanator wrote:
On Oct 13, 2:43 pm, <mma...@gmx.net wrote:
>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)
[GCC 4.3.2] on linux2
Type "help", "copyright" , "credits" or "license" for more information.>>[2, None].count(None)
1
>>>>from gmpy import mpz
[mpz(2), None].count(None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: coercion to gmpy.mpz type failed

Is this a bug in gmpy?

Does the underlying GMP code support Nulls?
I don't think it has to. Probably, it just should implement __ne__ to return
False if it cannot coerce. Of course, the codebase is relatively old, so it may
still be using __cmp__ and __coerce__. That would make things more difficult.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Oct 13 '08 #3
On Oct 13, 12:43*pm, <mma...@gmx.net wrote:
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)
[GCC 4.3.2] on linux2
Type "help", "copyright" , "credits" or "license" for more information.>>>[2, None].count(None)
1
>from gmpy import mpz
[mpz(2), None].count(None)

Traceback (most recent call last):
* File "<stdin>", line 1, in <module>
TypeError: coercion to gmpy.mpz type failed

Is this a bug in gmpy?

If yes is there any way to issue the bug athttp://code.google.com/p/gmpy/
without creating a gmail account?
I've added it for you.
>
Thanks

Martin
Thanks for reporting the issue.

casevh
Oct 14 '08 #4
On Oct 13, 5:16*pm, Robert Kern <robert.k...@gm ail.comwrote:
Mensanator wrote:
On Oct 13, 2:43 pm, <mma...@gmx.net wrote:
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)
[GCC 4.3.2] on linux2
Type "help", "copyright" , "credits" or "license" for more information.>>[2, None].count(None)
1
from gmpy import mpz
[mpz(2), None].count(None)
Traceback (most recent call last):
* File "<stdin>", line 1, in <module>
TypeError: coercion to gmpy.mpz type failed
Is this a bug in gmpy?
Does the underlying GMP code support Nulls?

I don't think it has to. Probably, it just should implement __ne__ to return
False if it cannot coerce. Of course, the codebase is relatively old, so it may
still be using __cmp__ and __coerce__. That would make things more difficult.
Ok, assuming you CAN fix it, the next question is SHOULD you
fix it? Afetr all, mpz(None) will still raise an exception and
wouldn't the behaviour then be inconsistent?

When I complained that sum([]) should return None instead of 0,
the general consensus was that the 0 choice is what most people
expect most of the time and although there are cases where None
is the logical choice, the 0 case is NOT a bug, "this behaviour
is by design" and I'll just have to live with it and not use
sum() if I expect the list may be empty.

I would expect that you could make the same argument with respect
to trying to compare an mpz to None.
>
--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
* that is made terrible by our own mad attempt to interpret it as though it had
* an underlying truth."
* *-- Umberto Eco- Hide quoted text -

- Show quoted text -
Oct 14 '08 #5
Mensanator wrote:
On Oct 13, 5:16 pm, Robert Kern <robert.k...@gm ail.comwrote:
>Mensanator wrote:
>>On Oct 13, 2:43 pm, <mma...@gmx.net wrote:
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)
[GCC 4.3.2] on linux2
Type "help", "copyright" , "credits" or "license" for more information.>>[2, None].count(None)
1
>>from gmpy import mpz
>>[mpz(2), None].count(None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: coercion to gmpy.mpz type failed
Is this a bug in gmpy?
Does the underlying GMP code support Nulls?
I don't think it has to. Probably, it just should implement __ne__ to return
False if it cannot coerce. Of course, the codebase is relatively old, so it may
still be using __cmp__ and __coerce__. That would make things more difficult.

Ok, assuming you CAN fix it, the next question is SHOULD you
fix it? Afetr all, mpz(None) will still raise an exception and
wouldn't the behaviour then be inconsistent?
I don't think so. There is no particular reason that an implementation of __eq__
or __ne__ *must* coerce its arguments and raise an exception if it can't. There
is certainly a case to be made for __lt__ and the rest, because they imply an
actual numerical comparison, but __eq__ and __ne__ are used for more than
numerical comparison in Python. One of the great things about moving away from
__cmp__ to the multiple comparison methods is that the two concepts were no
longer entangled.
When I complained that sum([]) should return None instead of 0,
the general consensus was that the 0 choice is what most people
expect most of the time and although there are cases where None
is the logical choice, the 0 case is NOT a bug, "this behaviour
is by design" and I'll just have to live with it and not use
sum() if I expect the list may be empty.

I would expect that you could make the same argument with respect
to trying to compare an mpz to None.
That it was by design? Possible, but I have no evidence of such. Do you? If that
is not what you meant, then I have no idea what argument you think applies to
both cases.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Oct 14 '08 #6
On Oct 14, 12:14*pm, Robert Kern <robert.k...@gm ail.comwrote:
Mensanator wrote:
On Oct 13, 5:16 pm, Robert Kern <robert.k...@gm ail.comwrote:
Mensanator wrote:
On Oct 13, 2:43 pm, <mma...@gmx.net wrote:
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)
[GCC 4.3.2] on linux2
Type "help", "copyright" , "credits" or "license" for more information.>>[2, None].count(None)
1
>from gmpy import mpz
>[mpz(2), None].count(None)
Traceback (most recent call last):
* File "<stdin>", line 1, in <module>
TypeError: coercion to gmpy.mpz type failed
Is this a bug in gmpy?
Does the underlying GMP code support Nulls?
I don't think it has to. Probably, it just should implement __ne__ to return
False if it cannot coerce. Of course, the codebase is relatively old, so it may
still be using __cmp__ and __coerce__. That would make things more difficult.
Ok, assuming you CAN fix it, the next question is SHOULD you
fix it? Afetr all, mpz(None) will still raise an exception and
wouldn't the behaviour then be inconsistent?

I don't think so. There is no particular reason that an implementation of__eq__
or __ne__ *must* coerce its arguments and raise an exception if it can't.There
is certainly a case to be made for __lt__ and the rest, because they imply an
actual numerical comparison, but __eq__ and __ne__ are used for more than
numerical comparison in Python. One of the great things about moving awayfrom
__cmp__ to the multiple comparison methods is that the two concepts were no
longer entangled.
Ok.
>
When I complained that sum([]) should return None instead of 0,
the general consensus was that the 0 choice is what most people
expect most of the time and although there are cases where None
is the logical choice, the 0 case is NOT a bug, "this behaviour
is by design" and I'll just have to live with it and not use
sum() if I expect the list may be empty.
I would expect that you could make the same argument with respect
to trying to compare an mpz to None.

That it was by design? Possible, but I have no evidence of such. Do you?
No, I was just saying IF it was intentional, then it's not a bug.
Although one could argue whether the intent was appropriate. As you
say
above, maybe the intent needs to be re-thought.
If that
is not what you meant, then I have no idea what argument you think applies to
both cases.
Ok, forget that. It just seems to me that since .count(None)
and mpz(None) both produce exceptions, _I_ don't see a problem.

And there _IS_ a workaround:
>>from types import *
a = [mpz(2),None,666 ,None,None,'har ry',33.33]
nonecount = 0
for i in a:
if isinstance(i,No neType):
nonecount += 1
>>print nonecount
3

>
--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
* that is made terrible by our own mad attempt to interpret it as though it had
* an underlying truth."
* *-- Umberto Eco- Hide quoted text -

- Show quoted text -
Oct 14 '08 #7
Mensanator wrote:
On Oct 14, 12:14 pm, Robert Kern <robert.k...@gm ail.comwrote:
>Mensanator wrote:
>>On Oct 13, 5:16 pm, Robert Kern <robert.k...@gm ail.comwrote:
Mensanator wrote:
On Oct 13, 2:43 pm, <mma...@gmx.net wrote:
>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)
>[GCC 4.3.2] on linux2
>Type "help", "copyright" , "credits" or "license" for more information.>>[2, None].count(None)
>1
>>>>from gmpy import mpz
>>>>[mpz(2), None].count(None)
>Tracebac k (most recent call last):
> File "<stdin>", line 1, in <module>
>TypeErro r: coercion to gmpy.mpz type failed
>Is this a bug in gmpy?
Does the underlying GMP code support Nulls?
I don't think it has to. Probably, it just should implement __ne__ to return
False if it cannot coerce. Of course, the codebase is relatively old, so it may
still be using __cmp__ and __coerce__. That would make things more difficult.
Ok, assuming you CAN fix it, the next question is SHOULD you
fix it? Afetr all, mpz(None) will still raise an exception and
wouldn't the behaviour then be inconsistent?
I don't think so. There is no particular reason that an implementation of __eq__
or __ne__ *must* coerce its arguments and raise an exception if it can't. There
is certainly a case to be made for __lt__ and the rest, because they imply an
actual numerical comparison, but __eq__ and __ne__ are used for more than
numerical comparison in Python. One of the great things about moving away from
__cmp__ to the multiple comparison methods is that the two concepts were no
longer entangled.

Ok.
>>When I complained that sum([]) should return None instead of 0,
the general consensus was that the 0 choice is what most people
expect most of the time and although there are cases where None
is the logical choice, the 0 case is NOT a bug, "this behaviour
is by design" and I'll just have to live with it and not use
sum() if I expect the list may be empty.
I would expect that you could make the same argument with respect
to trying to compare an mpz to None.
That it was by design? Possible, but I have no evidence of such. Do you?

No, I was just saying IF it was intentional, then it's not a bug.
Although one could argue whether the intent was appropriate. As you
say
above, maybe the intent needs to be re-thought.
And even then, it's not so much of a bug as a missing feature.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Oct 14 '08 #8

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

Similar topics

8
3447
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: what is the better replacement solution for manipulating long numbers. I want to do long numbers exponentiations. Thanks in advance for your answers. JP
2
1709
by: Mensanator | last post by:
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?
11
1756
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 check it at all). I can't reach sourceforge at the moment, so I have meanwhile put the exe file up at: http://www.aleax.it/Python/gmpy-1.0.win32-py2.4.exe Users of both gmpy and python 2.4 on windows are invited to dowload and install this,...
3
2426
by: mensanator | last post by:
Since the following discussion took place (unresolved), <http://groups.google.com/group/comp.lang.python/browse_frm/thread/c3bd08ef3e4c478a/2b54deb522c9b9d9?lnk=st&q=divm()+memory+leak+group:comp.lang.python+author:mensanator&rnum=1&hl=en#2b54deb522c9b9d9> I've kept it in the back of my mind as I've been learning to use the base gmp library in c. Now I believe I know what the problem is. First, divm() is not a gmp function. It is a...
22
1946
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 version (one thing I must still look at is divm's behavior when its args are not mutually prime). It currently compiles w/o warnings, and passes all of its 1040+ tests, w/the current release of GMP (4.1.4), Python (2.4.2), MacOSX (10.4.3), XCode...
3
1888
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 laborious, e.g. by explicitly going through string-forms). I'm thinking about possible ways to fix this, in whole or in part, but, before I spend more time on this, I was wondering if there's anybody else who'd be interested -- if so, maybe we...
3
2222
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 ## ## ## 0 0 0 0 0 0 0 0 0 0 ## 0 1 2 3 1 5 6 7 2 9
3
3741
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 following error in conversion from float() to gmpy.mpf() or how to avoid it: import gmpy
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8762
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8545
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7365
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6185
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5653
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1992
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.