[Pyrex] Question, plus suggestions for improvement?

Giovanni Bajo rasky at develer.com
Wed Aug 2 02:03:08 UTC 2006


Josiah Carlson <jcarlson at uci.edu> wrote:

>> Yes, this is why I said "what if you have unbounded size". I'm not
>> sure of what algorithms you are thinking of, but the ones I think
>> can't really have some hardcoded limit. One strategy is to get the
>> best of the two worlds: if the memory is smaller than a certain
>> amount, use the stack, otherwise go through malloc/free.
>
> From the look of the OP's source, it iterates through a predefined
> algorithm for generating all of the possible permutations of a
> sequence.
> As such, only short sequences would have any chance of executing to
> completion. Any sequence with more than about 16 unique values likely
> won't execute to completion, and any significantly larger sequence
> would
> only permute through an insignificant fraction of the total
> permutation space.

OK you are right for this very algorithm. In fact, why is a permutation
algorithm needed in Pyrex at all? I usually use this recipe:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/190465
which works quite well for me. I'd be surprised if the actual computation of
the permuation was a bottleneck.

Though I maintain that using malloc in Pyrex is the right way to go when you
manipulate large lists of floats/ints (that is, one typical scenario when Pyrex
is worth it).

Giovanni Bajo




More information about the Pyrex mailing list