-
-
Notifications
You must be signed in to change notification settings - Fork 11.9k
DOC, API: add random.__init__.pxd and document random.* functions #14948
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…funcs
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,34 +22,41 @@ Since Numpy version 1.17.0 the Generator can be initialized with a | |||||||
| number of different BitGenerators. It exposes many different probability | ||||||||
| distributions. See `NEP 19 <https://www.numpy.org/neps/ | ||||||||
| nep-0019-rng-policy.html>`_ for context on the updated random Numpy number | ||||||||
| routines. The legacy `.RandomState` random number routines are still | ||||||||
| routines. The legacy `RandomState` random number routines are still | ||||||||
| available, but limited to a single BitGenerator. | ||||||||
|
|
||||||||
| For convenience and backward compatibility, a single `~.RandomState` | ||||||||
| For convenience and backward compatibility, a single `RandomState` | ||||||||
| instance's methods are imported into the numpy.random namespace, see | ||||||||
| :ref:`legacy` for the complete list. | ||||||||
|
|
||||||||
| .. _random-quick-start: | ||||||||
|
|
||||||||
| Quick Start | ||||||||
| ----------- | ||||||||
|
|
||||||||
|
||||||||
| By default, `~Generator` uses bits provided by `PCG64` which | ||||||||
| has better statistical properties than the legacy mt19937 random | ||||||||
| number generator in `~.RandomState`. | ||||||||
| Call `default_rng` to get a new instance of a `Generator`, then call its | ||||||||
| methods to obtain samples from different distributions. By default, | ||||||||
| `Generator` uses bits provided by `PCG64` which has better statistical | ||||||||
| properties than the legacy `MT19937` used in `RandomState`. | ||||||||
|
|
||||||||
| .. code-block:: python | ||||||||
|
|
||||||||
| # Uses the old numpy.random.RandomState | ||||||||
| #Do this | ||||||||
mattip marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||
| from numpy.random import default_rng | ||||||||
| val = default_rng().standard_normal() | ||||||||
|
||||||||
| val = default_rng().standard_normal() | |
| rng = default_rng() | |
| val = rng.standard_normal() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adopting
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't there more bit generators in randomgen? If so, that seems worth mentioning. Otherwise, this subsection is probably best moved to THANKS.txt, it doesn't help the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are many more there still.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,3 +121,63 @@ Distributions | |
| ~RandomState.wald | ||
| ~RandomState.weibull | ||
| ~RandomState.zipf | ||
|
|
||
|
||
| Toplevel `numpy.random` functions | ||
|
||
| ================================= | ||
| Many of the RandomState methods above are exported as top-level `numpy.random` | ||
|
||
| functions. These are: | ||
|
|
||
| .. autosummary:: | ||
| :toctree: generated/ | ||
|
|
||
| beta | ||
| binomial | ||
| bytes | ||
| chisquare | ||
| choice | ||
| dirichlet | ||
| exponential | ||
| f | ||
| gamma | ||
| geometric | ||
| get_state | ||
| gumbel | ||
| hypergeometric | ||
| laplace | ||
| logistic | ||
| lognormal | ||
| logseries | ||
| multinomial | ||
| multivariate_normal | ||
| negative_binomial | ||
| noncentral_chisquare | ||
| noncentral_f | ||
| normal | ||
| pareto | ||
| permutation | ||
| poisson | ||
| power | ||
| rand | ||
| randint | ||
| randn | ||
| random | ||
| random_integers | ||
| random_sample | ||
| ranf | ||
| rayleigh | ||
| sample | ||
| seed | ||
| set_state | ||
| shuffle | ||
| standard_cauchy | ||
| standard_exponential | ||
| standard_gamma | ||
| standard_normal | ||
| standard_t | ||
| triangular | ||
| uniform | ||
| vonmises | ||
| wald | ||
| weibull | ||
| zipf | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| cimport numpy as np | ||
| from libc.stdint cimport uint32_t, uint64_t | ||
|
|
||
| cdef extern from "numpy/random/bitgen.h": | ||
| struct bitgen: | ||
| void *state | ||
| uint64_t (*next_uint64)(void *st) nogil | ||
| uint32_t (*next_uint32)(void *st) nogil | ||
| double (*next_double)(void *st) nogil | ||
| uint64_t (*next_raw)(void *st) nogil | ||
|
|
||
| ctypedef bitgen bitgen_t | ||
|
|
||
| from numpy.random._bit_generator cimport BitGenerator, SeedSequence |
Uh oh!
There was an error while loading. Please reload this page.