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.

Limitations

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

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.2.tar.gz (8.7 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.2-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: psh-pytorch-0.0.2.tar.gz
  • Upload date:
  • Size: 8.7 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.2.tar.gz
Algorithm Hash digest
SHA256 09fa80ca9a0b19e7ac71a692fd1207d5811227d09f6a828198869d6523d3947b
MD5 a60db53b2197c1ddc78b192717047125
BLAKE2b-256 cc0a42240a1fb0588be954a40ed46ea3b5c4446172b14caf40176888c4e9a3cf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: psh_pytorch-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.3 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3cbee96fa8410d434e742dc62dcf49426e23751a082febd17626cd8a91df436c
MD5 a25585a7a8263eec507cf56171be1ca5
BLAKE2b-256 a4cc036a11538b8080cbf74b287d074b7bab292827fe0044fa1ba5c9241d0db3

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