Hi Dag, Dag Sverre Seljebotn wrote: > I guess it depends on the motivation. I'm sceptical of hit-or-miss > optimization in general -- that is, I don't think we can aim for > "magically optimizing" very much user code through single optimization > points like this. They are more for users who already know that their > code will be both interpreted in Python and compiled with Cython -- of > course, for such users an optimized izip could still be useful.
Besides the obvious advantage of optimising Python code, I think even Cython code will benefit, as it's ugly when you have to unroll izip() yourself in your code. When you need that functionality, there should be no reason to work around it for performance reason. > I think my opinion is that I'd like to see this split this into a couple > of orthogonal and generic features: > > a) Auto-cimport (if a directive is set, which defaults to on?). I.e. if > you do a Python import, and a pxd file can be found, a cimport is done > automatically. +0.7 given that this may really have a performance impact, as Robert stated. There should at least be a cache for the standard include path that survives multiple compilations in one compiler run (another orthogonal feature that would be nice for .pxd files in general). > b) Overloading combined with fall-through to Python space. I started a > CEP on this [1], Robert discussed it with me, but it never got finished. > > One way is to allow e.g. (in "math.pxd") > > double sin(double x): return libc.math.sin(x) > object sin(object x) +1, nice feature. > Somehow it must be added here though that sin should be looked up at > module initialization using getattr rather than through > __pyx_capi/Cython call convention. That would be implied by the fact that you used a Python import. But leaving this to the poor importer might turn out to be error prone, given that the math module actually is a C extension... > c) For izip (and, in time, zip in __builtin__ too) I'm more in favour of > a slightly magic optimization -- it's easier to be an expert on hacking > pxd files than the Cython compiler. Namely: > > If a generator function contains exactly one "yield", and is declared > "inline", and used in a for-loop, then the entire generator will be > inlined into the function (putting the for-loop body at the position of > the yield). +1, another cool feature - once we have generator support in general. :) Stefan _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
