Skip to main content

NumPy-style histograms in PyTorch

Project description

NumPy-style histograms in PyTorch

The torchist package implements NumPy's histogram and histogramdd functions in PyTorch with support for non-uniform binning. The package also features implementations of ravel_multi_index, unravel_index and some useful functionals (e.g. KL divergence).

Installation

The torchist package is available on PyPI, which means it is installable with pip:

pip install torchist

Alternatively, if you need the latest features, you can install it using

pip install git+https://github.com/francois-rozet/torchist

or copy the package directly to your project, with

git clone https://github.com/francois-rozet/torchist
cp -R torchist/torchist <path/to/project>/torchist

Getting Started

import torch
import torchist

x = torch.rand(100, 3).cuda()

hist = torchist.histogramdd(x, bins=10, low=0., upp=1.)

print(hist.shape)  # (10, 10, 10)

Benchmark

The implementations of torchist are up to 3 times faster than those of numpy on CPU and benefit greately from CUDA capabilities.

$ python torchist/__init__.py
CPU
---
np.histogram : 1.3613 s
np.histogramdd : 19.8844 s
np.histogram (non-uniform) : 5.5652 s
np.histogramdd (non-uniform) : 17.5668 s
torchist.histogram : 0.9674 s
torchist.histogramdd : 6.3047 s
torchist.histogram (non-uniform) : 3.6520 s
torchist.histogramdd (non-uniform) : 14.1086 s

CUDA
----
torchist.histogram : 0.1032 s
torchist.histogramdd : 0.2668 s
torchist.histogram (non-uniform) : 0.1230 s
torchist.histogramdd (non-uniform) : 0.4407 s

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torchist-0.1.0.tar.gz (6.8 kB view hashes)

Uploaded Source

Built Distribution

torchist-0.1.0-py3-none-any.whl (7.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page