Cython - converting pointers to arrays into Python objects?

Makes the const appear in the C code, so you get typedef unsigned short const uint16_t in which the const is meaningless. (It also redefines the standard type uint16_t which it shouldn't. ).

Ctypedef unsigned short const_ushort "const uint16_t" makes the const appear in the C code, so you get typedef unsigned short const uint16_t in which the const is meaningless. (It also redefines the standard type uint16_t, which it shouldn't. ) You may have more success with ctypedef unsigned short *ushort_p "ushort_p" For some reason, Cython seems not to recognize the C const keyword.

You may have to use a wrapper around your callbacks to deal with the const issue. If you want the pointer translated into a Python object, wrap it in a cdef class. Make sure the class records the height and width, since these are not recorded with the C array.

Thanks, wrapping it in a cdef class seems to allow it to compile, but now I can't figure out how to access it within my python test script. – Josiah Mar 11 '11 at 20:17 @Josiah: it's not clear to me how indexing into your structure works; you seem to be using it as a matrix in C code and as an array in Python code. You might try to define a __getindex__ method in your cdef class and do a 1-d index into the C array from there.

– larsmans Mar 12 '11 at 0:20.

This is not quite what you're asking, but if what you want to do is work with an array of unsigned shorts in Cython and then make your answer accessible on the Python side, you can create a Numpy ndarray on the Python side and pass it into Cython where it is roughly the same as a multi-dimensional array. That way, you get both Python's memory management, some convenient indexing syntax, and the speed of working with a real array in Cython. Here's an example from my Project Euler solutions.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions