Skip to content

Commit

Permalink
Merge pull request #17276 from jakevdp:finfo-tests
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 559878846
  • Loading branch information
jax authors committed Aug 24, 2023
2 parents a71c0e6 + 71275b5 commit d452eea
Showing 1 changed file with 0 additions and 60 deletions.
60 changes: 0 additions & 60 deletions tests/dtypes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,66 +353,6 @@ def testDefaultDtypes(self):
self.assertEqual(dtypes.float_, np.float32 if precision == '32' else np.float64)
self.assertEqual(dtypes.complex_, np.complex64 if precision == '32' else np.complex128)

@parameterized.named_parameters(
{"testcase_name": f"_{dtype}", "dtype": dtype}
for dtype in float_dtypes)
def testFInfo(self, dtype):
if _fp8_enabled and dtype in fp8_dtypes:
self.skipTest("fp8 types do not yet have `compare` in HLO")

# Check that finfo attributes are self-consistent & reflect observed behavior.
dtype = np.dtype(dtype)

if dtype == np.float64 and not config.x64_enabled:
self.skipTest("x64 not enabled")
info = dtypes.finfo(dtype)

_ = str(info) # doesn't crash

def make_val(val):
return jnp.array(val, dtype=dtype)

def assertRepresentable(val):
self.assertEqual(make_val(val).item(), val)

@jtu.ignore_warning(category=RuntimeWarning, message="overflow")
def assertInfinite(val):
self.assertEqual(make_val(val), make_val(jnp.inf))

def assertZero(val):
self.assertEqual(make_val(val), make_val(0))

self.assertEqual(jnp.array(0, dtype).dtype, dtype)
self.assertIs(info.dtype, dtype)

self.assertEqual(info.bits, jnp.array(0, dtype).itemsize * 8)
self.assertEqual(info.nmant + info.nexp + 1, info.bits)

assertRepresentable(info.tiny)
assertRepresentable(info.max)
assertRepresentable(2.0 ** (info.maxexp - 1))

if dtype != np.float64: # avoid Python float overflows
assertInfinite(info.max * 2)
assertInfinite(2. ** info.maxexp)

# smallest_normal & smallest_subnormal added in numpy 1.22
assertRepresentable(info.smallest_subnormal)
assertZero(info.smallest_subnormal * 0.5)
self.assertEqual(info.tiny, info.smallest_normal)

# Identities according to the documentation:
self.assertAllClose(info.resolution, make_val(10 ** -info.precision))
self.assertEqual(info.epsneg, make_val(2 ** info.negep))
self.assertEqual(info.eps, make_val(2 ** info.machep))
self.assertEqual(info.iexp, info.nexp)

# Check that minexp is consistent with nmant
self.assertEqual(
make_val(2 ** info.minexp).view(UINT_DTYPES[info.bits]),
2 ** info.nmant,
)


class TestPromotionTables(jtu.JaxTestCase):

Expand Down

0 comments on commit d452eea

Please sign in to comment.