On 7 February 2016 at 10:02, Marko Loparic <
marko....@gmail.com> wrote:
> 1. Achieve C performance (ie. "nogil code", white cython html) for the loop.
> If possible, the value method/function should be inlined (so to avoid a C
> function call).
>
> 2. Separate the value function/method from the compute code in two different
> modules. The compute code ---a library, with a generic algorithm -- is to be
> used by different problems, each one with a different value routine. I know
> that in order to have my first goal met the link between the two modules has
> to be done in compilation time. The 'problem' object does not need to be a
> cython class. It can also be a cython module with functions.
>
> 3. Have these two modules in a cython pure python source code, so as to be
> able to run the code without cython (and without having two different
> versions of the same code).
A while ago I spent some time profiling different ways to achieve goal
2. I found that the most efficient method to achieve the redirection
is by subclassing and overriding a cdef method. This way the dispatch
is handled by a vtable (like in C++).
I have an example of that here:
https://github.com/oscarbenjamin/euler/blob/master/euler_10.pyx
https://github.com/oscarbenjamin/euler/blob/master/README.rst
I'm not sure if it's possible to combine this with pure Python mode
(goal 3) but I don't see any reason why it wouldn't work.
Whether or not you can meet goal 1 depends on the detail of you
problem. The importance of goal 2 does as well: if all you're overhead
is in value() then the expense of compute and the compute to value()
connection may be irrelevant.
--
Oscar