Cython: can't convert Python object to 'double *'

前端 未结 3 1506
心在旅途
心在旅途 2021-02-06 04:26

I\'m writting a Cython wrapper to a C function. I have a pxd file with the following signature:

double contr_hrr(int lena, double xa, double ya, double za, doubl         


        
3条回答
  •  广开言路
    2021-02-06 05:11

    1. cimport array:

      from cpython cimport array
      
    2. Create an array object from your list. array class constructor will do all the heavy lifting allocating memory and iterating over your list (could be any iterable actually).

      cdef array.array anorms2_arr = array.array('d', anorms2)
      
    3. Pass its data to your function:

      return contr_hrr(.., anorms2_arr.data.as_doubles)
      

    array is a standard Python module. Cython adds some special support on top, like buffer interface and direct access to the underlying memory block via arr.data.as_xxx. Unfortunately, this support is only documented here. You can also find some details about array usage in this recent thread.

提交回复
热议问题