Skip to content

Commit

Permalink
Float16_t with up to 32 bits is allowed (not just 16). (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpivarski authored Aug 16, 2021
1 parent 6ab8abd commit a48601d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/uproot/interpretation/identify.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def _float16_or_double32(branch, context, leaf, is_float16, dims):
right = title.index("]")

except (ValueError, AttributeError):
low, high, num_bits = 0, 0, 0
low, high, num_bits = 0, 0, "no brackets" # distinct from "None"

else:
source = title[left : right + 1]
Expand Down Expand Up @@ -280,19 +280,19 @@ def _float16_or_double32(branch, context, leaf, is_float16, dims):
)

if not is_float16:
if num_bits == 0:
if num_bits == "no brackets":
return uproot.interpretation.numerical.AsDtype(
numpy.dtype((">f4", dims)), numpy.dtype(("f8", dims))
)
elif num_bits is None:
elif num_bits is None or not 2 <= num_bits <= 32:
return uproot.interpretation.numerical.AsDouble32(low, high, 32, dims)
else:
return uproot.interpretation.numerical.AsDouble32(low, high, num_bits, dims)

else:
if num_bits == 0:
if num_bits == "no brackets":
return uproot.interpretation.numerical.AsFloat16(low, high, 12, dims)
elif num_bits is None:
elif num_bits is None or not 2 <= num_bits <= 32:
return uproot.interpretation.numerical.AsFloat16(low, high, 32, dims)
else:
return uproot.interpretation.numerical.AsFloat16(low, high, num_bits, dims)
Expand Down
4 changes: 2 additions & 2 deletions src/uproot/interpretation/numerical.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,8 @@ def __init__(self, low, high, num_bits, to_dims=()):
self._num_bits = num_bits
self._to_dims = to_dims

if not uproot._util.isint(num_bits) or not 2 <= num_bits <= 16:
raise TypeError("num_bits must be an integer between 2 and 16 (inclusive)")
if not uproot._util.isint(num_bits) or not 2 <= num_bits <= 32:
raise TypeError("num_bits must be an integer between 2 and 32 (inclusive)")
if high <= low and not self.is_truncated:
raise ValueError(
"high ({0}) must be strictly greater than low ({1})".format(high, low)
Expand Down

0 comments on commit a48601d

Please sign in to comment.