Wrap Numpy with Cython?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • martin.nordstrom87@gmail.com

    Wrap Numpy with Cython?

    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
  • Robert Kern

    #2
    Re: Wrap Numpy with Cython?

    martin.nordstro m87@gmail.com wrote:
    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:



    --
    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

    Comment

    Working...