Re: [SciPy-User] help speeding up a Runge-Kuta algorithm (cython, f2py, ...) (Sturla Molden)
************************************************************ Here is an example code of how to use Cython as a Fortran killer: https://github.com/sturlamolden/memview_benchmarks/blob/master/memview.pyx In this case, the performance with -O2 was just 2.2% slower than "plain C" with pointer arithmetics. It is possible to write very fast array code with Cython, but you must do it right. For comparison, this is very slow: https://github.com/sturlamolden/memview_benchmarks/blob/master/cythonized_nu... What this mean is this: For anything but trivial code, the NumPy syntax is just too slow and should be avoided! I breiefly looked at the Cython code posted in this thread, and it suffers form all these issues. Sturla ********************************************** Hello Sturla, I am wondering whether there is a problem with my phyton installation or something is missing in your "memview.pyx" file as the following compiling error arises: cythoning memview.pyx to memview.c Error compiling Cython file: ------------------------------------------------------------ ... cimport numpy as np cimport cython @cython.boundscheck(False) @cython.wraparound(False) cdef np.float64_t slice_func(np.float64_t[::1] Xi, ^ ------------------------------------------------------------ memview.pyx:7:42: Expected an identifier or literal Sergio PD. Compilation works fine in the other files (cythonized_numpy_2b.pyx cythonized_numpy_4.pyx pointer_arith.pyx cythonized_numpy_2.pyx cythonized_numpy.pyx cythonized_numpy_3.pyx). Taking out that module in the "runme.py" file the output is: >$ python runme.py numpy_only: 3.13 sec cythonized_numpy: 2.38 sec cythonized_numpy_2: 3.8 sec cythonized_numpy_2b: 3.27 sec cythonized_numpy_3: 1.52 sec cythonized_numpy_4: 1.19 sec pointer_arith: 1.19 sec
Which version of Cython do you have (use at least 0.16). Sturla Den 05.08.2012 20:33, skrev Sergio Rojas:
Sturla ********************************************** Hello Sturla, I am wondering whether there is a problem with my phyton installation or something is missing in your "memview.pyx" file as the following compiling error arises: cythoning memview.pyx to memview.c Error compiling Cython file: ------------------------------------------------------------ ... cimport numpy as np cimport cython @cython.boundscheck(False) @cython.wraparound(False) cdef np.float64_t slice_func(np.float64_t[::1] Xi, ^ ------------------------------------------------------------ memview.pyx:7:42: Expected an identifier or literal Sergio PD. Compilation works fine in the other files (cythonized_numpy_2b.pyx cythonized_numpy_4.pyx pointer_arith.pyx cythonized_numpy_2.pyx cythonized_numpy.pyx cythonized_numpy_3.pyx). Taking out that module in the "runme.py" file the output is: >$ python runme.py numpy_only: 3.13 sec cythonized_numpy: 2.38 sec cythonized_numpy_2: 3.8 sec cythonized_numpy_2b: 3.27 sec cythonized_numpy_3: 1.52 sec cythonized_numpy_4: 1.19 sec pointer_arith: 1.19 sec
_______________________________________________ SciPy-User mailing list SciPy-User@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-user
participants (2)
-
Sergio Rojas -
Sturla Molden