Skip to content

Preserve small differences in large integer local-peak inputs - #732

Merged
tompollard merged 3 commits into
MIT-LCP:mainfrom
Kulraj69:fix-local-peaks-integer-precision
Nov 25, 2026
Merged

tompollard merged 3 commits into
MIT-LCP:mainfrom
Kulraj69:fix-local-peaks-integer-precision

Conversation

@Kulraj69

Copy link
Copy Markdown
Contributor

Problem

processing.find_local_peaks sends integer signals through scipy.ndimage.maximum_filter1d, which rounds large 64-bit integers internally. Small differences on a large positive or negative offset can disappear, producing false or missing peaks.

For example, an int64 signal formed by adding 2**60 to [0, 1, 0] should retain its single peak at index 1. The same issue affects uint64 values near 2**63 and negative int64 offsets.

Change

Use the existing exact sample-by-sample scanning path when an integer signal contains values outside the exact integer range of a double. Ordinary integer and floating-point inputs retain their existing path. The constant-signal early return is unchanged.

This deliberately trades speed for exact comparisons on those large-integer inputs; no performance improvement is claimed for them. It does not alter the vectorized common-input path introduced in #655 or the separate find_peaks overflow fix in #664.

Add 18 regression cases spanning positive and negative int64 offsets, uint64, two radii and three signal shapes, including a plateau. Expected peaks come from explicit bounded windows over the small, exact shape values. Four small-value dtype controls and input-immutability checks are included, plus a changelog fragment.

Validation

Python 3.12.16, isolated against upstream 98df2c9fba00943004ceac42677744f85a98e702:

  • Unpatched regression file: 18 failed, 4 passed.
  • Exact files downloaded from the proposed branch, regression file plus tests/test_processing.py and tests/test_hr.py, excluding network tests: 238 passed.
  • Pinned Ruff 0.17.3 check and format passed for both changed Python files.
  • Strict Sphinx 9.0.4 HTML build (-W --keep-going -E) passed.

Other private fixes were not included. Full-repository tests, performance benchmarks, other Python/dependency versions and remote CI were not run for this change. Prepared and tested with AI assistance; no independent human review is claimed.

Refactor peak detection to handle flat mountain scenarios and improve dtype handling.
Add tests for local peak detection with large integers and small values.
The change adds a new entry to the changelog detailing improvements in handling local peaks for large integer inputs.

@tompollard tompollard left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed the large-integer fallback and its regression tests. It preserves exact peak comparisons while leaving the common fast path unchanged. Looks good to me, thanks again!

@tompollard
tompollard merged commit 92764c5 into MIT-LCP:main Nov 25, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants