add a feature = "serde"
This commit is contained in:
parent
60410cd118
commit
046f47a0c2
@ -13,6 +13,7 @@ keywords = ["stats", "mean", "skewness", "kurtosis", "quantile"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
conv = { version = "0.3", default-features = false }
|
conv = { version = "0.3", default-features = false }
|
||||||
quickersort = "3"
|
quickersort = "3"
|
||||||
|
serde = { version = "1", default-features = false, optional = true, features = ["derive"]}
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
bencher = "0.1"
|
bencher = "0.1"
|
||||||
|
@ -69,6 +69,9 @@
|
|||||||
|
|
||||||
extern crate conv;
|
extern crate conv;
|
||||||
extern crate quickersort;
|
extern crate quickersort;
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
#[macro_use]
|
||||||
|
extern crate serde;
|
||||||
|
|
||||||
#[macro_use] mod macros;
|
#[macro_use] mod macros;
|
||||||
mod moments;
|
mod moments;
|
||||||
|
@ -25,6 +25,7 @@ fn max(a: f64, b: f64) -> f64 {
|
|||||||
/// println!("The minimum is {}.", a.min());
|
/// println!("The minimum is {}.", a.min());
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct Min {
|
pub struct Min {
|
||||||
r: Reduce<fn(f64, f64) -> f64>,
|
r: Reduce<fn(f64, f64) -> f64>,
|
||||||
}
|
}
|
||||||
@ -106,6 +107,7 @@ impl Merge for Min {
|
|||||||
/// assert_eq!(a.max(), 5.);
|
/// assert_eq!(a.max(), 5.);
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct Max {
|
pub struct Max {
|
||||||
r: Reduce<fn(f64, f64) -> f64>,
|
r: Reduce<fn(f64, f64) -> f64>,
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
///
|
///
|
||||||
/// This can be used to estimate the standard error of the mean.
|
/// This can be used to estimate the standard error of the mean.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct Kurtosis {
|
pub struct Kurtosis {
|
||||||
/// Estimator of mean, variance and skewness.
|
/// Estimator of mean, variance and skewness.
|
||||||
avg: Skewness,
|
avg: Skewness,
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
/// println!("The mean is {}.", a.mean());
|
/// println!("The mean is {}.", a.mean());
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct Mean {
|
pub struct Mean {
|
||||||
/// Mean value.
|
/// Mean value.
|
||||||
avg: f64,
|
avg: f64,
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
///
|
///
|
||||||
/// This can be used to estimate the standard error of the mean.
|
/// This can be used to estimate the standard error of the mean.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct Skewness {
|
pub struct Skewness {
|
||||||
/// Estimator of mean and variance.
|
/// Estimator of mean and variance.
|
||||||
avg: MeanWithError,
|
avg: MeanWithError,
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
/// println!("The mean is {} ± {}.", a.mean(), a.error());
|
/// println!("The mean is {} ± {}.", a.mean(), a.error());
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct Variance {
|
pub struct Variance {
|
||||||
/// Estimator of average.
|
/// Estimator of average.
|
||||||
avg: Mean,
|
avg: Mean,
|
||||||
|
@ -10,6 +10,7 @@ use super::Estimate;
|
|||||||
// This uses the P² algorithm introduced here:
|
// This uses the P² algorithm introduced here:
|
||||||
// http://www.cs.wustl.edu/~jain/papers/ftp/psqr.pdf
|
// http://www.cs.wustl.edu/~jain/papers/ftp/psqr.pdf
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct Quantile {
|
pub struct Quantile {
|
||||||
/// Marker heights.
|
/// Marker heights.
|
||||||
q: [f64; 5],
|
q: [f64; 5],
|
||||||
|
@ -7,6 +7,7 @@ use super::{Estimate, Merge};
|
|||||||
/// Everything is calculated iteratively using constant memory, so the sequence
|
/// Everything is calculated iteratively using constant memory, so the sequence
|
||||||
/// of numbers can be an iterator.
|
/// of numbers can be an iterator.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct Reduce<F> {
|
pub struct Reduce<F> {
|
||||||
x: f64,
|
x: f64,
|
||||||
reduce: F,
|
reduce: F,
|
||||||
|
@ -17,6 +17,7 @@ use super::{MeanWithError, Estimate, Merge};
|
|||||||
/// println!("The weighted mean is {}.", a.mean());
|
/// println!("The weighted mean is {}.", a.mean());
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct WeightedMean {
|
pub struct WeightedMean {
|
||||||
/// Sum of the weights.
|
/// Sum of the weights.
|
||||||
weight_sum: f64,
|
weight_sum: f64,
|
||||||
@ -135,6 +136,7 @@ impl Merge for WeightedMean {
|
|||||||
/// println!("The weighted mean is {} ± {}.", a.weighted_mean(), a.error());
|
/// println!("The weighted mean is {} ± {}.", a.weighted_mean(), a.error());
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct WeightedMeanWithError {
|
pub struct WeightedMeanWithError {
|
||||||
/// Sum of the squares of the weights.
|
/// Sum of the squares of the weights.
|
||||||
weight_sum_sq: f64,
|
weight_sum_sq: f64,
|
||||||
|
Loading…
Reference in New Issue
Block a user