Skip to content

Commit

Permalink
Merge pull request #288 from bashtage/v1.12.2-rel
Browse files Browse the repository at this point in the history
MAINT: Small fixes for rel 1.20.2
  • Loading branch information
bashtage authored Apr 27, 2021
2 parents 81f0d8f + c59f561 commit a3d2d00
Show file tree
Hide file tree
Showing 18 changed files with 428 additions and 148 deletions.
2 changes: 1 addition & 1 deletion doc/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ numba>=0.49
nbsphinx
sphinx-material
sphinx>=3
ipython>=5
ipython>=6
numpydoc
20 changes: 16 additions & 4 deletions doc/source/change-log.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ Change Log
maintained until after NumPy 1.21 (or 2 releases after NumPy 1.19) for users who
cannot update NumPy.

Since v1.20.1
=============
v1.20.2
=======
- Fixed a bug in :class:`~randomgen.sfc.SFC64` the used the wrong value from the Weyl
sequence. In the original implmentation, the current value is added to the next random
sequence. In the original implementation, the current value is added to the next random
integer and then incremented. The buggy version was incrementing then adding, and so
was shifted by one value.
was shifted by one value. This sequence should be similarly random in appearance, but it
does not match the original specification and so has been changed.
- Added ``mode="numpy"`` support to :class:`~randomgen.pcg64.PCG64`,
:class:`~randomgen.mt19937.MT19937`, :class:`~randomgen.philox.Philox`, and
:class:`~randomgen.sfc.SFC64`. When using this mode, the sequence generated is
Expand All @@ -30,6 +31,17 @@ Since v1.20.1
- Added :func:`~randomgen.generator.ExtendedGenerator.random` with support for
``dtype="longdouble"`` to produce extended precision random floats.

.. ipython::

In [1]: import numpy as np

In [2]: from randomgen import ExtendedGenerator, PCG64

In [3]: eg = ExtendedGenerator(PCG64(20210501))

In [4]: eg.random(5, dtype=np.longdouble)


v1.20.1
=======
- Fixed a bug that affects :func:`~randomgen.generator.Generator.standard_gamma` when
Expand Down
2 changes: 2 additions & 0 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,5 @@ def show(*args, **kwargs):
matplotlib.pyplot.show = show
"""

numpydoc_show_class_members = False
4 changes: 2 additions & 2 deletions randomgen/common.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ cdef object prepare_cffi(bitgen_t *bitgen):
"""
try:
import cffi
except ImportError:
raise ImportError("cffi cannot be imported.")
except ImportError as exc:
raise ImportError("cffi cannot be imported.") from exc

