Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discontinuous curve with unequal dimensions and Compact #21

Open
fatteneder opened this issue Jul 15, 2022 · 2 comments
Open

Discontinuous curve with unequal dimensions and Compact #21

fatteneder opened this issue Jul 15, 2022 · 2 comments

Comments

@fatteneder
Copy link

MWE

using BijectiveHilbert

xy = zeros(Int64, 4, 8)
alg = Compact(Int64, [4, 8])
CI = CartesianIndices(xy)
for cixy in CI
  ix, iy = Tuple(cixy)
  z = encode_hilbert(alg, [ix, iy])
  xy[ix,iy] = z
  display(decode_hilbert!(alg, [ix,iy], z))
end

display(xy)

The above yields

4×8 Matrix{Int64}:
  1   4   5   6  59  60  61  64
  2   3   8   7  58  57  62  63
 15  14   9  10  55  56  51  50
 16  13  12  11  54  53  52  49

It appears that the indexing is off and that the curve is not continuous.

Am I doing something wrong or is it just not possible to have it continuous?

@fatteneder
Copy link
Author

Perhaps it is not really discontinuous because it wraps around through the boundary from 16->49.

@adolgert
Copy link
Owner

You found a bug! The goal of this algorithm is to give you continuous indices. It looks to me like the 6th bit, that gives the value 32, is extra on the right side. 49 - 32 = 17, so it would be next.

This is going to be difficult to debug because the original preprint had errors, the paper had errors, and the final code I used as a reference didn't have much testing, so who knows how it was? I just reread the main paper, and it will take some attention.

By the way, the best workaround for this is to use a regular Hilbert curve, record the indices, throw out the ones you don't want, and then sort them. It's an extra level of indirection, and it can be time consuming, but sometimes it's enough.

Meanwhile, I'll take a look again at the paper and code. And thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants