[SciPy-User] numpy.histogram is slow

Sturla Molden sturla at molden.no
Mon Oct 22 07:59:23 EDT 2012


On 18.10.2012 09:26, Jerome Kieffer wrote:

> I implemented a 1D and 2D histogram, weighted and unweighted using cython (>=0.17) in parallel.
> It is much faster than the one provided by numpy:
> 4ms vs 25ms in your case on my computer
> https://github.com/kif/pyFAI/blob/master/src/histogram.pyx

Is there a reason why you set cdivision to True in a code that has no 
integer division?

Also:

Cython prange scales badly unless you do a lot of work on each 
iteration. That is, each iteration of a prange loop does a barrier 
synchronization through an OpenMP flush. Don't use it the way you do 
here. A Cython prange loop is not nearly as cheap as a C loop with 
"#pragma omp parallel for". If you really want to use OpenMP, let your 
Cython code call C code.

NumPy does not have a build system for OpenMP. Python threads works fine 
too. It takes some more coding, but if you use closures in Cython it 
will not be nearly as difficult as the "Java threads" coding style.


Sturla











More information about the SciPy-User mailing list