On 10/19/2011 08:44 PM, St�fan van der Walt wrote:
On Wed, Oct 19, 2011 at 9:57 AM, Ralf Gommers <ralf.gommers@googlemail.com> wrote:
Does anyone here have experience with such approaches?
scipy.interpolate has Cython code with simple Mako templating, look at interpnd.pyx and generate_interpnd.py. If it's flexible enough for your needs then it'll be a lot more pleasant than using C++. This definitely gets us some way. We can modify our _build.cython call to first run the template engine on any .tpyx files.
But how should we dispatch to different functions, based on dtype? Let's say we have support for int16, uint16 and double in our algorithm, so via templating we'll get
myfunc_int16 myfunc_uint16 myfunc_double
for a single input argument (which is the most common case). We can then define a dispatch call such as
dtype_call('myfunc', img.dtype)
which calls the appropriate function. Does this sound about right? Sounds sensible. Doing the overloading "by hand" looks a bit ugly but it seems cython does not do overloading of cython functions: http://wiki.cython.org/enhancements/overloading Overloaded C++ functions on the other hand seem to be no problem <http://wiki.cython.org/WrappingCPlusPlus>.