[Numpy-discussion] problem w 32bit binomial?

David Warde-Farley dwf at cs.toronto.edu
Thu Feb 25 19:32:54 EST 2010


Hey James,

On 25-Feb-10, at 5:59 PM, James Bergstra wrote:

> In case this hasn't been solved in more recent numpy...
>
> I've tried the following lines on two installations of numpy 1.3  
> with python 2.6
>
>  numpy.random.binomial(n=numpy.asarray([2,3,4], dtype='int64'),
> p=numpy.asarray([.1, .2, .3], dtype='float64'))
>
> A 64bit computer gives an output of array length 3.
> A 32bit computer gives an error:
>
>     TypeError: array cannot be safely cast to required type

It seems to be not only 32-bit specific but x86-specific. On a ppc  
machine, 32-bit mode:

dwf at morrislab:~$ python-32
Python 2.6.4 (r264:75706, Feb 16 2010, 21:03:46)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> import numpy
 >>> numpy.__version__
'1.3.0'
 >>> numpy.random.binomial(n=numpy.asarray([2,3,4], dtype='int64'),  
p=numpy.asarray([.1,.2,.3], dtype='float64'))
array([1, 1, 2])

But I can confirm the bug on OS X/Intel 32-bit, and Linux x86-32 (both  
1.3.0 and most recent svn trunk), as well as its absence on Linux  
x86-64. The problem seems to be with this line in mtrand.pyx, line  
3306 in the trunk:

         on = <ndarray>PyArray_FROM_OTF(n, NPY_LONG, NPY_ALIGNED)

I recall there being some consistency problems with NPY_LONG across  
architectures. I thought it was only an issue for Python 2.4,  
though... Perhaps Chuck or David C. know what's going on.

David



More information about the NumPy-Discussion mailing list