On Mon, Apr 11, 2011 at 12:54 PM, Skipper Seabold <jsseabold@gmail.com> wrote:
All,

We noticed some failing tests for statsmodels between numpy 1.5.1 and
numpy >= 1.6.0. These are the versions where I noticed the change. It
seems that when you divide a float array and multiply by a boolean
array the answers are different (unless the others are also off by
some floating point). Can anyone replicate the following using this
script or point out what I'm missing?

import numpy as np
print np.__version__
np.random.seed(12345)

test = np.random.randint(0,2,size=10).astype(bool)
t = 1.345
arr = np.random.random(size=10)

arr # okay
t/arr # okay
(1-test)*arr # okay
(1-test)*t/arr # huh?

Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> print np.__version__
2.0.0.dev-fe3852f
>>> np.random.seed(12345)
>>>
>>> test = np.random.randint(0,2,size=10).astype(bool)
>>> t = 1.345
>>> arr = np.random.random(size=10)
>>>
>>> arr # okay
array([ 0.5955447 ,  0.96451452,  0.6531771 ,  0.74890664,  0.65356987,
       0.74771481,  0.96130674,  0.0083883 ,  0.10644438,  0.29870371])
>>> t/arr # okay
array([   2.25843668,    1.39448393,    2.05916589,    1.7959515 ,
         2.0579284 ,    1.79881418,    1.39913718,  160.342421  ,
        12.63570742,    4.50278968])
>>> (1-test)*arr # okay
array([ 0.5955447 ,  0.        ,  0.        ,  0.        ,  0.65356987,
       0.        ,  0.96130674,  0.0083883 ,  0.        ,  0.29870371])
>>> (1-test)*t/arr # huh?
array([   2.25797754,    0.        ,    0.        ,    0.        ,
         2.05751003,    0.        ,    1.39885274,  160.3098235 ,
         0.        ,    4.50187427])


Looks like it is going through float16:

In [2]: float16(1.345)/0.5955447
Out[2]: 2.25797754979601

The scalar 1.345 should be converted to double and that isn't happening.

<snip>

Chuck