numpy NaN, not surviving pickle/unpickle?
tjreedy at udel.edu
Mon Sep 14 19:48:39 CEST 2009
Gabriel Genellina wrote:
> En Sun, 13 Sep 2009 20:53:26 -0300, Steven D'Aprano
> <steve at remove-this-cybersource.com.au> escribió:
>> There may be something to be said for caching "common" floats, like pi,
>> small integers (0.0, 1.0, 2.0, ...), 0.5, 0.25 and similar, but I doubt
>> the memory savings would be worth the extra complexity.
Pi is already cached -- in the math module.
Zero is not because one can easily write zero=0.0, etc.
The main memory saving comes on allocation of large arrays or of
multiple medium arrays. For that, one can use one named object.
It is easy to cache and test for ints in a contiguous range.
Cached ints are heavily reused in the interpreter before it executes a
line of code.
Built-in equality tests for several floats would slow down all float
code. Interpreter does not use floats for its internal operations. So
idea was considered and rejected by devs.
> I've read some time ago, that simply caching 0.0 reduced appreciably the
> memory usage of a Zope application.
> (Note that Zope relies on pickling and unpickling objects all the time,
> so even if two objects started as the "same" zero, they may become
> different at a later time.)
More information about the Python-list