add a feature = "serde"

This commit is contained in:
Eh2406 2017-12-17 22:11:11 -05:00
parent 60410cd118
commit 046f47a0c2
10 changed files with 14 additions and 0 deletions

View File

@ -13,6 +13,7 @@ keywords = ["stats", "mean", "skewness", "kurtosis", "quantile"]
[dependencies]
conv = { version = "0.3", default-features = false }
quickersort = "3"
serde = { version = "1", default-features = false, optional = true, features = ["derive"]}
[dev-dependencies]
bencher = "0.1"

View File

@ -69,6 +69,9 @@
extern crate conv;
extern crate quickersort;
#[cfg(feature = "serde")]
#[macro_use]
extern crate serde;
#[macro_use] mod macros;
mod moments;

View File

@ -25,6 +25,7 @@ fn max(a: f64, b: f64) -> f64 {
/// println!("The minimum is {}.", a.min());
/// ```
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Min {
r: Reduce<fn(f64, f64) -> f64>,
}
@ -106,6 +107,7 @@ impl Merge for Min {
/// assert_eq!(a.max(), 5.);
/// ```
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Max {
r: Reduce<fn(f64, f64) -> f64>,
}

View File

@ -3,6 +3,7 @@
///
/// This can be used to estimate the standard error of the mean.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Kurtosis {
/// Estimator of mean, variance and skewness.
avg: Skewness,

View File

@ -10,6 +10,7 @@
/// println!("The mean is {}.", a.mean());
/// ```
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Mean {
/// Mean value.
avg: f64,

View File

@ -3,6 +3,7 @@
///
/// This can be used to estimate the standard error of the mean.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Skewness {
/// Estimator of mean and variance.
avg: MeanWithError,

View File

@ -13,6 +13,7 @@
/// println!("The mean is {} ± {}.", a.mean(), a.error());
/// ```
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Variance {
/// Estimator of average.
avg: Mean,

View File

@ -10,6 +10,7 @@ use super::Estimate;
// This uses the P² algorithm introduced here:
// http://www.cs.wustl.edu/~jain/papers/ftp/psqr.pdf
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Quantile {
/// Marker heights.
q: [f64; 5],

View File

@ -7,6 +7,7 @@ use super::{Estimate, Merge};
/// Everything is calculated iteratively using constant memory, so the sequence
/// of numbers can be an iterator.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Reduce<F> {
x: f64,
reduce: F,

View File

@ -17,6 +17,7 @@ use super::{MeanWithError, Estimate, Merge};
/// println!("The weighted mean is {}.", a.mean());
/// ```
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct WeightedMean {
/// Sum of the weights.
weight_sum: f64,
@ -135,6 +136,7 @@ impl Merge for WeightedMean {
/// println!("The weighted mean is {} ± {}.", a.weighted_mean(), a.error());
/// ```
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct WeightedMeanWithError {
/// Sum of the squares of the weights.
weight_sum_sq: f64,