You need to use "def", not "cpdef", when dealing with array arguments. Sorry, this should have been mentioned in the docs...
Dag Sverre Seljebotn -----Original Message----- From: Jean-Francois Moulin <[email protected]> Date: Friday, Sep 18, 2009 11:57 pm Subject: [Cython] numpy array declaration problem To: [email protected]: [email protected] Hi to all! > >I am trying to cythonize some code including operations on numpy arrays. >Following the user manual I declared the type of the arrays and tried to >compile, which fails with a syntax error message for which I can't see any >reason. It appears not to like the [] in my declaration (or at least notto >find the closing ]. I tried compiling without using the >DTYPE declaration at all (np.ndarray without specified type) and it >works, but of course the speed gain is not much. > >Any clue? > >Thanks in advance for your help >JF > > >The abridged code: > >> > DTYPE = np.int > > ctypedef np.int_t DTYPE_t > > > > ... > > > > #[email protected](False) #commented just to see if solves the >problem... NOPE > > cpdef tuple discri_sweep_2D(... > > np.ndarray[DTYPE_t, ndim=1] tof_histo, > > np.ndarray[DTYPE_t, ndim=3] slab > > ): > > ... > > >Compiling fails with the following output: > > >> > running build_ext > > cythoning discri.pyx to discri.c > > > > Error converting Pyrex file to C: > > ------------------------------------------------------------ > > ... > > np.ndarray[DTYPE_t,ndim=1]tof_histo, > > ^ > > ------------------------------------------------------------ > > > > /home/.../discri_Cython/discri_Cython.main/discri.pyx:197:51: >Expected ']' > > building 'discri' extension > > gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall >-Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c discri.c -o >build/temp.linux-x86_64-2.6/discri.o > > discri.c:1:2: error: #error Do not use this file, it is the result of a > > failed Cython compilation. > > error: command 'gcc' failed with exit status 1 >_______________________________________________ >Cython-dev mailing list >[email protected] >http://codespeak.net/mailman/listinfo/cython-dev > _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
