summaryrefslogtreecommitdiff
path: root/numpy/random/src/distributions
Commit message (Collapse)AuthorAgeFilesLines
* CLN: Move to legacy functionKevin Sheppard2021-02-261-18/+11
| | | | | | Avoid conditional compilation and move old version to legacy_vonmises Small clean up Additional comments
* BUG: Prevent RandomState from changingKevin Sheppard2021-02-261-7/+13
| | | | | | | | Apply vonmises fix only to Generator Add tests for correctness closes #17378 closes #17275
* Fixed style and added check for bounds in [-pi,pi] interval.Raúl Montón Pinillos2021-02-261-6/+17
|
* Fixed Von Mises distribution for big values of kappa by falling back to a ↵Raúl Montón Pinillos2021-02-261-3/+8
| | | | normal distribution (which the von mises distribution converges to).
* MAINT: Correct code producing warningsKevin Sheppard2021-02-181-1/+1
| | | | | Cast to avoid warnings Correct function
* MAINT: precompute log(2.0 * M_PI) in `random_loggam' (gh-16237)Elia Franzella2020-05-191-10/+12
| | | | Most compilers should optimize it, but it doesn't hurt to inline and has a better name now.
* MAINT: random: Add assert() statements.Warren Weckesser2020-04-261-0/+11
| | | | | Assert that an invalid value (2**n-1 for n = 8, 16, 32, 64) has not been passed to the Lemire function.
* BUG: random: Generator.integers(2**32) always returned 0.Warren Weckesser2020-04-261-11/+31
| | | | | | | | | | | | 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.
* BLD: use 0.3.7 release version, add dependency on libgfortran5mattip2020-01-172-2/+2
|
* API, DOC: change names to multivariate_hypergeometric, improve docsmattip2019-12-042-4/+4
|
* API: revert changes to standard_t, cauchymattip2019-11-301-2/+2
|
* API: rename functions in distributions.c,hmattip2019-11-291-46/+39
|
* API: restructure and document numpy.random C-API (#14604)Matti Picus2019-11-194-4/+4
| | | | | | | | | | | | | | | | * API: restructure and document numpy.random C-API * DOC: fix bad reference * API: ship, document, and start to test numpy.random C-API examples * API, DOC, TST: fix tests, refactor documentation to include snippets * BUILD: move public headers to numpy/core/include/numpy/random * TST: ignore DeprecationWarnings in setuptools and numba * DOC: document the C-API as used from Cython
* BUG: random: biased samples from integers() with 8 or 16 bit dtype.Warren Weckesser2019-10-241-14/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-182-0/+269
| | | | | | | | | | | | | | | | | | | | | | | | | 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.
* API: remove unused functions from distributions.hmattip2019-10-111-3/+15
|
* API: refactor function names in distribution.{h,c}, refactor float_fillmattip2019-10-112-211/+72
|
* API: rearrange the cython files in numpy.randommattip2019-10-113-216/+2
|
* BLD: remove unused functions, rearrange headers (from CC=clang) (#14534)Matti Picus2019-09-262-4/+3
| | | | | * BUILD: remove unused functions, rearrange headers (from CC=clang) * MAINT: check enum at API call, not in provate function
* MAINT: don't install partial numpy.random C/Cython API.Ralf Gommers2019-09-211-1/+1
| | | | | | | | | See https://mail.python.org/pipermail/numpy-discussion/2019-September/080088.html for discussion. We need to do this right, and add tests and docs. All this PR does is not install bitgen.h, common.pxd and bit_generator.pxd (they're still shipped in the sdist, that is needed). Should be backported to 1.17.x
* BUG: random: Create a legacy implementation of random.binomial.Warren Weckesser2019-09-162-6/+16
| | | | | | | | | Create a legacy implementation of the random_binomial method of RandomState that does not include the "short-circuit" check for n == 0 or p == 0. This ensures that the stream of variates is consistent with the behavior in 1.16. Closes gh-14522.
* BUG: Fix randint when range is 2**32Kevin Sheppard2019-09-141-2/+2
| | | | | | Fix randint to use 32-bit path when range is exactly 2**32 closes #14189
* MAINT: move location of bitgen.hmattip2019-06-271-1/+1
|
* ENH: use SeedSequence to generate entropy for seedingmattip2019-06-261-8/+1
|
* Merge pull request #13786 from WarrenWeckesser/random-warningsMatti Picus2019-06-181-4/+4
|\ | | | | MAINT: random: Fix a few compiler warnings.
| * MAINT: random: Fix a few compiler warnings.Warren Weckesser2019-06-141-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes: gcc: numpy/random/src/xoshiro256/xoshiro256.c numpy/random/src/xoshiro256/xoshiro256.c:39:16: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare] for (i = 0; i < sizeof JUMP / sizeof *JUMP; i++) ~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~ gcc: numpy/random/src/xoshiro512/xoshiro512.c numpy/random/src/xoshiro512/xoshiro512.c:43:17: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare] for (i = 0; i < sizeof JUMP / sizeof *JUMP; i++) ~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~ numpy/random/src/xoshiro512/xoshiro512.c:46:23: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare] for (w = 0; w < sizeof s_placeholder / sizeof *s_placeholder; w++) ~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ gcc: numpy/random/src/distributions/distributions.c numpy/random/src/distributions/distributions.c:185:14: warning: comparison of integers of different signs: 'int64_t' (aka 'long long') and 'const uint64_t' (aka 'const unsigned long long') [-Wsign-compare] if (rabs < ki_double[idx]) ~~~~ ^ ~~~~~~~~~~~~~~ numpy/random/src/distributions/distributions.c:230:14: warning: comparison of integers of different signs: 'int32_t' (aka 'int') and 'const uint32_t' (aka 'const unsigned int') [-Wsign-compare] if (rabs < ki_float[idx]) ~~~~ ^ ~~~~~~~~~~~~~
* | MAINT: random: Rewrite the hypergeometric distribution.Warren Weckesser2019-06-145-102/+436
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary of the changes: * Move the functions random_hypergeometric_hyp, random_hypergeometric_hrua and random_hypergeometric from distributions.c to legacy-distributions.c. These are now the legacy implementation of hypergeometric. * Add the files logfactorial.c and logfactorial.h, containing the function logfactorial(int64_t k). * Add the files random_hypergeometric.c and random_hypergeometric.h, containing the function random_hypergeometric (the new implementation of the hypergeometric distribution). See more details below. * Fix two tests in numpy/random/tests/test_generator_mt19937.py that used values returned by the hypergeometric distribution. The new implementation changes the stream, so those tests needed to be updated. * Remove another test obviated by an added constraint on the arguments of hypergeometric. Details of the rewrite: If you carefully step through the old function rk_hypergeometric_hyp(), you'll see that the end result is basically the same as the new function hypergeometric_sample(), but the new function accomplishes the result with just integers. The floating point calculations in the old code caused problems when the arguments were extremely large (explained in more detail in the unmerged pull request https://github.com/numpy/numpy/pull/9834). The new version of hypergeometric_hrua() is a new translation of Stadlober's ratio-of-uniforms algorithm for the hypergeometric distribution. It fixes a mistake in the old implementation that made the method less efficient than it could be (see the details in the unmerged pull request https://github.com/numpy/numpy/pull/11138), and uses a faster function for computing log(k!). The HRUA algorithm suffers from loss of floating point precision when the arguments are *extremely* large (see the comments in github issue 11443). To avoid these problems, the arguments `ngood` and `nbad` of hypergeometric must be less than 10**9. This constraint obviates an existing regression test that was run on systems with 64 bit long integers, so that test was removed.
* MAINT: random: Combine ziggurat.h and ziggurat_constants.hWarren Weckesser2019-06-123-277/+10
| | | | ... and remove the unused arrays that were in ziggurat.h.
* MAINT: random: Remove unused empty file binomial.h.Warren Weckesser2019-06-081-0/+0
| | | | The file numpy/random/src/distributions/binomial.h was empty and unused.
* ENH: Split poisson_lam_maxKevin Sheppard2019-05-231-2/+2
| | | | | | Use type-dependent poisson lam max Make private Fix backward compat issue in loggam
* BUG: Ensure integer-type stream on 32bitKevin Sheppard2019-05-202-75/+84
| | | | | | Ensure integer type is stream compatible on 32 bit Fix incorrect clause end Add integer-generator tests that check long streams
* MAINT: Implement API changes for randomgen-derived codemattip2019-05-202-430/+449
| | | | | | | | | | | | | | | | | | | | | remove numpy.random.gen, BRNG.generator, pcg*, rand, randn remove use_mask and Lemire's method, fix benchmarks for PCG removal convert brng to bitgen (in C) and bit_generator (in python) convert base R{NG,andom.*} to BitGenerator, fix last commit randint -> integers, remove rand, randn, random_integers RandomGenerator -> Generator, more "basic RNG" -> BitGenerator random_sample -> random, jump -> jumped, resync with randomgen Remove derived code from entropy Port over changes accepted in upstream to protect log(0.0) where relevant fix doctests for jumped, better document choice Remove Python 2.7 shims Use NPY_INLINE to simplify Fix performance.py to work Renam directory brng to bit_generators Fix examples wiht new directory structure Clarify relationship to historical RandomState Remove references to .generator Rename xoshiro256/512starstar
* BUG: Fix type in zipfKevin Sheppard2019-05-201-1/+1
| | | | Correct type form long to int64
* ENH: Extend multinomial and fix zipfKevin Sheppard2019-05-202-13/+42
| | | | | | Extend multinomial to allow broadcasting Fix zipf changes missed in NumPy Enable 0 as valid input for hypergeometric
* BENCH: convert bencmarks to asv formatmattip2019-05-206-0/+3564
remove files that were part of the origal repo rework randomgen docs to integrate with numpy and fix some links remove convenience functions, require explicit call to gen.brng move code out of numpy.random.randomgen into numpy.random