Alex
Alex

Reputation: 160

Cython compilation : error: invalid operands to binary expression ('__pyx_t_double_complex' and '__pyx_t_double_complex')

I'm using the following script :

from distutils.core import setup 
from distutils.extension import Extension
from Cython.Distutils import build_ext

import bumpy
numpy_include=numpy.get_include()
file = ["triad.pyx"]
out  = "triad"

setup(                                                                
     cmdclass = { 'build_ext': build_ext } ,
     include_dirs = [ numpy_include ] ,
     ext_modules = [Extension( out, file) ]
)

to compile the following cython code :

import numpy as np 
cimport numpy as np

cdef triad_cyx ( np.ndarray[dtype=np.complex128_t, ndim=3] AP,
                 np.ndarray[dtype=np.complex128_t, ndim=3] AM,
                 np.ndarray[dtype=np.complex128_t, ndim=3] BP,
                 np.ndarray[dtype=np.complex128_t, ndim=3] BM,
                 np.ndarray[dtype=np.int64_t, ndim=3] Kx,              
                 np.ndarray[dtype=np.int64_t, ndim=3] Ky,
                 np.ndarray[dtype=np.int64_t, ndim=3] Kz,
                 np.ndarray[dtype=np.complex128_t, ndim=3] HpqkPPP,
                 np.ndarray[dtype=np.complex128_t, ndim=3] HpqkPPM,
                 np.ndarray[dtype=np.complex128_t, ndim=3] HpqkPMP,
                 np.ndarray[dtype=np.complex128_t, ndim=3] HpqkPMM,
                 np.ndarray[dtype=np.complex128_t, ndim=3] HpqkMPP,
                 np.ndarray[dtype=np.complex128_t, ndim=3] HpqkMPM,
                 np.ndarray[dtype=np.complex128_t, ndim=3] HpqkMMP,
                 np.ndarray[dtype=np.complex128_t, ndim=3] HpqkMMM,
                 int NX, int NY, int NZ ) :
    cdef int iterr, jterr, kterr, lterr, mterr, nterr, rterr, sterr, tterr

    for iterr in range(NX) :
        for jterr in range(NY) :
            for kterr in range(NZ) :
                for lterr in range(NX) : 
                    for mterr in range(NY) : 
                        for nterr in range(NZ) : 
                            rterr = ( -Kx[iterr]-Kx[lterr] ) % NX
                            sterr = ( -Ky[jterr]-Ky[mterr] ) % NY
                            tterr = ( -Kz[kterr]-Kz[nterr] ) % NZ
                                       ### PPP
                            BP[rterr,sterr,tterr] += np.conjugate ( 
                                HpqkPPP[iterr,jterr,kterr, lterr,mterr,nterr, rterr,sterr,tterr] 
                                * AP[iterr,jterr,kterr] * AP[lterr,mterr,nterr]
                                ) 
                                       # PPM
                            BM[rterr,sterr,tterr] += np.conjugate (
                                HpqkPPM[iterr,jterr,kterr, lterr,mterr,nterr, rterr,sterr,tterr] 
                                * AP[iterr,jterr,kterr] * AP[lterr,mterr,nterr]
                                ) 
                                        ## PMP
                            BP[rterr,sterr,tterr] += np.conjugate ( 
                                HpqkPMP[iterr,jterr,kterr, lterr,mterr,nterr, rterr,sterr,tterr] 
                                * AP[iterr,jterr,kterr] * AM[lterr,mterr,nterr]
                                ) 
                                        # PMM
                            BM[rterr,sterr,tterr] += np.conjugate ( 
                                HpqkPMM[iterr,jterr,kterr, lterr,mterr,nterr, rterr,sterr,tterr] 
                                * AP[iterr,jterr,kterr] * AM[lterr,mterr,nterr]
                                ) 
                                        ### MPP
                            BP[rterr,sterr,tterr] += np.conjugate ( 
                                HpqkMPP[iterr,jterr,kterr, lterr,mterr,nterr, rterr,sterr,tterr] 
                                * AM[iterr,jterr,kterr] * AP[lterr,mterr,nterr]
                                ) 
                                       # MPM
                            BM[rterr,sterr,tterr] += np.conjugate ( 
                                HpqkMPM[iterr,jterr,kterr, lterr,mterr,nterr, rterr,sterr,tterr] 
                                * AM[iterr,jterr,kterr] * AP[lterr,mterr,nterr]
                                ) 
                                        ## MMP
                            BP[rterr,sterr,tterr] += np.conjugate ( 
                                HpqkMMP[iterr,jterr,kterr, lterr,mterr,nterr, rterr,sterr,tterr] 
                                * AM[iterr,jterr,kterr] * AM[lterr,mterr,nterr]
                                ) 
                                        # MMM
                            BM[rterr,sterr,tterr] += np.conjugate ( 
                                HpqkMMM[iterr,jterr,kterr, lterr,mterr,nterr, rterr,sterr,tterr] 
                                * AM[iterr,jterr,kterr] * AM[lterr,mterr,nterr]
                                ) 
    return

