Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## [UNRELEASED] - YYYY-MM-DD
### Changed
- Precompute the little-endian sample dtype once per stream instead of per sample in `_read_chunk3`, speeding up loading of large numeric streams (~8% faster on a 553k-sample, 99-channel EEG recording) with byte-identical output ([#170](https://github.com/xdf-modules/pyxdf/pull/170) by [Stefan Appelhoff](https://github.com/sappelhoff))

### Fixed
- Fix `playback_lsl.py` for cases where no metadata is available in the to-be-streamed XDF file ([#160] by [Stefan Appelhoff](https://github.com/sappelhoff))

Expand Down
2 changes: 1 addition & 1 deletion src/pyxdf/pyxdf.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cdef class StreamData:
cdef readonly int nchns, samplebytes
cdef readonly fmt
cdef public double effective_srate
cdef public time_stamps, time_series, clock_times, clock_values, dtype, fmts
cdef public time_stamps, time_series, clock_times, clock_values, dtype, dtype_le, fmts

cdef bytearray _read_varlen_int_buf

Expand Down
7 changes: 4 additions & 3 deletions src/pyxdf/pyxdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ def __init__(self, xml):
# pre-calc some parsing parameters for efficiency
if self.fmt != "string":
self.dtype = np.dtype(fmts[self.fmt])
# little-endian view of the dtype, precomputed once because it is used
# once per sample in _read_chunk3 (XDF sample data is little-endian)
self.dtype_le = self.dtype.newbyteorder("<")
# number of bytes to read from stream to handle one sample
self.samplebytes = self.nchns * self.dtype.itemsize

Expand Down Expand Up @@ -478,9 +481,7 @@ def _read_chunk3(f, s):
# read the values
f.readinto(raw)
# no fromfile(), see https://github.com/numpy/numpy/issues/13319
values[k, :] = np.frombuffer(
raw, dtype=s.dtype.newbyteorder("<"), count=s.nchns
)
values[k, :] = np.frombuffer(raw, dtype=s.dtype_le, count=s.nchns)
return nsamples, stamps, values


Expand Down
Loading