From f78cd0b00a75f794a81c1e101dd82b7bf8a1534d Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 21:19:56 +0000 Subject: [PATCH 1/4] Per-bin work of integer planes in NumPy int64 (speed plan D6) The bin starts, the sums of per-value counts into bins, the integer bin limits, the representatives, max_representative_error and the bin of each order statistic of the range check were Python loops over every bin (a 65,537-item list per plane and call). New module integer_bins computes the same integers with NumPy int64, and keeps v0.7.0's exact Python integers where int64 could not be exact: bin_count * width >= 2**62, pixels from 2**51 on, per-value totals from 2**52 on, and histograms built with NumPy integer limits. Every output is bitwise v0.7.0's; no new dependency. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01G3qp9AxjpGPw9xfWAUJNqc --- AGENTS.md | 8 +- CHANGELOG.md | 26 +++++ pyproject.toml | 1 + src/morphobricks_normalization/histogram.py | 52 ++++----- .../integer_bins.py | 104 ++++++++++++++++++ .../integer_representatives.py | 11 +- tools/code_rules_baseline.json | 3 +- 7 files changed, 170 insertions(+), 35 deletions(-) create mode 100644 src/morphobricks_normalization/integer_bins.py diff --git a/AGENTS.md b/AGENTS.md index 058bcd6..5a29916 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -36,6 +36,9 @@ src/morphobricks_normalization/ bins a value can fall in and whether centres map back (#86) integer_representatives.py integer bin representatives (nearest float64 midpoint) and their exact bound for 64-bit values float64 cannot hold (#28) + integer_bins.py whole-number bin starts and limits of integer planes, per-value counts + summed into bins, the bin of a value: NumPy int64 where no step can + overflow, exact Python integers (as in v0.7.0) for wide 64-bit ranges ranges.py HistogramSettings, RangeCheck, range_check_issues (Milestone 5) integrity.py invariants every PlaneHistogram and HistogramTail checks when made (counts, limits, tail moments) and the pixel type of every block @@ -88,7 +91,10 @@ tests/ pytest with simulated planes (tests/simulation.py); tests/da stain_v060_parity.json, the v0.6.0 refusals and output digests of tests/test_stain_check_options.py (recorded by tests/stain_parity_cases.py), and region_v061_parity.json, the v0.6.1 region whites and stain vectors of - tests/test_regions.py (recorded by tests/region_parity_cases.py) + tests/test_regions.py (recorded by tests/region_parity_cases.py), and + histogram_v070_parity.json, the v0.7.0 histograms, representatives, bounds + and range checks of tests/test_histogram_parity.py (recorded by + tests/histogram_parity_cases.py) tools/check.py the release gate: ruff format, pytest and the code standards (design v0.4 §9); `--rules` runs only the standards (CI); tools/code_rules.py is the shared copy (SHA-256 pinned in tests/test_code_rules.py), tools/code_rules_baseline.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 3594c7d..9216722 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,32 @@ Release notes and migration notes of `morphobricks-normalization`. Numbers are p issues of [CellMigrationLab/morphobricks-normalization](https://github.com/CellMigrationLab/morphobricks-normalization). The decisions are in [docs/plan.md](docs/plan.md) §12. +## Unreleased + +Speed only (MorphoBricks preprocessing speed plan, step D6; measured in preprocessing draft PR +#318, `experiments/histogram_numba_study/`): every output is bitwise that of v0.7.0. No new +dependency (NumPy only, no Numba), no API, file format or message change. + +- **Per-bin work of integer planes in NumPy int64** (new module `integer_bins`). The bin starts + (a 65,537-item Python list per call before), the sums of per-value counts into bins, the + integer bin limits, the representatives, `max_representative_error` and the bin of each order + statistic of the range check were Python loops over every bin; they are now NumPy int64 + arithmetic on the same formulas (the bin of a value is one exact integer division). +- **The exact Python integers are kept where int64 could not be exact**, chosen by explicit + conditions: bin starts when `bin_count * width >= 2**62` (64-bit planes with a wide range); + representatives and the bound from `2**51` on (unchanged `Fraction` bound, #28); bin sums + when a plane's per-value counts total `2**52` or more (v0.7.0's float64 sums are kept there); + and histograms a caller built with NumPy integer limits, so their results keep v0.7.0's NumPy + types. Float bin positions, tail moments and 32/64-bit pixel binning are unchanged. +- **Identity**: `tests/test_histogram_parity.py` compares every `PlaneHistogram` field, the + representatives and bound as raw bits, the integer bin limits and their types, `is_exact` and + the `RangeCheck` of 4,236 cases (the ten pixel types, NaN and +/-inf, subnormal, constant, + empty and dtype-extreme planes, bin-edge float grids, several bin counts, min-max and robust, + whole and in 3 blocks, 64-bit ranges on both sides of each int64 condition) with + `tests/data/histogram_v070_parity.json`, recorded on v0.7.0 (`c6a9f9d`) by + `tests/histogram_parity_cases.py`; and the kept Python paths with the int64 ones switched off. + `tools/dump_outputs.py` (default and `--corpus`) gives the digests of v0.7.0. + ## v0.7.0 (2026-11-15) Step 1 of MorphoBricks-Spec [ADR 0005](https://github.com/CellMigrationLab/MorphoBricks-Spec/blob/main/docs/adr/0005-binary-masks.md) diff --git a/pyproject.toml b/pyproject.toml index fb6f081..9e3af86 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -107,6 +107,7 @@ baseline = "tools/code_rules_baseline.json" "morphobricks_normalization.fitting" = "pure" "morphobricks_normalization.histogram" = "pure" "morphobricks_normalization.integrity" = "pure" +"morphobricks_normalization.integer_bins" = "pure" "morphobricks_normalization.integer_representatives" = "pure" "morphobricks_normalization.issues" = "pure" "morphobricks_normalization.normalization" = "pure" diff --git a/src/morphobricks_normalization/histogram.py b/src/morphobricks_normalization/histogram.py index ec6a624..394698b 100644 --- a/src/morphobricks_normalization/histogram.py +++ b/src/morphobricks_normalization/histogram.py @@ -42,7 +42,6 @@ from __future__ import annotations -import bisect import math from collections.abc import Callable, Iterable from dataclasses import dataclass @@ -53,6 +52,12 @@ from .bin_centres import float_bin_centres, float_bin_position from .dtypes import check_supported, default_bin_count, is_integer, validate_bin_count +from .integer_bins import ( + counts_from_per_value, + integer_bin_index, + integer_bin_offsets, + search_starts, +) from .integer_representatives import beyond_float_exact, integer_representatives, wide_integer_error from .integrity import check_histogram, check_tail, checked_blocks from .ranges import CENTRAL_PERCENTILES, HistogramSettings, RangeCheck @@ -191,7 +196,10 @@ def max_representative_error(self) -> float: return wide_integer_error(self) if is_integer(self.dtype): first, last = self._integer_bin_limits - widest = max(b - a + 1 for a, b in zip(first, last, strict=True)) + if isinstance(first, np.ndarray): + widest = int((last - first).max()) + 1 + else: + widest = max(b - a + 1 for a, b in zip(first, last, strict=True)) bins = (widest - 1) / 2 else: lo, hi = float(self.binning_min), float(self.binning_max) @@ -223,15 +231,16 @@ def integer_bin_limits(self) -> list[tuple[int, int]]: if self.is_empty: return [] first, last = self._integer_bin_limits + if isinstance(first, np.ndarray): + first, last = first.tolist(), last.tolist() return [ (self.binning_min + a, self.binning_min + b) for a, b in zip(first, last, strict=True) ] @cached_property - def _integer_bin_limits(self) -> tuple[list[int], list[int]]: - """Bin limits as offsets from ``binning_min`` (exact Python integers).""" - starts = _integer_bin_starts(self.binning_max + 1 - self.binning_min, self.bin_count) - return starts[:-1], [s - 1 for s in starts[1:]] + def _integer_bin_limits(self) -> tuple[np.ndarray, np.ndarray] | tuple[list[int], list[int]]: + """Bin limits as offsets from ``binning_min``: int64 arrays or exact Python integers.""" + return integer_bin_offsets(self.binning_min, self.binning_max, self.bin_count) def compute_plane_histogram( @@ -417,14 +426,6 @@ def _measure( return _wide_histogram(blocks, dtype, n, settings, check) -def _integer_bin_starts(width: int, bin_count: int) -> list[int]: - """Offsets at which bins ``0 .. bin_count`` start (the last entry is ``width``).""" - if width <= bin_count: - # One value per bin from the start; the remaining bins stay empty. - return [min(i, width) for i in range(bin_count + 1)] - return [-((-i * width) // bin_count) for i in range(bin_count + 1)] - - def _as_ordered_uint64(values: np.ndarray) -> np.ndarray: """Map integers to uint64 while keeping their order, without overflow.""" if values.dtype.kind == "u": @@ -432,13 +433,6 @@ def _as_ordered_uint64(values: np.ndarray) -> np.ndarray: return values.astype(np.int64).view(np.uint64) ^ np.uint64(1 << 63) -def _counts_from_per_value(per_value: np.ndarray, starts: list[int], n: int) -> np.ndarray: - """Sum per-value counts (offsets ``0 .. width - 1``) into bins starting at ``starts``.""" - bin_of_value = np.searchsorted(np.array(starts[:-1]), np.arange(per_value.size), side="right") - counts = np.bincount(bin_of_value - 1, weights=per_value, minlength=n) - return np.rint(counts).astype(np.int64) - - def _small_integer_histogram( blocks: Iterable[np.ndarray], dtype: np.dtype, @@ -466,9 +460,7 @@ def _small_integer_histogram( smallest = int(np.iinfo(dtype).min) def min_max() -> PlaneHistogram: - counts = _counts_from_per_value( - table[first : last + 1], _integer_bin_starts(last + 1 - first, n), n - ) + counts = counts_from_per_value(table[first : last + 1], n) lo, hi = smallest + first, smallest + last return PlaneHistogram(dtype, n, lo, hi, counts, total, total, pixel_min=lo, pixel_max=hi) @@ -486,8 +478,7 @@ def order(q: float) -> _Order: orders = [order(q) for q in quantiles] if settings.robust: low, high = orders[0].value - smallest, orders[1].value - smallest - starts = _integer_bin_starts(high + 1 - low, n) - counts = _counts_from_per_value(table[low : high + 1], starts, n) + counts = counts_from_per_value(table[low : high + 1], n) histogram = PlaneHistogram( dtype, n, @@ -614,11 +605,11 @@ def _integer_bins( under: TailMoments, over: TailMoments, ) -> np.ndarray: + """Count integer pixels into bins: per value up to 2**24 values, else by searching starts.""" width = hi + 1 - lo - starts = _integer_bin_starts(width, n) origin = _as_ordered_uint64(np.array([lo], dtype=dtype))[0] per_value = np.zeros(width, dtype=np.int64) if width <= _PER_VALUE_COUNT_LIMIT else None - bin_starts = np.array(starts[:-1], dtype=np.uint64) + bin_starts = search_starts(width, n) if per_value is None else None counts = np.zeros(n, dtype=np.int64) for values in checked_blocks(blocks(), dtype): if values.size == 0: @@ -638,7 +629,7 @@ def _integer_bins( index = np.searchsorted(bin_starts, offsets, side="right") - 1 counts += np.bincount(index, minlength=n) if per_value is not None: - counts = _counts_from_per_value(per_value, starts, n) + counts = counts_from_per_value(per_value, n) return counts @@ -824,8 +815,7 @@ def _bin_index( ) -> int: """Return the bin of ``value`` with bins over ``[lo, hi]``, values outside clipped.""" if is_integer(dtype): - starts = _integer_bin_starts(hi + 1 - lo, n) - index = bisect.bisect_right(starts, value - lo, hi=n) - 1 + index = integer_bin_index(value - lo, hi + 1 - lo, n) elif lo == hi: index = 0 else: diff --git a/src/morphobricks_normalization/integer_bins.py b/src/morphobricks_normalization/integer_bins.py new file mode 100644 index 0000000..e430730 --- /dev/null +++ b/src/morphobricks_normalization/integer_bins.py @@ -0,0 +1,104 @@ +"""Whole-number bin limits of integer planes, in int64 where that is exact. + +Bin ``i`` of ``n`` bins over ``width`` values starts at offset ``ceil(i * width / n)`` +(or ``min(i, width)`` when ``width <= n``, one value per bin). Until v0.7.0 these limits, +the sums of per-value counts into bins and the bin of a value were found with loops over +every bin in Python. Here the same integers come from NumPy int64 arithmetic wherever no +step can overflow, and from the exact Python integers of v0.7.0 everywhere else +(64-bit planes with a wide range), so no count, limit or float built from them changes. +""" + +from __future__ import annotations + +import numpy as np + +INT64_STARTS_LIMIT = 2**62 +"""Bin starts are int64 when ``bin_count * width`` is below this: no product can overflow.""" + +EXACT_FLOAT_TOTAL = 2.0**52 +"""Per-value counts are summed in int64 while their float64 total is below this. + +Every partial sum is then below ``2**53``, so the float64 sums used until v0.7.0 were +exact and equal the int64 sums; beyond it (never for one plane in memory) they are kept. +""" + + +def integer_bin_starts(width: int, bin_count: int) -> list[int]: + """Offsets at which bins ``0 .. bin_count`` start (the last entry is ``width``).""" + if width <= bin_count: + # One value per bin from the start; the remaining bins stay empty. + return [min(i, width) for i in range(bin_count + 1)] + return [-((-i * width) // bin_count) for i in range(bin_count + 1)] + + +def integer_bin_starts_int64(width: int, bin_count: int) -> np.ndarray | None: + """Return :func:`integer_bin_starts` as an int64 array, or None if int64 could overflow. + + The same integers from the same formula: NumPy's integer floor division rounds towards + minus infinity, as Python's does. None when ``bin_count * width`` reaches ``2**62`` + (64-bit planes with a wide range), where only Python integers are exact. + """ + if bin_count * max(width, 1) >= INT64_STARTS_LIMIT: + return None + index = np.arange(bin_count + 1, dtype=np.int64) + if width <= bin_count: + return np.minimum(index, width) + return -((-index * width) // bin_count) + + +def integer_bin_offsets( + binning_min: int, binning_max: int, bin_count: int +) -> tuple[np.ndarray, np.ndarray] | tuple[list[int], list[int]]: + """Return every bin's first and last value, as offsets from ``binning_min``. + + int64 arrays when both limits are Python integers (as in every histogram computed or + read by this library) and the starts fit int64; otherwise the exact Python integers of + v0.7.0, so that results built from them keep their values and types. + """ + width = binning_max + 1 - binning_min + starts = integer_bin_starts_int64(width, bin_count) if type(width) is int else None + if starts is not None: + return starts[:-1], starts[1:] - 1 + starts = integer_bin_starts(width, bin_count) + return starts[:-1], [s - 1 for s in starts[1:]] + + +def search_starts(width: int, bin_count: int) -> np.ndarray: + """Return the starts of bins ``0 .. bin_count - 1`` as uint64, for a sorted search.""" + starts = integer_bin_starts_int64(width, bin_count) + if starts is None: # a wide 64-bit range: computed as exact Python integers + return np.array(integer_bin_starts(width, bin_count)[:-1], dtype=np.uint64) + return starts[:-1].astype(np.uint64) + + +def counts_from_per_value(per_value: np.ndarray, bin_count: int) -> np.ndarray: + """Sum per-value counts (offsets ``0 .. width - 1``) into ``bin_count`` bins over that width. + + Exact int64 sums (differences of the cumulative counts at the bin starts) while the + total is below :data:`EXACT_FLOAT_TOTAL`; otherwise the float64 sums of v0.7.0. + """ + width = per_value.size + starts = integer_bin_starts_int64(width, bin_count) + if starts is not None and float(np.sum(per_value, dtype=np.float64)) < EXACT_FLOAT_TOTAL: + cumulative = np.zeros(width + 1, dtype=np.int64) + np.cumsum(per_value, out=cumulative[1:]) + return cumulative[starts[1:]] - cumulative[starts[:-1]] + starts = integer_bin_starts(width, bin_count) + bin_of_value = np.searchsorted(np.array(starts[:-1]), np.arange(width), side="right") + counts = np.bincount(bin_of_value - 1, weights=per_value, minlength=bin_count) + return np.rint(counts).astype(np.int64) + + +def integer_bin_index(offset: int, width: int, bin_count: int) -> int: + """Return ``bisect_right(integer_bin_starts(width, n), offset, hi=n) - 1`` in O(1). + + Exact integer arithmetic: -1 below the range. With no more values than bins, value + ``offset`` is in bin ``offset`` and a value above the range in the last bin. Otherwise + bin ``i`` starts at ``ceil(i * width / n)``, which is at most ``offset`` exactly when + ``i <= offset * n / width``. + """ + if offset < 0: + return -1 + if width <= bin_count: + return offset if offset < width else bin_count - 1 + return min(offset * bin_count // width, bin_count - 1) diff --git a/src/morphobricks_normalization/integer_representatives.py b/src/morphobricks_normalization/integer_representatives.py index 0c14f09..2ad6058 100644 --- a/src/morphobricks_normalization/integer_representatives.py +++ b/src/morphobricks_normalization/integer_representatives.py @@ -26,7 +26,16 @@ def integer_representatives(histogram: PlaneHistogram) -> np.ndarray: - """Return the float64 nearest the midpoint of every bin of a non-empty integer plane.""" + """Return the float64 nearest the midpoint of every bin of a non-empty integer plane. + + Below ``2**51`` with int64 bin limits, ``first + last`` is an int64 below ``2**53`` and + so an exact float64, and halving it is exact: the same floats as the Python division. + """ + # The histogram's own limits (int64 arrays, or Python integers for wide 64-bit ranges). + first, last = histogram._integer_bin_limits + if isinstance(first, np.ndarray) and not beyond_float_exact(histogram): + lo = histogram.binning_min + return ((first + lo) + (last + lo)).astype(np.float64) / 2 return np.array( [(first + last) / 2 for first, last in histogram.integer_bin_limits()], dtype=np.float64 ) diff --git a/tools/code_rules_baseline.json b/tools/code_rules_baseline.json index 41e8958..009f600 100644 --- a/tools/code_rules_baseline.json +++ b/tools/code_rules_baseline.json @@ -19,8 +19,7 @@ "src/morphobricks_normalization/histogram.py _float_bins: private function of # lines without a docstring": 20, "src/morphobricks_normalization/histogram.py _integer_bins: # Ruff findings too-many-arguments": 1, "src/morphobricks_normalization/histogram.py _integer_bins: # parameters (max #)": 9, - "src/morphobricks_normalization/histogram.py _integer_bins: private function of # lines without a docstring": 25, - "src/morphobricks_normalization/histogram.py: # lines (max #)": 835, + "src/morphobricks_normalization/histogram.py: # lines (max #)": 825, "src/morphobricks_normalization/parameters.py _check_rgb_columns: private function of # lines without a docstring": 20, "src/morphobricks_normalization/parameters.py _text: # Ruff findings any-type": 1, "src/morphobricks_normalization/pooling.py __init__: # Ruff findings missing-return-type-special-method": 1, From 74d72a05fd5f71c6d087a364a25257d0ec308195 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 21:19:57 +0000 Subject: [PATCH 2/4] Tests: v0.7.0 histogram parity table and the int64 conditions tests/histogram_parity_cases.py ports the preprocessing study's differential check (PR #318, diffcheck.py), made smaller: 4,236 cases over the ten pixel types, NaN/inf, subnormals, constant/empty/extreme planes, bin-edge float grids, several bin counts, min-max and robust, whole and in 3 blocks, and 64-bit ranges on both sides of every int64 condition. tests/data/histogram_v070_parity.json is its table recorded on v0.7.0 (c6a9f9d). test_histogram_parity.py checks every plane against it, the kept Python path with the int64 path switched off, a negative control, and each int64 formula and condition against the Python integers. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01G3qp9AxjpGPw9xfWAUJNqc --- tests/data/histogram_v070_parity.json | 966 ++++++++++++++++++++++++++ tests/histogram_parity_cases.py | 221 ++++++ tests/test_histogram_parity.py | 209 ++++++ 3 files changed, 1396 insertions(+) create mode 100644 tests/data/histogram_v070_parity.json create mode 100644 tests/histogram_parity_cases.py create mode 100644 tests/test_histogram_parity.py diff --git a/tests/data/histogram_v070_parity.json b/tests/data/histogram_v070_parity.json new file mode 100644 index 0000000..d78216a --- /dev/null +++ b/tests/data/histogram_v070_parity.json @@ -0,0 +1,966 @@ +{ +"base_commit": "c6a9f9d", +"numpy": "2.5.5", +"planes": { +"float32_120x97_k0": [ +20, +"a92097b2a150b8edfdb304fee48d52b892f561295c91fde0af21ed74ece7119a" +], +"float32_120x97_k1": [ +20, +"198137ef9284f4c984d16e06ae68710270c9886ce14bc5cfc70d45cd0ae6d5ec" +], +"float32_120x97_k2": [ +20, +"37cef2e0ac7d8ff6a033a9a8a276c6a4b86401ef716b748d344ade0ad781eafe" +], +"float32_120x97_k3": [ +20, +"63ae673ec97e4173fcc96340c8c4fbb3df79222b0ac91c4e6fd253b1c446cc01" +], +"float32_120x97_k4": [ +20, +"f52a47be2baac744eacd16438b0efd89ce0ecc5dd265e351503c0d6092676937" +], +"float32_120x97_k5": [ +20, +"fafe5374034924eda0d2f048636c0269a15e29a7a3a84478a5a3244853dac996" +], +"float32_1_k0": [ +20, +"555814bc1c890bc9b1c879e9a0d9fbdaede6983571c747bbbacec463a1646c66" +], +"float32_1_k1": [ +20, +"700d182cb4d432a12121068b36145e298032ac973db2bbb5efb09a3abc94d15f" +], +"float32_1_k2": [ +20, +"700d182cb4d432a12121068b36145e298032ac973db2bbb5efb09a3abc94d15f" +], +"float32_1_k3": [ +20, +"e2a19e29853d01daf0e00fb37bb3158bc0fe1e5448ae895364eb5fb9e47e8d5c" +], +"float32_1_k4": [ +20, +"782b35252c8487cb01631d3e6cd51ddc8ed4574582c4ffa128984606bfec8623" +], +"float32_1_k5": [ +20, +"e2a19e29853d01daf0e00fb37bb3158bc0fe1e5448ae895364eb5fb9e47e8d5c" +], +"float32_7x5_k0": [ +20, +"b1dacf0aac25c300f3b8f6b1ac7a2cdd07ba989e0299204138ce7f50d7bf79ed" +], +"float32_7x5_k1": [ +20, +"16288725c405e81bb4b053fbbace1c62ed1ea1dbd02ed072f66092d95eb12039" +], +"float32_7x5_k2": [ +20, +"8ad3edff85e23b61e395f589bb8f9825faea6622db0ed1ba82cf638b2c4eda99" +], +"float32_7x5_k3": [ +20, +"31968baf030c067a43e1a599817f662800477399809783f87f61590a89926d5b" +], +"float32_7x5_k4": [ +20, +"52d25737eb023059ab6e2823f64edcc92b7af2a76d3be188fb37454c2597eb61" +], +"float32_7x5_k5": [ +20, +"f41674a621efb41fed6ba5002c410642271f5e28e42fdcdcc745ad15bd299865" +], +"float32_all_nan": [ +20, +"e3528ff14e31454f9b751d6728f7f91b756dc2def1041dab5b26c1699c1da38a" +], +"float32_edges_10000_-1.5_7.25": [ +4, +"6ccb6c32c0d9087b6f016f409e83b19a988599e7e823d1fd407ec6a89fb11f05" +], +"float32_edges_10000_-1000000.0_3000000.0": [ +4, +"ba47fd57d977c80a58d61af3017ebf120ad9ae6a9533d2fd05b8033077237845" +], +"float32_edges_10000_0.001_1.0": [ +4, +"69a546fb26932882ebee3e3b86ee2e858909470d6175e414fb89a3b9090f228b" +], +"float32_edges_10000_0.0_10000.0": [ +4, +"b271800c097b6417ccc19d2cb494acad337b1d4608601f66bcacd291dd9dea1c" +], +"float32_edges_10000_0.1_0.7": [ +4, +"8b2920eaffd85fef07615e51d4f120a2ce354d1061fd597338cdb7545613f728" +], +"float32_edges_256_-1.5_7.25": [ +4, +"8a19c6295dde8a6d80952ced5a649ecfb1f89fda7893314df6704301b9172456" +], +"float32_edges_256_-1000000.0_3000000.0": [ +4, +"8d1011d631886d0160692b320175acf13e30e00b030c0c99678387fa9d1bf07a" +], +"float32_edges_256_0.001_1.0": [ +4, +"2da5d569ca562d7a9f698fc7c56da47d843a7160a549bfd8a997da9282fab5df" +], +"float32_edges_256_0.0_256.0": [ +4, +"d16a3370d3592214efef0be7f32b63854120b9f78fecce11e744268e81e039ea" +], +"float32_edges_256_0.1_0.7": [ +4, +"e4d82c0ac4a1fc712ebaed736c5af620f78061a11413a1dec6a26086ea477eb5" +], +"float32_edges_3_-1.5_7.25": [ +4, +"9147c0fa43b8c739f740211a93795e07811b68da94c668ed342465750d237aef" +], +"float32_edges_3_-1000000.0_3000000.0": [ +4, +"38d9d8f2d965a00b7ccd07fce4452f6f9c22c3848800d6ac1a27e93c6f232bbb" +], +"float32_edges_3_0.001_1.0": [ +4, +"5a9f2b9ba578aaaef763cebc3611211df868b9651ccb4342a8f8f5f5417ac8f4" +], +"float32_edges_3_0.0_3.0": [ +4, +"ebb84fcd197d5b2472426673bcdf8e31805de9caec67f03508fe6aa90427e796" +], +"float32_edges_3_0.1_0.7": [ +4, +"d20d0a8ee123cad7d12db305a07b0bcc340eb66e6f7f841b2e9019cb4e0ae928" +], +"float32_edges_500_-1.5_7.25": [ +4, +"cd42158e0e5a357c77369a80daaae45b652bcb91d365896fcf91e5262692492c" +], +"float32_edges_500_-1000000.0_3000000.0": [ +4, +"33ca402259b50e03721831cc194c1d9a497d9b494e57f71a873d3de659812630" +], +"float32_edges_500_0.001_1.0": [ +4, +"ee0d4f4293a1f8c700db6afb6abd7d0e0d5534444b6273f5e192d63eec828df0" +], +"float32_edges_500_0.0_500.0": [ +4, +"34c46eecf906fc8735009ca90728c1481fdc88b1fab37704f7b564705aade1ca" +], +"float32_edges_500_0.1_0.7": [ +4, +"0e217736d51bc8344a38f3db5cf24112891d7182fba50164f6eb14329aefbb9b" +], +"float32_empty": [ +20, +"5b3074df0e90a1a081f2c8b1fc876a87a6cccd2322adc9dff6911ac22c6d2987" +], +"float64_120x97_k0": [ +20, +"5935c441c7f0ce89cb2533c3f424e9b20aa6f3edaf7ed720d621af4fc19f8fae" +], +"float64_120x97_k1": [ +20, +"a28a8d612f3fffa2ea5f97c22a3587737b5a38b1e248e5652e73be8fe45e414f" +], +"float64_120x97_k2": [ +20, +"209ce068e0ffe220e21747d7eab642fd093575f17250cf7ce5aad4281217d8ec" +], +"float64_120x97_k3": [ +20, +"41562e04b07af3f49b50f2c89c8a338ed46ab684b976e2af335e8d2507b4e899" +], +"float64_120x97_k4": [ +20, +"be6a3ad528428a4d7a7b95b43834e37d9bbe24441ba1dd44a954233c53ea6e50" +], +"float64_120x97_k5": [ +20, +"1b8332a9a74f0ac1c854baf39cdf2517b989eb59fea5c9c7a5c4749ddfbea697" +], +"float64_1_k0": [ +20, +"a20427ef29b4f1dd473d53d7e47bd9f1e5baf4ff59c1da7e325041b457fe90b3" +], +"float64_1_k1": [ +20, +"08c3f05d047c6f73508ee4b458baec53d112eafc97b54dd0bad2086ee5f32573" +], +"float64_1_k2": [ +20, +"cda188a5cae352675d020b29b6c711a828da47cf47ba0567be822260f48083ca" +], +"float64_1_k3": [ +20, +"a507b97d48587a250e72426b312c1584feaf6987de4f7baa541a3503bf28cebf" +], +"float64_1_k4": [ +20, +"7edebc3196ec5efc18b2f709742b11d6841f98633f1069f167c617f409b56df9" +], +"float64_1_k5": [ +20, +"26c9198bafc4cf9e455def78effe56788a03b36e9c775628b33da2ffaeb00405" +], +"float64_7x5_k0": [ +20, +"58fe84702d36f744e25174487b062894855581c7eaf4966b84db0468484b34bc" +], +"float64_7x5_k1": [ +20, +"9582563d0a815547355f65e146ec591e20384cab60504b11af35dcc27e718851" +], +"float64_7x5_k2": [ +20, +"8fe882a9e94dd751089d4f8d251f1068aa0b13f6d8e4477a6fe0bc4d3cfd8d02" +], +"float64_7x5_k3": [ +20, +"72df6aaf2feed0603aad1945a26686cfe6258877b7909f7ef53a5721f0c77eb2" +], +"float64_7x5_k4": [ +20, +"31ff8402211e9e06c2a6b5db5ce6cba47e6a4457f7b3a41484b6afd4f23dae50" +], +"float64_7x5_k5": [ +20, +"1f4b80def31be55aa17792ec9ae545fadd7222c57094bb5e96fee2d1492c4eb0" +], +"float64_edges_10000_-1.5_7.25": [ +4, +"c5202651a8f56c146e3c072b7e0feb1d6236dea9d40582aa1064952a779cac56" +], +"float64_edges_10000_-1000000.0_3000000.0": [ +4, +"f4eb933ad677ad48f0c71345da0b180a1a013c1937a5788b6f65b6ac4b5e19a5" +], +"float64_edges_10000_0.001_1.0": [ +4, +"75b717b308425bb8f46f0b2cb736f0c0e769dcd2db8fef5987619c4831747eff" +], +"float64_edges_10000_0.0_10000.0": [ +4, +"89da70e1b9f244a88cef7dd9e5fa907220bb9611290172e94fabdf7b32a20fdd" +], +"float64_edges_10000_0.1_0.7": [ +4, +"9808fd5dae9e9252ef091d4c2466d037aed153038d381044020adb4a237efae5" +], +"float64_edges_256_-1.5_7.25": [ +4, +"79ff03f63761e668254dc22a2ca63d080feafbda323b99ac92bea3a9d52c743a" +], +"float64_edges_256_-1000000.0_3000000.0": [ +4, +"04600882c3afcc15c360d33ade098207abe416e517cdccd317a575752d592226" +], +"float64_edges_256_0.001_1.0": [ +4, +"0c929b0ae67e13557737fcb1abf7d6637348c82ce339a60be51cfb6aa98ba941" +], +"float64_edges_256_0.0_256.0": [ +4, +"193cd77bb7cdd756eefd798bdd8d7de52940ff2953182d647fb9a90600bd7f60" +], +"float64_edges_256_0.1_0.7": [ +4, +"fcb6188c42c361e3d37acd4340e41d6e974993a461894e77a60bc617f7dbc596" +], +"float64_edges_3_-1.5_7.25": [ +4, +"0f8654d1e32fc66a2e27d62e1232cb120bf1e96651a087f4382f54b2bd70111f" +], +"float64_edges_3_-1000000.0_3000000.0": [ +4, +"01c2376ef6fa85bf6963b9a2905a6a5618fc1b764004458df484a0d6fe3ccec8" +], +"float64_edges_3_0.001_1.0": [ +4, +"c8fc8c68fb8a9a3654003e00809fda6d75416e83a5ccd1a4400588884b217af5" +], +"float64_edges_3_0.0_3.0": [ +4, +"60a94577eaee023c29c12e1857a3d7bb951929476e379b391a64b76a49686614" +], +"float64_edges_3_0.1_0.7": [ +4, +"e3c598560ef11284463e13d74c3473d766ee452ddfb02e11318edb93075f80f2" +], +"float64_edges_500_-1.5_7.25": [ +4, +"a75829d277ab06e87aeb823fdb6440a9c4e556142a03b7726da2edd039ac6962" +], +"float64_edges_500_-1000000.0_3000000.0": [ +4, +"be3eaddb12b68e55588df5778abd751998f27e78c29ba84eb41fd2ca325d6ad1" +], +"float64_edges_500_0.001_1.0": [ +4, +"f67a7d73d9767e4267c2a6c21c4de8c752f8c150ad6ad9a956d2db46b5fbd251" +], +"float64_edges_500_0.0_500.0": [ +4, +"1805b3e181dd708209d8fb2c6d4771bae2b75d78540528b2a9f47bb2e1c2ed08" +], +"float64_edges_500_0.1_0.7": [ +4, +"1d347df9e9300ee3c067bd601d53ce945904ac672fe2640ccec11d934daf92fe" +], +"float64_empty": [ +20, +"b383fb2d10fccb7f35f6424f4f4eb1be379ddcbc6672e222848d29b7cf847e31" +], +"float64_negative_zero": [ +20, +"a7a371266520df4fb98d079a8c9e4994f8b580b6a97e3a963a181a1a81312582" +], +"int16_120x97_k0": [ +24, +"f221dc54ee32aee7916727f9bd60712338f0cc90f91e9b02a19742ba44986d78" +], +"int16_120x97_k1": [ +24, +"e542374a38131ecd1b53ecbf7456ecd6c5ad35e1a33d1a68a45e239cd4061a50" +], +"int16_120x97_k2": [ +24, +"35ca177e0453847028ba54b8b44593a829db50117b1f802aa8c69864dff6a51c" +], +"int16_120x97_k3": [ +24, +"4426d2744726cf203733a01a4ef453d1b9a5291cdb929f5d1b60ab5b3110e34d" +], +"int16_120x97_k4": [ +24, +"b5833756b5c8653a61b5c5e29ddd0a3497f0e9efa8b3224f9d544ea09f3fdd92" +], +"int16_120x97_k5": [ +24, +"b7652afd983c70d70b9c030b3fbe0287810488cd7a3957ad3f7f606a7d7be165" +], +"int16_1_k0": [ +24, +"ccb2a9ef80694df477ba5c0967420a47a1bc09a1e8a1fa56a0960b35dbf0fe95" +], +"int16_1_k1": [ +24, +"69a719b141f7daa064fd6c8146bf36e35f31ce851689be17323d13b86ae0cd8b" +], +"int16_1_k2": [ +24, +"2662160870b8b572e0efb65bf9b56cb0dd530e2ee6e8d050d8a37b81f2554675" +], +"int16_1_k3": [ +24, +"8bc0e705a920cf499e9895e3c257b063f1e1683af908f3cdc8f164f637512512" +], +"int16_1_k4": [ +24, +"f021cfc75879597f38ed16212fac651354f5eec048aff112cb727957232e0303" +], +"int16_1_k5": [ +24, +"61b06a77a54d053915db6165a9ef42cf43eec53fd1ef830a2fa0116256e72492" +], +"int16_7x5_k0": [ +24, +"b638039622670e06ec01a65809b378ffbb57c2e122a7cae1ea88778062d6fa39" +], +"int16_7x5_k1": [ +24, +"f2ad9c3294673e60997b338bf0e1d3d821daecfa502a40680baee61c7bedc2a3" +], +"int16_7x5_k2": [ +24, +"1fdce9100aa0124d4eb3463305ce2d6cf47025d577f2ad6353bca3e39c2c18af" +], +"int16_7x5_k3": [ +24, +"c315a27a6ac2512e1372f11c6c24fe6d5802868f11c850e62f5c64e50c38630d" +], +"int16_7x5_k4": [ +24, +"7b278b8982a55a8cb144e58745893a18208f37b7e0726aa2f151025565ed2e03" +], +"int16_7x5_k5": [ +24, +"3e31d7cd8e4474ebafecc13f47b222d6432b28303993c72f3a55e3705f6a32ae" +], +"int16_empty": [ +24, +"3e5ad72c4fcce14783a1e601e333ffa1ab30f8d95891196cec08f3b579b09fbe" +], +"int32_120x97_k0": [ +24, +"b277261d22434eac045a30e8ca83cb57fe75e5642ca023711ce9da974a3fdbdb" +], +"int32_120x97_k1": [ +24, +"c7b51f34e0f3389bae43e1acd345df149c4be1a9c6cb77bac7f6096dfa2d87eb" +], +"int32_120x97_k2": [ +24, +"5f69dcd4034a8ec865d01dc0a4e4547e7d658126806d92e00947c3cc62c58967" +], +"int32_120x97_k3": [ +24, +"74a6c36fe154d4bfe62fbec117345d1c2e0e7b1fdf357026ea6cef4265fab1e6" +], +"int32_120x97_k4": [ +24, +"b9092107f0e22fcf5a616cc4ac6912959f395cf500554bea3553d02e461f6d13" +], +"int32_120x97_k5": [ +24, +"05a5bdbc7e288c030649eabb9c4f74279fa37916a212db55f7ac5468daa46f65" +], +"int32_1_k0": [ +24, +"cb48d635d7c8cd8e0a22cf6768e0051b23c1b0e37a94e796b16f20d38abbb9f1" +], +"int32_1_k1": [ +24, +"af3d2b0c795a8fa747ec6476014cd9165198f85a3f35566ae9744525d280e999" +], +"int32_1_k2": [ +24, +"af3d2b0c795a8fa747ec6476014cd9165198f85a3f35566ae9744525d280e999" +], +"int32_1_k3": [ +24, +"09a5a78a7c127d3c4ab563bbb84043bbbcf0a42ad2851071122dd831c9e84780" +], +"int32_1_k4": [ +24, +"dc6fd0016a900f8bf9c12d383d1f81b641ce207c25ffc108437dbf5e6148bbe2" +], +"int32_1_k5": [ +24, +"95fdcf4f569992f0187d3b12f890598c9000e86cded9d85d47637f2872ded653" +], +"int32_7x5_k0": [ +24, +"aebc3938c3358f26689fd9169a072aa1d4c10cb14eabc474aff1e5d63ec7d65e" +], +"int32_7x5_k1": [ +24, +"ea28856b118407f88afed603b7d7bb004dd646cfe934c069f9fef16dabb61a0f" +], +"int32_7x5_k2": [ +24, +"ab9d6458e3b27f81d648dd10722dafeaf03fdfdfb7d389b1916e7e773ca23535" +], +"int32_7x5_k3": [ +24, +"3ed99c5f9f6249ebbfe714b0e2eb37f7fee9c3e05884e05b5bb0f1de8cfde0de" +], +"int32_7x5_k4": [ +24, +"1d5b7384e18450f2ce1ac19c6fd12a405aaaf00f49e35e4363cd9aa8e228ce5d" +], +"int32_7x5_k5": [ +24, +"91838de046930c76643c13abaf8986866139ab04497b101a933ce954b4643d42" +], +"int32_empty": [ +24, +"8fe0e235038f02c05672d398ef93c9e718bbf7def03214ba3b106bd59b515093" +], +"int64_120x97_k0": [ +16, +"862b28e5ea43e969cd5c77c6a7e49190d0d18598554536ebda0ac19cc37dfcc1" +], +"int64_120x97_k1": [ +24, +"eb954b5300226446fa659ed4931d474f1f2087128d914be902b38c2e76b10330" +], +"int64_120x97_k2": [ +24, +"b258ee570d8f4cda9a1c998e69538b8174b73f32f793fb05a24a9fbb0686be36" +], +"int64_120x97_k3": [ +16, +"42744d21629479562689cfb5b882cc0ed8c085b28ce55baa919c9d97d1b39086" +], +"int64_120x97_k4": [ +24, +"28dd95e3d1a58deb106330df776d2d986ad51e906607916df2f936c937fbe02b" +], +"int64_120x97_k5": [ +16, +"2307bc9d98f09b714c1a193a5b8908c25c3990a3f48c1699d0c177370bbf2260" +], +"int64_1_k0": [ +16, +"c9fb3680ed12bb6ef3f2915302f7be9d2852103f2ffc3ae324b0a6a10846e789" +], +"int64_1_k1": [ +24, +"808b41af728329576e07669f4726cb460d078693d485ddc5497f57d3d49d1fa2" +], +"int64_1_k2": [ +24, +"6e0081e0169421c532b4c00429940eeb2d53b8dac5e7ced2555bfd933cb9dc87" +], +"int64_1_k3": [ +16, +"20d7b9f6d8a6d4d7b8b71ef471578a76416878b25b1a6b31011cc5f436493930" +], +"int64_1_k4": [ +24, +"f6e2aa579d444f2564305bc27263ef5d78605bfb7ded20f104369ce9c1208e92" +], +"int64_1_k5": [ +16, +"db52e7df98dbf38b507154dea0ca54013076bf50157590c461e75eb9b2dd40da" +], +"int64_7x5_k0": [ +16, +"acba92d682fad2715651e2146b227f39ba8ad001b6d76b4de236bf3d243aa1c4" +], +"int64_7x5_k1": [ +24, +"b49b6d01b292670a02d8cb722976f5d2c90abbf53a42b3f148f2d1945fc7098d" +], +"int64_7x5_k2": [ +24, +"6e29475610cb6771093dd374db2f590f9ad92738b36007ff9a79456b73618149" +], +"int64_7x5_k3": [ +16, +"25566c11c0069ab36c84a9e84b3c40aa5b5ecf417f085fde52a6eaa838540a2f" +], +"int64_7x5_k4": [ +24, +"7caa24e09b1431590e208a4ecfa296b6499707d5fd100849da935f12bfb9010e" +], +"int64_7x5_k5": [ +16, +"8375341aa56f8c873af514b11270248afa805304d8a507fd09d7c968e3350b77" +], +"int64_empty": [ +24, +"8a5e6d2334b0dad64605cd987b7ddd3a47f7ea932b18de9f82aaf8a37474b44d" +], +"int64_range_-1099511627776_1099511627776": [ +12, +"3b1010664cdb82d99e3bd35481756af0d9c397f4d54c8afaea665d6f6b753b21" +], +"int64_range_-1125899906842624_1125899906842624": [ +12, +"01e966f0da31ae127ebd6543ccf7d9682c99bd206db9c62bd0b822465ee30049" +], +"int64_range_-2251799813685247_2251799813685247": [ +12, +"41859a73da04b605c8afa5a3be090997344871f3a56a794f09e4d88b2c580279" +], +"int64_range_0_1125899906842622": [ +4, +"8b0b3d2912e6968aea8c368222e14ea682ebc160faf6475fb55a73aa989b00b3" +], +"int64_range_0_1125899906842623": [ +4, +"92364af7750c0500a8d1b33cdcef6f8dffa8ad4f83921796a87ead6df2b2180f" +], +"int8_120x97_k0": [ +16, +"3c838b90c8719b1c190aea0f7e42120e262cecbff8c0d16fd7a6afb0abfa0ee1" +], +"int8_120x97_k1": [ +16, +"ed0052f776942904f9babe476944f7a72380a75a635c4bd7387a2fb703c06275" +], +"int8_120x97_k2": [ +16, +"d932a728180593d60819be7822e6d679b4218a4072f9e24f738d84547d3bc415" +], +"int8_120x97_k3": [ +16, +"4922954bf8e694ede23ae0abf0d9244881398c444c887d1ec10f2a587c91c861" +], +"int8_120x97_k4": [ +16, +"8ffb13903488a75b016a833ee3d5b48ff3977a95413031582a69fb5d0e796ffd" +], +"int8_120x97_k5": [ +16, +"e65462238e27ce8f928dc3f06843de8ac5094d531ab2db26458f7903b935347b" +], +"int8_1_k0": [ +16, +"2e65f3cecca4ebce2b57805772a816066abeccd5c5552e5b85bfd96c62942284" +], +"int8_1_k1": [ +16, +"9e5d5790a77322df3088c0cc7e13c6663a0457768658667c53d022fcac0bd208" +], +"int8_1_k2": [ +16, +"0547a6c01c109d70b1df3492e96b097e7551042aa075dd29fcdcd49cc3f8f82b" +], +"int8_1_k3": [ +16, +"7cfbd3af919ff23ea25d6e642bd6e758378bb2fcc7497581e858c599969f0cc7" +], +"int8_1_k4": [ +16, +"5fc971d583a806594313ffdd5517650edaf5a4d00b959092169c5f3fc1704c88" +], +"int8_1_k5": [ +16, +"1ccbf4d221983b0a5c94303b052775b0378bc0d012295eaed0a0c4c599468fea" +], +"int8_7x5_k0": [ +16, +"355319984130f61264b11e24ae32013945e2d41a5339fe34528d00ad85b5105b" +], +"int8_7x5_k1": [ +16, +"1841c7c5f2ac912af11ac661d9a564aebf495b6f1ad2e11e289470bdc393be9e" +], +"int8_7x5_k2": [ +16, +"30b76c802284c23e4682fb9af464c3a380feb7480f3f217774c5c92eb2ce373f" +], +"int8_7x5_k3": [ +16, +"236ddb61fd1658502b6ab111a0866c0e64f3ebd671165277a70181b7ab3b7ea1" +], +"int8_7x5_k4": [ +16, +"e817e708a6dd262a5423ea24308816a767251451b394ae21a1844484e062a128" +], +"int8_7x5_k5": [ +16, +"0a8b2c446101eb629fa18d8f93642b6b6de4774825334b20a4d181363163974c" +], +"int8_empty": [ +16, +"57e48e23f1afe0eff97a150787c52e061e74bb7fdd0a606cd08dfd45abb69f98" +], +"uint16_120x97_k0": [ +24, +"92b2594c5ecf2497221bfd16215011817025913b66061ce0cf909ec450628310" +], +"uint16_120x97_k1": [ +24, +"42a79711b23425102851b26939f84ee178c06a0f14f3fe82667a4cf9f501c739" +], +"uint16_120x97_k2": [ +24, +"6d97deea383dc17b7f3882fad9a9dc981aedaff4deafa6ee605d1ce9f8e86517" +], +"uint16_120x97_k3": [ +24, +"c28e772da23b3f6108215a940d9d4b6061a84904274ce4369749bb7398bb1ca9" +], +"uint16_120x97_k4": [ +24, +"76c9b3f1589877f5182aaccc9b99a1a5b4f6304b43ff13c0a0ebff0a8f28a2bc" +], +"uint16_120x97_k5": [ +24, +"c9be40ac8c64de66f2e39d7775b6fe3b3e8a1f4d7a9f8ebb85916f1066c4e833" +], +"uint16_1_k0": [ +24, +"06ff35d320fb60e65b175b598c95ec759f82cb41ee8c01c31af3f6b9c885539c" +], +"uint16_1_k1": [ +24, +"3f59a40276e22e00cc75f7f0cceb780c85943353c40fd2e34b880b6aa8aa53b8" +], +"uint16_1_k2": [ +24, +"1a9fefdb17c7d0d41b7429340b66dd6918b55e853ef889b5dee2a1b99a899153" +], +"uint16_1_k3": [ +24, +"512fb12c699a67818af62452d24258ca044f5b509675ff33b579d24ea151a148" +], +"uint16_1_k4": [ +24, +"b801ff2b442817ef94beaa613650f5cbb6ede6724a8ea227bb595dc69c10877c" +], +"uint16_1_k5": [ +24, +"dcb9a67fbf146217ef9bc18259e35623d05a81ca46b2386d13d047755c72669e" +], +"uint16_7x5_k0": [ +24, +"ccfcaeae97a0fbaa1d3f7e44bcd0ba9eb7cba0817ce3c14c732d71f6e7c5ef79" +], +"uint16_7x5_k1": [ +24, +"6ed497fb97f5de4c30ee0d8f40474753b16120a3d6b5ab9436a49fb9b5f49740" +], +"uint16_7x5_k2": [ +24, +"09386c2a64e70d300afcd48fca1d56faa786dc5e82d6de8f9e11244819e8102f" +], +"uint16_7x5_k3": [ +24, +"58e75e84f5ce95601269db108d10823adfba1ec8d6b5623a0d0e7dc5f168f18c" +], +"uint16_7x5_k4": [ +24, +"7a24ad7c1b7e77f495a25cb8bc37722f0ecf3d9a645cef73dddc9501f5108c9b" +], +"uint16_7x5_k5": [ +24, +"9a20b0133061d90cad794a5361ff177af56a7cfb8670191a07d253e6c27c8b4e" +], +"uint16_empty": [ +24, +"c8a16641ac52d3494568a1a027447a47132e292ddafb723f66d641db9ede55b7" +], +"uint32_120x97_k0": [ +24, +"b6e2c115b474b6af70831bd43eee5ca7de2762c60457f418c6a70b9d748d9232" +], +"uint32_120x97_k1": [ +24, +"39ae698d57ff2bb31b0bf097a04576636616b9aa252a5b16904554e4ebc7556a" +], +"uint32_120x97_k2": [ +24, +"7b3246c8f7f878edd62dea6c40eec3832c6380f4653f372148f2fd5d867f13ae" +], +"uint32_120x97_k3": [ +24, +"ec09d5dd8da67778256b8bcd3fa7840d720b0603ee6be0d2816957bb5eb905f9" +], +"uint32_120x97_k4": [ +24, +"c8d8813ec59abdeceb5678d9936656e7f29697446e0b159abbd26e9461d56e21" +], +"uint32_120x97_k5": [ +24, +"a8cb0f2fc39ad8ca2bcd07ccc9616591d6e81e38142f0fa69e8ab2af00ad212e" +], +"uint32_1_k0": [ +24, +"97bcaefde12dee43c5e5b1658db45e0c2ac813c32b756bedd0f845988d28d62a" +], +"uint32_1_k1": [ +24, +"cc45ecef25aa269e99c26305493fb5fe10838501155d0655d50890643edcccc3" +], +"uint32_1_k2": [ +24, +"11b9c0bc10554062ea5c3a58edd7e90a79eb367b88030b8bf06acc7eaab21cc6" +], +"uint32_1_k3": [ +24, +"03daf1c33122c8ad58c3f084f77021f4b381fd372c3198cd8224d4386ae7ae2e" +], +"uint32_1_k4": [ +24, +"ddd7bcb7a8259bbc528100a9a329a19a7c9300d02f9187c344d4733d7d27ad9c" +], +"uint32_1_k5": [ +24, +"bcd22e81d4761572d797f8a8ef1baa9cb9bb7036ab1657a7b810f1194c2ddfc4" +], +"uint32_7x5_k0": [ +24, +"74dc2cb012841f3b975e7bd667370d44f733f074ea5f689fda83741297dce966" +], +"uint32_7x5_k1": [ +24, +"0dcab9178869385aa70c3c3b7c4df69622eb7baaadf7a271c0f42971b05431bf" +], +"uint32_7x5_k2": [ +24, +"d2fac436badb173bfebb68048dd6e82061f02874c417d695a4b03bfb5627cf02" +], +"uint32_7x5_k3": [ +24, +"7a695f6c6c70ab12526e1edd22e84c4bd8d64b0b168cabf9960b697d1ac18722" +], +"uint32_7x5_k4": [ +24, +"abb9c049192472141653b0dcd453e8f7031107a0633953a934a261834284ef0f" +], +"uint32_7x5_k5": [ +24, +"4d9ee83044e90a7cd29db65470f3c86a14cd2aa9c0ac44f9bb9d6cf965c9f302" +], +"uint32_empty": [ +24, +"6642ba5f70c6e1144541185344d34e4c341651ffe4881d99082b359459008473" +], +"uint64_120x97_k0": [ +16, +"c9f26438d6683c1f9c495cfa202ffcd6f4686e3a5f56a58445afa10d4f43e692" +], +"uint64_120x97_k1": [ +24, +"bf54715befa20b1c9d5271d1bce16ed2d8ac42c00e80320ba6b98625f1b13bd5" +], +"uint64_120x97_k2": [ +24, +"628e1705d3af69a5d91c8b3fc6f804757543fa6b3c8e3952c615def7e9cb761a" +], +"uint64_120x97_k3": [ +16, +"7f6f8c49140c67c36d7a9de277a91ace65142a0e5cae98e4d565cf0d5c9f3a1c" +], +"uint64_120x97_k4": [ +24, +"cc0159e305237e5951c64720c50a65527bd5fb4cf1600d21b21ff9745aa961ad" +], +"uint64_120x97_k5": [ +16, +"f31568f57351e036cdd2b5ea4d1df04f0fbafe323e13da91cd60b89ffe07c655" +], +"uint64_1_k0": [ +16, +"a84ba2260a39eca8e03b6aeb4b45cecd0d56ef9ef3213fcbd89e530bf7c97139" +], +"uint64_1_k1": [ +24, +"06d972c7d8e5e9f392730cc4111229dff7b171e400f1b2c9c205072977134049" +], +"uint64_1_k2": [ +24, +"8aeb76a3178d252980e3b6a3cc41df8d1b8a4a239350c179034d1e92905934af" +], +"uint64_1_k3": [ +16, +"18149d98f34d31170dabaa103cb255291967f75ecd581010e452a3ab00ca9af4" +], +"uint64_1_k4": [ +24, +"9b237656792a5435cf3df3a1b7b367da1635995daa624aefc0ef5ca07e3b0651" +], +"uint64_1_k5": [ +16, +"8e1b21b5aa64d985922656dc0e4af2fa8630347882194a2b2dd6dfb6f73684e9" +], +"uint64_7x5_k0": [ +16, +"8ff52226b8887a8468e36a3c018f7ef60e5cec6d37afed4fa3bc31da53f8d7ee" +], +"uint64_7x5_k1": [ +24, +"b325064ac57be0cdaf7d974d3939c11b851834086a8b1719122a5ce7ae1c8c87" +], +"uint64_7x5_k2": [ +24, +"db76e4c50cef09c67df56be6325f824ea51bf4ae604f6e16ffce23d101ab3e2b" +], +"uint64_7x5_k3": [ +16, +"19bdb358c8cd34d4b877ac087cd160e9280856bb6fa0311f35b7c00f21a48962" +], +"uint64_7x5_k4": [ +24, +"4fea0b3ec6bb0ff68c8cd0abdb8ebf4a7b80b1d916254d1e12b22d2ffd4fff6e" +], +"uint64_7x5_k5": [ +16, +"d89d13f68cb8d0e6ca15c2956ecba67d48f66fd12bf14db71ac5b4fa5955f989" +], +"uint64_empty": [ +24, +"81732af7ba9205fbbe04de11b06e06197f50665086b323954e58ccff7b24ba56" +], +"uint64_range_2251799813685243_2251799813685253": [ +12, +"9074008ace7684d3e1bff84f4d0dfa33ffc1cd5a83ff7e4334fb301119c90cc9" +], +"uint64_range_35184372088832_35192962023424": [ +12, +"416abb50e10cfb68edc16021515db52ce78e09808e54c24c41f36c2c9763972d" +], +"uint64_range_9223372036854775808_18446744073709551615": [ +8, +"015d9e124c632d30afa94dd0260a27a92b69cc6a6ec42f7cddfdea581d34abb1" +], +"uint8_120x97_k0": [ +16, +"6df70bde5227aa5b9fed64ab4101115235e468843dd991fbc83f012811e87c70" +], +"uint8_120x97_k1": [ +16, +"6c20ae13a5c819178abc3b369062fc5206be3a20bd7e04d205979e49120f201f" +], +"uint8_120x97_k2": [ +16, +"f2eacdcdf9e52dc38f2120bbee4c2c6bf6cde8510b7702d461cb56ca19de5025" +], +"uint8_120x97_k3": [ +16, +"34c713e1171b5a268c9761bd5fe2dfe89e9ad3e69e76088efcfabcfa35adc55f" +], +"uint8_120x97_k4": [ +16, +"2b6b420e3ffdbd765b3bb5edb8576f42dbc7476ab4b0f96c12d5b6e192f72c02" +], +"uint8_120x97_k5": [ +16, +"890efb8f4d0fe8febc49e92c9e34b547c1a823d4f303313215ebe96c5ca6eae7" +], +"uint8_1_k0": [ +16, +"81abd20589ba1b646696e2053ff44a3f0d6abda6cb89a617a126b26c3eeec811" +], +"uint8_1_k1": [ +16, +"0f8a665d524b078cef2246fb238c4b22cf9f152d7a239433757ef3293e665f4b" +], +"uint8_1_k2": [ +16, +"19b3815ca7192f84cd79bf305a38825d0d7c869932cc97b8c04fb7267f7925bc" +], +"uint8_1_k3": [ +16, +"a2f1fcb343dfb4c3e53c5e4926e9d9bdb90929afd1a638cf54f1d73dde92e37c" +], +"uint8_1_k4": [ +16, +"1c21821b8e9420582bf0e6b0fc190bd5d52fee2aff20e07c180c18c671f132df" +], +"uint8_1_k5": [ +16, +"8552749cee1923c43292e8281b37ecf6d521fefb7ae184f5a2946968cb9f1a09" +], +"uint8_7x5_k0": [ +16, +"038cab734594d94e3686b1eeac316c489b305fccf4c0ed382e2e1cbf3ed08d23" +], +"uint8_7x5_k1": [ +16, +"3935d4fe930820017cdd15278478d14607930a72bc84673c181677ce7368bdd7" +], +"uint8_7x5_k2": [ +16, +"b3134a0004e63e119532c96a4cd42d2105e074139d5ce5d5d81dbcfb56cba8a4" +], +"uint8_7x5_k3": [ +16, +"88be1057c1d692d72e3aabb82c188433820535f22e6d3ec7b82c72d34d8482ae" +], +"uint8_7x5_k4": [ +16, +"e03f1ca6673e4af5ad391e65ff29a303d41e9ad1f174362cdb4f9dd7355c7d0c" +], +"uint8_7x5_k5": [ +16, +"1913ac30bad57d4bb26594930f765971be34c5317ab473705f06e7950935f09c" +], +"uint8_empty": [ +16, +"42c56a07e14ba40775dcf5d43f3119769396577a88888661a49be263e244541d" +] +} +} diff --git a/tests/histogram_parity_cases.py b/tests/histogram_parity_cases.py new file mode 100644 index 0000000..7d9bc61 --- /dev/null +++ b/tests/histogram_parity_cases.py @@ -0,0 +1,221 @@ +"""Inputs of the v0.7.0 histogram parity table of tests/test_histogram_parity.py. + +``tests/data/histogram_v070_parity.json`` freezes, as one SHA-256 per plane (over all its +bin counts, both ranges and both block splits), every field v0.7.0 (commit ``c6a9f9d``) gave +for these planes: the ``PlaneHistogram`` (limits, counts, pixel counts, both tails), its +``representatives`` and ``max_representative_error`` as raw float64 bits, its integer bin +limits, ``is_exact`` and the ``RangeCheck``. The per-bin work of integer planes moved from +Python loops to NumPy int64 after v0.7.0; every one of these fields must stay bitwise equal. +The cases are the differential check of the preprocessing study +``experiments/histogram_numba_study/diffcheck.py`` (preprocessing PR #318), made smaller: +the ten pixel types, NaN and +/-inf, subnormals, constant, empty and dtype-extreme planes, +bin-edge float grids, several bin counts, the min-max and robust ranges, whole planes and +three blocks, plus 64-bit ranges on both sides of the int64 limits of ``integer_bins``. To +record the table again:: + + git worktree add /tmp/v070 c6a9f9d + PYTHONPATH=/tmp/v070/src /bin/python tests/histogram_parity_cases.py \\ + > tests/data/histogram_v070_parity.json + git worktree remove /tmp/v070 + +The script prints the path of the ``histogram`` module it used on standard error: check that +it is the worktree's. +""" + +from __future__ import annotations + +import hashlib +import itertools +import json +import struct +import sys +from collections.abc import Iterator +from typing import Any + +import numpy as np + +from morphobricks_normalization import histogram as H +from morphobricks_normalization.dtypes import is_integer +from morphobricks_normalization.ranges import HistogramSettings + +BASE_COMMIT = "c6a9f9d" +SEED = 12345 +DTYPES = ( + "uint8", + "int8", + "uint16", + "int16", + "uint32", + "int32", + "uint64", + "int64", + "float32", + "float64", +) +SHAPES = ((1,), (7, 5), (120, 97)) +BIN_COUNTS = (None, 1, 3, 256, 500, 10_000) +KINDS = 6 +# 64-bit planes beyond 2**51 (full range, near the minimum or the maximum) take the exact +# Fraction bound of every bin, unchanged since v0.7.0 and slow with many bins: those planes +# get up to 500 bins; the 64-bit planes below 2**51 keep every bin count. +BEYOND_FLOAT_KINDS = (0, 3, 5) +BEYOND_FLOAT_BIN_COUNTS = (1, 3, 256, 500) + + +def _bits(x: Any) -> str: + """Return ``x`` as text that tells every float bit and every array byte apart.""" + if isinstance(x, np.ndarray): + return f"{x.dtype.str}:{x.shape}:{hashlib.sha256(x.tobytes()).hexdigest()}" + if isinstance(x, float | np.floating): + return f"{type(x).__name__}:{struct.pack(' str: + """Return every field of a histogram (and its range check) as text.""" + h = histogram + parts = [ + h.dtype.str, + repr(h.bin_count), + _bits(h.binning_min), + _bits(h.binning_max), + _bits(h.counts), + repr(h.total_pixel_count), + repr(h.valid_pixel_count), + _bits(h.pixel_min), + _bits(h.pixel_max), + *(_bits(v) for t in (h.underflow, h.overflow) for v in (t.count, t.mean, t.std)), + _bits(h.representatives), + _bits(h.max_representative_error), + repr(h.is_exact), + ] + if is_integer(h.dtype) and not h.is_empty: + flat = list(itertools.chain.from_iterable(h.integer_bin_limits())) + values = np.array(flat) # int64 or uint64; object (as text) only beyond both + parts.append(_bits(values) if values.dtype != object else " ".join(map(str, flat))) + parts.append(repr(sorted(t.__name__ for t in set(map(type, flat))))) + if check is not None: + parts.extend(f"{k}={_bits(v)}" for k, v in sorted(vars(check).items())) + return "|".join(parts) + + +def _integer_plane(rng: np.random.Generator, d: np.dtype, shape: tuple, kind: int) -> np.ndarray: + info = np.iinfo(d) + lo, hi = [ + (info.min, info.max), + (0, 10), + (5, 5), + (int(info.min), int(info.min) + 3), + (max(info.min, -1000), min(info.max, 70000)), + (info.max - 2, info.max), + ][kind] + return rng.integers(lo, hi, size=shape, dtype=d, endpoint=True) + + +def _float_plane(rng: np.random.Generator, d: np.dtype, shape: tuple, kind: int) -> np.ndarray: + scale = (1, 1e-310, 0, 1e300, 1e5, 1)[kind] # normal, subnormal, constant, overflowing + with np.errstate(over="ignore"): # float32 * 1e300 is inf, a non-finite pixel on purpose + a = (rng.standard_normal(shape) * scale).astype(d) + # No plane mixes -0.0 and +0.0: which of the two NumPy's min and max return then depends + # on the platform (seen on Windows and macOS runners), so its bits are not a fixed + # reference. Adding +0.0 turns -0.0 into +0.0 and changes no other value. + a = a + d.type(0.0) + if kind == 5: + a.flat[::7] = np.nan + a.flat[1::11] = np.inf + a.flat[2::13] = -np.inf + if kind == 4: + a.flat[0] = np.finfo(d).max + a.flat[-1] = np.finfo(d).min + if kind == 2 and a.size > 3: + a.flat[:3] = np.nan + return a + + +def planes() -> Iterator[tuple[str, np.ndarray, tuple]]: + """Yield ``(case ID, plane, bin counts)``.""" + rng = np.random.default_rng(SEED) + for name in DTYPES: + d = np.dtype(name) + make = _integer_plane if d.kind in "iu" else _float_plane + for shape in SHAPES: + for kind in range(KINDS): + label = f"{name}_{'x'.join(map(str, shape))}_k{kind}" + bins = BIN_COUNTS + if d.itemsize == 8 and d.kind in "iu" and kind in BEYOND_FLOAT_KINDS: + bins = BEYOND_FLOAT_BIN_COUNTS + yield label, make(rng, d, shape, kind), bins + yield f"{name}_empty", np.zeros(0, d), BIN_COUNTS + yield "float32_all_nan", np.full((4, 4), np.nan, np.float32), BIN_COUNTS + negative_zero = np.full((5, 3), -0.0) + negative_zero.flat[::4] = np.nan + yield "float64_negative_zero", negative_zero, BIN_COUNTS + # Values on or next to bin edges: integer-valued floats over [0, n] and k * step grids. + for name in ("float32", "float64"): + for n in (3, 256, 500, 10_000): + for lo, hi in ((0.0, float(n)), (-1.5, 7.25), (1e-3, 1.0), (-1e6, 3e6), (0.1, 0.7)): + grid = lo + (hi - lo) * np.arange(n + 1) / n + edges = np.concatenate( + [grid, np.nextafter(grid, -np.inf), np.nextafter(grid, np.inf)] + ) + a = np.clip(edges, lo, hi).astype(name) + a = np.concatenate([a, np.array([np.nan, np.inf, -np.inf], name)]) + yield f"{name}_edges_{n}_{lo}_{hi}", a, (n,) + # 64-bit ranges around the int64 limits of integer_bins: wider than 2**24 values with + # int64 bin starts; below 2**51 but too wide for int64 starts with 65,536 bins (not with + # 500); bin count times width just below and at 2**62; at 2**51 and beyond. + for name, low, high, bin_counts in ( + ("int64", -(2**40), 2**40, (None, 3, 500)), + ("uint64", 2**45, 2**45 + 2**33, (None, 3, 500)), + ("int64", -(2**50), 2**50, (None, 3, 500)), + ("int64", -(2**51) + 1, 2**51 - 1, (None, 3, 500)), + ("int64", 0, 2**50 - 2, (4096,)), + ("int64", 0, 2**50 - 1, (4096,)), + ("uint64", 2**51 - 5, 2**51 + 5, (None, 3, 500)), + ("uint64", 2**63, 2**64 - 1, (3, 500)), + ): + a = rng.integers(low, high, size=(31, 29), dtype=name, endpoint=True) + a.flat[:2] = (low, high) + yield f"{name}_range_{low}_{high}", a, bin_counts + + +def variants(plane: np.ndarray, bin_counts: tuple) -> Iterator[tuple[int | None, bool, int]]: + """Yield ``(bin count, robust, blocks)`` for every allowed bin count of a plane.""" + for bins in bin_counts: + try: + H.validate_bin_count( + plane.dtype, H.default_bin_count(plane.dtype) if bins is None else bins + ) + except ValueError: + continue + for robust in (False, True): + for blocks in (1, 3): + yield bins, robust, blocks + + +def outputs(plane: np.ndarray, bins: int | None, robust: bool, blocks: int) -> str: + """Return both histograms of a variant and its range check as text.""" + parts = np.array_split(plane.ravel(), blocks) + settings = HistogramSettings(histogram_range="robust") if robust else None + histogram = H.compute_block_histogram(lambda: iter(parts), plane.dtype, bins, settings=settings) + checked, check = H.histogram_with_range_check( + lambda: iter(parts), plane.dtype, bins, settings=settings + ) + variant = f"bins={bins} robust={robust} blocks={blocks}" + return f"{variant}#{fingerprint(histogram, None)}#{fingerprint(checked, check)}" + + +def table() -> dict[str, list]: + """Return ``[variants, SHA-256 of all their outputs]`` for every plane.""" + found = {} + for label, plane, bin_counts in planes(): + texts = [outputs(plane, *variant) for variant in variants(plane, bin_counts)] + found[label] = [len(texts), hashlib.sha256("\n".join(texts).encode()).hexdigest()] + return found + + +if __name__ == "__main__": + print(H.__file__, file=sys.stderr) + record = {"base_commit": BASE_COMMIT, "numpy": np.__version__, "planes": table()} + json.dump(record, sys.stdout, indent=0, sort_keys=True) + sys.stdout.write("\n") diff --git a/tests/test_histogram_parity.py b/tests/test_histogram_parity.py new file mode 100644 index 0000000..e8a2e16 --- /dev/null +++ b/tests/test_histogram_parity.py @@ -0,0 +1,209 @@ +"""The per-bin work of integer planes in NumPy int64: bitwise the outputs of v0.7.0. + +``tests/data/histogram_v070_parity.json`` holds what v0.7.0 (``c6a9f9d``) gave for the +planes of ``tests/histogram_parity_cases.py`` (the preprocessing study's differential check, +made smaller). Every plane must give the same bits now, through the int64 paths of +``integer_bins`` and, with those paths switched off, through the Python integers kept for +64-bit ranges. The conditions choosing between the two, and each int64 formula against the +Python one, are tested directly below. +""" + +import bisect +import hashlib +import json +from pathlib import Path + +import numpy as np +import pytest + +from histogram_parity_cases import BASE_COMMIT, outputs, planes, variants +from morphobricks_normalization import compute_plane_histogram, integer_bins +from morphobricks_normalization import histogram as histogram_module +from morphobricks_normalization.histogram import PlaneHistogram +from morphobricks_normalization.integer_bins import ( + EXACT_FLOAT_TOTAL, + INT64_STARTS_LIMIT, + counts_from_per_value, + integer_bin_index, + integer_bin_offsets, + integer_bin_starts, + integer_bin_starts_int64, + search_starts, +) + +V070 = json.loads((Path(__file__).parent / "data" / "histogram_v070_parity.json").read_text()) +PLANES = list(planes()) + + +def _digest(plane, bin_counts): + texts = [outputs(plane, *variant) for variant in variants(plane, bin_counts)] + return [len(texts), hashlib.sha256("\n".join(texts).encode()).hexdigest()] + + +def test_the_table_is_v070s_and_covers_every_plane(): + assert V070["base_commit"] == BASE_COMMIT == "c6a9f9d" + assert set(V070["planes"]) == {label for label, _, _ in PLANES} + # The ten pixel types, and both sides of the int64 limits of integer_bins. + assert {plane.dtype.name for _, plane, _ in PLANES} == { + "uint8", + "int8", + "uint16", + "int16", + "uint32", + "int32", + "uint64", + "int64", + "float32", + "float64", + } + assert sum(count for count, _ in V070["planes"].values()) > 4000 + + +@pytest.mark.parametrize( + ("label", "plane", "bin_counts"), PLANES, ids=[label for label, _, _ in PLANES] +) +def test_every_output_is_bitwise_v070s(label, plane, bin_counts): + assert _digest(plane, bin_counts) == V070["planes"][label] + + +# Integer planes, with the bin counts for which the Python path is quick. +INTEGER_PLANES = [case for case in PLANES if case[1].dtype.kind in "iu" and case[1].size <= 35] +INTEGER_PLANES += [case for case in PLANES if "_range_" in case[0]] + + +@pytest.mark.parametrize( + ("label", "plane", "bin_counts"), INTEGER_PLANES, ids=[label for label, _, _ in INTEGER_PLANES] +) +def test_the_python_path_kept_for_wide_ranges_gives_the_same_bits( + monkeypatch, label, plane, bin_counts +): + quick = [bins for bins in bin_counts if bins is not None and bins <= 4096] + fast = [outputs(plane, *variant) for variant in variants(plane, quick)] + # No int64 starts at all: every limit, sum and representative takes the Python integers. + monkeypatch.setattr(integer_bins, "INT64_STARTS_LIMIT", 0) + assert integer_bin_starts_int64(1, 1) is None + assert [outputs(plane, *variant) for variant in variants(plane, quick)] == fast + assert fast + + +@pytest.mark.parametrize("perturbation", ["bin_index", "representative"]) +def test_the_table_catches_a_one_step_change(monkeypatch, perturbation): + """Negative control: one bin or one float64 step off is a different digest.""" + label, plane, bin_counts = next(p for p in PLANES if p[0] == "uint16_120x97_k4") + if perturbation == "bin_index": + original = histogram_module.integer_bin_index + monkeypatch.setattr( + histogram_module, "integer_bin_index", lambda o, w, n: min(original(o, w, n) + 1, n) + ) + else: + original = histogram_module.integer_representatives + monkeypatch.setattr( + histogram_module, + "integer_representatives", + lambda h: np.nextafter(original(h), np.inf), + ) + assert _digest(plane, bin_counts) != V070["planes"][label] + + +# --- each int64 formula against the Python integers, and the conditions between them --- + + +def test_int64_bin_starts_are_the_python_integers(): + widths = (*range(1, 70), 255, 256, 257, 4900, 65_535, 65_536, 65_537, 2**24 + 1, 2**32) + pairs = [(w, n) for w in widths for n in (1, 2, 3, 7, 64, 65, 256, 500, 10_000, 65_536)] + pairs += [(2**40 + 1, 500), (2**46 - 1, 65_536), (2**51, 2_047), (2**50 - 1, 4096)] + for width, n in pairs: + starts = integer_bin_starts_int64(width, n) + assert starts.dtype == np.int64 + assert starts.tolist() == integer_bin_starts(width, n), (width, n) + assert search_starts(width, n).tolist() == integer_bin_starts(width, n)[:-1] + + +def test_bin_starts_take_python_integers_from_2_62(): + # Below the limit: int64; at it: None, so that i * width can never overflow int64. + assert integer_bin_starts_int64(2**50 - 1, 4096) is not None + assert integer_bin_starts_int64(2**50, 4096) is None + assert 4096 * 2**50 == INT64_STARTS_LIMIT + assert integer_bin_starts_int64(2**64, 3) is None + starts = search_starts(2**64, 3) # a full uint64 plane + assert starts.dtype == np.uint64 + assert starts.tolist() == integer_bin_starts(2**64, 3)[:-1] + + +def test_bin_offsets_keep_python_integers_for_numpy_limits(): + # Histograms built by a caller with NumPy integer limits keep v0.7.0's NumPy results. + first, last = integer_bin_offsets(np.int64(10), np.int64(20), 4) + assert isinstance(first, list) and isinstance(last, list) + first, last = integer_bin_offsets(10, 20, 4) + assert first.tolist() == [0, 3, 6, 9] and last.tolist() == [2, 5, 8, 10] + counts = np.array([3, 3, 3, 2], np.int64) + numpy_limits = PlaneHistogram( + np.dtype("uint16"), 4, np.int64(10), np.int64(20), counts, 11, 11, 10, 20 + ) + python_limits = PlaneHistogram(np.dtype("uint16"), 4, 10, 20, counts, 11, 11, 10, 20) + assert numpy_limits.integer_bin_limits() == python_limits.integer_bin_limits() + assert type(numpy_limits.integer_bin_limits()[0][0]) is np.int64 + assert type(python_limits.integer_bin_limits()[0][0]) is int + assert type(numpy_limits.max_representative_error) is np.float64 + assert type(python_limits.max_representative_error) is float + assert numpy_limits.max_representative_error == python_limits.max_representative_error == 1.0 + np.testing.assert_array_equal(numpy_limits.representatives, python_limits.representatives) + + +@pytest.mark.parametrize("width", [1, 2, 3, 7, 40]) +@pytest.mark.parametrize("n", [1, 2, 3, 5, 40, 41]) +def test_bin_index_is_the_search_of_the_starts(width, n): + starts = integer_bin_starts(width, n) + for offset in range(-3, width + 4): + assert integer_bin_index(offset, width, n) == bisect.bisect_right(starts, offset, hi=n) - 1 + + +def test_bin_index_of_wide_ranges_is_exact(): + rng = np.random.default_rng(7) + for width, n in [(2**64, 65_536), (2**64, 3), (2**51 + 3, 500), (10**6 + 1, 65_536)]: + starts = integer_bin_starts(width, n) + offsets = [0, width - 1, width, *starts[1:4], *(s - 1 for s in starts[1:4])] + offsets += [int(x) for x in rng.integers(0, width - 1, 50, dtype=np.uint64, endpoint=True)] + for offset in offsets: + expected = bisect.bisect_right(starts, offset, hi=n) - 1 + assert integer_bin_index(offset, width, n) == expected + + +def _v070_counts(per_value, n): + """The v0.7.0 sums: float64 weights per bin, rounded back to integers.""" + starts = integer_bin_starts(per_value.size, n) + bin_of_value = np.searchsorted(np.array(starts[:-1]), np.arange(per_value.size), side="right") + return np.rint(np.bincount(bin_of_value - 1, weights=per_value, minlength=n)).astype(np.int64) + + +@pytest.mark.parametrize(("width", "n"), [(1, 1), (5, 3), (3, 5), (1000, 7), (70_001, 65_536)]) +def test_int64_sums_of_per_value_counts_are_v070s(width, n): + per_value = np.random.default_rng(width).integers(0, 10**6, width).astype(np.int64) + per_value[::3] = 0 + counts = counts_from_per_value(per_value, n) + assert counts.dtype == np.int64 + np.testing.assert_array_equal(counts, _v070_counts(per_value, n)) + assert int(counts.sum()) == int(per_value.sum()) + + +def test_sums_from_2_52_pixels_stay_v070s_float_sums(): + # Never for one plane in memory; there v0.7.0's float64 sums are kept, so nothing changes. + below = np.array([2**51, 2**51 - 2, 1], np.int64) + assert float(below.sum()) < EXACT_FLOAT_TOTAL + np.testing.assert_array_equal(counts_from_per_value(below, 1), [2**52 - 1]) + beyond = np.array([2**53, 1], np.int64) # float64 cannot hold 2**53 + 1 + np.testing.assert_array_equal(counts_from_per_value(beyond, 1), _v070_counts(beyond, 1)) + assert counts_from_per_value(beyond, 1).tolist() == [2**53] + + +def test_representatives_below_2_51_are_python_midpoints(): + plane = np.array([-(2**51) + 1, 2**51 - 1, 0, 12345], np.int64) + for n in (1, 3, 500, 65_536): + hist = compute_plane_histogram(plane, n) + first, _ = hist._integer_bin_limits + assert isinstance(first, np.ndarray) == (n < 65_536) # 65,536 * 2**52 >= 2**62 + limits = hist.integer_bin_limits() + midpoints = [(a + b) / 2 for a, b in limits] + assert hist.representatives.tobytes() == np.array(midpoints).tobytes() + widest = max(b - a + 1 for a, b in limits) + assert hist.max_representative_error == (widest - 1) / 2 From a70b0df52b580d56431b9ae0d7386f3f4ffccdb8 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 21:19:57 +0000 Subject: [PATCH 3/4] Benchmark notes: 1.46x serial, 1.29-1.50x with workers, same bytes The preprocessing study's data and scripts (PR #318), preprocessing v0.6.1, 5 interleaved repeats of v0.7.0 and this change at workers 1/2/4/auto on a shared 4-CPU machine; median (min-max) wall times in the CHANGELOG. All 40 runs wrote identical bytes in every output file. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01G3qp9AxjpGPw9xfWAUJNqc --- CHANGELOG.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9216722..90d915d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,21 @@ dependency (NumPy only, no Numba), no API, file format or message change. `tests/data/histogram_v070_parity.json`, recorded on v0.7.0 (`c6a9f9d`) by `tests/histogram_parity_cases.py`; and the kept Python paths with the int64 ones switched off. `tools/dump_outputs.py` (default and `--corpus`) gives the digests of v0.7.0. +- **Measured** (the study's data and scripts: `tools/benchmark_run_workers.py` at scale 1, 14 images, + 76 planes, 303 MiB, memory limit 64 MiB; preprocessing v0.6.1 `37c583e`; Linux, 4 shared CPUs, + load average 2.6–3.4, Python 3.13.18, NumPy 2.5.5; 5 repeats, variants interleaved in rotating + order, a fresh process per run). Wall time of `run_experiment`, median (min–max): + + | workers | v0.7.0 | this change | speed-up | + |---|---|---|---| + | 1 (serial) | 7.23 s (6.25–7.70) | 4.95 s (4.66–5.31) | 1.46× | + | 2 | 6.24 s (5.78–6.63) | 4.16 s (4.10–5.04) | 1.50× | + | 4 | 6.18 s (5.66–6.52) | 4.78 s (4.16–5.17) | 1.29× | + | auto (4) | 6.40 s (5.54–6.56) | 4.51 s (4.11–4.75) | 1.42× | + + Median CPU time fell from 6.6–7.3 s to 4.9–5.5 s. All 40 runs wrote the same bytes in all 6 + files (fixed clock). The normalization suite runs in 20 s instead of 51 s before the new + parity tests (45 s with them). ## v0.7.0 (2026-11-15) From 53730491b87dc6e8fa7bbfa64d0b38b271113faf Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 21:36:01 +0000 Subject: [PATCH 4/4] Keep the Python bin starts for a NumPy bin count A caller-built PlaneHistogram may carry a NumPy integer bin count. Then bin_count * width in integer_bin_starts_int64 is a NumPy product that wraps silently: a uint64 histogram over 0 .. 2**50 with np.int64(65_536) bins got negative bin limits and representatives, where v0.7.0 raised OverflowError; narrower ranges returned Python ints where v0.7.0 gave np.int64 limits and an np.float64 bound. integer_bin_offsets now takes the int64 path only when the bin count is a Python int as well, so these histograms keep v0.7.0's values, types and refusals. Computed histograms are unaffected (validate_bin_count returns int). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01G3qp9AxjpGPw9xfWAUJNqc --- CHANGELOG.md | 4 ++-- .../integer_bins.py | 10 +++++---- tests/test_histogram_parity.py | 21 +++++++++++++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90d915d..c171ba7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,8 +19,8 @@ dependency (NumPy only, no Numba), no API, file format or message change. conditions: bin starts when `bin_count * width >= 2**62` (64-bit planes with a wide range); representatives and the bound from `2**51` on (unchanged `Fraction` bound, #28); bin sums when a plane's per-value counts total `2**52` or more (v0.7.0's float64 sums are kept there); - and histograms a caller built with NumPy integer limits, so their results keep v0.7.0's NumPy - types. Float bin positions, tail moments and 32/64-bit pixel binning are unchanged. + and histograms a caller built with NumPy integer limits or a NumPy bin count, so their + results keep v0.7.0's NumPy types (and int64 products never wrap). Float bin positions, tail moments and 32/64-bit pixel binning are unchanged. - **Identity**: `tests/test_histogram_parity.py` compares every `PlaneHistogram` field, the representatives and bound as raw bits, the integer bin limits and their types, `is_exact` and the `RangeCheck` of 4,236 cases (the ten pixel types, NaN and +/-inf, subnormal, constant, diff --git a/src/morphobricks_normalization/integer_bins.py b/src/morphobricks_normalization/integer_bins.py index e430730..fe8e5f3 100644 --- a/src/morphobricks_normalization/integer_bins.py +++ b/src/morphobricks_normalization/integer_bins.py @@ -51,12 +51,14 @@ def integer_bin_offsets( ) -> tuple[np.ndarray, np.ndarray] | tuple[list[int], list[int]]: """Return every bin's first and last value, as offsets from ``binning_min``. - int64 arrays when both limits are Python integers (as in every histogram computed or - read by this library) and the starts fit int64; otherwise the exact Python integers of - v0.7.0, so that results built from them keep their values and types. + int64 arrays when both limits and the bin count are Python integers (as in every + histogram computed or read by this library) and the starts fit int64; otherwise the + exact Python integers of v0.7.0, so that results built from them keep their values and + types. A NumPy bin count would make ``bin_count * width`` a NumPy product that can wrap. """ width = binning_max + 1 - binning_min - starts = integer_bin_starts_int64(width, bin_count) if type(width) is int else None + python_ints = type(width) is int and type(bin_count) is int + starts = integer_bin_starts_int64(width, bin_count) if python_ints else None if starts is not None: return starts[:-1], starts[1:] - 1 starts = integer_bin_starts(width, bin_count) diff --git a/tests/test_histogram_parity.py b/tests/test_histogram_parity.py index e8a2e16..c15af2a 100644 --- a/tests/test_histogram_parity.py +++ b/tests/test_histogram_parity.py @@ -207,3 +207,24 @@ def test_representatives_below_2_51_are_python_midpoints(): assert hist.representatives.tobytes() == np.array(midpoints).tobytes() widest = max(b - a + 1 for a, b in limits) assert hist.max_representative_error == (widest - 1) / 2 + + +def test_bin_offsets_keep_python_integers_for_a_numpy_bin_count(): + # A caller may build a histogram with a NumPy bin count. v0.7.0 then gave NumPy limits, + # or refused with an OverflowError where i * width does not fit int64; int64 starts would + # wrap there silently (negative limits for a uint64 plane), so the Python path is kept. + counts = np.array([3, 3, 3, 2], np.int64) + numpy_count = PlaneHistogram(np.dtype("uint16"), np.int64(4), 10, 20, counts, 11, 11, 10, 20) + python_count = PlaneHistogram(np.dtype("uint16"), 4, 10, 20, counts, 11, 11, 10, 20) + assert numpy_count.integer_bin_limits() == python_count.integer_bin_limits() + assert type(numpy_count.integer_bin_limits()[0][1]) is np.int64 + assert type(numpy_count.max_representative_error) is np.float64 + assert numpy_count.representatives.tobytes() == python_count.representatives.tobytes() + counts = np.zeros(65_536, np.int64) + counts[[0, -1]] = 1 + wide = PlaneHistogram(np.dtype("uint64"), np.int64(65_536), 0, 2**50, counts, 2, 2, 0, 2**50) + try: + limits = wide.integer_bin_limits() + except OverflowError: # v0.7.0's refusal: Python int too large to convert to C long + return + assert limits[-1] == (2**50 - 2**34 + 1, 2**50)