Beispiel #1
0
    def test_random_function_noshape_noargs(self):
        # Test if random_function helper works without args or shape
        rng_R = random_state_type()

        # No shape, no args -> TypeError
        with pytest.raises(TypeError):
            poisson(rng_R, size=None, ndim=2)
Beispiel #2
0
    def test_poisson(self):
        # Test that raw_random.poisson generates the same results as numpy.
        # Check over two calls to see if the random state is correctly updated.
        rng_R = random_state_type()
        # Use non-default parameters, and larger dimensions because of
        # the integer nature of the result
        post_r, out = poisson(rng_R, lam=5, size=(11, 8))

        f = compile.function(
            [
                compile.In(
                    rng_R,
                    value=np.random.RandomState(utt.fetch_seed()),
                    update=post_r,
                    mutable=True,
                )
            ],
            [out],
            accept_inplace=True,
        )

        numpy_rng = np.random.RandomState(utt.fetch_seed())
        val0 = f()
        val1 = f()
        numpy_val0 = numpy_rng.poisson(5, size=(11, 8))
        numpy_val1 = numpy_rng.poisson(5, size=(11, 8))
        assert np.allclose(val0, numpy_val0)
        assert np.allclose(val1, numpy_val1)