def triad_pyx ( APlMi, Kgrid, Htens, NXYZ ) :
    [NX, NY, NZ] = NXYZ
    tycx=np.complex128
    Bnew = [np.zeros((NX,NY,NZ), dtype= tycx), np.zeros((NX,NY,NZ), dtype= tycx)]
    triad_cyx ( APlMi[0], APlMi[1], Bnew[0], Bnew[1], 
                Kgrid.Kx, Kgrid.Ky, Kgrid.Kz, 
                (Htens.Hpqk)[0][0][0], (Htens.Hpqk)[0][0][1], 
                (Htens.Hpqk)[0][1][0], (Htens.Hpqk)[0][1][1], 
                (Htens.Hpqk)[1][0][0], (Htens.Hpqk)[1][0][1], 
                (Htens.Hpqk)[1][1][0], (Htens.Hpqk)[1][1][1], 
                NX, NY, NZ) 
    return Bnew

Cythonizing didn't have any problem. However, when I run the command: python setup.py build_ext -i I get the following error message:

running build_ext skipping 'triad.c' Cython extension (up-to-date)
building 'triad' extension gcc -fno-strict-aliasing
-I/Users/alex/anaconda/include -arch x86_64 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/alex/anaconda/lib/python2.7/site-packages/numpy/core/include -I/Users/alex/anaconda/include/python2.7 -c triad.c -o build/temp.macosx-10.5-x86_64-2.7/triad.o In file included from
triad.c:258: In file included from
/Users/alex/anaconda/lib/python2.7/site-packages/numpy/core/include/numpy/arrayobject.h:4:
In file included from
/Users/alex/anaconda/lib/python2.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:17:
In file included from
/Users/alex/anaconda/lib/python2.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1804:
/Users/alex/anaconda/lib/python2.7/site-
packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2:
warning: 
"Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-W#warnings]
#warning "Using deprecated NumPy API, disable it by " \  ^ triad.c:1852:264: error: invalid operands to binary expression
('__pyx_t_double_complex' and '__pyx_t_double_complex')  
...*__Pyx_BufPtrStrided3d(__pyx_t_double_complex *,
__pyx_pybuffernd_BP.rcbuffer->pybuffer.buf, __pyx_t_32, __pyx_pybuffernd_BP.diminfo[0].strides, __pyx_t_33, __pyx_pybuffernd_BP.diminfo[1].strides, __pyx_t_34, __pyx_pybuffernd_BP.diminfo[2].strides) += __pyx_t_29;
triad.c:2042:264: error: invalid operands to binary
expression ('__pyx_t_double_complex' and '__pyx_t_double_complex')  
...*__Pyx_BufPtrStrided3d(__pyx_t_double_complex *,
__pyx_pybuffernd_BM.rcbuffer->pybuffer.buf, __pyx_t_41, __pyx_pybuffernd_BM.diminfo[0].strides, __pyx_t_42, __pyx_pybuffernd_BM.diminfo[1].strides, __pyx_t_43, __pyx_pybuffernd_BM.diminfo[2].strides) += __pyx_t_29;
triad.c:2232:264: error: invalid operands to binary
expression ('__pyx_t_double_complex' and '__pyx_t_double_complex')  
...*__Pyx_BufPtrStrided3d(__pyx_t_double_complex *,
__pyx_pybuffernd_BP.rcbuffer->pybuffer.buf, __pyx_t_50, __pyx_pybuffernd_BP.diminfo[0].strides, __pyx_t_51, __pyx_pybuffernd_BP.diminfo[1].strides, __pyx_t_52, __pyx_pybuffernd_BP.diminfo[2].strides) += __pyx_t_29;
triad.c:2422:264: error: invalid operands to binary
expression ('__pyx_t_double_complex' and '__pyx_t_double_complex')  
...*__Pyx_BufPtrStrided3d(__pyx_t_double_complex *,
__pyx_pybuffernd_BM.rcbuffer->pybuffer.buf, __pyx_t_59, __pyx_pybuffernd_BM.diminfo[0].strides, __pyx_t_60, __pyx_pybuffernd_BM.diminfo[1].strides, __pyx_t_61, __pyx_pybuffernd_BM.diminfo[2].strides) += __pyx_t_29;
triad.c:2612:264: error: invalid operands to binary
expression ('__pyx_t_double_complex' and '__pyx_t_double_complex')  
...*__Pyx_BufPtrStrided3d(__pyx_t_double_complex *,
__pyx_pybuffernd_BP.rcbuffer->pybuffer.buf, __pyx_t_68, __pyx_pybuffernd_BP.diminfo[0].strides, __pyx_t_69, __pyx_pybuffernd_BP.diminfo[1].strides, __pyx_t_70, __pyx_pybuffernd_BP.diminfo[2].strides) += __pyx_t_29;
triad.c:2802:264: error: invalid operands to binary
expression ('__pyx_t_double_complex' and '__pyx_t_double_complex')  
...*__Pyx_BufPtrStrided3d(__pyx_t_double_complex *,
__pyx_pybuffernd_BM.rcbuffer->pybuffer.buf, __pyx_t_77, __pyx_pybuffernd_BM.diminfo[0].strides, __pyx_t_78, __pyx_pybuffernd_BM.diminfo[1].strides, __pyx_t_79, __pyx_pybuffernd_BM.diminfo[2].strides) += __pyx_t_29;
 triad.c:2992:264: error: invalid operands to binary
