Dag, > > 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.
yep, I figured that much. there is still the ability to call in the C-stubs the Reflex library is generating (C++ isn't a model of portability...) so I'll go that way in waiting for the end of the gsoc. > 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). as you can see I have no understanding of how the cython parser works, but I was under the impression that when cython was compiling python code to C using the python C-api it knew somehow how to translate e.g. def foo(): t = (1,2,3) return t into the appropriate PyTuple_xyz calls... and I had the wild dream I could hook myself in there. > 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. type inference and/or type annotations are indeed a holy grail in python to which I am sympathetic but rather clueless as to how to even start :) somehow I think unladen-swallow will give us some tools to do it. cheers, sebastien. -- ######################################### # Dr. Sebastien Binet # Laboratoire de l'Accelerateur Lineaire # Universite Paris-Sud XI # Batiment 200 # 91898 Orsay ######################################### _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
