Skip to main content

Perfect Spatial Hashing in PyTorch

Project description

Perfect Spatial Hashing in PyTorch

This library is an unofficial implementation of Perfect Spatial Hashing by Lefebvre and Hoppe.

Usage

Install the library with:

# For the latest version:
pip install git+https://github.com/dli7319/psh-pytorch.git

# For the PyPI version:
# pip install psh-pytorch

Instantiate a PerfectSpatialHash object with:

from psh_pytorch import PerfectSpatialHash

occupancy_grid # A 2D (or higher dimensional) occupancy grid
out_features = 3
perfect_hash = PerfectSpatialHash(
    occupancy_grid, out_features)

# 2D forward pass
indices = torch.stack(torch.meshgrid(
    torch.arange(128, device=device),
    torch.arange(128, device=device),
    indexing='ij'), -1)
values, sparsity = perfect_hash(indices.reshape(-1, 2))
#   Values are of shape (128 * 128, 3)
#   Sparsity is of shape (128 * 128)
#   Note that values are unmasked
masked_values = values * sparsity.unsqueeze(-1)

Examples

See examples/ for a simple example of how to use the library.

If you clone the repository, you can run the example with:

python -m examples.2D_bulb

Limitations

  1. Currently, interpolation is not supported. Hence, you must use long indices and there are no gradients with respect to the indices.

Development

  • Run tests with pytest.

Acknowledgement

If you find this library useful, please consider citing the original paper:

@article{lefebvre2006perfect,
author = {Lefebvre, Sylvain and Hoppe, Hugues},
title = {Perfect Spatial Hashing},
year = {2006},
issue_date = {July 2006},
publisher = {Association for Computing Machinery},
address = {New York, NY, USA},
volume = {25},
number = {3},
issn = {0730-0301},
url = {https://doi.org/10.1145/1141911.1141926},
doi = {10.1145/1141911.1141926},
journal = {ACM Trans. Graph.},
month = {jul},
pages = {579–588},
numpages = {10},
keywords = {vector images, minimal perfect hash, sparse data, adaptive textures, multidimensional hashing, 3D-parameterized textures}
}

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

psh-pytorch-0.0.3.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

psh_pytorch-0.0.3-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file psh-pytorch-0.0.3.tar.gz.

File metadata

  • Download URL: psh-pytorch-0.0.3.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.0

File hashes

Hashes for psh-pytorch-0.0.3.tar.gz
Algorithm Hash digest
SHA256 0dd81aabad80dc281ace12faf8afdd02cd52883ec14efd4f443e8eb11a0fc178
MD5 310b29884c95e728c2e16f5283ae148b
BLAKE2b-256 a004396cf4f5695928c72034acea62210a776b77eb427a67e8ebea65c44fcb1a

See more details on using hashes here.

File details

Details for the file psh_pytorch-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: psh_pytorch-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.0

File hashes

Hashes for psh_pytorch-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4135c597f281b5408afa30dda2bc5cb419402501c1fb3aad11cebc4ca9edc950
MD5 4d97d645b61352648ef0d6f7822f1460
BLAKE2b-256 6a9c20dc8e20b8e22f2191dd0673dc7657cc108a3cd8495c70fd3f4fd44b90db

See more details on using hashes here.

Supported by

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