Re: [Numpy-discussion] Round away from zero (towards +/- infinity)
On Fri, Oct 3, 2014 at 11:28 AM, T J tjhn...@gmail.com wrote: It does, but it is not portable. That's why I was hoping NumPy might think about supporting more rounding algorithms. On Thu, Oct 2, 2014 at 10:00 PM, John Zwinck jzwi...@gmail.com wrote: On 3 Oct 2014 07:09, T J tjhn...@gmail.com wrote: Any bites on this? On Wed, Sep 24, 2014 at 12:23 PM, T J tjhn...@gmail.com wrote: Python's round function goes away from zero, so I am looking for the NumPy equivalent (and using vectorize() seems undesirable). In this sense, it seems that having a ufunc for this type of rounding could be helpful. Aside: Is there interest in a more general around() that allows users to specify alternative tie-breaking rules, with the default staying 'round half to nearest even'? [1] --- [1] http://stackoverflow.com/questions/16000574/tie-breaking-of-round-with-numpy I like the solution given in that Stack Overflow post, namely using ctypes to call fesetround(). Does that work for you? In [4]: def roundout(x): ...: return trunc(x + copysign(.5, x)) ...: Will do what you want, if not quite as nicely as a ufunc. Won't work as is for complex, but that could be handled with a view. Chuck ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Round away from zero (towards +/- infinity)
It does, but it is not portable. That's why I was hoping NumPy might think about supporting more rounding algorithms. On Thu, Oct 2, 2014 at 10:00 PM, John Zwinck jzwi...@gmail.com wrote: On 3 Oct 2014 07:09, T J tjhn...@gmail.com wrote: Any bites on this? On Wed, Sep 24, 2014 at 12:23 PM, T J tjhn...@gmail.com wrote: Python's round function goes away from zero, so I am looking for the NumPy equivalent (and using vectorize() seems undesirable). In this sense, it seems that having a ufunc for this type of rounding could be helpful. Aside: Is there interest in a more general around() that allows users to specify alternative tie-breaking rules, with the default staying 'round half to nearest even'? [1] --- [1] http://stackoverflow.com/questions/16000574/tie-breaking-of-round-with-numpy I like the solution given in that Stack Overflow post, namely using ctypes to call fesetround(). Does that work for you? ___ 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] Round away from zero (towards +/- infinity)
Any bites on this? On Wed, Sep 24, 2014 at 12:23 PM, T J tjhn...@gmail.com wrote: Is there a ufunc for rounding away from zero? Or do I need to do x2 = sign(x) * ceil(abs(x)) whenever I want to round away from zero? Maybe the following is better? x_ceil = ceil(x) x_floor = floor(x) x2 = where(x = 0, x_ceil, x_floor) Python's round function goes away from zero, so I am looking for the NumPy equivalent (and using vectorize() seems undesirable). In this sense, it seems that having a ufunc for this type of rounding could be helpful. Aside: Is there interest in a more general around() that allows users to specify alternative tie-breaking rules, with the default staying 'round half to nearest even'? [1] Also, what is the difference between NumPy's fix() and trunc() functions? It seems like they achieve the same goal. trunc() was added in 1.3.0. So is fix() just legacy? --- [1] http://stackoverflow.com/questions/16000574/tie-breaking-of-round-with-numpy ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Round away from zero (towards +/- infinity)
On 3 Oct 2014 07:09, T J tjhn...@gmail.com wrote: Any bites on this? On Wed, Sep 24, 2014 at 12:23 PM, T J tjhn...@gmail.com wrote: Python's round function goes away from zero, so I am looking for the NumPy equivalent (and using vectorize() seems undesirable). In this sense, it seems that having a ufunc for this type of rounding could be helpful. Aside: Is there interest in a more general around() that allows users to specify alternative tie-breaking rules, with the default staying 'round half to nearest even'? [1] --- [1] http://stackoverflow.com/questions/16000574/tie-breaking-of-round-with-numpy I like the solution given in that Stack Overflow post, namely using ctypes to call fesetround(). Does that work for you? ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] Round away from zero (towards +/- infinity)
Is there a ufunc for rounding away from zero? Or do I need to do x2 = sign(x) * ceil(abs(x)) whenever I want to round away from zero? Maybe the following is better? x_ceil = ceil(x) x_floor = floor(x) x2 = where(x = 0, x_ceil, x_floor) Python's round function goes away from zero, so I am looking for the NumPy equivalent (and using vectorize() seems undesirable). In this sense, it seems that having a ufunc for this type of rounding could be helpful. Aside: Is there interest in a more general around() that allows users to specify alternative tie-breaking rules, with the default staying 'round half to nearest even'? [1] Also, what is the difference between NumPy's fix() and trunc() functions? It seems like they achieve the same goal. trunc() was added in 1.3.0. So is fix() just legacy? --- [1] http://stackoverflow.com/questions/16000574/tie-breaking-of-round-with-numpy ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion