@@ -68,7 +68,9 @@ cdef extern from "distributions.h":
68
68
69
69
cdef void entropy_init (aug_state * state ) nogil
70
70
71
- cdef double random_standard_uniform (aug_state * state ) nogil
71
+ cdef float random_standard_uniform32 (aug_state * state ) nogil
72
+
73
+ cdef double random_standard_uniform64 (aug_state * state ) nogil
72
74
cdef double random_gauss (aug_state * state ) nogil
73
75
cdef double random_gauss_zig (aug_state * state ) nogil
74
76
cdef double random_gauss_zig_julia (aug_state * state ) nogil
@@ -114,7 +116,8 @@ cdef extern from "distributions.h":
114
116
cdef void random_bounded_uint16_fill (aug_state * state , uint16_t off , uint16_t rng , intptr_t cnt , uint16_t * out ) nogil
115
117
cdef void random_bounded_uint8_fill (aug_state * state , uint8_t off , uint8_t rng , intptr_t cnt , uint8_t * out ) nogil
116
118
cdef void random_bounded_bool_fill (aug_state * state , np .npy_bool off , np .npy_bool rng , intptr_t cnt , np .npy_bool * out ) nogil
117
- cdef void random_uniform_fill (aug_state * state , intptr_t cnt , double * out ) nogil
119
+ cdef void random_uniform_fill32 (aug_state * state , intptr_t cnt , double * out ) nogil
120
+ cdef void random_uniform_fill64 (aug_state * state , intptr_t cnt , double * out ) nogil
118
121
cdef void random_standard_exponential_fill (aug_state * state , intptr_t count , double * out ) nogil
119
122
cdef void random_gauss_fill (aug_state * state , intptr_t count , double * out ) nogil
120
123
cdef void random_gauss_zig_julia_fill (aug_state * state , intptr_t count , double * out ) nogil
@@ -680,7 +683,7 @@ cdef class RandomState:
680
683
self .get_state ())
681
684
682
685
# Basic distributions:
683
- def random_sample (self , size = None ):
686
+ def random_sample (self , size = None , dtype = np . float64 ):
684
687
"""
685
688
random_sample(size=None)
686
689
@@ -698,6 +701,9 @@ cdef class RandomState:
698
701
Output shape. If the given shape is, e.g., ``(m, n, k)``, then
699
702
``m * n * k`` samples are drawn. Default is None, in which case a
700
703
single value is returned.
704
+ dtype : dtype, optional
705
+ Desired dtype of the result, either np.float64 (default)
706
+ or np.float32.
701
707
702
708
Returns
703
709
-------
@@ -722,7 +728,12 @@ cdef class RandomState:
722
728
[-1.23204345, -1.75224494]])
723
729
724
730
"""
725
- return double_fill (& self .rng_state , & random_uniform_fill , size , self .lock )
731
+ if dtype is np .float64 :
732
+ return double_fill (& self .rng_state , & random_uniform_fill64 , size , self .lock )
733
+ elif dtype is np .float32 :
734
+ return float_fill (& self .rng_state , & random_uniform_fill32 , size , self .lock )
735
+ else :
736
+ raise ValueError ('Unknown dtype' )
726
737
727
738
def tomaxint (self , size = None ):
728
739
"""
0 commit comments