Skip to content

Commit

Permalink
cast filebytes to int64
Browse files Browse the repository at this point in the history
NPY_PROMOTION_STATE=weak_and_warn reports that several variables changed from int64 to uint8. Casting to int64 addresses the issue.
  • Loading branch information
tompollard committed Oct 9, 2024
1 parent 56b7d5c commit 97f1107
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions wfdb/io/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2134,6 +2134,7 @@ def proc_ann_bytes(filebytes, sampto):
"""
# Base annotation fields
sample, label_store, subtype, chan, num, aux_note = [], [], [], [], [], []
filebytes = filebytes.astype(np.int64)

# Indexing Variables

Expand Down Expand Up @@ -2216,16 +2217,17 @@ def proc_core_fields(filebytes, bpi):
"""
sample_diff = 0
filebytes = filebytes.astype(np.int64)

# The current byte pair will contain either the actual d_sample + annotation store value,
# or 0 + SKIP.
while filebytes[bpi, 1] >> 2 == 59:
# 4 bytes storing dt
skip_diff = (
(int(filebytes[bpi + 1, 0]) << 16)
+ (int(filebytes[bpi + 1, 1]) << 24)
+ (int(filebytes[bpi + 2, 0]) << 0)
+ (int(filebytes[bpi + 2, 1]) << 8)
(filebytes[bpi + 1, 0] << 16)
+ (filebytes[bpi + 1, 1] << 24)
+ (filebytes[bpi + 2, 0] << 0)
+ (filebytes[bpi + 2, 1] << 8)
)

# Data type is long integer (stored in two's complement). Range -2**31 to 2**31 - 1
Expand All @@ -2237,7 +2239,9 @@ def proc_core_fields(filebytes, bpi):

# Not a skip - it is the actual sample number + annotation type store value
label_store = filebytes[bpi, 1] >> 2
sample_diff += int(filebytes[bpi, 0] + 256 * (filebytes[bpi, 1] & 3))
sample_diff += np.int64(filebytes[bpi, 0]) + 256 * np.int64(
filebytes[bpi, 1] & 3
)
bpi = bpi + 1

return sample_diff, label_store, bpi
Expand Down

0 comments on commit 97f1107

Please sign in to comment.