Skip to content

Commit

Permalink
missing Copy impls for distributions.
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamDennis committed Mar 21, 2015
1 parent c6f5bf7 commit 106ad0e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/distributions/gamma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ use super::{Distribution, Exp};
/// 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(Copy)]
pub struct Gamma {
repr: GammaRepr,
}

#[derive(Copy)]
enum GammaRepr {
Large(GammaLargeShape),
One(Exp),
Expand All @@ -75,6 +77,7 @@ enum GammaRepr {
///
/// See `Gamma` for sampling from a Gamma distribution with general
/// shape parameters.
#[derive(Copy)]
struct GammaSmallShape {
inv_shape: f64,
large_shape: GammaLargeShape
Expand All @@ -84,6 +87,7 @@ struct GammaSmallShape {
///
/// See `Gamma` for sampling from a Gamma distribution with general
/// shape parameters.
#[derive(Copy)]
struct GammaLargeShape {
scale: f64,
c: f64,
Expand Down Expand Up @@ -182,10 +186,12 @@ impl Distribution<f64> for GammaLargeShape {
/// let v = chi.sample(&mut rand::thread_rng());
/// println!("{} is from a χ²(11) distribution", v)
/// ```
#[derive(Copy)]
pub struct ChiSquared {
repr: ChiSquaredRepr,
}

#[derive(Copy)]
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-
Expand Down Expand Up @@ -235,6 +241,7 @@ impl Distribution<f64> for ChiSquared {
/// let v = f.sample(&mut rand::thread_rng());
/// println!("{} is from an F(2, 32) distribution", v)
/// ```
#[derive(Copy)]
pub struct FisherF {
numer: ChiSquared,
denom: ChiSquared,
Expand Down Expand Up @@ -275,6 +282,7 @@ impl Distribution<f64> for FisherF {
/// let v = t.sample(&mut rand::thread_rng());
/// println!("{} is from a t(11) distribution", v)
/// ```
#[derive(Copy)]
pub struct StudentT {
chi: ChiSquared,
dof: f64
Expand Down
3 changes: 3 additions & 0 deletions src/distributions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl <'a, D: Distribution<T>, T> Distribution<T> for &'a D {

/// A wrapper for generating types that implement `Distribution` via the
/// `Rand` trait.
#[derive(Copy)]
pub struct RandDistribution<Sup> {
_marker: marker::PhantomData<fn() -> Sup>,
}
Expand All @@ -74,6 +75,8 @@ pub struct Weighted<T> {
pub item: T,
}

impl <T: Copy> Copy for Weighted<T> {}

/// A distribution that selects from a finite collection of weighted items.
///
/// Each item has an associated weight that influences how likely it
Expand Down
2 changes: 2 additions & 0 deletions src/distributions/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ pub struct Range<X> {
accept_zone: X
}

impl <X: Copy> Copy for Range<X> {}

impl<X: RangeDistribution + PartialOrd> Range<X> {
/// Create a new `Range` instance that samples uniformly from
/// `[low, high)`. Panics if `low >= high`.
Expand Down

0 comments on commit 106ad0e

Please sign in to comment.