Repository navigation
Write signal views and arrays through private model state - #879
Conversation
tompollard
left a comment
There was a problem hiding this comment.
The behaviour is right, and it's ready after #878, with two structural points. The offline suite (2,182 passed, 48 skipped) and Ruff pass locally. CI hasn't run on this PR, which targets refactor/model-write-record rather than main. Please retarget it to main after #878 merges and let the full matrix run before merging.
What I checked
- Writes don't change inputs. I ran 1,464
SignalRead.writecalls across the sample records (both kinds and layouts, converted views, both alignments, folder, archive andformats="32"targets) and 155 mixedwrite_record/SignalRead.writecalls. No array, mask or retained-record field changed, and the error counts (232 and 18) match the code before this stack. - Performance is unchanged or better. On the same
100skewbenchmark (15 runs, write only),SignalRead.writetakes 8.00 → 8.08 ms for digital and 16.90 → 17.05 ms for physical.write_signalswith physical values and calculated calibration goes from 35.15 to 32.71 ms. Peak memory is identical. - The parity cases for explicit and calculated calibration with
NaN, masked gaps in formats 16 and 212, and skewed views cover the paths this PR changes.
1. The validation preamble is duplicated
The new write_signals repeats about 100 lines of argument checks from _legacy_write_signals: layout, formats, names, units, fs, dates, comments, calibration and the missing-value rules. The new SignalRead.write likewise repeats the path, format and file-name handling from _legacy_write. Those checks aren't what this refactor is changing, so a shared _validate_write_signals_arguments(...) (and a shared path/format helper for SignalRead) used by both versions would keep the comparison meaningful for the encoding route. It would also mean a fix to the checks before the cleanup can't land in only one copy.
2. Avoid the after_features callback
_WriteModel.write(after_features=...) exists so write_signals can check physical values once calibration has been calculated. A callback into the middle of the write is hard to follow, and it gives only one of three writers that check. An alternative is for _WriteModel.write to validate the digital values itself, for range and the reserved marker, after features are derived and before _write_files, for every writer. That replaces the callback. It also covers the write_record bug I noted on #878, which leaves a .hea behind and raises IndexError for out-of-range samples. That part changes write_record's behaviour, so it could be a follow-up PR. If so, a # TODO(#866) on after_features would mark it as temporary.
|
Thanks. I pushed 44561ac to address the duplicated preambles. The legacy and model I kept I’ll retarget #879 to |
44561ac to
4bf6a8f
Compare
Summary
Continue #866 after #878.
SignalRead.writenow sends its selected values and current metadata to private_WriteModelstate instead of callingRecord.wrsamp.write_signalsbuilds that model directly from validated arrays and channel fields instead of constructing a temporaryRecord. These changes keep the existing missing-sample, calibration, format, skew, and destination rules.This PR is stacked on #878 and should be merged after it. The previous two functions remain temporarily as
_legacy_writeand_legacy_write_signalsfor the differential tests; they can be removed with the other legacy paths at the end of #866. No public API or file-output change is intended, so there is no changelog entry.Checks
SignalReadviews in both layouts and kinds.SignalRead.writeno longer callsRecord.wrsampandwrite_signalsno longer constructs aRecord. The existing preparation test now checks memory sharing at the model boundary.The private model still inherits the legacy encoder mixins and projects fields into parallel lists. The final #866 cleanup will remove those dependencies after reference bytes from the pinned baseline are in place.