Skip to content

Fix file size calculation in write_binary()#4607

Open
grahamfindlay wants to merge 2 commits into
SpikeInterface:mainfrom
grahamfindlay:bugfix/write_binary_with_dtype_conversion
Open

Fix file size calculation in write_binary()#4607
grahamfindlay wants to merge 2 commits into
SpikeInterface:mainfrom
grahamfindlay:bugfix/write_binary_with_dtype_conversion

Conversation

@grahamfindlay
Copy link
Copy Markdown
Contributor

write_binary() was determining the file size and seek offests based on the source dtype's itemsize, but the data is cast to the target dtype before writing. This means that if the target dtype has a different itemsize than the source dtype, a corrupted file of the wrong size and layout was produced.

The solution was just just use the target dtype's itemsize for all file size and seek offset calculations.

`write_binary()` was determining the file size and seek offests based on
the source dtype's itemsize, but the data is cast to the target dtype before
writing. This means that if the target dtype has a different itemsize than
the source dtype, a corrupted file of the wrong size and layout was produced.

The solution was just just use the target dtype's itemsize for all
file size and seek offset calculations.
@alejoe91 alejoe91 added the core Changes to core module label Jun 5, 2026
@alejoe91
Copy link
Copy Markdown
Member

alejoe91 commented Jun 5, 2026

@grahamfindlay I extended the signature of the get_sample_size_in_bytes to optionally accept the dtype. I thimk it's better for readibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Changes to core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants