def mcint(a, b, f, sample_count=100000): rng = m.PCG32() i = m.UInt32(0) result = m.Float(0) l = m.Loop(i, rng, result) while l.cond(i < sample_count): result += f(ek.lerp(a, b, rng.next_float32())) i += 1 return result * (b - a) / sample_count
def test04_chi2(variant_packet_rgb, warp, attempt): # Chi^2 test to make sure that the warping schemes are producing # the right distribution. Test for all supported variants of # N-dimensional warps (N = 0..3) from mitsuba.core import ScalarBoundingBox2f from mitsuba.python.chi2 import ChiSquareTest, PlanarDomain cls = getattr(mitsuba.core, warp) ndim = int(warp[-1]) + 2 np.random.seed(all_warps.index(warp) * 10 + attempt) shape = np.random.randint(2, 8, ndim) param_res = [sorted(np.random.rand(s)) for s in shape[:-2]] if attempt == 9: values = np.ones(shape) else: values = np.random.rand(*shape) * 10 instance = cls(values, param_res) for j in range(10 if ndim > 2 else 1): param = [ ek.lerp(param_res[i][0], param_res[i][-1], np.random.rand()) for i in range(0, ndim - 2) ] chi2 = ChiSquareTest( domain=PlanarDomain(ScalarBoundingBox2f(0, 1)), sample_func=lambda p: instance.sample(p, param=param)[0], pdf_func=lambda p: instance.eval(p, param=param), sample_dim=2, res=31, sample_count=100000) assert chi2.run(test_count=11 * len(all_warps))