[SciPy-dev] Question: general heap implementation versus specific?

Sturla Molden sturla@molden...
Tue Mar 3 04:42:38 CST 2009


On 3/3/2009 5:24 AM, Anne Archibald wrote:

> While C++ templates should be able to help with this sort of thing, I
> think as long as one is sticking to C and to cython, there's no good
> solution to making a general-enough library. Of course, if you want a
> fully-flexible heap at the python level, that exists already. But I
> think, annoying as it is, we're stuck reimplementing heaps.

Python is a fantastic text processor though. It is easy to set up an ad 
hoc template system in Python. In its simplest form:

 >>> code = """
cdef T1 foobar(T2 *t):
    return <T1> t[0]
"""
 >>> print code.replace('T1', 'int').replace('T2', 'double')

cdef int foobar(double *t):
    return <int> t[0]


Sturla Molden






More information about the Scipy-dev mailing list