[Numpy-discussion] Numexpr giving randomized results on arrays larger than 2047 elements
Warren Weckesser
warren.weckesser at enthought.com
Mon Jan 24 14:35:55 EST 2011
On Mon, Jan 24, 2011 at 1:13 PM, John Salvatier
<jsalvati at u.washington.edu>wrote:
> Looks like this is related to issue 41 (
> http://code.google.com/p/numexpr/issues/detail?id=41&can=1).
That might not be the same issue.
You can fix the "randomness" by setting the number of threads to 1, as in
input [6] here:
In [1]: import numexpr as ne
In [2]: x = zeros(8192)+0.01
In [3]: ne.evaluate('sum(x, axis=0)')
Out[3]: array(71.119999999999479)
In [4]: ne.evaluate('sum(x, axis=0)')
Out[4]: array(81.920000000005004)
In [5]: ne.evaluate('sum(x, axis=0)')
Out[5]: array(68.379999999998077)
In [6]: ne.set_num_threads(1)
In [7]: ne.evaluate('sum(x, axis=0)')
Out[7]: array(81.920000000005004)
In [8]: ne.evaluate('sum(x, axis=0)')
Out[8]: array(81.920000000005004)
In [9]: ne.evaluate('sum(x, axis=0)')
Out[9]: array(81.920000000005004)
Warren
>
>
> On Mon, Jan 24, 2011 at 10:29 AM, John Salvatier <
> jsalvati at u.washington.edu> wrote:
>
>> I also get the same issue with prod()
>>
>>
>> On Mon, Jan 24, 2011 at 10:23 AM, Warren Weckesser <
>> warren.weckesser at enthought.com> wrote:
>>
>>> I see the same "randomness", but at a different array size:
>>>
>>> In [23]: numpy.__version__
>>> Out[23]: '1.4.0'
>>>
>>> In [24]: import numexpr
>>>
>>> In [25]: numexpr.__version__
>>> Out[25]: '1.4.1'
>>>
>>> In [26]: x = zeros(8192)+0.01
>>>
>>> In [27]: print evaluate('sum(x, axis=0)')
>>> 72.97
>>>
>>> In [28]: print evaluate('sum(x, axis=0)')
>>> 66.92
>>>
>>> In [29]: print evaluate('sum(x, axis=0)')
>>> 67.9
>>>
>>> In [30]: x = zeros(8193)+0.01
>>>
>>> In [31]: print evaluate('sum(x, axis=0)')
>>> 72.63
>>>
>>> In [32]: print evaluate('sum(x, axis=0)')
>>> 71.74
>>>
>>> In [33]: print evaluate('sum(x, axis=0)')
>>> 81.93
>>>
>>> In [34]: x = zeros(8191)+0.01
>>>
>>> In [35]: print evaluate('sum(x, axis=0)')
>>> 81.91
>>>
>>> In [36]: print evaluate('sum(x, axis=0)')
>>> 81.91
>>>
>>>
>>> Warren
>>>
>>>
>>>
>>> On Mon, Jan 24, 2011 at 12:19 PM, John Salvatier <
>>> jsalvati at u.washington.edu> wrote:
>>>
>>>> Forgot to mention that I am using numexpr 1.4.1 and numpy 1.5.1
>>>>
>>>>
>>>> On Mon, Jan 24, 2011 at 9:47 AM, John Salvatier <
>>>> jsalvati at u.washington.edu> wrote:
>>>>
>>>>> Hello,
>>>>>
>>>>> I have discovered a strange bug with numexpr. numexpr.evaluate gives
>>>>> randomized results on arrays larger than 2047 elements. The following
>>>>> program demonstrates this:
>>>>>
>>>>> from numpy import *
>>>>> from numexpr import evaluate
>>>>>
>>>>> def func(x):
>>>>>
>>>>> return evaluate("sum(x, axis = 0)")
>>>>>
>>>>>
>>>>> x = zeros(2048)+.01
>>>>>
>>>>> print evaluate("sum(x, axis = 0)")
>>>>> print evaluate("sum(x, axis = 0)")
>>>>>
>>>>> For me this prints different results each time, for example:
>>>>>
>>>>> 11.67
>>>>> 14.84
>>>>>
>>>>> If we set the size to 2047 I get consistent results.
>>>>>
>>>>> 20.47
>>>>> 20.47
>>>>>
>>>>> Interestingly, if I do not add .01 to x, it consistently sums to 0.
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> NumPy-Discussion mailing list
>>>> NumPy-Discussion at scipy.org
>>>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>>>
>>>>
>>>
>>> _______________________________________________
>>> NumPy-Discussion mailing list
>>> NumPy-Discussion at scipy.org
>>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>>
>>>
>>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110124/5bd1e947/attachment.html>
More information about the NumPy-Discussion
mailing list