expression ('__pyx_t_double_complex' and '__pyx_t_double_complex')  
...*__Pyx_BufPtrStrided3d(__pyx_t_double_complex *,
__pyx_pybuffernd_BP.rcbuffer->pybuffer.buf, __pyx_t_86, __pyx_pybuffernd_BP.diminfo[0].strides, __pyx_t_87, __pyx_pybuffernd_BP.diminfo[1].strides, __pyx_t_88, __pyx_pybuffernd_BP.diminfo[2].strides) += __pyx_t_29;
triad.c:3182:264: error: invalid operands to binary
expression ('__pyx_t_double_complex' and '__pyx_t_double_complex')  
...*__Pyx_BufPtrStrided3d(__pyx_t_double_complex *,
__pyx_pybuffernd_BM.rcbuffer->pybuffer.buf, __pyx_t_95, __pyx_pybuffernd_BM.diminfo[0].strides, __pyx_t_96, __pyx_pybuffernd_BM.diminfo[1].strides, __pyx_t_97, __pyx_pybuffernd_BM.diminfo[2].strides) += __pyx_t_29; 1 warning and 8 errors generated. error: command 'gcc' failed with exit status 1

I would be grateful if anyone could help me out.

Upvotes: 0

Views: 349

Answers (1)

ev-br
ev-br

Reputation: 26090

Try replacing inplace addition involving complex variables, a += b, by a =a + b.

https://groups.google.com/forum/m/#!searchin/cython-users/Complex$20inplace/cython-users/fK5kONPMlF0

Upvotes: 2

Related Questions