Hi!

I tried to use the cdef instead as cpdef as suggested and it still
fails, complaining for a missing closing ] (which is actually not
missing)...

I reduced the code down to this and it produces the error:

> import numpy as np
> cimport numpy as np
> import cython

> DTYPE = np.int
> ctypedef np.int_t DTYPE_t

> @cython.boundscheck(False)
> cdef test(np.ndarray[DTYPE_t,ndim=1]tof_histo):

>     print tof_histo


Just in case, here is the compile output:

python setup_np_ndarray.py build_ext --inplace
running build_ext
cythoning np_ndarray_test.pyx to np_ndarray_test.c

Error converting Pyrex file to C:
------------------------------------------------------------
...

DTYPE = np.int
ctypedef np.int_t DTYPE_t

@cython.boundscheck(False)
cdef test(np.ndarray[DTYPE_t,ndim=1]tof_histo):
                                     ^
------------------------------------------------------------

/home/jfmoulin/My_Progs/dev/cython/np_ndarray_test.pyx:9:38: Expected ']'
building 'testnpnd' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall
-Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c np_ndarray_test.c
-o build/temp.linux-x86_64-2.6/np_ndarray_test.o
np_ndarray_test.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


Dag Sverre Seljebotn wrote:
> 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

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to