@@ -80,6 +80,7 @@ cdef extern from "distributions.h":
8080 cdef double random_gauss_zig (aug_state * state ) nogil
8181 cdef double random_gauss_zig_julia (aug_state * state ) nogil
8282 cdef double random_standard_exponential (aug_state * state ) nogil
83+ cdef double random_standard_exponential_ziggurat (aug_state * state ) nogil
8384 cdef double random_standard_cauchy (aug_state * state ) nogil
8485
8586 cdef double random_exponential (aug_state * state , double scale ) nogil
@@ -124,12 +125,14 @@ cdef extern from "distributions.h":
124125
125126 cdef void random_gauss_zig_float_fill (aug_state * state , intptr_t count , float * out ) nogil
126127 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
127129 cdef void random_standard_exponential_fill_float (aug_state * state , intptr_t count , float * out ) nogil
128130 cdef void random_gauss_fill_float (aug_state * state , intptr_t count , float * out ) nogil
129131
130132 cdef void random_gauss_zig_double_fill (aug_state * state , intptr_t count , double * out ) nogil
131133 cdef void random_uniform_fill_double (aug_state * state , intptr_t cnt , double * out ) nogil
132134 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
133136 cdef void random_gauss_fill (aug_state * state , intptr_t count , double * out ) nogil
134137 cdef void random_gauss_zig_julia_fill (aug_state * state , intptr_t count , double * out ) nogil
135138
@@ -2014,9 +2017,9 @@ cdef class RandomState:
20142017 0.0 , '' , CONS_NONE ,
20152018 None )
20162019
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 ):
20182021 """
2019- standard_exponential(size=None, dtype=np.float64, out=None)
2022+ standard_exponential(size=None, dtype=np.float64, method='inv', out=None)
20202023
20212024 Draw samples from the standard exponential distribution.
20222025
@@ -2033,6 +2036,9 @@ cdef class RandomState:
20332036 Desired dtype of the result. All dtypes are determined by their
20342037 name, either 'float64' or 'float32'. The default value is
20352038 '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.
20362042 out : ndarray, optional
20372043 Alternative output array in which to place the result. If size is not None,
20382044 it must have the same shape as the provided size and must match the type of
@@ -2048,17 +2054,28 @@ cdef class RandomState:
20482054 Output a 3x8000 array:
20492055
20502056 >>> n = np.random.standard_exponential((3, 8000))
2051-
20522057 """
2058+ if method != u'zig' and method != u'inv' :
2059+ raise ValueError ("method must be either 'bm' or 'zig'" )
20532060 key = np .dtype (dtype ).name
20542061 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 )
20582070 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 )
20622079 else :
20632080 raise TypeError ('Unsupported dtype "%s" for standard_exponential'
20642081 % key )
0 commit comments