Fast histogramming in python built on pybind11 and OpenMP.
Project description
pygram11
Simple and fast histogramming in Python via pybind11 and accelerated with OpenMP.
pygram11
provides fast functions for calculating histograms (and
their sums-of-weights squared). The API is very simple, documentation
found here (you'll also find some
benchmarks
there). I also wrote a blog
post with some simple
examples.
Installing
pygram11 requires NumPy and pybind11 (and therefore a C++ compiler with C++11 support).
From conda-forge
For a simple installation process which provides OpenMP acceleration, pygram11 is part of conda-forge.
conda install pygram11 -c conda-forge
From PyPI
Note: When using PyPI (or source), pybind11
must be installed
explicitly before pygram11
(because setup.py
uses pybind11
to
determine include directories; not an issue if using the conda-forge
build). For ensuring OpenMP acceleration is available in your
installation read this section of the
documentation.
$ pip install pybind11 ## or `conda install pybind11`
$ pip install pygram11
From Source
$ pip install pybind11
$ pip install git+https://github.com/drdavis/pygram11.git@master
In Action
A histogram (with fixed bin width) of weighted data in one dimension, accelerated with OpenMP:
>>> x = np.random.randn(10000)
>>> w = np.random.uniform(0.8, 1.2, 10000)
>>> h, staterr = pygram11.histogram(x, bins=40, range=(-4, 4), weights=w, omp=True)
A histogram with fixed bin width which saves the under and overflow in the first and last bins:
>>> x = np.random.randn(1000000)
>>> h = pygram11.histogram(x, bins=20, range=(-3, 3), flow=True, omp=True)
A histogram in two dimensions with variable width bins:
>>> x = np.random.randn(10000)
>>> y = np.random.randn(10000)
>>> xbins = [-2.0, -1.0, -0.5, 1.5, 2.0]
>>> ybins = [-3.0, -1.5, -0.1, 0.8, 2.0]
>>> h = pygram11.histogram2d(x, y, bins=[xbins, ybins])
Other Libraries
- There is an effort to develop an object oriented histogramming library for Python called boost-histogram. This library will be feature complete w.r.t. everything a physicist needs with histograms.
- Simple and fast histogramming in Python using the NumPy C API: fast-histogram. No weights or overflow).
- If you want to calculate histograms on a GPU in Python, cqheck out cupy.histogram. They only have 1D histograms (no weights over overflow).
If there is something you'd like to see in pygram11, please open an issue or pull request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file pygram11-0.3.1.tar.gz
.
File metadata
- Download URL: pygram11-0.3.1.tar.gz
- Upload date:
- Size: 14.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 822362704c35364704d2de22d9491ff0ff343f322b9754b2467ff18bd2f3cb68 |
|
MD5 | 27d2badefb3010ae61b7181cff36649a |
|
BLAKE2b-256 | 1ff24d19c53c2b3e087d16ee73ab61df08aca342947d7b51f8f3406e75287c2b |