[SciPy-dev] NumPy f2py GSOC project
Dag Sverre Seljebotn
dagss at student.matnat.uio.no
Fri Mar 27 04:58:48 EDT 2009
David Cournapeau wrote:
> If you are interested in working on scipy-related projects, something
> which could help the transition is to replace C code by cython. This
> would be particularly helpful in scipy - there are many modules which
> are crufty and would benefit from code cleaning, but if you don't know
> cython, maybe that's not something that interesting for you. Cython is
> not difficult to use, though. scipy.signal comes to mind, to take
> something where I could definitely help you - but there are other
> modules as well, where other people would be more qualified
> (scipy.ndimage, etc...). One module means that it would be easier for
> you to work on, easier for use to help/coordinate, and at least in the
> case of scipy.signal, there is definitely some new features which are
> needed as well (new feature is generally more fun than code cleanup/bug
> hunting). Of course, you should choose modules which interest you.
If something like this is done, one idea I have for SciPy is quick
Cython callbacks for solvers/integrators. Perhaps Lisandro would be
interested in being Cython-side mentor? Though the main mentor would
need to be from SciPy.
People often write on the Cython list about code like this:
def f(double x): return x*x
some_scipy_function(f, 0, 10)
The problem here is that a Python overhead is encurred on all function
evaluations. What one could do is add a "Cython protocol" like this:
cdef class DoubleFunction:
cpdef double eval(double x): return 0
Then inside SciPy core (psuedo-code):
PyObject* some_scipy_function(...) {
PyObject* callback = parse argument...
...
if (callback is instance of DoubleFunction) {
call using quick Cython dispatch
} else {
call using Python API
}
}
Then in user code:
cdef class MyFunc(DoubleFunction):
cpdef double eval(double x): return x*x
some_scipy_function(MyFunc(), 0, 10)
Voila!, 50x speedup of solvers from Cython.
--
Dag Sverre
More information about the SciPy-Dev
mailing list