Wrap Numpy with Cython?

M

martin.nordstrom87

Hi! I'm trying to wrap numpy with Cython and I've tried to use this
guide to manage this: http://wiki.cython.org/WrappingNumpy
However when I send an array to mysum() it gives me the right answer
only when dtype of the array is float, otherwise it gives me random
answers. The problem may be that the array is converted to a C double
which is just as long as float for Numpyarrays and therefore it works
only when the dtype is float. How do I make a Numpywrapper that works
with an arbitrary dtype?

I've also tried to convert a tuple or list with only numbers in it to
a C array with Cython but I've failed. Does anyone have an example of
how to do this?

Thanks!
Martin
 
R

Robert Kern

Hi! I'm trying to wrap numpy with Cython and I've tried to use this
guide to manage this: http://wiki.cython.org/WrappingNumpy
However when I send an array to mysum() it gives me the right answer
only when dtype of the array is float, otherwise it gives me random
answers. The problem may be that the array is converted to a C double
which is just as long as float for Numpyarrays and therefore it works
only when the dtype is float. How do I make a Numpywrapper that works
with an arbitrary dtype?

You will need a Cython function for each dtype and dispatch based on the dtype.

You will want to ask further numpy questions on the numpy mailing list:

http://www.scipy.org/Mailing_Lists

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top