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/douglasdavis/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 (using __
to catch the None
returned due
to the absence of weights):
>>> 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, check 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.5.0a2.tar.gz
.
File metadata
- Download URL: pygram11-0.5.0a2.tar.gz
- Upload date:
- Size: 145.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5690f25f4cd1d4360a39652ba3354972fb5307854f517b97dff8387924b88e6 |
|
MD5 | b61a9f24f6722ec2c4cb51f082a22e92 |
|
BLAKE2b-256 | 0763e712a3fe4c399e95e415033b36b63078c5d52599fc371b863b20d1f1cf86 |