Created
February 27, 2020 19:13
-
-
Save galtay/e3a37d0bf89122e5ea981282c68a88a5 to your computer and use it in GitHub Desktop.
example hilbert curves for khalid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import time | |
from hilbertcurve.hilbertcurve import HilbertCurve | |
N = 40 | |
num_vecs = 100_000 | |
for p in [1, 2, 3, 4]: | |
hilbert_curve = HilbertCurve(p, N) | |
print("N={}, p={}".format(N, p)) | |
print("coordinate limits in any dimension: ({}, {})".format(0, hilbert_curve.max_x)) | |
print("max distance along curve: {}".format(hilbert_curve.max_h)) | |
print("calculating distance along curve for {} {}-dimensional coordinates".format(num_vecs, N)) | |
t0 = time.time() | |
coords = np.random.randint(0, hilbert_curve.max_x + 1, size=(num_vecs, N)) | |
dists = [] | |
for coord in coords: | |
dist = hilbert_curve.distance_from_coordinates(coord) | |
dists.append(dist) | |
t1 = time.time() | |
print("dt = {:.3f}s".format(t1-t0)) | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment