1010
1111//! The Gamma and derived distributions.
1212
13+ use core:: fmt;
14+
1315use self :: GammaRepr :: * ;
1416use self :: ChiSquaredRepr :: * ;
1517
@@ -44,6 +46,19 @@ pub struct Gamma {
4446 repr : GammaRepr ,
4547}
4648
49+ impl fmt:: Debug for Gamma {
50+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
51+ f. debug_struct ( "Gamma" )
52+ . field ( "repr" ,
53+ & match self . repr {
54+ GammaRepr :: Large ( _) => "Large" ,
55+ GammaRepr :: One ( _) => "Exp" ,
56+ GammaRepr :: Small ( _) => "Small"
57+ } )
58+ . finish ( )
59+ }
60+ }
61+
4762enum GammaRepr {
4863 Large ( GammaLargeShape ) ,
4964 One ( Exp ) ,
@@ -182,6 +197,18 @@ pub struct ChiSquared {
182197 repr : ChiSquaredRepr ,
183198}
184199
200+ impl fmt:: Debug for ChiSquared {
201+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
202+ f. debug_struct ( "ChiSquared" )
203+ . field ( "repr" ,
204+ & match self . repr {
205+ ChiSquaredRepr :: DoFExactlyOne => "DoFExactlyOne" ,
206+ ChiSquaredRepr :: DoFAnythingElse ( _) => "DoFAnythingElse" ,
207+ } )
208+ . finish ( )
209+ }
210+ }
211+
185212enum ChiSquaredRepr {
186213 // k == 1, Gamma(alpha, ..) is particularly slow for alpha < 1,
187214 // e.g. when alpha = 1/2 as it would be for this case, so special-
@@ -203,11 +230,13 @@ impl ChiSquared {
203230 ChiSquared { repr : repr }
204231 }
205232}
233+
206234impl Sample < f64 > for ChiSquared {
207235 fn sample < R : Rng > ( & mut self , rng : & mut R ) -> f64 {
208236 self . ind_sample ( rng)
209237 }
210238}
239+
211240impl IndependentSample < f64 > for ChiSquared {
212241 fn ind_sample < R : Rng > ( & self , rng : & mut R ) -> f64 {
213242 match self . repr {
@@ -248,17 +277,29 @@ impl FisherF {
248277 }
249278 }
250279}
280+
251281impl Sample < f64 > for FisherF {
252282 fn sample < R : Rng > ( & mut self , rng : & mut R ) -> f64 {
253283 self . ind_sample ( rng)
254284 }
255285}
286+
256287impl IndependentSample < f64 > for FisherF {
257288 fn ind_sample < R : Rng > ( & self , rng : & mut R ) -> f64 {
258289 self . numer . ind_sample ( rng) / self . denom . ind_sample ( rng) * self . dof_ratio
259290 }
260291}
261292
293+ impl fmt:: Debug for FisherF {
294+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
295+ f. debug_struct ( "FisherF" )
296+ . field ( "numer" , & self . numer )
297+ . field ( "denom" , & self . denom )
298+ . field ( "dof_ratio" , & self . dof_ratio )
299+ . finish ( )
300+ }
301+ }
302+
262303/// The Student t distribution, `t(nu)`, where `nu` is the degrees of
263304/// freedom.
264305pub struct StudentT {
@@ -277,18 +318,29 @@ impl StudentT {
277318 }
278319 }
279320}
321+
280322impl Sample < f64 > for StudentT {
281323 fn sample < R : Rng > ( & mut self , rng : & mut R ) -> f64 {
282324 self . ind_sample ( rng)
283325 }
284326}
327+
285328impl IndependentSample < f64 > for StudentT {
286329 fn ind_sample < R : Rng > ( & self , rng : & mut R ) -> f64 {
287330 let StandardNormal ( norm) = rng. gen :: < StandardNormal > ( ) ;
288331 norm * ( self . dof / self . chi . ind_sample ( rng) ) . sqrt ( )
289332 }
290333}
291334
335+ impl fmt:: Debug for StudentT {
336+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
337+ f. debug_struct ( "StudentT" )
338+ . field ( "chi" , & self . chi )
339+ . field ( "dof" , & self . dof )
340+ . finish ( )
341+ }
342+ }
343+
292344#[ cfg( test) ]
293345mod tests {
294346 use distributions:: { IndependentSample , Sample } ;
0 commit comments