File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,7 +19,6 @@ use rand::distributions::IndependentSample;
1919use ndarray:: {
2020 ArrayBase ,
2121 Dimension ,
22- Data ,
2322 DataOwned ,
2423} ;
2524
@@ -103,3 +102,23 @@ unsafe fn to_vec<I>(iter: I) -> Vec<I::Item>
103102 debug_assert_eq ! ( size, result. len( ) ) ;
104103 result
105104}
105+
106+ /// A wrapper type that allows casting f64 distributions to f32
107+ #[ derive( Copy , Clone , Debug ) ]
108+ pub struct F32 < S > ( pub S ) ;
109+
110+ impl < S > Sample < f32 > for F32 < S >
111+ where S : Sample < f64 >
112+ {
113+ fn sample < R > ( & mut self , rng : & mut R ) -> f32 where R : Rng {
114+ self . 0 . sample ( rng) as f32
115+ }
116+ }
117+
118+ impl < S > IndependentSample < f32 > for F32 < S >
119+ where S : IndependentSample < f64 >
120+ {
121+ fn ind_sample < R > ( & self , rng : & mut R ) -> f32 where R : Rng {
122+ self . 0 . ind_sample ( rng) as f32
123+ }
124+ }
You can’t perform that action at this time.
0 commit comments