ffi = cffi.FFI()
_cffi = interface(<uintptr_t>bitgen.state,
Expand Down
4 changes: 1 addition & 3 deletions randomgen/dsfmt.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import numpy as np
from randomgen.common import BitGenerator
from randomgen.typing import IntegerSequenceSeed, SeedMode

DSFMTState: Dict[
str, Union[str, int, np.ndarray, Dict[str, Union[int, np.ndarray]]]
] = ...
DSFMTState = Dict[str, Union[str, int, np.ndarray, Dict[str, Union[int, np.ndarray]]]]

class DSFMT(BitGenerator):
def __init__(
Expand Down
240 changes: 181 additions & 59 deletions randomgen/generator.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from threading import Lock
from typing import Any, Dict, Literal, Optional, Sequence, Union
from typing import Any, Dict, Literal, Optional, Sequence, Tuple, Union, overload

import numpy as np
from numpy import ndarray
Expand All @@ -14,7 +14,7 @@ class Generator:
def __init__(self, bit_generator: Optional[BitGenerator] = ...) -> None: ...
@property
def bit_generator(self) -> BitGenerator: ...
def seed(self, *args, **kwargs): ...
def seed(self, *args: Any, **kwargs: Any) -> None: ...
@property
def state(self) -> Dict[str, Any]: ...
@state.setter
Expand All @@ -25,96 +25,213 @@ class Generator:
def random_uintegers(
self, size: Size = ..., bits: Literal[32, 64] = ...
) -> Union[int, ndarray]: ...
def random_sample(self, *args, **kwargs) -> Union[float, ndarray]: ...
def random_sample(
self, *args: Tuple[int, ...], **kwargs: Dict[str, Tuple[int, ...]]
) -> Union[float, ndarray]: ...
def random(
self, size: Size = ..., dtype=np.float64, out: ndarray = ...
self, size: Size = ..., dtype: str = ..., out: ndarray = ...
) -> Union[float, ndarray]: ...
def beta(
self, a: Union[float, ndarray], b: Union[float, ndarray], size: Size = ...
) -> Union[float, ndarray]: ...
def exponential(
self, scale: Optional[Union[float, ndarray]] = ..., size: Size = ...
) -> Union[float, ndarray]: ...
def beta(self, a, b, size: Size = ...) -> Union[float, ndarray]: ...
def exponential(self, scale=1.0, size: Size = ...) -> Union[float, ndarray]: ...
def standard_exponential(
self, size: Size = ..., dtype=np.float64, method="zig", out: ndarray = ...
self, size: Size = ..., dtype: str = ..., method: str = ..., out: ndarray = ...
) -> Union[float, ndarray]: ...
def tomaxint(self, size: Size = ...) -> Union[int, ndarray]: ...
def randint(self, *args, **kwargs) -> Union[int, ndarray]: ...
def randint(
self,
*args: Tuple[Union[int, Tuple[int, ...]], ...],
**kwargs: Dict[str, Union[int, Tuple[int, ...]]]
) -> Union[int, ndarray]: ...
def integers(
self,
low,
high=None,
low: Union[int, ndarray],
high: Optional[Union[int, ndarray]] = ...,
size: Size = ...,
dtype=np.int64,
use_masked=None,
endpoint=False,
closed=None,
dtype: str = ...,
use_masked: Optional[bool] = ...,
endpoint: bool = ...,
closed: bool = ...,
) -> Union[int, ndarray]: ...
def bytes(self, length) -> ndarray: ...
def bytes(self, length: int) -> ndarray: ...
def choice(
self, a, size: Size = ..., replace=True, p=None, axis=0, shuffle=True
): ...
def uniform(self, low=0.0, high=1.0, size: Size = ...) -> Union[float, ndarray]: ...
def rand(self, *args, dtype=np.float64) -> Union[float, ndarray]: ...
def randn(self, *args, dtype=np.float64) -> Union[float, ndarray]: ...
self,
a: Union[int, Sequence[Any]],
size: Size = ...,
replace: bool = ...,
p: Optional[ndarray] = ...,
axis: int = ...,
shuffle: bool = ...,
) -> Sequence[Any]: ...
def uniform(
self,
low: Optional[Union[float, ndarray]] = ...,
high: Optional[Union[float, ndarray]] = ...,
size: Size = ...,
) -> Union[float, ndarray]: ...
def rand(
self, *args: Tuple[int, ...], dtype: str = ...
) -> Union[float, ndarray]: ...
def randn(
self, *args: Tuple[int, ...], dtype: str = ...
) -> Union[float, ndarray]: ...
def random_integers(
self, low, high=None, size: Size = ...
self,
low: Union[int, ndarray],
high: Optional[Union[int, ndarray]] = ...,
size: Size = ...,
) -> Union[int, ndarray]: ...
# Complicated, continuous distributions:...
def standard_normal(
self, size: Size = ..., dtype=np.float64, out: ndarray = ...
self, size: Size = ..., dtype: str = ..., out: ndarray = ...
) -> Union[float, ndarray]: ...
def normal(
self,
loc: Optional[Union[float, ndarray]] = ...,
scale: Optional[Union[float, ndarray]] = ...,
size: Size = ...,
) -> Union[float, ndarray]: ...
def normal(self, loc=0.0, scale=1.0, size: Size = ...) -> Union[float, ndarray]: ...
def standard_gamma(
self, shape, size: Size = ..., dtype=np.float64, out: ndarray = ...
self,
shape: Union[float, ndarray],
size: Size = ...,
dtype: str = ...,
out: ndarray = ...,
) -> Union[float, ndarray]: ...
def gamma(
self,
shape: Union[float, ndarray],
scale: Optional[Union[float, ndarray]] = ...,
size: Size = ...,
) -> Union[float, ndarray]: ...
def f(
self,
dfnum: Union[float, ndarray],
dfden: Union[float, ndarray],
size: Size = ...,
) -> Union[float, ndarray]: ...
def gamma(self, shape, scale=1.0, size: Size = ...) -> Union[float, ndarray]: ...
def f(self, dfnum, dfden, size: Size = ...) -> Union[float, ndarray]: ...
def noncentral_f(
self, dfnum, dfden, nonc, size: Size = ...
self,
dfnum: Union[float, ndarray],
dfden: Union[float, ndarray],
nonc: Union[float, ndarray],
size: Size = ...,
) -> Union[float, ndarray]: ...
def chisquare(
self, df: Union[float, ndarray], size: Size = ...
) -> Union[float, ndarray]: ...
def chisquare(self, df, size: Size = ...) -> Union[float, ndarray]: ...
def noncentral_chisquare(
self, df, nonc, size: Size = ...
self, df: Union[float, ndarray], nonc: Union[float, ndarray], size: Size = ...
) -> Union[float, ndarray]: ...
def standard_cauchy(self, size: Size = ...) -> Union[float, ndarray]: ...
def standard_t(self, df, size: Size = ...) -> Union[float, ndarray]: ...
def vonmises(self, mu, kappa, size: Size = ...) -> Union[float, ndarray]: ...
def pareto(self, a, size: Size = ...) -> Union[float, ndarray]: ...
def weibull(self, a, size: Size = ...) -> Union[float, ndarray]: ...
def power(self, a, size: Size = ...) -> Union[float, ndarray]: ...
def standard_t(
self, df: Union[float, ndarray], size: Size = ...
) -> Union[float, ndarray]: ...
def vonmises(
self, mu: Union[float, ndarray], kappa: Union[float, ndarray], size: Size = ...
) -> Union[float, ndarray]: ...
def pareto(
self, a: Union[float, ndarray], size: Size = ...
) -> Union[float, ndarray]: ...
def weibull(
self, a: Union[float, ndarray], size: Size = ...
) -> Union[float, ndarray]: ...
def power(
self, a: Union[float, ndarray], size: Size = ...
) -> Union[float, ndarray]: ...
def laplace(
self, loc=0.0, scale=1.0, size: Size = ...
self,
loc: Optional[Union[float, ndarray]] = ...,
scale: Optional[Union[float, ndarray]] = ...,
size: Size = ...,
) -> Union[float, ndarray]: ...
def gumbel(
self,
loc: Optional[Union[float, ndarray]] = ...,
scale: Optional[Union[float, ndarray]] = ...,
size: Size = ...,
) -> Union[float, ndarray]: ...
def gumbel(self, loc=0.0, scale=1.0, size: Size = ...) -> Union[float, ndarray]: ...
def logistic(
self, loc=0.0, scale=1.0, size: Size = ...
self,
loc: Optional[Union[float, ndarray]] = ...,
scale: Optional[Union[float, ndarray]] = ...,
size: Size = ...,
) -> Union[float, ndarray]: ...
def lognormal(
self, mean=0.0, sigma=1.0, size: Size = ...
self,
mean: Optional[Union[float, ndarray]] = ...,
sigma: Optional[Union[float, ndarray]] = ...,
size: Size = ...,
) -> Union[float, ndarray]: ...
def rayleigh(
self, scale: Optional[Union[float, ndarray]] = ..., size: Size = ...
) -> Union[float, ndarray]: ...
def wald(
self,
mean: Union[float, ndarray],
scale: Union[float, ndarray],
size: Size = ...,
) -> Union[float, ndarray]: ...
def rayleigh(self, scale=1.0, size: Size = ...) -> Union[float, ndarray]: ...
def wald(self, mean, scale, size: Size = ...) -> Union[float, ndarray]: ...
def triangular(
self, left, mode, right, size: Size = ...
self,
left: Union[float, ndarray],
mode: Union[float, ndarray],
right: Union[float, ndarray],
size: Size = ...,
) -> Union[float, ndarray]: ...
# Complicated, discrete distributions:
def binomial(self, n, p, size: Size = ...) -> Union[int, ndarray]: ...
def negative_binomial(self, n, p, size: Size = ...) -> Union[int, ndarray]: ...
def poisson(self, lam=1.0, size: Size = ...) -> Union[int, ndarray]: ...
def zipf(self, a, size: Size = ...) -> Union[int, ndarray]: ...
def geometric(self, p, size: Size = ...) -> Union[int, ndarray]: ...
def binomial(
self, n: Union[int, ndarray], p: Union[float, ndarray], size: Size = ...
) -> Union[int, ndarray]: ...
def negative_binomial(
self, n: Union[int, ndarray], p: Union[float, ndarray], size: Size = ...
) -> Union[int, ndarray]: ...
def poisson(
self, lam: Optional[Union[float, ndarray]] = ..., size: Size = ...
) -> Union[int, ndarray]: ...
def zipf(
self, a: Union[float, ndarray], size: Size = ...
) -> Union[int, ndarray]: ...
def geometric(
self, p: Union[float, ndarray], size: Size = ...
) -> Union[int, ndarray]: ...
def hypergeometric(
self, ngood, nbad, nsample, size: Size = ...
self,
ngood: Union[int, ndarray],
nbad: Union[int, ndarray],
nsample: Union[int, ndarray],
size: Size = ...,
) -> Union[int, ndarray]: ...
def logseries(
self, p: Union[float, ndarray], size: Size = ...
) -> Union[int, ndarray]: ...
def logseries(self, p, size: Size = ...) -> Union[int, ndarray]: ...
# Multivariate distributions:
def multivariate_normal(
self, mean, cov, size: Size = ..., check_valid="warn", tol=1e-8, *, method="svd"
self,
mean: ndarray,
cov: ndarray,
size: Size = ...,
check_valid: str = ...,
tol: float = ...,
*,
method: str = ...
) -> ndarray: ...
def multinomial(self, n, pvals, size: Size = ...) -> ndarray: ...
def dirichlet(self, alpha, size: Size = ...) -> ndarray: ...
def multinomial(
self, n: Union[int, ndarray], pvals: Union[float, ndarray], size: Size = ...
) -> ndarray: ...
def dirichlet(self, alpha: ndarray, size: Size = ...) -> ndarray: ...
# Shuffling and permutations:
def shuffle(self, x: Sequence[Any]) -> None: ...
def permutation(self, x: Sequence[Any]) -> None: ...
def complex_normal(
self, loc=0.0, gamma=1.0, relation=0.0, size: Size = ...
self,
loc: Optional[Union[float, ndarray]] = ...,
gamma: Optional[Union[float, ndarray]] = ...,
relation: Optional[Union[float, ndarray]] = ...,
size: Size = ...,
) -> Union[complex, ndarray]: ...

class ExtendedGenerator:
Expand All @@ -128,13 +245,18 @@ class ExtendedGenerator:
def state(self) -> Dict[str, Any]: ...
@state.setter
def state(self, value: Dict[str, Any]) -> None: ...
@overload
def uintegers(self, size: None, bits: Literal[32, 64] = ...) -> int: ...
def uintegers(
self, size: RequiredSize, bits: Literal[32, 64] = ...
) -> Union[int, ndarray]: ...
@overload
def uintegers(self, size: RequiredSize, bits: Literal[32, 64] = ...) -> ndarray: ...
@overload
def random(self) -> float: ... # type: ignore[misc]
@overload
def random(self, size: None = ...) -> float: ... # type: ignore[misc]
@overload
def random(
self, size: Size = ..., dtype=np.float64, out: ndarray = ...
) -> Union[float, ndarray]: ...
self, size: Size = ..., dtype: str = ..., out: Optional[ndarray] = ...
) -> ndarray: ...
# Multivariate distributions:
def multivariate_normal(
self,
Expand All @@ -147,14 +269,14 @@ class ExtendedGenerator:
method: Literal["svd", "eigh", "cholesky", "factor"] = ...
) -> ndarray: ...
@overload
def complex_normal(
def complex_normal( # type: ignore[misc]
self,
loc: complex = ...,
gamma: complex = ...,
relation: complex = ...,
) -> complex: ...
@overload
def complex_normal(
def complex_normal( # type: ignore[misc]
self,
loc: complex = ...,
gamma: complex = ...,
Expand Down
1 change: 1 addition & 0 deletions randomgen/mt19937.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ class MT19937(BitGenerator):
Dict[str, Union[str, Dict[str, Union[int, np.ndarray]]]],
],
) -> None: ...
def _jump_tester(self) -> MT19937: ...
Loading

0 comments on commit a3d2d00

Please sign in to comment.