33About
44-----
55
6- Sometimes you just want to compute simple 1D or 2D histograms with regular bins. Fast. No
6+ Sometimes you just want to compute simple 1D, 2D, or multidimensional histograms with regular bins. Fast. No
77nonsense. `Numpy's <http://www.numpy.org >`__ histogram functions are
88versatile, and can handle for example non-regular binning, but this
99versatility comes at the expense of performance.
@@ -13,8 +13,9 @@ histogram functions for regular bins that don't compromise on performance. It do
1313anything complicated - it just implements a simple histogram algorithm
1414in C and keeps it simple. The aim is to have functions that are fast but
1515also robust and reliable. The result is a 1D histogram function here that
16- is **7-15x faster ** than ``numpy.histogram ``, and a 2D histogram function
17- that is **20-25x faster ** than ``numpy.histogram2d ``.
16+ is **2-15x faster ** than ``numpy.histogram ``, a 2D histogram function
17+ that is **10x faster ** than ``numpy.histogram2d ``, and a multidimensional
18+ histogram function that is **5-10x faster ** than ``numpy.histogramdd ``.
1819
1920To install::
2021
@@ -24,12 +25,12 @@ or if you use conda you can instead do::
2425
2526 conda install -c conda-forge fast-histogram
2627
27- The ``fast_histogram `` module then provides two functions:
28- ``histogram1d `` and ``histogram2d ``:
28+ The ``fast_histogram `` module then provides three functions:
29+ ``histogram1d ``, `` histogram2d ``, and ``histogramdd ``:
2930
3031.. code :: python
3132
32- from fast_histogram import histogram1d, histogram2d
33+ from fast_histogram import histogram1d, histogram2d, histogramdd
3334
3435 Example
3536-------
@@ -46,24 +47,26 @@ histogram:
4647 In [3 ]: y = np.random.random(10_000_000 )
4748
4849 In [4 ]: % timeit _ = np.histogram2d(x, y, range = [[- 1 , 2 ], [- 2 , 4 ]], bins = 30 )
49- 935 ms ± 58.4 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
50+ 562 ms ± 5.83 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
5051
5152 In [5 ]: from fast_histogram import histogram2d
5253
5354 In [6 ]: % timeit _ = histogram2d(x, y, range = [[- 1 , 2 ], [- 2 , 4 ]], bins = 30 )
54- 40.2 ms ± 624 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
55+ 55.9 ms ± 583 μs per loop (mean ± std. dev. of 7 runs, 10 loops each)
5556
5657 (note that ``10_000_000 `` is possible in Python 3.6 syntax, use ``10000000 `` instead in previous versions)
5758
58- The version here is over 20 times faster! The following plot shows the
59+ The version here is over 10 times faster! The following plot shows the
5960speedup as a function of array size for the bin parameters shown above:
6061
6162.. figure :: https://github.com/astrofrog/fast-histogram/raw/main/speedup_compared.png
6263 :alt: Comparison of performance between Numpy and fast-histogram
6364
64- as well as results for the 1D case, also with 30 bins. The speedup for
65- the 2D case is consistently between 20-25x, and for the 1D case goes
66- from 15x for small arrays to around 7x for large arrays.
65+ as well as results for the 1D and 3D cases, also with 30 bins. The speedup for
66+ the 2D case is consistently between 10-12x, and for the 1D case goes
67+ from 15x for small arrays to around 2x for large arrays.
68+ We have benchmarked the ``histogramdd `` function with a 3D array, and the speedup
69+ is found to be between 5-10x.
6770
6871Q&A
6972---
0 commit comments