[Cython] CEP1000: Native dispatch through callables

Nathaniel Smith njs at pobox.com
Thu Apr 19 16:28:54 CEST 2012

On Thu, Apr 19, 2012 at 2:18 PM, Dag Sverre Seljebotn
<d.s.seljebotn at astro.uio.no> wrote:
> On 04/19/2012 01:20 PM, Nathaniel Smith wrote:
>> @cython.inline
>> def square(x):
>>     return x * x
>> # .specialize is an un-standardized Cython interface
>> # square_double is an object implementing the standardized C-callable
>> interface
>> square_double = square.specialize("d->d")
>> scipy.integrate.quad(square_double)
>> That'd be enough to get started, and doesn't rule out later extensions
>> that do automatic type selection, once we have more experience.
> Well, I want np.sin to replace "cdef extern from 'math.h'", and then this
> seems to be needed... at least the possibility to have both "d->d" and
> "O->O".

Except, the C function implementing np.sin on doubles actually has a
signature that's something like "&&t&i&i&t->"
(PyUFuncGenericFunction), not "d->d"... so maybe this is a good
example to work through! It isn't at all obvious to me how this should
be made to work in any of these proposals.

(Isn't "O->O" just obj->ob_type->tp_call in any case?)

-- Nathaniel

More information about the cython-devel mailing list