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

Float16_t with up to 32 bits is allowed (not just 16). #411

Merged
merged 1 commit into from
Aug 16, 2021
Merged
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
10 changes: 5 additions & 5 deletions src/uproot/interpretation/identify.py
Original file line number Diff line number Diff line change
@@ -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]
@@ -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)
4 changes: 2 additions & 2 deletions src/uproot/interpretation/numerical.py
Original file line number Diff line number Diff line change
@@ -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)