Skip to content

Commit 0344442

Browse files
committed
refactor(chunk-grids): remove VaryingDimension.cumulative
The per-chunk prefix sums were no longer used by any lookup and cost time and memory in the number of chunks on every access. `chunk_offset` gives the start of a chunk from the runs. Assisted-by: ClaudeCode:claude-fable-5.1
1 parent 6808f75 commit 0344442

3 files changed

Lines changed: 2 additions & 12 deletions

File tree

‎changes/4479.bugfix.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Opening an array with a rectilinear chunk grid, and indexing it, now costs time and memory proportional to the size of the grid's run-length encoded metadata rather than to its number of chunks: a stored grid such as `[[1, 1000000000000]]`, a few hundred bytes of JSON, previously took seconds per ten million chunks to open and could exhaust memory. The explicit edges in `RectilinearChunkGridMetadata.chunk_shapes` and `VaryingDimension.edges` are now held as `zarr.core.common.RunLengthEdges`, an immutable run-length encoded value that is not a sequence: it has no `len`, indexing or iteration and does not compare equal to a `tuple`. Its `expand()` method yields one entry per chunk. `VaryingDimension.cumulative` is now computed on access. The repr of a chunk grid shows a dimension of more than 100 chunks in its run-length encoded form.
1+
Opening an array with a rectilinear chunk grid, and indexing it, now costs time and memory proportional to the size of the grid's run-length encoded metadata rather than to its number of chunks: a stored grid such as `[[1, 1000000000000]]`, a few hundred bytes of JSON, previously took seconds per ten million chunks to open and could exhaust memory. The explicit edges in `RectilinearChunkGridMetadata.chunk_shapes` and `VaryingDimension.edges` are now held as `zarr.core.common.RunLengthEdges`, an immutable run-length encoded value that is not a sequence: it has no `len`, indexing or iteration and does not compare equal to a `tuple`. Its `expand()` method yields one entry per chunk. `VaryingDimension.cumulative` is removed; `VaryingDimension.chunk_offset` gives the start of a chunk. The repr of a chunk grid shows a dimension of more than 100 chunks in its run-length encoded form.

‎src/zarr/core/chunk_grids.py‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,6 @@ def __init__(self, edges: Sequence[int] | RunLengthEdges, extent: int) -> None:
178178
object.__setattr__(self, "nchunks", n)
179179
object.__setattr__(self, "ngridcells", rle.num_edges)
180180

181-
@property
182-
def cumulative(self) -> tuple[int, ...]:
183-
"""Prefix sums of the edges, one entry per chunk.
184-
185-
Lookups do not use this: it is computed on each access, in time and
186-
memory proportional to the number of chunks.
187-
"""
188-
return tuple(itertools.accumulate(self.edges.expand()))
189-
190181
def index_to_chunk(self, idx: int) -> int:
191182
if idx < 0 or idx >= self.extent:
192183
raise IndexError(f"Index {idx} out of bounds for dimension with extent {self.extent}")

‎tests/test_unified_chunk_grid.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,9 @@ def test_fixed_dimension_rejects_invalid(size: int, extent: int, match: str) ->
248248

249249

250250
def test_varying_dimension_construction() -> None:
251-
"""VaryingDimension stores edges, cumulative sums, nchunks, and extent correctly"""
251+
"""VaryingDimension stores edges, nchunks, and extent correctly"""
252252
d = VaryingDimension([10, 20, 30], extent=60)
253253
assert tuple(d.edges.expand()) == (10, 20, 30)
254-
assert d.cumulative == (10, 30, 60)
255254
assert d.nchunks == 3
256255
assert d.extent == 60
257256

0 commit comments

Comments
 (0)