Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preallocate the read buffer for numerical data #46

Merged
merged 2 commits into from
Oct 7, 2019
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [1.16.2] - 2019-?
### Changed
- Speed up loading of numerical data ([#46](https://github.com/xdf-modules/xdf-python/pull/46) by [Tristan Stenner](https://github.com/tstenner))

## [1.16.1] - 2019-09-28
### Fixed
- Remove Python 2 compatibility from `setup.py` ([#45](https://github.com/xdf-modules/xdf-Python/pull/45) by [Clemens Brunner](https://github.com/cbrnr)).
Expand Down
4 changes: 3 additions & 1 deletion pyxdf/pyxdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@ def _read_chunk3(f, s):
else:
# read a sample comprised of numeric values
values = np.zeros((nsamples, s.nchns), dtype=s.dtype)
# read buffer
raw = bytearray(s.nchns * values.dtype.itemsize)
# for each sample...
for k in range(values.shape[0]):
# read or deduce time stamp
Expand All @@ -413,7 +415,7 @@ def _read_chunk3(f, s):
stamps[k] = s.last_timestamp + s.tdiff
s.last_timestamp = stamps[k]
# read the values
raw = f.read(s.nchns * values.dtype.itemsize)
f.readinto(raw)
# no fromfile(), see
# https://github.com/numpy/numpy/issues/13319
values[k, :] = np.frombuffer(raw,
Expand Down