[Pyrex] Question, plus suggestions for improvement?

Josiah Carlson jcarlson at uci.edu
Wed Aug 2 01:16:13 UTC 2006


"Bill Mill" <bill.mill at gmail.com> wrote:
> 
> > If you need to perform many accesses, it's better to convert it to a
> > standard C array of integers/floats, allocated with malloc() (and freed with
> > free()). You can index it with any "cdef int" variable, and this will
> > provide C-like performance. This is especially useful if the same data is
> > used many times (eg: convert the data to C array in the constructor, and
> > then use it in all the methods).
> 
> While very interesting, I won't copy the thread between you and
> Josiah. Instead, I'll give you both some more requirements.
> 
> Since the size of the input list is limited severely by practical
> concerns (it has factorial(len(input_list)) permutations), my problem
> is largely one of many array accesses.
> 
> Would it be better to convert the list into a C array? How should I do
> so? I assume I'll need to convert it back to a python array when I'm
> done - is that going to kill any performance gains I may see inside
> the main loop? (Well, if you answer the second question, I'll just
> experiment and answer the third for you.)

See my most recent post, which includes an optimized version which does
not require converting the input in any way.  It copies the input, and
initializes an array of ints.  From then on, it permutes this list of
ints (which is fast), and just before returning, copies the original
input to the copy initially made (thus creating a permutation), and
returns.  It should be about as fast as you could get this particular
algorithm in Pyrex.

 - Josiah




More information about the Pyrex mailing list