Hi All, What's the best type of array to use for decimal values? (ie: where I care about precision and want to avoid any possible rounding errors) cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk
On Sat, Aug 20, 2011 at 17:37, Chris Withers
Hi All,
What's the best type of array to use for decimal values? (ie: where I care about precision and want to avoid any possible rounding errors)
dtype=object -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
On 20/08/2011 15:38, Robert Kern wrote:
On Sat, Aug 20, 2011 at 17:37, Chris Withers
wrote: Hi All,
What's the best type of array to use for decimal values? (ie: where I care about precision and want to avoid any possible rounding errors)
dtype=object
Thanks! What are the performance implications, if any, of this array type? Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk
On Sat, Aug 20, 2011 at 4:49 PM, Chris Withers
On 20/08/2011 15:38, Robert Kern wrote:
On Sat, Aug 20, 2011 at 17:37, Chris Withers
wrote: Hi All,
What's the best type of array to use for decimal values? (ie: where I care about precision and want to avoid any possible rounding errors)
dtype=object
Thanks!
What are the performance implications, if any, of this array type?
It will be slower, the effect depends on how much data/computation you have. You need to look into using the decimal objects in decimal modulehttp://docs.python.org/library/decimal.html, i.e., import decimal. Note that 1/7 still isn't going to be exact in decimals. Chuck
On Sat, Aug 20, 2011 at 17:49, Chris Withers
On 20/08/2011 15:38, Robert Kern wrote:
On Sat, Aug 20, 2011 at 17:37, Chris Withers
wrote: Hi All,
What's the best type of array to use for decimal values? (ie: where I care about precision and want to avoid any possible rounding errors)
dtype=object
Thanks!
What are the performance implications, if any, of this array type?
It will be slower than floats, obviously, because there will be several C function calls and plenty of extra instructions for each operation on each element. But it will be somewhat faster than looping in Python. Note that decimal.Decimal objects are implemented in pure Python, so you will also be paying for Python function call overhead and other costs going through ceval.c several times over. You may want to try the cdecimal package: http://pypi.python.org/pypi/cdecimal/ This will provide an extension module defining an extension type implemented in C. You can avoid the ceval.c overhead entirely during the array operation. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
On Sun, Aug 21, 2011 at 1:08 AM, Robert Kern
You may want to try the cdecimal package:
I'll second this suggestion. cdecimal is an extraordinarily carefully written and well-tested (almost) drop-in replacement for the decimal module, and well worth a try. It would probably be in the Python standard library by now if anyone had had proper time to review it... Mark
On 22/08/2011 00:18, Mark Dickinson wrote:
On Sun, Aug 21, 2011 at 1:08 AM, Robert Kern
wrote: You may want to try the cdecimal package:
I'll second this suggestion. cdecimal is an extraordinarily carefully written and well-tested (almost) drop-in replacement for the decimal module, and well worth a try. It would probably be in the Python standard library by now if anyone had had proper time to review it...
Who would need to review it? I'm surprised this isn't in EPD... any ideas why? cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk
On Mon, Aug 22, 2011 at 4:07 PM, Chris Withers
On 22/08/2011 00:18, Mark Dickinson wrote:
On Sun, Aug 21, 2011 at 1:08 AM, Robert Kern
wrote: You may want to try the cdecimal package:
I'll second this suggestion. cdecimal is an extraordinarily carefully written and well-tested (almost) drop-in replacement for the decimal module, and well worth a try. It would probably be in the Python standard library by now if anyone had had proper time to review it...
Who would need to review it?
Well, anyone who has the time and understands the domain, really; it's just useful to have a second pair of eyes going through the code. Putting several thousands of lines of unreviewed C code into the Python standard library is a bit of a no-no. Mark
On Mon, Aug 22, 2011 at 10:07, Chris Withers
On 22/08/2011 00:18, Mark Dickinson wrote:
On Sun, Aug 21, 2011 at 1:08 AM, Robert Kern
wrote: You may want to try the cdecimal package:
I'll second this suggestion. cdecimal is an extraordinarily carefully written and well-tested (almost) drop-in replacement for the decimal module, and well worth a try. It would probably be in the Python standard library by now if anyone had had proper time to review it...
Who would need to review it?
I'm surprised this isn't in EPD... any ideas why?
No one has asked for it, to my knowledge. We do provide it in our PyPI repository, so $ enpkg cdecimal should install it if you are an EPD subscriber. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
On Aug 22, 2011, at 3:51 PM, Robert Kern wrote:
On Mon, Aug 22, 2011 at 10:07, Chris Withers
wrote: On 22/08/2011 00:18, Mark Dickinson wrote:
On Sun, Aug 21, 2011 at 1:08 AM, Robert Kern
wrote: You may want to try the cdecimal package:
I'll second this suggestion. cdecimal is an extraordinarily carefully written and well-tested (almost) drop-in replacement for the decimal module, and well worth a try. It would probably be in the Python standard library by now if anyone had had proper time to review it...
Who would need to review it?
I'm surprised this isn't in EPD... any ideas why?
No one has asked for it, to my knowledge. We do provide it in our PyPI repository, so
$ enpkg cdecimal
should install it if you are an EPD subscriber.
This should work with EPDFree even if you aren't an EPD subscriber as well. The fact that cDecimal isn't in EPD is a good thing for you in this case. Automatically built PyPI packages are provided to everybody as long as the package itself is not in EPD proper (to avoid our EPD customers getting "automatic" builds of core packages instead of our tested and verified builds). -Travis
-- Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
--- Travis Oliphant Enthought, Inc. oliphant@enthought.com 1-512-536-1057 http://www.enthought.com
participants (5)
-
Charles R Harris
-
Chris Withers
-
Mark Dickinson
-
Robert Kern
-
Travis Oliphant