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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: torchist-0.1.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.22.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.5

File hashes

Hashes for torchist-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d3978232be0300b8766399b775c3ee62d75e9f21a602b4e728e4b635b2f2d2e4
MD5 979f54d63b1bb5c0fb14ab332e0c7c21
BLAKE2b-256 8b93772c6c625abab35d202e772fe0d557dcf22e2044d7b46ff3e1682482b1f0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchist-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.22.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.5

File hashes

Hashes for torchist-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 42d47a9bb1f2aa9d512696f484dac683a783c699c9a3c9b63ddc67b1dfa0f707
MD5 9ba499607756ee3df729b6d49400058e
BLAKE2b-256 1b4cba79290ce62a6773a8700fdd49179f5eec4156c2ff930126b00dbdf005c7

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