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 on par or faster than those of numpy on CPU and benefit greately from CUDA capabilities.

$ python torchist/__init__.py
CPU
---
np.histogram : 1.2559 s
np.histogramdd : 20.7816 s
np.histogram (non-uniform) : 5.4878 s
np.histogramdd (non-uniform) : 17.3757 s
torchist.histogram : 1.3975 s
torchist.histogramdd : 9.6160 s
torchist.histogram (non-uniform) : 5.0883 s
torchist.histogramdd (non-uniform) : 17.2743 s

CUDA
----
torchist.histogram : 0.1363 s
torchist.histogramdd : 0.3754 s
torchist.histogram (non-uniform) : 0.1355 s
torchist.histogramdd (non-uniform) : 0.5137 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.5.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

torchist-0.1.5-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file torchist-0.1.5.tar.gz.

File metadata

  • Download URL: torchist-0.1.5.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5

File hashes

Hashes for torchist-0.1.5.tar.gz
Algorithm Hash digest
SHA256 d57bec6302f1a5c2da741a184b097ea3769e4dd2baf4b8036ef9cd602ff4c1dc
MD5 670d500cf26a31891591415e0d90d846
BLAKE2b-256 23a120ee0618441e068a010df50d36fc4e475876e0f1e2c3665e67089d72206e

See more details on using hashes here.

File details

Details for the file torchist-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: torchist-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5

File hashes

Hashes for torchist-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 0a25410e2aad5d33ef8a7028a69b8b77a66abbc373d6886548fd42a2d07b5ea6
MD5 af3cfb1d65b57d6f3a223d94e685f4b1
BLAKE2b-256 f62a2d8174acfcc12d4660d855f9f90acd25a26860631b1142a92bccd8c212aa

See more details on using hashes here.

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