0

The following code

cdef extern from "<complex.h>" nogil: #namespace "std" nogil:    
    double complex conj(double complex z)
    float complex conjf(float complex z)


cpdef float complex [:,::1] Function_A ( int nf, int max_k, int [::1] ind_max_arr, float complex [:,::1] dft, float complex [::1] H_1st ):
    cdef:
        int i, k, ind_max 
        float complex [:,::1] OUT = np.zeros( [max_k, nf] , dtype=np.complex64 )
    for i in range(nf):
        ind_max = ind_max_arr[i]        
        for k in range(max_k):
            if k < ind_max:
                OUT[k, i] = dft[ ind_max, i ] * conjf( H_1st[ind_max - k] )   ### this line is problematic
            else:
                OUT[k, i] = dft[ ind_max, i ] * H_1st[k - ind_max] 
    return OUT

would fail during compilation with error: binary '*': '__pyx_t_float_complex' does not define this operator or a conversion to a type acceptable to the predefined operator.

The same Function A above would be successful if I switched everything to double complex and use conj. The error above refers to the line where conjf is used. Last I check complex.h does have the function conjf. Not sure what is wrong. Help please.

EDIT: Additional info: compiler: Microsoft Visual language: c++ (if i use c, even more errors)

Ong Beng Seong
  • 196
  • 1
  • 11
  • How complex is handled in cython depends on used compiler and language(c, c++). You probably need to add this information. – ead Jun 19 '21 at 04:36
  • Probably when using c++, best is to use `conj` from `libcpp.complex` (https://github.com/cython/cython/blob/master/Cython/Includes/libcpp/complex.pxd#L67) it saves one a lot of pain... Mixing c++ and complex.h is not a good idea, e.g. https://stackoverflow.com/a/62134393/5769463 – ead Jun 19 '21 at 05:29

0 Answers0