summaryrefslogtreecommitdiff
path: root/numpy/random/tests/test_generator_mt19937.py
Commit message (Collapse)AuthorAgeFilesLines
* TST: Add a random integers bounds checking test that previously failedSebastian Berg2023-02-131-0/+2
|
* TST: Skip tests that are not currently supported in wasmHood Chatham2022-11-111-1/+3
|
* TST,MAINT: Replace most `setup` with `setup_method` (also teardown)Sebastian Berg2022-10-271-6/+6
| | | | | | | | In some cases, the replacement is clearly not what is intended, in those (where setup was called explicitly), I mostly renamed `setup` to `_setup`. The `test_ccompile_opt` is a bit confusing, so left it right now (this will probably fail)
* BUG: Fix boundschecking for `random.logseries`Sebastian Berg2022-10-181-4/+16
| | | | | | | | Logseries previously did not enforce bounds to be strictly exclusive for the upper bound, where it leads to incorrect behavior. The NOT_NAN check is removed, since it was never used: The current bounded version always excludes NaNs.
* TST: Fix spellingKevin Sheppard2022-07-191-1/+1
|
* BUG/ENH: ALlow bit generators to supply their own ctorKevin Sheppard2022-07-191-0/+13
| | | | | | | Allow bit generators to supply their own constructors to enable Generator objects using arbitrary bit generators to be supported closes #22012
* MAINT: random: Update to disallowing complex inputs to multivariate_normal.warren2022-06-161-1/+5
| | | | | | | * Disallow both mean and cov from being complex. * Raise a TypeError instead of a NotImplementedError if mean or cov is complex. * Expand and fix the unit test.
* MAINT: random: Disallow complex covariances in multivariate_normalHameer Abbasi2022-06-161-0/+2
| | | | | This commit disallows complex covariances in multivariate_normal as passing them can silently lead to incorrect results.
* Performance improvements for negative_binomial checksRaúl Montón Pinillos2022-02-181-0/+1
|
* Simplify check and add test for invalid combinations of p and n in ↵Raúl Montón Pinillos2022-02-171-0/+6
| | | | negative_binomial
* MAINT, DOC: discard repeated wordsDimitri Papadopoulos2022-01-131-1/+1
|
* BUG: random: Check 'writeable' flag in 'shuffle' and 'permuted'.warren2021-12-181-0/+13
|
* ENH: random: Add broadcast support to Generator.multinomial (#16740)Kevin Sheppard2021-11-121-6/+58
| | | | xref github issue #15201
* BUG: Get full precision for 32 bit floating point random values.warren2021-11-061-0/+12
| | | | | | | | | | | | | | | | The formula to convert a 32 bit random integer to a random float32, (next_uint32(bitgen_state) >> 9) * (1.0f / 8388608.0f) shifts by one bit too many, resulting in uniform float32 samples always having a 0 in the least significant bit. The formula is corrected to (next_uint32(bitgen_state) >> 8) * (1.0f / 16777216.0f) Occurrences of the incorrect formula in numpy/random/tests/test_direct.py were also corrected. Closes gh-17478.
* BUG: Seed random state in test_vonmises_large_kappa_range.Charles Harris2021-07-271-0/+1
| | | | | This makes the test reproducible. See comments on failing test in #19540.
* BUG: Check out requirements and raise when not satisfiedKevin Sheppard2021-04-071-0/+23
| | | | | | Check that out is C-contiguous when using user-supplied arguments closes #18704
* PERF: Use exponentials in place of inversionKevin Sheppard2021-03-221-7/+11
| | | | Use exponentials rather than generating exponentials via inversion
* ENH: Improve the exception for default low in Generator.integersKevin Sheppard2021-03-171-0/+15
| | | | | | | Improve the exception when low is 0 in case the single input form was used. closes #14333
* Port error to RandomStateKevin Sheppard2021-02-261-1/+1
|
* ENH: Improve error message in multinomialKevin Sheppard2021-02-261-0/+8
| | | | | | | | Improve error message when the sum of pvals is larger than 1 when the input data is an ndarray closes #8317 xref #16732
* BUG: Prevent RandomState from changingKevin Sheppard2021-02-261-1/+21
| | | | | | | | Apply vonmises fix only to Generator Add tests for correctness closes #17378 closes #17275
* BUG: Remove check in shuffle for non-ndarraysKevin Sheppard2021-02-111-0/+8
| | | | | | Remove ndim for non-ndarrays and check axis is 0 closes #18142
* BUG: shuffling empty array with axis=1 was brokenRalf Gommers2021-01-231-1/+14
| | | | | | | | | | | | | This would trigger: ``` NotImplementedError: Axis argument is only supported on ndarray objects ``` because empty arrays and array scalars would take the "untyped" path. The bug exists only for Generator, not in RandomState (it doesn't have axis keyword for `shuffle`), but update both because it keeps implementations in sync and the change results in more understandable code also for RandomState.
* Revert changes to mtrandKevin Sheppard2020-12-111-0/+9
| | | | This doesn't qualify for fixing under the NEP.
* BUG: Enforce high >= low on uniform number generatorsKevin Sheppard2020-12-111-0/+6
| | | | | | Check that high is weakly larger than low and raise if now closes #17905
* TST: Make test suite work in FIPS (140-2) ModeNikola Forró2020-10-291-25/+25
| | | | | | | | | Tests using MD5 algorithms fail in FIPS Mode because MD5 is not FIPS compliant. Replace MD5 with SHA256 to overcome that. Signed-off-by: Nikola Forró <nforro@redhat.com>
* ENH: random: Add the method `permuted` to Generator. (#15121)Warren Weckesser2020-09-021-0/+50
| | | | | | | | | | | * ENH: random: Make _shuffle_raw and _shuffle_int standalone functions. * ENH: random: Add the method `permuted` to Generator. The method permuted(x, axis=None, out=None) shuffles an array. Unlike the existing shuffle method, it shuffles the slices along the given axis independently. Closes gh-5173.
* BUG: Validate output size in bin- and multinomialKevin Sheppard2020-07-141-0/+10
| | | | | | Check that size is not being broadcast closes #16833
* BUG: Correct broadcasting when size is not NoneKevin Sheppard2020-06-051-0/+41
| | | | | | | Broadcastable size with inputs does not produce an error when size produces a smaller output array than the broadcast input shape. Patch checks that the output shape matches the outer shape of the broadcast fo all inputs and the size when given.
* REF: Refactor jump codeKevin Sheppard2020-05-121-5/+11
| | | | | | Refactor polynomial to be unsigned long array Remove unused code Fix md5 calculation on BE
* BUG: Correct loop order in MT19937 jumpKevin Sheppard2020-05-121-3/+43
| | | | | | Use the original loop order instead of an inverted order closes #15394
* BUG: Fix numpy.random.dirichlet returns NaN for small 'alpha' parameters. ↵Benjamin Trendelkamp-Schroer2020-04-291-0/+25
| | | | | | | | | | | | | | | (#14924) * Add stick-breaking * Add tests demonstrating slowness for beta and dirichlet generators for small alpha (and beta) values * Remove the test for beta with small `a` and `b` * Switch from standard to stick-breaking method whenever alpha.max() < 0.1 Co-authored-by: Warren Weckesser <warren.weckesser@gmail.com> Co-authored-by: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net>
* TST: random: Add more repeatability tests for random integers.Warren Weckesser2020-04-271-0/+23
| | | | | | | Add repeatability tests for when the range of the integers is `2**32` (and `2**32 +/- 1` for good measure) with broadcasting. The underlying functions called by Generator.integers and random.randint when the inputs are broadcast are different than when the inputs are scalars.
* BUG: random: Generator.integers(2**32) always returned 0.Warren Weckesser2020-04-261-0/+15
| | | | | | | | | | | | When the input to Generator.integers was 2**32, the value 2**32-1 was being passed as the `rng` argument to the 32-bit Lemire method, but that method requires `rng` be strictly less then 2**32-1. The fix was to handle 2**32-1 by calling next_uint32 directly. This also works for the legacy code without changing the stream of random integers from `randint`. Closes gh-16066.
* BUG: Alpha parameter must be 1D in `generator.dirichlet` (#15951)panpiort82020-04-181-0/+6
| | | | | Only one dimensional alpha paramter is currently supported, but higher dimensions were silently allowed and gave an incorrect results. This fixes the regression. In the future, the API could be extended to allow higher dimensional arrays for alpha. Fixes gh-15915
* Merge pull request #15876 from panpiort8/multinomial_pvals_1dMatti Picus2020-04-111-0/+6
|\ | | | | BUG: Check that `pvals` is 1D in `_generator.multinomial`.
| * Add minor tests enhancementPan Jan2020-04-061-1/+1
| |
| * Add testing and replace checkPan Jan2020-04-011-0/+6
| |
* | BUG: random: Disallow p=0 in negative_binomialWarren Weckesser2020-04-051-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | Make `Generator.negative_binomial` raise a ValueError if p=0. `negative_binomial(n, p)` draws samples from the distribution of the number of failures until n successes are encountered. If p is 0, then a success is never encountered, so the probability distribution is 0 for any finite number of failures. In other words, it is not really a meaningful distribution, so we disallow p=0. Closes gh-15913.
* | Bug: Fix eigh mnd cholesky methods of numpy.random.multivariate_normalMax Balandat2020-04-041-0/+24
|/ | | | Fixes #15871
* MAINT: Remove implicit inheritance from object class (#15236)Jon Dufresne2020-01-051-10/+10
| | | | | | | Inheriting from object was necessary for Python 2 compatibility to use new-style classes. In Python 3, this is unnecessary as there are no old-style classes. Dropping the object is more idiomatic Python.
* MAINT: random: Remove a few unused imports from test files.Warren Weckesser2019-12-151-1/+0
|
* MAINT: Remove uses of scalar aliasesEric Wieser2019-11-131-7/+6
| | | | Relates to gh-6103
* merge latest changes on master branchRedRuM2019-11-031-3/+222
|\
| * BUG: random: biased samples from integers() with 8 or 16 bit dtype.Warren Weckesser2019-10-241-2/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When an 8 or 16 bit dtype was given to the integers() method of the Generator class, the resulting sample was biased. The problem was the lines of the form const uint8_t threshold = -rng_excl % rng_excl; in the implementations of Lemire's method, in the C file distributions.c. The intent was to compute (UINT8_MAX+1 - rng_excl) % rng_excl However, when the type of rng_excl has integer conversion rank lower than a C int (which is almost certainly the case for the 8 and 16 bit types), the terms in the expression -rng_excl % rng_excl are promoted to int, and the result of the calculation is always 0. The fix is to make the expression explicit, and write it as const uint8_t threshold = (UINT8_MAX - rng) % rng_excl; rng is used, because rng_excl is simply rng + 1; by using rng, we we only need the constant UINT#_MAX, without the extra +1. For consistency, I made the same change for all the data types (8, 16, 32 and 64 bit). Closes gh-14774.
| * ENH: random: Add the multivariate hypergeometric distributionWarren Weckesser2019-10-181-1/+135
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The new method multivariate_hypergeometric(self, object colors, object nsample, size=None, method='marginals') of the class numpy.random.Generator implements the multivariate hypergeometric distribution; see https://en.wikipedia.org/wiki/Hypergeometric_distribution, specifically the section "Multivariate hypergeometric distribution". Two algorithms are implemented. The user selects which algorithm to use with the `method` parameter. The default, `method='marginals'`, is based on repeated calls of the univariate hypergeometric distribution function. The other algorithm, selected with `method='count'`, is a brute-force method that allocates an internal array of length ``sum(colors)``. It should only be used when that value is small, but it can be much faster than the "marginals" algorithm in that case. The C implementations of the two methods are in the files random_mvhg_count.c and random_mvhg_marginals.c in numpy/random/src/distributions.
| * BUG: random: Use correct length when axis is given to shuffle.Warren Weckesser2019-10-081-0/+9
| | | | | | | | | | | | | | When an axis argument was given, shuffle was using the original length of the array instead of the length of the given axis. This meant that, for example, if an array with shape (2, 10) was shuffled with axis=1, only the first two columns were shuffled.
| * ENH: Improve permutation and shuffle functions on a given axisKexuan Sun2019-09-141-0/+45
| |
| * BUG: Fix segfault in `random.permutation(x)` when x is a string. (#14241)Maxwell Aladago2019-08-221-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * fixing segfault error in np.random.permutation(x) where x is str * removed whitespace * changing error type to ValueError * changing error type to ValueError * changing error type to ValueError * tests * changed error to IndexError for backward compatibility with numpy 1.16 * fixes numpy.randomstate.permutation segfault too * Rolled back to ValueError for Generator.permutation() for all 0-dimensional * fixes refuige erro and rolls backs to AxisError
* | MAINT: remove stray commentsRedRuM2019-10-161-4/+0
| |