Re: [Numpy-discussion] Caution about using intrisincs, and other 'advanced' optimizations
On Fri, Nov 15, 2013 at 8:47 PM, Julian Taylor jtaylor.deb...@googlemail.com wrote: Will do, but the errors I am seeing only appear in the simc.inc.src-based implementation of BOOL_logical_or (they disappear if I disable the simd intrinsics manually in the numpy headers). that is because the simd code always looks at the stride (as it only can run with unit strides) while the simple loop doesn't if the dimension is 1. GCC 4.1 is older than python2.5 which we do not support anymore in numpy = 1.8. If you insist on using a buggy old compiler one could always use numpy 1.7. Compiler age and Python version are not equivalent. The former is much harder to upgrade, and much more depends on it for a user. OS X still ships gcc 4.2, and the default compiler for Python 2.6 on OS X is gcc 4.0 which we definitely still support. On Windows we even need gcc 3.4.5 until we find the right way to get rid of it. Ralf Also intrinsics are not more prone to compiler bugs than any other code, so I see no reason to special case them. The code itself is more prone bugs due to its higher complexity in some parts, but I think it is reasonably well tested. ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] runtime warning for where
The program at the bottom of this message returns the following runtime warning: python test.py test.py:5: RuntimeWarning: invalid value encountered in divide return np.where(x==0., 1., np.sin(x)/x) The function works correctly returning x = np.array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]) y = np.array([ 1., 0.84147098, 0.45464871, 0.04704 , -0.18920062, -0.19178485, -0.04656925, 0.09385523, 0.12366978, 0.04579094, -0.05440211]) The runtime warning suggests that np.where evaluates np.sin(x)/x at all x, including x=0, even though the np.where function returns the correct value of 1. when x is 0. This seems odd to me. Why issue a runtime warning? Nothing is wrong. Moreover, I don't recall numpy issuing such warnings in earlier versions. import numpy as np import matplotlib.pyplot as plt def sinc(x): return np.where(x==0., 1., np.sin(x)/x) x = np.linspace(0., 10., 11) y = sinc(x) plt.plot(x, y) plt.show() ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] runtime warning for where
On Sat, Nov 16, 2013 at 8:28 AM, David Pine djp...@gmail.com wrote: The program at the bottom of this message returns the following runtime warning: python test.py test.py:5: RuntimeWarning: invalid value encountered in divide return np.where(x==0., 1., np.sin(x)/x) The function works correctly returning x = np.array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]) y = np.array([ 1., 0.84147098, 0.45464871, 0.04704 , -0.18920062, -0.19178485, -0.04656925, 0.09385523, 0.12366978, 0.04579094, -0.05440211]) The runtime warning suggests that np.where evaluates np.sin(x)/x at all x, including x=0, even though the np.where function returns the correct value of 1. when x is 0. This seems odd to me. Why issue a runtime warning? Nothing is wrong. Moreover, I don't recall numpy issuing such warnings in earlier versions. import numpy as np import matplotlib.pyplot as plt def sinc(x): return np.where(x==0., 1., np.sin(x)/x) x = np.linspace(0., 10., 11) y = sinc(x) plt.plot(x, y) plt.show() For what it's worth, you can see the different strategies that numpy and scipy use to work around this warning. https://github.com/numpy/numpy/blob/master/numpy/lib/function_base.py#L2662 https://github.com/scipy/scipy/blob/master/scipy/special/basic.py#L43 Numpy sinc uses a small number instead of zero. Scipy sinc disables the warning explicitly. ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] runtime warning for where
On Sat, Nov 16, 2013 at 8:28 AM, David Pine djp...@gmail.com wrote: The program at the bottom of this message returns the following runtime warning: python test.py test.py:5: RuntimeWarning: invalid value encountered in divide return np.where(x==0., 1., np.sin(x)/x) The function works correctly returning x = np.array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]) y = np.array([ 1., 0.84147098, 0.45464871, 0.04704 , -0.18920062, -0.19178485, -0.04656925, 0.09385523, 0.12366978, 0.04579094, -0.05440211]) The runtime warning suggests that np.where evaluates np.sin(x)/x at all x, including x=0, even though the np.where function returns the correct value of 1. when x is 0. This seems odd to me. Why issue a runtime warning? Nothing is wrong. Moreover, I don't recall numpy issuing such warnings in earlier versions. import numpy as np import matplotlib.pyplot as plt def sinc(x): return np.where(x==0., 1., np.sin(x)/x) x = np.linspace(0., 10., 11) y = sinc(x) plt.plot(x, y) plt.show() Also notice that scipy.stats.distributions has its own private implementation of where, called _lazywhere. It avoids evaluating the function when the condition is false. https://github.com/scipy/scipy/blob/master/scipy/stats/distributions.py#L506 ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] runtime warning for where
Hi, Don't forget that np.where is not smart. First np.sin(x)/x is computed for the array, which is why you see the warning, and then np.where selects the proper final results. Cheers, Matthieu 2013/11/16 David Pine djp...@gmail.com: The program at the bottom of this message returns the following runtime warning: python test.py test.py:5: RuntimeWarning: invalid value encountered in divide return np.where(x==0., 1., np.sin(x)/x) The function works correctly returning x = np.array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]) y = np.array([ 1., 0.84147098, 0.45464871, 0.04704 , -0.18920062, -0.19178485, -0.04656925, 0.09385523, 0.12366978, 0.04579094, -0.05440211]) The runtime warning suggests that np.where evaluates np.sin(x)/x at all x, including x=0, even though the np.where function returns the correct value of 1. when x is 0. This seems odd to me. Why issue a runtime warning? Nothing is wrong. Moreover, I don't recall numpy issuing such warnings in earlier versions. import numpy as np import matplotlib.pyplot as plt def sinc(x): return np.where(x==0., 1., np.sin(x)/x) x = np.linspace(0., 10., 11) y = sinc(x) plt.plot(x, y) plt.show() ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion -- Information System Engineer, Ph.D. Blog: http://matt.eifelle.com LinkedIn: http://www.linkedin.com/in/matthieubrucher Music band: http://liliejay.com/ ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] runtime warning for where
Thanks. I must have had runtime warnings turned off in my previous versions of python. On Sat, Nov 16, 2013 at 8:42 AM, alex argri...@ncsu.edu wrote: On Sat, Nov 16, 2013 at 8:28 AM, David Pine djp...@gmail.com wrote: The program at the bottom of this message returns the following runtime warning: python test.py test.py:5: RuntimeWarning: invalid value encountered in divide return np.where(x==0., 1., np.sin(x)/x) The function works correctly returning x = np.array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]) y = np.array([ 1., 0.84147098, 0.45464871, 0.04704 , -0.18920062, -0.19178485, -0.04656925, 0.09385523, 0.12366978, 0.04579094, -0.05440211]) The runtime warning suggests that np.where evaluates np.sin(x)/x at all x, including x=0, even though the np.where function returns the correct value of 1. when x is 0. This seems odd to me. Why issue a runtime warning? Nothing is wrong. Moreover, I don't recall numpy issuing such warnings in earlier versions. import numpy as np import matplotlib.pyplot as plt def sinc(x): return np.where(x==0., 1., np.sin(x)/x) x = np.linspace(0., 10., 11) y = sinc(x) plt.plot(x, y) plt.show() Also notice that scipy.stats.distributions has its own private implementation of where, called _lazywhere. It avoids evaluating the function when the condition is false. https://github.com/scipy/scipy/blob/master/scipy/stats/distributions.py#L506 ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] runtime warning for where
Don't forget that np.where is not smart And there's really no way it could be. np.where, like all Python functions, must evaluate all of the arguments first, then call the function. ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion