views:

192

answers:

1

Hello, i am trying to subistute a small bit of Python Code with Cython for a speed up. While Cython itself dosen't complain, but gcc does.

from __future__ import division
import numpy 

cimport numpy        
cimport cython

def calc_shg(numpy.ndarray[numpy.complex128_t, ndim = 1] par,
         numpy.ndarray[numpy.complex128_t, ndim = 1] spectrum,
         numpy.ndarray[numpy.complex128_t, ndim = 1] phase,
         numpy.ndarray[numpy.complex128_t, ndim = 1] filter, float best_fit):
cdef int pix
cdef int i 
cdef numpy.ndarray[numpy.complex128_t, ndim = 1] shaped_pulse

shaped_pulse = numpy.zeros(4096)
par = numpy.exp(-1j * par * 0.002 * numpy.pi)
for pix in xrange(128):
    for i in xrange(25 - 1):
        filter[2048 - 25 * 64 + pix * 25 + i] = par[pix]                 
for i in xrange(4096):
    shaped_pulse[i] = numpy.fft.ifft(spectrum[i] * (phase[i] * filter[i]))
return - sum(numpy.real(shaped_pulse) ** 4) / best_fit

Error:

Sim_Cython.c: In function `__pyx_pf_10Sim_Cython_calc_shg':
Sim_Cython.c:1187: error: incompatible type for argument 1 of `__pyx_t_double_complex_mul'
Sim_Cython.c:1187: error: incompatible type for argument 2 of `__pyx_t_double_complex_mul'
Sim_Cython.c:1187: error: incompatible type for argument 1 of `__pyx_t_double_complex_mul'
Sim_Cython.c:1187: error: incompatible type for argument 1 of `__pyx_t_double_complex_mul'
Sim_Cython.c:1187: error: incompatible type for argument 2 of `__pyx_t_double_complex_mul'
Sim_Cython.c:1187: error: incompatible type for argument 1 of `__pyx_t_double_complex_mul'
Sim_Cython.c:1198: error: incompatible types in assignment
A: 

Which cython are you using ? Complex support is relatively recent. I could compile and link your example fine with cython 0.11.3 (I have not tested it though).

David Cournapeau
I have Cython 0.12, which compilier did you use?
tillsten
I tried again with cython 0.12.1 + numpy 1.4.1 on python 2.6 (Ubuntu), and it works without any issue. Could you post the whole traceback for the compilation failure ?
David Cournapeau