summaryrefslogtreecommitdiff
path: root/numpy/random/tests
Commit message (Collapse)AuthorAgeFilesLines
* MAINT: random: In a test module, don't use a global non-deterministically ↵warren2023-05-011-24/+21
| | | | Generator.
* BUG: random: Don't return negative values from Generator.geometric.warren2023-04-301-0/+7
| | | | | | | | | | In C, when the integer part of a double exceeds the maximum int64, casting the double to int64_t is undefined behavior. On some platforms, the result is 2**64-1 and on others it is -2**64. That results in rng.geometric() returning -2**64 when p was sufficiently small on some platforms. The fix is to never invoke undefined behavior by ensuring we don't attempt to cast very large double values to int64_t.
* BUG: accept zeros on numpy.random dirichlet function (#23440)Paulo Almeida2023-04-111-0/+4
| | | | | Changed alpha value error to pass a null value. This way, dirichlet function (on the generator, not mtrand) won't raise a value exception at 0. Also added test.
* Merge pull request #23195 from seberg/public-rng-spawnCharles Harris2023-02-231-0/+40
|\ | | | | API: Add `rng.spawn()`, `bit_gen.spawn()`, and `bit_gen.seed_seq`
| * API: Add `rng.spawn()`, `bit_gen.spawn()`, and `bit_gen.seed_seq`Sebastian Berg2023-02-141-0/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This makes the seed sequence interface more public facing by: 1. Adding `BitGenerator.seed_seq` to give clear access to `_seed_seq` 2. Add `spawn()` to both the generator and the bit generator as convenience methods for spawning new instances. I somewhat remember that we always meant to consider making this more public and adding such convenient methods, but did not do so originally. So, now, I do wonder whether it is time to make this fully public? It would be nice to follow up at some point with a bit of best practices. This also doesn't add it to the `RandomState`, although doing it via `RandomState._bit_generator` is of course valid. Can we define as this kind of access as stable enough that downstream libraries could use it? I fear that backcompat with `RandomState` might make adopting newer things like spawning hard for libraries?
* | TST: Add a random integers bounds checking test that previously failedSebastian Berg2023-02-131-0/+2
|/
* Merge pull request #22713 from seberg/numba-systemerrorCharles Harris2022-12-021-1/+2
|\ | | | | TST: Skip when numba/numpy compat issues cause SystemError
| * TST: Skip when numba/numpy compat issues cause SystemErrorSebastian Berg2022-12-021-1/+2
| | | | | | | | | | | | | | | | numba is a bit buggy when wrapping ufuncs, so what should be nothing is (on non dev versions) a SystemError and not even an ImportError. So simply catch those too, since it can be a confusing error during dev otherwise.
* | MAINT: Move _inspect and _pep440 from compat to _utilsSebastian Berg2022-11-251-1/+1
|/ | | | | Note that unfortunately, compat does expose _inspect as well, so the import remains (just the definition place moves).
* TST: Skip tests that are not currently supported in wasmHood Chatham2022-11-114-3/+10
|
* TST,MAINT: Replace most `setup` with `setup_method` (also teardown)Sebastian Berg2022-10-273-16/+16
| | | | | | | | 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-182-9/+30
| | | | | | | | 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: Implemented an unused test for np.random.randintMatteo Raso2022-08-251-17/+16
| | | | In numpy/random/tests/test_random.py, a class called TestSingleEltArrayInput had a method called test_randint that was commented out, with the instructions to uncomment it once np.random.randint was able to broadcast arguments. Since np.random.randint has been able to broadcast arguments for a while now, I uncommented the test. The only modification I made to the code was fixing a small error, where the author incorrectly tried to call "assert_equal" as a method of the TestSingleEltArrayInput instead of a function that was imported from numpy.testing. I ran runtests.py, and the new test passed.
* ENH: Add the capability to swap the singleton bit generatorKevin Sheppard2022-08-111-0/+67
| | | | | | | Add a new version or seed that supports seeding any bit gen Add set/get_bit_generator as explicity methodds to support swapping closes #21808
* TST: Fix spellingKevin Sheppard2022-07-192-2/+2
|
* BUG/ENH: ALlow bit generators to supply their own ctorKevin Sheppard2022-07-192-0/+31
| | | | | | | 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.
* Tests/Docs: Update tests to Cython 0.29.30, mention in docsEwout ter Hoeven2022-05-201-2/+2
| | | | | | Cython 0.29.30 is required for building Numpy with Python 3.11. This commit updates that in the core/tests/test_cython.py and random/tests/test_exending.py files. It also mentions that Cython 0.29.30 is needed in the INSTALL documentation.
* Merge pull request #21005 from Androp0v/negative_binomial-checksCharles Harris2022-03-131-0/+7
|\ | | | | BUG: Add parameter check to negative_binomial
| * 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: Replace LooseVersion by _pep440.Charles Harris2022-02-051-4/+4
|/ | | | | | | | LooseVersion is provided by Python distutils, which is going away in 3.12. This PR vendors _pep440 from scipy and uses it as a replacement. Numpy distutils is not touched, replacing LooseVersion in that package was considered too risky, and numpy distutils will need to go away when Python distutils does.
* MAINT, DOC: discard repeated wordsDimitri Papadopoulos2022-01-131-1/+1
|
* BUG: random: Check 'writeable' flag in 'shuffle' and 'permuted'.warren2021-12-182-0/+19
|
* BUG: Protect divide by 0 in multinomial (#20490)Kevin Sheppard2021-12-021-0/+13
| | | | | | | | | | Guard against empty pvals closes #20483 * MAINT: Correct exception type Raise TypeError for enhanced backward compat when pvals is scalar
* ENH: provide a convenience function to replace npy_load_module (#20395)Matti Picus2021-11-191-4/+4
| | | | | | | `load_module` is deprecated since python 3.4 and will be removed in python 3.12. Use `exec_module` instead. Provide a convenience function in `distutils.misc_utils` instead of `npy_load_module` from `compat.py3k`.
* 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-062-5/+20
| | | | | | | | | | | | | | | | 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.
* Merge pull request #20071 from alessiamarcolini/refactorCharles Harris2021-10-221-1/+1
|\ | | | | MAINT: Remove unused imports and remove duplicated tests
| * MAINT: remove unused importsAlessia Marcolini2021-10-081-1/+1
| |
* | BUG: Correct incorrect advance in PCG with emulated int128Kevin Sheppard2021-10-061-0/+22
|/ | | | | | | Correct incorrect implemetation of carry in PCG64 and PCG64DXSM when advancing more than 2**64 steps closes #20048
* index_tricks.py file not modifiedshubham119411402021-08-193-6/+6
|
* 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.
* ENH: Add PCG64DXSM implementation.Robert Kern2021-05-044-3/+2045
|
* 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
* Merge pull request #18438 from seberg/shuffle-objectsCharles Harris2021-03-181-0/+27
|\ | | | | BUG: Correct shuffling of objects in 1-d array likes
| * STY: Fix hanging indentation.Charles Harris2021-03-171-3/+3
| |
| * STY: Break long line.Charles Harris2021-03-171-1/+3
| |
| * BUG: Correct shuffling of objects in 1-d array likesSebastian Berg2021-02-221-0/+25
| | | | | | | | | | | | | | | | | | While introducing the buffer fixed the in-place problem years ago, running valgrind (and masked arrays) pointed out to me that without the additional `...` NumPy will unpack and repack objects leading to slightly incorrect results. MAINT: Warn about shuffle bug instead of fixing it in old random API
* | 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-262-1/+9
| |
* | 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-265-12/+32
| | | | | | | | | | | | | | | | Apply vonmises fix only to Generator Add tests for correctness closes #17378 closes #17275
* | Added test for [-np.pi, np.pi] range for the von mises distribution using ↵Raúl Montón Pinillos2021-02-263-0/+9
|/ | | | large values of kappa (>1e6)
* TST: Add test for shuffle warning and assert stacklevelSebastian Berg2021-02-191-0/+12
| | | | | | | The test checks that the warning originates in the correct file (test_random.py). I am not quite sure how safe the test is, though. Unfortunately, there is no "obvious" way to test stacklevels.
* 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
* MAINT: gracefully shuffle memoryviewsTyler Reddy2021-02-011-0/+15
| | | | | | * allow graceful shuffling of memoryviews, with same behavior as arrays, instead of producing a warning on `memoryview` shuffle
* BUG: shuffling empty array with axis=1 was brokenRalf Gommers2021-01-232-2/+19
| | | | | | | | | | | | | 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.