thouis / numpy-trac-migration

numpy Trac to github issues migration
2 stars 3 forks source link

NameError: PyArray_ContiguousFromObject on FC3; affects mtrand (migrated from Trac #219) #1772

Closed thouis closed 11 years ago

thouis commented 11 years ago

Original ticket http://projects.scipy.org/numpy/ticket/219 Reported 2006-08-01 by trac user TomLoredo, assigned to unknown.

C code that calls PyArray_ContiguousFromObject (both my own and within numpy) compiles fine but gives a NameError at runtime on Fedora Core 3 (Python 2.4.3). Calling random.set_state displays the bug. If I edit mtrand.pyx to change its 3 PyArray_ContiguousFromObject calls to PyArray_ContiguousFromAny, run generate_mtrand_c.py, and reinstall, the error goes away. A sample IPython session is copied below.

I deleted my previous numpy package from site-packages before installing this one.

I do not have this problem on OS X (10.3.9, MacPy 2.4.1).

I am unclear of the status of PyArray_ContiguousFromObject. It is no longer mentioned in the Guide To Numpy. Is it deprecated?

-Tom Loredo

In [1]: import numpy
In [2]: numpy.__version__
Out[2]: '1.0b2.dev2941'
In [3]: from numpy import random
In [4]: s=random.get_state()
In [5]: s
Out[5]:
('MT19937',
 array([-1367602364,   599621924,  1947610538,  -686169956, -1451278673,
        1648572372, -1175619180,  -205273143,    13145610,  1292301198,
[snip]
        -716751809,   622130452,   123887232, -2052494269]),
 624)
In [6]: random.set_state(s)
---------------------------------------------------------------------------
exceptions.NameError                                 Traceback (most recent call last)

/home/loredo/research/exoplanets/rv/<ipython console>

/home/loredo/research/exoplanets/rv/mtrand.pyx in mtrand.RandomState.set_state()
NameError: PyArray_ContiguousFromObject
thouis commented 11 years ago

Comment in Trac by atmention:teoliphant, 2006-08-01

This is a problem with the mtrand Pyrex interface only. In particular it is a problem with the numpy.pxi file used in that interface. PyArray_ContiguousFromObject is used in mtrand.pyx but not specified in the numpy.pxi interface file.

Not all of the C-API is specified in the numpy.pxi file. Only the commands that are used.

PyArray_ContiguousFromObject is the old Numeric interface which is and will be supported by NumPy. It is not documented in the Guide to NumPy because there are other commands that are more flexible which replace it.

In particular, the PyArray_ContiguousFromObject always returns an ndarray object even if given a sub-class. The PyArray_ContiguousFromAny call can return a sub-class if one is given.

This is fixed in r2942