On 2009-09-30 12:34 PM, Christopher Barker wrote:

> The "standard practice" is to accumulate in a python list, then convert
> the final result into an array. This is a good idea because Python lists
> are standard, well tested, efficient, etc.
 >
> However, as was pointed out in that lengthy discussion, if what you are
> doing is accumulating is a whole bunch of numbers (ints, floats,
> whatever), or particularly if you need to accumulate a data type that
> plain python doesn't support, there is a lot of overhead involved: a
> python float type is pretty heavyweight. If performance or memory use is
>    important, it might create issues.

array.array() solves these problems if your type is supported. It follows the 
same preallocation strategy as lists. One may create a numpy array from it 
quickly using np.frombuffer().

> What I have in mind is very simple. It would be:
>    - Only 1-d
>    - Support append() and extend() methods
>    - Support any valid numpy dtype
>      - which could even get you pseudo n-d arrays...
>    - maybe it would act like an array in other ways, I'm not so sure..
>
>
> It could be written in pure python, using np.resize()(or concatenate,
> or,...), and certainly written efficiently in Cython or even (no!) C.

An Appender object that maintains an array that .resize()s (the ndarray method, 
not the function! They are quite different.) according to the list/array.array 
preallocation strategy would be quite useful. I do recommend that you keep the 
array "private" until you are done with it. This helps prevent views being made 
of the array so you can keep using the .resize() method.

-- 
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

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to