将numpy 2D双复数数组传递给cython作为memoryview

时间:2018-07-23 18:57:56

标签: python numpy cython cythonize memoryview

以下代码在jupyter笔记本中失败。但是,如果我使用double而不是double complex,则一切正常。

%%cython 
cpdef test_array(double complex [:,::1] test):
    cdef int x1,y1 
    x1,y1 = test.shape[0],test.shape[1]
    for i in range(x1):
        for j in range(y1):
            test[i][j]+=0

双重复杂的错误是:

/home/sajid/.cache/ipython/cython/_cython_magic_b61ff75cef6df4a7db32aeafc6c3f9ff.c: In function '__pyx_f_46_cython_magic_b61ff75cef6df4a7db32aeafc6c3f9ff_test_array':
/home/sajid/.cache/ipython/cython/_cython_magic_b61ff75cef6df4a7db32aeafc6c3f9ff.c:2149:183: error: invalid operands to binary + (have '__pyx_t_double_complex {aka struct <anonymous>}' and '__pyx_t_double_complex {aka struct <anonymous>}')
       *((__pyx_t_double_complex *) ( /* dim=1 */ ((char *) (((__pyx_t_double_complex *) ( /* dim=0 */ (__pyx_v_test.data + __pyx_t_17 * __pyx_v_test.strides[0]) )) + __pyx_t_18)) )) += __pyx_t_double_complex_from_parts(0, 0);
                                                                                                                                                                                       ^~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/sajid/.cache/ipython/cython/_cython_magic_b61ff75cef6df4a7db32aeafc6c3f9ff.c: In function '__pyx_f_46_cython_magic_b61ff75cef6df4a7db32aeafc6c3f9ff_test_array':
/home/sajid/.cache/ipython/cython/_cython_magic_b61ff75cef6df4a7db32aeafc6c3f9ff.c:2149:183: error: invalid operands to binary + (have '__pyx_t_double_complex {aka struct <anonymous>}' and '__pyx_t_double_complex {aka struct <anonymous>}')
       *((__pyx_t_double_complex *) ( /* dim=1 */ ((char *) (((__pyx_t_double_complex *) ( /* dim=0 */ (__pyx_v_test.data + __pyx_t_17 * __pyx_v_test.strides[0]) )) + __pyx_t_18)) )) += __pyx_t_double_complex_from_parts(0, 0);

我需要在函数外使用numpy并将其作为memoryview传递,以启用使用nogil的并行操作。

0 个答案:

没有答案