Skip to content

Commit

Permalink
Merge pull request #59 from jakevdp:finfo-max-test
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 523479429
  • Loading branch information
The ml_dtypes Authors committed Apr 11, 2023
2 parents afc05bd + c555b40 commit e5f6502
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion ml_dtypes/tests/finfo_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
ml_dtypes.float8_e5m2fnuz,
]

DTYPES_WITH_NO_INFINITY = [
ml_dtypes.float8_e4m3b11,
ml_dtypes.float8_e4m3fn,
ml_dtypes.float8_e4m3fnuz,
ml_dtypes.float8_e5m2fnuz,
]

UINT_TYPES = {
8: np.uint8,
16: np.uint16,
Expand Down Expand Up @@ -58,7 +65,11 @@ def assert_representable(val):
self.assertEqual(make_val(val).item(), val)

def assert_infinite(val):
self.assertNanEqual(make_val(val), make_val(np.inf))
val = make_val(val)
if dtype in DTYPES_WITH_NO_INFINITY:
self.assertTrue(np.isnan(val), f"expected NaN, got {val}")
else:
self.assertTrue(np.isposinf(val), f"expected inf, got {val}")

def assert_zero(val):
self.assertEqual(make_val(val), make_val(0))
Expand All @@ -70,7 +81,13 @@ def assert_zero(val):
self.assertEqual(info.nmant + info.nexp + 1, info.bits)

assert_representable(info.tiny)

assert_representable(info.max)
assert_infinite(np.spacing(info.max))

assert_representable(info.min)
assert_infinite(-np.spacing(info.min))

assert_representable(2.0 ** (info.maxexp - 1))
assert_infinite(2.0**info.maxexp)

Expand Down

0 comments on commit e5f6502

Please sign in to comment.