[Numpy-discussion] Is this a bug, and if so, who's?
Ken Basye
kbasye1 at jhu.edu
Wed Apr 21 11:47:48 EDT 2010
Folks,
Apologies for asking here, but I ran across this problem yesterday
and probably need to file a bug. The problem is I don't know if this is
a Numpy bug, a Python bug, or both. Here's an illustration, platform
information follows.
TIA,
Ken
#############################################
import collections
import numpy as np
class A (collections.namedtuple('ANT', ('x', 'y'))):
def __float__(self):
return self.y
# Same as A, but explicitly convert y to a float in __float__() - this
works around the assert fail
class B (collections.namedtuple('BNT', ('x', 'y'))):
def __float__(self):
return float(self.y)
a0 = A(1.0, 2.0)
f0 = np.float64(a0)
print f0
a1 = A(float(1.0), float(2.0))
f1 = np.float64(a1)
print f1
b1 = B(np.float64(1.0), np.float64(2.0))
f2 = np.float64(b1)
print f2
a2 = A(np.float64(1.0), np.float64(2.0))
# On some platforms, the next line will trigger an
assert:
# python: Objects/floatobject.c:1674: float_subtype_new: Assertion
`((((PyObject*)(tmp))->ob_type) == &PyFloat_Type)' failed.
f3 = np.float64(a2)
print f3
#############################################
Platform info:
Python 2.6.5 (r265:79063, Apr 14 2010, 13:32:56)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
>>> numpy.__version__
'1.3.0'
~--$ uname -srvmpio
Linux 2.6.18-164.el5 #1 SMP Thu Sep 3 03:28:30 EDT 2009 x86_64 x86_64
x86_64 GNU/Linux
More information about the NumPy-Discussion
mailing list