Fast histogramming in Python build on pybind11 and OpenMP.
Project description
pygram11
Simple and fast histogramming in Python accelerated with OpenMP (with help from pybind11).
pygram11
provides fast functions for calculating histograms (and the
variance in each bin). The API is very simple; documentation can be
found here (you'll also find some
benchmarks
there).
Installing
Using pygram11 only requires NumPy. To build and install from source you'll just need a compiler with support for C++11 and OpenMP.
From PyPI
Binary wheels are provided for Linux and macOS. They can be installed from PyPI via pip.
pip install pygram11
From conda-forge
For installation via the conda
package manager pygram11 is part of
conda-forge.
conda install pygram11 -c conda-forge
Please note that on macOS the OpenMP libraries from LLVM (libomp
)
and Intel (libiomp
) may clash if your conda
environment includes
the Intel Math Kernel Library (MKL) package distributed by
Anaconda. You may need to install the nomkl
package to prevent the
clash (Intel MKL accelerates many linear algebra operations, but does
not impact pygram11):
conda install nomkl ## sometimes necessary fix (macOS only)
From Source
All you need is a C++11 compiler and OpenMP. If you are using a
relatively modern GCC release on Linux then you probably don't have to
worry about the OpenMP dependency. If you are on macOS, you can
install libomp
from Homebrew. With those dependencies met, simply
run:
pip install git+https://github.com/douglasdavis/pygram11.git@master
In Action
A histogram (with fixed bin width) of weighted data in one dimension:
>>> x = np.random.randn(10000)
>>> w = np.random.uniform(0.8, 1.2, 10000)
>>> h, err = pygram11.histogram(x, bins=40, range=(-4, 4), weights=w)
A histogram with fixed bin width which saves the under and overflow in the first and last bins:
>>> x = np.random.randn(1000000)
>>> h, err = pygram11.histogram(x, bins=20, range=(-3, 3), flow=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, err = pygram11.histogram2d(x, y, bins=[xbins, ybins])
Histogramming multiple weight variations for the same data, then putting the result in a DataFrame (the input pandas DataFrame will be interpreted as a NumPy array):
>>> weights = pd.DataFrame({"weight_a" : np.abs(np.random.randn(10000)),
... "weight_b" : np.random.uniform(0.5, 0.8, 10000),
... "weight_c" : np.random.rand(10000)})
>>> data = np.random.randn(10000)
>>> count, err = pygram11.histogram(data, bins=20, range=(-3, 3), weights=weights, flow=True)
>>> count_df = pd.DataFrame(count, columns=weights.columns)
>>> err_df = pd.DataFrame(err, columns=weights.columns)
I also wrote a blog post with some simple examples.
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, check out cupy.histogram. They only have 1D histograms (no weights or 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
Built Distributions
File details
Details for the file pygram11-0.9.0.tar.gz
.
File metadata
- Download URL: pygram11-0.9.0.tar.gz
- Upload date:
- Size: 528.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59f143967ae5c1cb498a5ecb739e1482df1d68e78a32ce0a8f22371ce8fe2b45 |
|
MD5 | 30bc52f72d661735d56146262e521657 |
|
BLAKE2b-256 | 77c51452b78d453e2357187112872edd024bac974cb519acd6c8530b14d286c0 |
File details
Details for the file pygram11-0.9.0-cp38-cp38-manylinux2010_x86_64.whl
.
File metadata
- Download URL: pygram11-0.9.0-cp38-cp38-manylinux2010_x86_64.whl
- Upload date:
- Size: 267.5 kB
- Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 064a1856b385b5d81ddd6481a335ef9a26baa3f24773a749ca2623118664589c |
|
MD5 | 487b6c663ea504dc73230b217e964c68 |
|
BLAKE2b-256 | fa80bf8d5aa14e699ba4d24339be643a4aef56e74b3461576cd927d86ff0e1ea |
File details
Details for the file pygram11-0.9.0-cp38-cp38-manylinux1_x86_64.whl
.
File metadata
- Download URL: pygram11-0.9.0-cp38-cp38-manylinux1_x86_64.whl
- Upload date:
- Size: 204.5 kB
- Tags: CPython 3.8
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11078364a23a0a6027a51d6242ecf259ba9032fbdc139be8ea771790e51b6277 |
|
MD5 | 177347439d2620e31850c9305e3e077e |
|
BLAKE2b-256 | d45cbc6b637431f858e193729616ae7ba3e4289af3cebac89c02a3e19e717dd3 |
File details
Details for the file pygram11-0.9.0-cp38-cp38-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pygram11-0.9.0-cp38-cp38-macosx_10_9_x86_64.whl
- Upload date:
- Size: 402.0 kB
- Tags: CPython 3.8, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 475f76f453778f5d7065a30b2ed6e1fa42edc2f8e08c5dfea408f4570515bc4c |
|
MD5 | 234398c27aa5392a2c87f5bb8782aae0 |
|
BLAKE2b-256 | 18c93adef7bc12aea069f3f13303f46e8bf87d4cf7ff289558a6980f416cb33d |
File details
Details for the file pygram11-0.9.0-cp37-cp37m-manylinux2010_x86_64.whl
.
File metadata
- Download URL: pygram11-0.9.0-cp37-cp37m-manylinux2010_x86_64.whl
- Upload date:
- Size: 266.0 kB
- Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42ec032be72124656713b042cc42077c6103d3a721ed4ae173f507d9bb23250b |
|
MD5 | a4f82947ddbf87a4065b9fbed3c9ab1b |
|
BLAKE2b-256 | 1b0f5c7b0fecef3434b9d425cdeb1391d1d3b3a5ef948a6efd82f7768695c88c |
File details
Details for the file pygram11-0.9.0-cp37-cp37m-manylinux1_x86_64.whl
.
File metadata
- Download URL: pygram11-0.9.0-cp37-cp37m-manylinux1_x86_64.whl
- Upload date:
- Size: 206.8 kB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3fd9d0bae7ed8f2bf0cc0394db924e9f511fd9f9412754e23b81bb26c9630516 |
|
MD5 | 543d936c7e79468beea1ca6da9accc11 |
|
BLAKE2b-256 | 9a972768dd5ab75b58f0e81cbad2ab96ecf7395554f1f1e25b44ce92f1d4cf20 |
File details
Details for the file pygram11-0.9.0-cp37-cp37m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pygram11-0.9.0-cp37-cp37m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 397.8 kB
- Tags: CPython 3.7m, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d06794dc613aa7b41179afc58f790e1de362914baec2dc22cbe41a0b3880c72 |
|
MD5 | 971e8b5a7add8640d533de1a6b4bde17 |
|
BLAKE2b-256 | 889ffd085ba11d599f940ec574bcbf336785255c5a1a0cd71a3a9efa6cb51897 |
File details
Details for the file pygram11-0.9.0-cp36-cp36m-manylinux2010_x86_64.whl
.
File metadata
- Download URL: pygram11-0.9.0-cp36-cp36m-manylinux2010_x86_64.whl
- Upload date:
- Size: 265.8 kB
- Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc158c289ab2c814bc4116bcc2f86358458bc69d600f10b99990a8a85a8fcf7a |
|
MD5 | 643835c2db87f4933e62a25ad0865029 |
|
BLAKE2b-256 | 35c4a030a406c7ce4ce801c0bc67cd568f66924c5441646f89ace07104215b5a |
File details
Details for the file pygram11-0.9.0-cp36-cp36m-manylinux1_x86_64.whl
.
File metadata
- Download URL: pygram11-0.9.0-cp36-cp36m-manylinux1_x86_64.whl
- Upload date:
- Size: 206.3 kB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92342a489294ac5b4dd2ac1dc070431c99dc94e8fbee979e3978592ea7ebc368 |
|
MD5 | 3f12a9c9be3128a1bcb867d62e7040a0 |
|
BLAKE2b-256 | e2fbf3a33a8c945ff83ad196ae6948772f16009272e8df19b5a9c5eb3b562fd7 |
File details
Details for the file pygram11-0.9.0-cp36-cp36m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pygram11-0.9.0-cp36-cp36m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 397.8 kB
- Tags: CPython 3.6m, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7152f329fb540a3cf13106de4e27d7c5d2e6185b5075d887420eeae15d40bd60 |
|
MD5 | b74661d9855c8c3beb682edb4f9039dc |
|
BLAKE2b-256 | df2d9363f9fcb4631a1c8771e52dfe5459099d7140fc2f364c82dc12f4708bba |