@@ -80,6 +80,7 @@ cdef extern from "distributions.h":
80
80
cdef double random_gauss_zig (aug_state * state ) nogil
81
81
cdef double random_gauss_zig_julia (aug_state * state ) nogil
82
82
cdef double random_standard_exponential (aug_state * state ) nogil
83
+ cdef double random_standard_exponential_ziggurat (aug_state * state ) nogil
83
84
cdef double random_standard_cauchy (aug_state * state ) nogil
84
85
85
86
cdef double random_exponential (aug_state * state , double scale ) nogil
@@ -124,12 +125,14 @@ cdef extern from "distributions.h":
124
125
125
126
cdef void random_gauss_zig_float_fill (aug_state * state , intptr_t count , float * out ) nogil
126
127
cdef void random_uniform_fill_float (aug_state * state , intptr_t cnt , double * out ) nogil
128
+ cdef void random_standard_exponential_zig_float_fill (aug_state * state , intptr_t count , float * out ) nogil
127
129
cdef void random_standard_exponential_fill_float (aug_state * state , intptr_t count , float * out ) nogil
128
130
cdef void random_gauss_fill_float (aug_state * state , intptr_t count , float * out ) nogil
129
131
130
132
cdef void random_gauss_zig_double_fill (aug_state * state , intptr_t count , double * out ) nogil
131
133
cdef void random_uniform_fill_double (aug_state * state , intptr_t cnt , double * out ) nogil
132
134
cdef void random_standard_exponential_fill_double (aug_state * state , intptr_t count , double * out ) nogil
135
+ cdef void random_standard_exponential_zig_double_fill (aug_state * state , intptr_t count , double * out ) nogil
133
136
cdef void random_gauss_fill (aug_state * state , intptr_t count , double * out ) nogil
134
137
cdef void random_gauss_zig_julia_fill (aug_state * state , intptr_t count , double * out ) nogil
135
138
@@ -2014,9 +2017,9 @@ cdef class RandomState:
2014
2017
0.0 , '' , CONS_NONE ,
2015
2018
None )
2016
2019
2017
- def standard_exponential (self , size = None , dtype = np .float64 , out = None ):
2020
+ def standard_exponential (self , size = None , dtype = np .float64 , method = u'inv' , out = None ):
2018
2021
"""
2019
- standard_exponential(size=None, dtype=np.float64, out=None)
2022
+ standard_exponential(size=None, dtype=np.float64, method='inv', out=None)
2020
2023
2021
2024
Draw samples from the standard exponential distribution.
2022
2025
@@ -2033,6 +2036,9 @@ cdef class RandomState:
2033
2036
Desired dtype of the result. All dtypes are determined by their
2034
2037
name, either 'float64' or 'float32'. The default value is
2035
2038
'float64'.
2039
+ method : str, optional
2040
+ Either 'inv' or 'zig'. 'inv' uses the default inverse CDF method.
2041
+ 'zig' uses the much faster Ziggurat method of Marsaglia and Tsang.
2036
2042
out : ndarray, optional
2037
2043
Alternative output array in which to place the result. If size is not None,
2038
2044
it must have the same shape as the provided size and must match the type of
@@ -2048,17 +2054,28 @@ cdef class RandomState:
2048
2054
Output a 3x8000 array:
2049
2055
2050
2056
>>> n = np.random.standard_exponential((3, 8000))
2051
-
2052
2057
"""
2058
+ if method != u'zig' and method != u'inv' :
2059
+ raise ValueError ("method must be either 'bm' or 'zig'" )
2053
2060
key = np .dtype (dtype ).name
2054
2061
if key == 'float64' :
2055
- return double_fill (& self .rng_state ,
2056
- & random_standard_exponential_fill_double ,
2057
- size , self .lock , out )
2062
+ if method == 'zig' :
2063
+ return double_fill (& self .rng_state ,
2064
+ & random_standard_exponential_zig_double_fill ,
2065
+ size , self .lock , out )
2066
+ else :
2067
+ return double_fill (& self .rng_state ,
2068
+ & random_standard_exponential_fill_double ,
2069
+ size , self .lock , out )
2058
2070
elif key == 'float32 ':
2059
- return float_fill (& self .rng_state ,
2060
- & random_standard_exponential_fill_float ,
2061
- size , self .lock , out )
2071
+ if method == 'zig' :
2072
+ return float_fill (& self .rng_state ,
2073
+ & random_standard_exponential_zig_float_fill ,
2074
+ size , self .lock , out )
2075
+ else :
2076
+ return float_fill (& self .rng_state ,
2077
+ & random_standard_exponential_fill_float ,
2078
+ size , self .lock , out )
2062
2079
else :
2063
2080
raise TypeError ('Unsupported dtype "%s" for standard_exponential'
2064
2081
% key )
0 commit comments