# NumPy-style histograms in PyTorch
The `torchist` package implements NumPy's [`histogram`](https://numpy.org/doc/stable/reference/generated/numpy.histogram.html) and [`histogramdd`](https://numpy.org/doc/stable/reference/generated/numpy.histogramdd.html) functions in PyTorch with CUDA support. The package also features implementations of [`ravel_multi_index`](https://numpy.org/doc/stable/reference/generated/numpy.ravel_multi_index.html), [`unravel_index`](https://numpy.org/doc/stable/reference/generated/numpy.unravel_index.html) and some useful functionals like `entropy` or `kl_divergence`.
## Installation
The `torchist` package is available on [PyPI](https://pypi.org/project/torchist), 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
```python
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` on CPU and benefit greately from CUDA capabilities.
```console
$ 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
```
Raw data
{
"_id": null,
"home_page": "https://github.com/francois-rozet/torchist",
"name": "torchist",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "torch, histogram",
"author": "Fran\u00e7ois Rozet",
"author_email": "francois.rozet@outlook.com",
"download_url": "https://files.pythonhosted.org/packages/82/a4/fd1a4af353ef5ba575456cfd16a91109481a102a233f3400dbe066a8e4a4/torchist-0.2.3.tar.gz",
"platform": null,
"description": "# NumPy-style histograms in PyTorch\n\nThe `torchist` package implements NumPy's [`histogram`](https://numpy.org/doc/stable/reference/generated/numpy.histogram.html) and [`histogramdd`](https://numpy.org/doc/stable/reference/generated/numpy.histogramdd.html) functions in PyTorch with CUDA support. The package also features implementations of [`ravel_multi_index`](https://numpy.org/doc/stable/reference/generated/numpy.ravel_multi_index.html), [`unravel_index`](https://numpy.org/doc/stable/reference/generated/numpy.unravel_index.html) and some useful functionals like `entropy` or `kl_divergence`.\n\n## Installation\n\nThe `torchist` package is available on [PyPI](https://pypi.org/project/torchist), which means it is installable with `pip`.\n\n```\npip install torchist\n```\n\nAlternatively, if you need the latest features, you can install it from the repository.\n\n```\npip install git+https://github.com/francois-rozet/torchist\n```\n\n## Getting Started\n\n```python\nimport torch\nimport torchist\n\nx = torch.rand(100, 3).cuda()\n\nhist = torchist.histogramdd(x, bins=10, low=0.0, upp=1.0)\n\nprint(hist.shape) # (10, 10, 10)\n```\n\n## Benchmark\n\nThe implementations of `torchist` are on par or faster than those of `numpy` on CPU and benefit greately from CUDA capabilities.\n\n```console\n$ python torchist/__init__.py\nCPU\n---\nnp.histogram : 1.2559 s\nnp.histogramdd : 20.7816 s\nnp.histogram (non-uniform) : 5.4878 s\nnp.histogramdd (non-uniform) : 17.3757 s\ntorchist.histogram : 1.3975 s\ntorchist.histogramdd : 9.6160 s\ntorchist.histogram (non-uniform) : 5.0883 s\ntorchist.histogramdd (non-uniform) : 17.2743 s\n\nCUDA\n----\ntorchist.histogram : 0.1363 s\ntorchist.histogramdd : 0.3754 s\ntorchist.histogram (non-uniform) : 0.1355 s\ntorchist.histogramdd (non-uniform) : 0.5137 s\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "NumPy-style histograms in PyTorch",
"version": "0.2.3",
"project_urls": {
"Homepage": "https://github.com/francois-rozet/torchist"
},
"split_keywords": [
"torch",
" histogram"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3759f340823a5a07418e90d7861812014dc9b0df98c518aa33153ce0bd05ffe1",
"md5": "84a8f1deee50777c43a8630946c0150a",
"sha256": "887702fc55aa74bccebc00c7e9238407844a548443aecc773a5e3985496e103b"
},
"downloads": -1,
"filename": "torchist-0.2.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "84a8f1deee50777c43a8630946c0150a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 7900,
"upload_time": "2024-04-03T14:47:51",
"upload_time_iso_8601": "2024-04-03T14:47:51.351714Z",
"url": "https://files.pythonhosted.org/packages/37/59/f340823a5a07418e90d7861812014dc9b0df98c518aa33153ce0bd05ffe1/torchist-0.2.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "82a4fd1a4af353ef5ba575456cfd16a91109481a102a233f3400dbe066a8e4a4",
"md5": "e08bffcdca630efbcbee5d11c84c6303",
"sha256": "56423cceb5deb843faaa8b4dbbefc4a6b5ea72a5d5f49b43dc26f32f616d182b"
},
"downloads": -1,
"filename": "torchist-0.2.3.tar.gz",
"has_sig": false,
"md5_digest": "e08bffcdca630efbcbee5d11c84c6303",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 8139,
"upload_time": "2024-04-03T14:47:53",
"upload_time_iso_8601": "2024-04-03T14:47:53.080923Z",
"url": "https://files.pythonhosted.org/packages/82/a4/fd1a4af353ef5ba575456cfd16a91109481a102a233f3400dbe066a8e4a4/torchist-0.2.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-03 14:47:53",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "francois-rozet",
"github_project": "torchist",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "torchist"
}