Best Practices for passing numpy data pointer to C ?
2012-06-27 20:23:13 GMT
Hi folks, We need to be able to pass the data pointer from a numpy array to C -- so that the data can be modified in place, and the changes seen in the numpy array, without any data copying. I found this thread on the list: https://groups.google.com/forum/?fromgroups#!topic/cython-users/VW_AH2HEFfU but I'm still a bit confused about best practices. I've got two ways working now -- one is using the numpy array's data member, and the other the address of the first element: c_multiply (<double*> input.data, value, m, n) c_multiply (&input[0,0], value, m, n) In both cases, the array has been cdef'd to: np.ndarray[double, ndim=2, mode="c"] why might I choose one over the other? Or is there an even better way? I've enclosed a complete working example, with setup.py, etc. if anyone wants to take a look, or try another approach. Also the cython code below: I'll post the final result on the Wiki -- I think this would be(Continue reading)