Skip to main content

A python library for converting between d-dimensional points and indices on a hilbert curve

Project description

Hilbert Bytes

build pypi docs

Hilbert Bytes is a python library for converting to and from points in d-dimensions and their corresponding index on a hilbert curve. It's similar to hilbertcurve and numpy-hilbert-curve but is faster and more space efficient than either by keeping manipulations at the byte level, and using numba to compile the results. It also uses arbitrary precision integers, allowing you to make the grid arbitrarily fine

Installation

pip install hilbert-bytes

Usage

import hilbert_bytes
import numpy as np

points = ... # arbitrary d-dimensional points
num, dim = points.shape
# convert to big-endian bytes
points_bytes = points[..., None].astype(">u8").view("u1")
index_bytes = hilbert_bytes.encode(points_bytes)  # indies as big-endian ints
new_points_bytes = hilbert_bytes.decode(index_bytes)

If you want the indices as multi-byte ints, you can can do a similar trick in reverse:

index_bytes = ... # an array of big-endian ints
indices = index_bytes.view(">u8").astype("u8")[..., 0]

But note that this will only work if your index fits in 8 bytes

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

hilbert_bytes-0.3.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

hilbert_bytes-0.3.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file hilbert_bytes-0.3.0.tar.gz.

File metadata

  • Download URL: hilbert_bytes-0.3.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.11 Darwin/24.2.0

File hashes

Hashes for hilbert_bytes-0.3.0.tar.gz
Algorithm Hash digest
SHA256 8b569df2ff0a67be92ebf90b60303dd87719c0b5072e4be3670a135276099fe6
MD5 f3faaccf677a2eda8e6b43905261e8c8
BLAKE2b-256 0818e215158c3f26f4150d0988de69a3bff131da581d495cfbc0d7d3e03c7eac

See more details on using hashes here.

File details

Details for the file hilbert_bytes-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: hilbert_bytes-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.11 Darwin/24.2.0

File hashes

Hashes for hilbert_bytes-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1afd1a3df521bafb3b5aea958bc369dbc0e7fb03b3d8f822d33773c9c4914805
MD5 935b9d03a04be18a94d0293307dc46ff
BLAKE2b-256 2a9ac8884f9a89a379d08cb041a3a0c37590f89ec1150e98a21027391166ba44

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