Merge pull request #137 from jacwah/derive-debug
Derive Debug for distibutions
diff --git a/src/distributions/exponential.rs b/src/distributions/exponential.rs
index 1be1f8d..c3c924c 100644
--- a/src/distributions/exponential.rs
+++ b/src/distributions/exponential.rs
@@ -34,7 +34,7 @@
/// let Exp1(x) = rand::random();
/// println!("{}", x);
/// ```
-#[derive(Clone, Copy)]
+#[derive(Clone, Copy, Debug)]
pub struct Exp1(pub f64);
// This could be done via `-rng.gen::<f64>().ln()` but that is slower.
@@ -71,7 +71,7 @@
/// let v = exp.ind_sample(&mut rand::thread_rng());
/// println!("{} is from a Exp(2) distribution", v);
/// ```
-#[derive(Clone, Copy)]
+#[derive(Clone, Copy, Debug)]
pub struct Exp {
/// `lambda` stored as `1/lambda`, since this is what we scale by.
lambda_inverse: f64
diff --git a/src/distributions/gamma.rs b/src/distributions/gamma.rs
index 7ecbc03..1cff4dd 100644
--- a/src/distributions/gamma.rs
+++ b/src/distributions/gamma.rs
@@ -49,12 +49,12 @@
/// for Generating Gamma Variables" *ACM Trans. Math. Softw.* 26, 3
/// (September 2000),
/// 363-372. DOI:[10.1145/358407.358414](http://doi.acm.org/10.1145/358407.358414)
-#[derive(Clone, Copy)]
+#[derive(Clone, Copy, Debug)]
pub struct Gamma {
repr: GammaRepr,
}
-#[derive(Clone, Copy)]
+#[derive(Clone, Copy, Debug)]
enum GammaRepr {
Large(GammaLargeShape),
One(Exp),
@@ -75,7 +75,7 @@
///
/// See `Gamma` for sampling from a Gamma distribution with general
/// shape parameters.
-#[derive(Clone, Copy)]
+#[derive(Clone, Copy, Debug)]
struct GammaSmallShape {
inv_shape: f64,
large_shape: GammaLargeShape
@@ -85,7 +85,7 @@
///
/// See `Gamma` for sampling from a Gamma distribution with general
/// shape parameters.
-#[derive(Clone, Copy)]
+#[derive(Clone, Copy, Debug)]
struct GammaLargeShape {
scale: f64,
c: f64,
@@ -195,12 +195,12 @@
/// let v = chi.ind_sample(&mut rand::thread_rng());
/// println!("{} is from a χ²(11) distribution", v)
/// ```
-#[derive(Clone, Copy)]
+#[derive(Clone, Copy, Debug)]
pub struct ChiSquared {
repr: ChiSquaredRepr,
}
-#[derive(Clone, Copy)]
+#[derive(Clone, Copy, Debug)]
enum ChiSquaredRepr {
// k == 1, Gamma(alpha, ..) is particularly slow for alpha < 1,
// e.g. when alpha = 1/2 as it would be for this case, so special-
@@ -253,7 +253,7 @@
/// let v = f.ind_sample(&mut rand::thread_rng());
/// println!("{} is from an F(2, 32) distribution", v)
/// ```
-#[derive(Clone, Copy)]
+#[derive(Clone, Copy, Debug)]
pub struct FisherF {
numer: ChiSquared,
denom: ChiSquared,
@@ -297,7 +297,7 @@
/// let v = t.ind_sample(&mut rand::thread_rng());
/// println!("{} is from a t(11) distribution", v)
/// ```
-#[derive(Clone, Copy)]
+#[derive(Clone, Copy, Debug)]
pub struct StudentT {
chi: ChiSquared,
dof: f64
diff --git a/src/distributions/mod.rs b/src/distributions/mod.rs
index 8a9e6d2..f128b75 100644
--- a/src/distributions/mod.rs
+++ b/src/distributions/mod.rs
@@ -17,8 +17,6 @@
//! internally. The `IndependentSample` trait is for generating values
//! that do not need to record state.
-#![allow(missing_debug_implementations)]
-
use std::marker;
use {Rng, Rand};
@@ -55,6 +53,7 @@
/// A wrapper for generating types that implement `Rand` via the
/// `Sample` & `IndependentSample` traits.
+#[derive(Debug)]
pub struct RandSample<Sup> {
_marker: marker::PhantomData<fn() -> Sup>,
}
@@ -81,8 +80,7 @@
}
/// A value with a particular weight for use with `WeightedChoice`.
-#[derive(Copy)]
-#[derive(Clone)]
+#[derive(Copy, Clone, Debug)]
pub struct Weighted<T> {
/// The numerical weight of this item
pub weight: u32,
@@ -115,6 +113,7 @@
/// println!("{}", wc.ind_sample(&mut rng));
/// }
/// ```
+#[derive(Debug)]
pub struct WeightedChoice<'a, T:'a> {
items: &'a mut [Weighted<T>],
weight_range: Range<u32>
diff --git a/src/distributions/normal.rs b/src/distributions/normal.rs
index 42872fa..280613d 100644
--- a/src/distributions/normal.rs
+++ b/src/distributions/normal.rs
@@ -33,7 +33,7 @@
/// let StandardNormal(x) = rand::random();
/// println!("{}", x);
/// ```
-#[derive(Clone, Copy)]
+#[derive(Clone, Copy, Debug)]
pub struct StandardNormal(pub f64);
impl Rand for StandardNormal {
@@ -88,7 +88,7 @@
/// let v = normal.ind_sample(&mut rand::thread_rng());
/// println!("{} is from a N(2, 9) distribution", v)
/// ```
-#[derive(Clone, Copy)]
+#[derive(Clone, Copy, Debug)]
pub struct Normal {
mean: f64,
std_dev: f64,
@@ -136,7 +136,7 @@
/// let v = log_normal.ind_sample(&mut rand::thread_rng());
/// println!("{} is from an ln N(2, 9) distribution", v)
/// ```
-#[derive(Clone, Copy)]
+#[derive(Clone, Copy, Debug)]
pub struct LogNormal {
norm: Normal
}
diff --git a/src/distributions/range.rs b/src/distributions/range.rs
index 3a3f3e7..7206941 100644
--- a/src/distributions/range.rs
+++ b/src/distributions/range.rs
@@ -46,7 +46,7 @@
/// println!("{}", sum);
/// }
/// ```
-#[derive(Clone, Copy)]
+#[derive(Clone, Copy, Debug)]
pub struct Range<X> {
low: X,
range: X,