dfm/emcee

Tests for longdouble behavior have started failing

dfm opened this issue · 0 comments

dfm commented

In #436 we saw that the following test has started to fail:

def test_longdouble_actually_needed(cls):
if issubclass(cls, TempHDFBackend) and not does_hdf5_support_longdouble():
pytest.xfail("HDF5 does not support long double on this platform")
mjd = np.longdouble(58000.0)
sigma = 100 * np.finfo(np.longdouble).eps * mjd
def log_prob(x):
assert x.dtype == np.longdouble
return -0.5 * np.sum(((x - mjd) / sigma) ** 2)
ndim, nwalkers = 1, 20
steps = 1000
p0 = sigma * np.random.randn(nwalkers, ndim).astype(np.longdouble) + mjd
assert not all(p0 == mjd)
with cls(dtype=np.longdouble) as backend:
sampler = emcee.EnsembleSampler(
nwalkers, ndim, log_prob, backend=backend
)
sampler.run_mcmc(p0, steps)
samples = sampler.get_chain().reshape((-1,))
assert samples.dtype == np.longdouble
assert not np.all(samples == mjd)
assert np.abs(np.mean(samples) - mjd) < 10 * sigma / np.sqrt(
len(samples)
)
assert 0.1 * sigma < np.std(samples) < 10 * sigma

@hendriko373 noted that the test is not seeded (which we probably should fix), but this never failed previously so I worry that something else is problematic.

@aarchiba: Since you developed this feature, do you have any thoughts about this? Thanks!