Thanks for these answers! That will for sure help me. I actually tried and my code is ... slower after the declaration than before... ( I have to check that I changed only this though and not a 'subtle' performance killer)
What I have is a big 3d L array for which I need to increment a single element by one at each call (so, there really isn't much of work for numpy, only later do I use the full power of Numpy/Scipy). So, for now I can separate more sophisticated operations and perform them later once the array is finalized... I can thus build my array as a huge list of lists and eventually convert it to np.ndarray once the time expensive work is done (many, many fn calls... millions of them actually). Or is it worth (possible?) to use the array.array object of python. The type of the elements would then be defined... I read the CEP 517: Cython array type and understand that it is work in progress. But does that mean that the array.array python object will not be efficiently (or at all) understood by cython? Thanks again for answering my naive questions (to call my C background thin would be a kind of understatement). JF Dag Sverre Seljebotn wrote: > cdef vs. def only affects the speed of the *call* of the function, not the > time spent in the function itself. If you are processing anything but a very > small amount of array data there won't be a difference. > > Or did you mean that your function only wants to e.g. process a single > element? Yes, then you need to not use arrays at the moment. > > Dag Sverre Seljebotn > -----Original Message----- > From: Jean-Francois Moulin <[email protected]> > Date: Sunday, Sep 20, 2009 3:52 pm > Subject: Re: [Cython] numpy array declaration problem > To: [email protected]: [email protected] > > >> Oooppss... sorry for not reading correctly! >> But... does that mean that there will be no speed imporvement for these >> functions (which are the ones I want to speed up the most in my code) >> Moreover I see (now) in the manual that the def fns might include some >> cdef declarations of np.ndarrays.... what is happening there? >> Should I better try to implement my stuff without numpy arrays if I am >> really looking for speed (I do not think that would be very wise in my >> case). >> >> Thanks for your patience! ;0) >> Best >> JF >> Johan Grönqvist wrote: >>> Hi, >>> >>> You must use def, not cdef. It is not possible to use such a dtype >>> declaration with cdef. >>> >>> <http://trac.cython.org/cython_trac/ticket/177> >>> >>> / johan >>> >>> Jean-Francois Moulin skrev: >>>> I tried to use the cdef instead as cpdef as suggested and it still >>>> fails, >>>> 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]> >>>>> >>>>>>> cpdef tuple discri_sweep_2D(... >>>>>>> np.ndarray[DTYPE_t, ndim=1] tof_histo, >>>>>>> np.ndarray[DTYPE_t, ndim=3] slab >>>>>>> ): >>> _______________________________________________ >>> 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 _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
