[Pyrex] Question about +=, -=, *=, etc.
Fernando Perez
Fernando.Perez at colorado.edu
Thu Jun 3 19:52:29 CEST 2004
Phillip J. Eby wrote:
> Try this as a simple workaround:
>
> cdef extern from "Python.h":
> object PyNumber_InPlaceAdd(object o1, object o2)
>
> for i in long_list:
> my_array = PyNumber_InPlaceAdd(my_array,some_function(i))
>
> This is effectively the code that a += operator would generate.
>
> In general, if you're looking to improve Python performance via Pyrex, it's
> important to know what functions are available in the Python/C API, as
> calling these functions directly can, under the right circumstances, yield
> further performance boosts over "naive" Pyrex code.
Many thanks! I'm a complete pyrex newbie, so I didn't realize that Py/C API
calls could be made directly from within pyrex code. This is actually great
to know, since I think it will allow me to cut through the dynamic typing
overhead in the critical loops of my code.
Best,
Fernando
More information about the Pyrex
mailing list