On Fri, May 23, 2014 at 8:28 AM, Chris Barker <
chris....@noaa.gov> wrote:
> On Fri, May 23, 2014 at 1:27 AM, Julien Delafontaine <
mura...@gmail.com>
> wrote:
>
>>
>> Anyway, your advice is very precious here! Eventually I will replace some
>> of my code by C++ functions,
>
>
> do you mean hand-written C++, or do you mean C++ generated by Cython?
> Ideally, there should be no need to hand-write C++ unless you need it for
> other purposes -- or you are familiar with C++, and prefer to use it.
>
>> but I always want to keep a version that I can run with the Python
>> compiler only (for diplomatic reasons). So I cannot put any "cdef" in it,
>> and if I don't call it ".pyx", it will never import the .pxd.
>>
>> Usually my workflow is
>> - Edit a A.py version
>> - Copy A.py to B.pyx
>> - Compile B.pyx with B.pxd
>>
>> The only thing I want to do is to replace my functions by a C version with
>> fixed types at compilation time, by overriding them in the .pxd.
>
>
> This is a bit of an add structure / work flow. Maybe it works for you, but:
You might also want to look at pure mode:
http://docs.cython.org/src/tutorial/pure.html
> Robert is quite right, of course you can put pure python in *.pyx files and
> compile them. But then they are harder to change, test, debug, etc,
Hopefully not by much, and we're looking at closing this gap.
> and pure python doesn't buy you much when cythonized.
That depends on the code.
> I'll stay away for calling this
> "usual" or "accepted", but my recommended work flow for something like this
> is:
>
> - Prototype in pure python: A.py
> - If parts of that code need optimizing with Cython for some reason or
> another:
> - copy the parts of A.py that need Cythonizing to B.pyx (maybe one
> function, etc. at a time)
> - keep the high level calling code, test code, etc in A.py
> - import the cythonized pieces from B into A (so the A namespace looks
> the same)
> - add the needed cdefs, etc to B.py (and maybe to B.pxd) -- probably a
> bit at a time, profiling and testing as you go.
> - when you've got the performance you need (or are going to get...) you're
> done.
I do the same, but module-by-module rather than function-by-function,
just renaming A.py to A.pyx. This avoids issues with circular
dependencies between A and B, and chopping splitting up a single
logical module into two separate files.
> B.pxd is mostly useful if you need to share declarations with other Cython
> modules -- that's what they are for.
>
> my $0.2
Woah, 20 cents :)
> -- hope it's helpful.
Yes, I think typical workflows of experienced developers is useful. Thanks.
- Robert