Skip to content

BlackrockRawIO: align the .nev spike dtype to avoid a segfault on numpy 2.0 and 2.1 - #1962

Merged
h-mayorquin merged 1 commit into
NeuralEnsemble:masterfrom
h-mayorquin:fix_blackrock_bug
Nov 9, 2026
Merged

h-mayorquin merged 1 commit into
NeuralEnsemble:masterfrom
h-mayorquin:fix_blackrock_bug

Conversation

@h-mayorquin

Copy link
Copy Markdown
Contributor

I merged #1955 (lazy waveform reading) recently but there is a problem there that was not detected by the tests. The reason for this is that the CI matrix of #1955 had numpy 1.26 and 2.3.3, and numpy 2.0.2 only joined it with #1922 (drop NumPy < 2.0) the day before the merge. Right now the IO tests on master crash with a segfault in the numpy 2.0.2 job, and open PRs like #1961 (event extraction on ABF) fail the same way. This PR solves this.

The problem is that in #1955 I built the spike table with a packed dtype and its timestamp field ends up unaligned in memory. On numpy 2.0 and 2.1 comparing that field against a negative Python int segfaults. This happens in _match_nsx_and_nev_segment_ids, and only when another Blackrock file was parsed earlier in the same process. I can't reproduce it from numpy 2.2 on and I think it is a numpy bug that got fixed there. The fix is simple: building the dtype with align=True makes numpy pad each field to the alignment of its type, at the cost of one byte per spike in most files.

I measured the parse memory again on the Trellis file from #1955 and the savings remain as the memory held after parse_header only goes from 0.38 GB to 0.40 GB (measured with tracemalloc).

@h-mayorquin
h-mayorquin merged commit e899f3e into NeuralEnsemble:master Nov 9, 2026
5 checks passed
@h-mayorquin

Copy link
Copy Markdown
Contributor Author

Merging this to avoid it getting on the way of other tests

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