Skip to content

Commit 58d79f8

Browse files
committed
Revert "replace morton order by np unravel index"
This reverts commit adc3240.
1 parent 52b54a8 commit 58d79f8

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/zarr/core/indexing.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,20 @@ def make_slice_selection(selection: Any) -> list[slice]:
13251325

13261326

13271327
def decode_morton(z: int, chunk_shape: ChunkCoords) -> ChunkCoords:
1328-
out = [int(i) for i in np.unravel_index(z, chunk_shape)]
1328+
# Inspired by compressed morton code as implemented in Neuroglancer
1329+
# https://github.com/google/neuroglancer/blob/master/src/neuroglancer/datasource/precomputed/volume.md#compressed-morton-code
1330+
bits = tuple(math.ceil(math.log2(c)) for c in chunk_shape)
1331+
max_coords_bits = max(bits)
1332+
input_bit = 0
1333+
input_value = z
1334+
out = [0] * len(chunk_shape)
1335+
1336+
for coord_bit in range(max_coords_bits):
1337+
for dim in range(len(chunk_shape)):
1338+
if coord_bit < bits[dim]:
1339+
bit = (input_value >> input_bit) & 1
1340+
out[dim] |= bit << coord_bit
1341+
input_bit += 1
13291342
return tuple(out)
13301343

13311344

0 commit comments

Comments
 (0)