Skip to content

ENH: Finish hypergeometric 0 #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions numpy/random/generator.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ cdef class RandomGenerator:

def __reduce__(self):
from ._pickle import __generator_ctor
return (__generator_ctor,
(self.brng.state['brng'],),
self.brng.state)
return __generator_ctor, (self.brng.state['brng'],), self.brng.state

def random_sample(self, size=None, dtype=np.float64, out=None):
"""
Expand Down Expand Up @@ -3323,7 +3321,7 @@ cdef class RandomGenerator:
nbad : int or array_like of ints
Number of ways to make a bad selection. Must be nonnegative.
nsample : int or array_like of ints
Number of items sampled. Must be at least 1 and at most
Number of items sampled. Must be nonnegative and less than
``ngood + nbad``.
size : int or tuple of ints, optional
Output shape. If the given shape is, e.g., ``(m, n, k)``, then
Expand Down Expand Up @@ -3415,14 +3413,14 @@ cdef class RandomGenerator:
return disc(&random_hypergeometric, self._brng, size, self.lock, 0, 3,
lngood, 'ngood', CONS_NON_NEGATIVE,
lnbad, 'nbad', CONS_NON_NEGATIVE,
lnsample, 'nsample', CONS_GTE_1)
lnsample, 'nsample', CONS_NON_NEGATIVE)

if np.any(np.less(np.add(ongood, onbad), onsample)):
raise ValueError("ngood + nbad < nsample")
return discrete_broadcast_iii(&random_hypergeometric, self._brng, size, self.lock,
ongood, 'ngood', CONS_NON_NEGATIVE,
onbad, 'nbad', CONS_NON_NEGATIVE,
onsample, 'nsample', CONS_GTE_1)
onsample, 'nsample', CONS_NON_NEGATIVE)

def logseries(self, p, size=None):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ from libc.stdint cimport uint64_t
import numpy as np
cimport numpy as np

from ..distributions cimport brng_t
from .distributions cimport brng_t

cdef extern from "../src/legacy/distributions-boxmuller.h":

Expand Down
6 changes: 2 additions & 4 deletions numpy/random/mtrand.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ from .bounded_integers cimport *
from .bounded_integers import _randint_types
from .common cimport *
from .distributions cimport *
from .legacy.legacy_distributions cimport *
from .legacy_distributions cimport *
from .mt19937 import MT19937 as _MT19937

np.import_array()
Expand Down Expand Up @@ -113,9 +113,7 @@ cdef class RandomState:
def __reduce__(self):
state = self.get_state(legacy=False)
from ._pickle import __randomstate_ctor
return (__randomstate_ctor,
(state['brng'],),
state)
return __randomstate_ctor, (state['brng'],), state

cdef _reset_gauss(self):
self._aug_state.has_gauss = 0
Expand Down
4 changes: 2 additions & 2 deletions numpy/random/tests/test_generator_mt19937.py
Original file line number Diff line number Diff line change
Expand Up @@ -1837,7 +1837,7 @@ def test_hypergeometric(self):
nsample = [2]
bad_ngood = [-1]
bad_nbad = [-2]
bad_nsample_one = [0]
bad_nsample_one = [-1]
bad_nsample_two = [4]
hypergeom = random.hypergeometric
desired = np.array([1, 1, 1])
Expand Down Expand Up @@ -1868,7 +1868,7 @@ def test_hypergeometric(self):

assert_raises(ValueError, hypergeom, -1, 10, 20)
assert_raises(ValueError, hypergeom, 10, -1, 20)
assert_raises(ValueError, hypergeom, 10, 10, 0)
assert_raises(ValueError, hypergeom, 10, 10, -1)
assert_raises(ValueError, hypergeom, 10, 10, 25)

def test_logseries(self):
Expand Down