Skip to content

Commit a2ad048

Browse files
committed
New parametrization for indexes
1 parent c31f0e1 commit a2ad048

2 files changed

Lines changed: 25 additions & 29 deletions

File tree

src/blosc2/indexing.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3248,24 +3248,20 @@ def _index_chunk_multiplier_for_optlevel(optlevel: int) -> int:
32483248
"""Return the chunk-local index chunk multiplier for *optlevel*."""
32493249
if optlevel <= 1:
32503250
return 1
3251-
if optlevel <= 3:
3252-
return 2
32533251
if optlevel <= 6:
3254-
return 3
3252+
return 2
32553253
if optlevel == 9:
3256-
return 5
3257-
return 4
3254+
return 4
3255+
return 3
32583256

32593257

32603258
def _opsi_max_cycles_for_optlevel(optlevel: int) -> int:
32613259
"""Return the OPSI max cycles for *optlevel*."""
32623260
if optlevel <= 1:
32633261
return 1
3264-
if optlevel <= 3:
3265-
return 2
32663262
if optlevel <= 6:
3267-
return 3
3268-
return 4
3263+
return 2
3264+
return 3
32693265

32703266

32713267
def _opsi_storage_chunk_len(chunk_len: int, block_len: int, multiplier: int = 1) -> int:

tests/ndarray/test_indexing.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ def test_opsi_index_accepts_non_multiple_chunk_and_block_lengths():
7070
[
7171
(1, 1),
7272
(3, 2),
73-
(4, 4),
74-
(6, 4),
75-
(7, 8),
76-
(9, 16),
73+
(4, 2),
74+
(6, 2),
75+
(7, 3),
76+
(9, 4),
7777
],
7878
)
7979
def test_opsi_optlevel_controls_chunk_multiplier(optlevel, expected_multiplier):
@@ -99,10 +99,10 @@ def test_opsi_optlevel_controls_chunk_multiplier(optlevel, expected_multiplier):
9999
[
100100
(1, 1),
101101
(3, 2),
102-
(4, 4),
103-
(6, 4),
104-
(7, 8),
105-
(9, 16),
102+
(4, 2),
103+
(6, 2),
104+
(7, 3),
105+
(9, 4),
106106
],
107107
)
108108
def test_chunk_local_indexes_optlevel_controls_chunk_multiplier(kind, optlevel, expected_multiplier):
@@ -554,7 +554,7 @@ def test_chunk_local_index_descriptor_and_lookup_path(tmp_path, kind):
554554
meta = descriptor["bucket"] if kind == "bucket" else descriptor["partial"]
555555

556556
assert meta["layout"] == "chunk-local-v1"
557-
expected_chunk_multiplier = 4
557+
expected_chunk_multiplier = 2
558558
expected_chunk_len = arr.chunks[0] * expected_chunk_multiplier
559559
assert meta["chunk_multiplier"] == expected_chunk_multiplier
560560
assert meta["chunk_len"] == expected_chunk_len
@@ -1237,21 +1237,20 @@ def test_forced_ooc_full_index_merge_preserves_sorted_sidecars(monkeypatch, tmp_
12371237

12381238

12391239
@pytest.mark.parametrize(
1240-
("optlevel", "expected_multiplier", "expected_budget"),
1240+
("optlevel", "expected_multiplier"),
12411241
[
1242-
(1, 1, 1024 / 2),
1243-
(3, 2, 1 * 1024),
1244-
(4, 4, 2 * 1024),
1245-
(6, 4, 2 * 1024),
1246-
(7, 8, 4 * 1024),
1247-
(9, 16, 8 * 1024),
1242+
(1, 1),
1243+
(3, 2),
1244+
(4, 2),
1245+
(6, 2),
1246+
(7, 3),
1247+
(9, 4),
12481248
],
12491249
)
1250-
def test_full_ooc_run_items_follow_optlevel(
1251-
monkeypatch, tmp_path, optlevel, expected_multiplier, expected_budget
1252-
):
1250+
def test_full_ooc_run_items_follow_optlevel(monkeypatch, tmp_path, optlevel, expected_multiplier):
1251+
nitems = 4096
12531252
path = tmp_path / f"full_ooc_optlevel_{optlevel}.b2nd"
1254-
data = np.arange(4096, dtype=np.int64)
1253+
data = np.arange(nitems, dtype=np.int64)
12551254
arr = blosc2.asarray(data, urlpath=path, mode="w", chunks=(256,), blocks=(64,))
12561255
indexing = __import__("blosc2.indexing", fromlist=["FULL_OOC_RUN_ITEMS"])
12571256
monkeypatch.setattr(indexing, "FULL_OOC_RUN_ITEMS", 512)
@@ -1260,6 +1259,7 @@ def test_full_ooc_run_items_follow_optlevel(
12601259
full = descriptor["full"]
12611260

12621261
expected_sidecar_chunk_len = arr.chunks[0] * expected_multiplier
1262+
expected_budget = expected_multiplier * (nitems / 8)
12631263
assert full["ooc_run_item_budget"] == expected_budget
12641264
assert full["ooc_run_items"] == max(expected_sidecar_chunk_len, min(arr.size, expected_budget))
12651265
assert full["ooc_run_item_budget_source"] == "optlevel"

0 commit comments

Comments
 (0)