Skip to content

Commit adc3240

Browse files
committed
replace morton order by np unravel index
1 parent 2abd3d2 commit adc3240

File tree

1 file changed

+1
-14
lines changed

1 file changed

+1
-14
lines changed

src/zarr/core/indexing.py

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

13261326

13271327
def decode_morton(z: int, chunk_shape: ChunkCoords) -> ChunkCoords:
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
1328+
out = [int(i) for i in np.unravel_index(z, chunk_shape)]
13421329
return tuple(out)
13431330

13441331

0 commit comments

Comments
 (0)