Skip to content

Commit d0173b4

Browse files
author
Benjamin Moody
committed
calc_checksum: handle non-smooth partial records.
calc_checksum is called in order to calculate checksums of the signal data (d_signal or e_d_signal) in a record. In particular, if rdrecord is used to read only part of a record, it will call calc_checksum to determine the checksums of that part of the record. However, at that time, self.n_sig is still equal to the total number of signals in the input record (not the number of signals stored in d_signal or e_d_signal, which might be different if a subset of channels are selected). Thus, if expanded is true and self.n_sig > len(self.e_d_signal), this would crash. For simplicity, and consistency with the expanded=False case, ignore n_sig and simply calculate the checksums of e_d_signal.
1 parent 1b9c90c commit d0173b4

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

wfdb/io/_signal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ def calc_checksum(self, expanded=False):
750750
751751
"""
752752
if expanded:
753-
cs = [int(np.sum(self.e_d_signal[ch]) % 65536) for ch in range(self.n_sig)]
753+
cs = [int(np.sum(s) % 65536) for s in self.e_d_signal]
754754
else:
755755
cs = np.sum(self.d_signal, 0) % 65536
756756
cs = [int(c) for c in cs]

0 commit comments

Comments
 (0)