Skip to main content

NumPy-style histograms in PyTorch

The torchist package implements NumPy's histogram and histogramdd functions in PyTorch with CUDA support. The package also features implementations of ravel_multi_index, unravel_index and some useful functionals like entropy or 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 from the repository.

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

Getting Started

import torch
import torchist

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

hist = torchist.histogramdd(x, bins=10, low=0.0, upp=1.0)

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

Benchmark

The implementations of torchist are on par or faster than those of numpy and torch on CPU. On GPU (CUDA), they are much faster.

$ torchist-benchmark
CPU
---
np.histogram                      0.8917 s
np.histogram (edges)              0.5993 s
np.histogramdd                   16.8441 s
np.histogramdd (edges)           13.7680 s
torch.histogram                   0.3251 s
torch.histogram (edges)           0.4217 s
torch.histogramdd                 1.0528 s
torch.histogramdd (edges)         1.1955 s
torchist.histogram                0.4250 s
torchist.histogram (edges)        0.6372 s
torchist.histogramdd              1.6266 s
torchist.histogramdd (edges)      3.8619 s

CUDA
----
torchist.histogram                0.1045 s
torchist.histogram (edges)        0.0672 s
torchist.histogramdd              0.0906 s
torchist.histogramdd (edges)      0.1170 s

Metadata

Release files for torchist 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for torchist 1.0.1
File Size Uploaded
torchist-1.0.1.tar.gz 9.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for torchist 1.0.1
File Interpreter ABI Platform
torchist-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 18.0 kB

Release files / torchist-1.0.1.tar.gz

Download URL torchist-1.0.1.tar.gz
Size 9.5 kB
Tags Source
SHA-256 checksum
How to use checksums
8c5533ce07c3f35bcf23b2c03c2378bf132df2a59004cd529ffbf840137e12a5
BLAKE2b-256 checksum
How to use checksums
5ed90dc9c395bd9957318f7a65de9fdbf16142cc2ab16a87f718db229f4c69dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.9

Release files / torchist-1.0.1-py3-none-any.whl

Download URL torchist-1.0.1-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
92eeca41c4dc5c3426eb61f3567e261935770bb6d06eb26a562e051083b7c480
BLAKE2b-256 checksum
How to use checksums
6c9dc34a447947d291e691fa48c9615274a5fc92caaef46665528ca8a296ccb7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.7

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.2

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page