Skip to content

Sum whole signals at once in _checksums - #676

Merged
tompollard merged 1 commit into
mainfrom
checksums-axis-sum
Nov 24, 2026
Merged

tompollard merged 1 commit into
mainfrom
checksums-axis-sum

Conversation

@tompollard

Copy link
Copy Markdown
Member

A small follow-up to #653. _checksums sums each column in a Python loop, which has two side effects for calc_checksum:

axis=0 (this PR) per column
10M x 12, int16 74 ms 40 ms
10M x 2, int32 40 ms 6 ms
1M x 64, int16 25 ms 138 ms
1-D d_signal TypeError [0, 1, 2, ...]

The loop is faster for records with few channels, but several times slower for recordings with many channels. The absolute cost is small either way. The more important difference is that a 1-D array returns one value per sample instead of raising an error.

_checksums goes back to a single reduction along axis 0, which is what calc_checksum and wfdb_to_mat used before #653. For integer samples the result is the same either way.

read_edf is the only caller with float samples, where the order of the additions can change the truncated result (ten values of 0.1 sum to 1.0 by column, and to 0.9999999999999999 along axis 0). It keeps summing each channel separately, so its checksums don't change.

Testing:

  • test_checksums_rejects_1d is restored.
  • New test_float_checksum reads a small two-channel EDF file and checks the checksums. It fails if read_edf uses _checksums.
  • uv run pytest -m "not network" -W error passes (566), as do ruff format --check and ruff check.

No changelog entry, since #653 is not released and behaviour is the same as in the last release.

@tompollard 🟥 red 🐳 whale · quince

Summing a C-ordered signal column by column is several times slower for
records with many channels, and a 1-D array returned one value per
sample instead of raising an error. Go back to a single reduction along
axis 0.

read_edf is the only caller with float samples, where the order of the
additions can change the result, so it keeps summing each channel
separately.

@tompollard tompollard left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Reviewed commit 02de0d7. I found no issues. The integer checksum reduction preserves the prior per-channel result, while read_edf retains separate channel summation for float signals. The 6 focused checksum tests and 39 converter tests pass. CI has no failures so far, with some matrix jobs still running.

@tompollard
tompollard merged commit 3547521 into main Nov 24, 2026
18 checks passed
@tompollard
tompollard deleted the checksums-axis-sum branch November 24, 2026 01:33
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.

1 participant