Repository: numpy/numpy
File: numpy/random/tests/test_generator_mt19937.py (Python)

Code before:
        def gen_random(state, out):
            out[...] = state.normal(size=10000)

        self.check_function(gen_random, sz=(10000,))

    def test_exp(self):
        def gen_random(state, out):
            out[...] = state.exponential(scale=np.ones((100, 1000)))

        self.check_function(gen_random, sz=(100, 1000))

    def test_multinomial(self):
        def gen_random(state, out):
            out[...] = state.multinomial(10, [1 / 6.] * 6, size=10000)

        self.check_function(gen_random, sz=(10000, 6))


# See Issue #4263
class TestSingleEltArrayInput:
    def _create_arrays(self):
        argOne = np.array([2])
        argTwo = np.array([3])
        argThree = np.array([4])
        tgtShape = (1,)
        return argOne, argTwo, argThree, tgtShape

    def test_one_arg_funcs(self):
        argOne, _, _, tgtShape = self._create_arrays()
        funcs = (random.exponential, random.standard_gamma,
                 random.chisquare, random.standard_t,
                 random.pareto, random.weibull,
                 random.power, random.rayleigh,
                 random.poisson, random.zipf,
                 random.geometric, random.logseries)

        probfuncs = (random.geometric, random.logseries)

        for func in funcs:
            if func in probfuncs:  # p < 1.0
                out = func(np.array([0.5]))

            else:
                out = func(argOne)

            assert_equal(out.shape, tgtShape)

    def test_two_arg_funcs(self):
        argOne, argTwo, _, tgtShape = self._create_arrays()
        funcs = (random.uniform, random.normal,
                 random.beta, random.gamma,

Review comment (suggestion):
IMO in this case binding the variable names just makes this harder to read, since the one-liner fits nicely on one line.

```suggestion
        return np.array([2]), np.array([3]), np.array([4]), (1,)
```

Code after:
    def test_normal(self):
        def gen_random(state, out):
            out[...] = state.normal(size=10000)

        self.check_function(gen_random, sz=(10000,))

    def test_exp(self):
        def gen_random(state, out):
            out[...] = state.exponential(scale=np.ones((100, 1000)))

        self.check_function(gen_random, sz=(100, 1000))

    def test_multinomial(self):
        def gen_random(state, out):
            out[...] = state.multinomial(10, [1 / 6.] * 6, size=10000)

        self.check_function(gen_random, sz=(10000, 6))


# See Issue #4263
class TestSingleEltArrayInput:
    def _create_arrays(self):
        return np.array([2]), np.array([3]), np.array([4]), (1,)

    def test_one_arg_funcs(self):
        argOne, _, _, tgtShape = self._create_arrays()
        funcs = (random.exponential, random.standard_gamma,
                 random.chisquare, random.standard_t,
                 random.pareto, random.weibull,
                 random.power, random.rayleigh,
                 random.poisson, random.zipf,
                 random.geometric, random.logseries)

        probfuncs = (random.geometric, random.logseries)

        for func in funcs:
            if func in probfuncs:  # p < 1.0
                out = func(np.array([0.5]))

            else:
                out = func(argOne)

            assert_equal(out.shape, tgtShape)

    def test_two_arg_funcs(self):
        argOne, argTwo, _, tgtShape = self._create_arrays()
        funcs = (random.uniform, random.normal,
                 random.beta, random.gamma,
                 random.f, random.noncentral_chisquare,
                 random.vonmises, random.laplace,
                 random.gumbel, random.logistic,