def check_d_samples(dfn, n, rtol=1e-2, atol=1e-2):
    counts = defaultdict(lambda: 0)
    #print 'sample', dfn.rvs(size=n)
    inc = n / 1.0
    for s in dfn.rvs(size=n):
        counts[s] += inc
    for ii, p in sorted(counts.items()):
        t = np.allclose(dfn.pmf(ii), p, rtol=rtol, atol=atol)
        if not t:
            print 'Error in sampling frequencies', ii
            print 'value\tpmf\tfreq'
            for jj in sorted(counts):
                print ('%.2f\t%.3f\t%.4f' % (
                    jj, dfn.pmf(jj), counts[jj]))
            npt.assert_(t,
                "n = %i; pmf = %f; p = %f" % (
                    n, dfn.pmf(ii), p))
dataset/ETHPy150Open hyperopt/hyperopt/hyperopt/tests/test_rdists.py/check_d_samples/swapped operands of `/`