Skip to content

Commit

Permalink
Fix test failure in LaxBackedNumpyTest.testFrexp4 on Windows.
Browse files Browse the repository at this point in the history
NumPy is inconsistent between platforms on what it returns for the exponent of an infinite input. On Linux/Mac it returns 0, and on Windows it returns -1. Normalize the test reference result to use 0 in this case.
  • Loading branch information
hawkinsp committed Jun 14, 2023
1 parent 068abc4 commit 638cdf5
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions tests/lax_numpy_test.py
Expand Up @@ -2311,12 +2311,17 @@ def testFrexp(self, shape, dtype, rng_factory):
and not config.x64_enabled):
self.skipTest("Only run float64 testcase when float64 is enabled.")
rng = rng_factory(self.rng())
np_fun = lambda x: np.frexp(x)
jnp_fun = lambda x: jnp.frexp(x)
args_maker = lambda: [rng(shape, dtype)]
self._CheckAgainstNumpy(np_fun, jnp_fun, args_maker,
def np_frexp(x):
mantissa, exponent = np.frexp(x)
# NumPy is inconsistent between Windows and Linux/Mac on what the
# value of exponent is if the input is infinite. Normalize to the Linux
# behavior.
exponent = np.where(np.isinf(mantissa), np.zeros_like(exponent), exponent)
return mantissa, exponent
self._CheckAgainstNumpy(np_frexp, jnp.frexp, args_maker,
check_dtypes=np.issubdtype(dtype, np.inexact))
self._CompileAndCheck(jnp_fun, args_maker)
self._CompileAndCheck(jnp.frexp, args_maker)

@jtu.sample_product(
[dict(shape=shape, axis1=axis1, axis2=axis2)
Expand Down

0 comments on commit 638cdf5

Please sign in to comment.