Sebastien Binet wrote:
> hi there,
>
> say I have a set of C++ libraries for which python bindings have already been
> generated (with Reflex [1])
> using these bindings is quite easy but then users complain that their code is
> slower than in C++ (d'oh!)
>
> so I was playing with the idea to use python+reflex introspections
> capabilities to automatically generate a cython module out of some python
> code:
>
> ##
> def do_silly_stuff():
> import ROOT
> h = ROOT.THistogram(...)
> for i in xrange(100):
> h.Fill(ROOT.TRandom())
> return h
>
> (ROOT is the python module which gives access to these C++ libraries.)
>
> my goal is to bypass the python wrapper and call directly into either the C++
> function/method or its C-stub equivalent.
>
> I see 2 ways:
> - automatically generate a .pyx/.pxd file containing the definition of the
> wrapped classes and stuff
> - tab into the cython parser to help him recognise that ROOT.THistogram is a
> C++ statement and that there is no need to go through the python C-api or any
> other mambo-jumbo...
>
> any advice on how to achieve that ? (which way is simpler and faster to be
> done, code to start with,...)
First of all, this will likely be much easier if you wait until after
summer, when there will be more C++ support in Cython.
Using Reflex to automatically generate pyx/pxd files make sense,
shouldn't be too much work (especially after the summer with more C++
support) and would be very useful. But one must then write Cython, not
Python, code in order to get the speedup. I.e.
cimport ROOT
def do_silly_stuff():
cdef Root.THistogram h = ROOT.THistogram(...)
...
and so on; that is, one must explicitly type variables to get the C++
speedup.
The second option is not really an option -- ROOT is a Python module,
and there's no way of finding out "what is beneath" and call it directly
(except for the existing mechanism of a) writing pxds and b) using types).
Anything close to the "automatic speedup" you seem to want (that is,
without adding types manually in client code) would require adding
automatic type inference to Cython. This is something there's a lot of
interest in, but it is also a significant amount of work.
We're certainly very enthusiastic about any efforts in this direction
(and willing to assist with planning and guidance); but I don't think
there's any shortcuts, unfortunately.
--
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev