Skip to content

Commit

Permalink
adding stats functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kevloui committed Aug 1, 2020
1 parent a73eb8c commit 9a6965c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions amadeus-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ sum = { version = "0.1", features = ["futures", "serde"] }
tokio = { version = "0.2", features = ["blocking", "rt-core"] }
walkdir = "2.2"
widestring = "0.4"
num = "0.3"

[target.'cfg(target_arch = "wasm32")'.dependencies]
js-sys = "0.3"
Expand Down
24 changes: 18 additions & 6 deletions amadeus-core/src/par_sink/stats.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
extern crate num;

use derive_new::new;
use educe::Educe;
use serde::{Deserialize, Serialize};
use std::{iter, marker::PhantomData, mem};
use num::ToPrimitive;

use super::{
folder_par_sink, FolderSync, FolderSyncReducer, ParallelPipe, ParallelSink
Expand Down Expand Up @@ -42,10 +45,10 @@ pub struct StepB;

impl<B, Item> FolderSync<Item> for MeanFolder<B, StepA>
where
B: iter::Sum<Item> + iter::Sum<B>,
B: iter::Sum<Item> + iter::Sum<B> + ToPrimitive,
{
type State = (B, usize);
type Done = Self::State;
type Done = f64;

#[inline(always)]
fn zero(&mut self) -> Self::State {
Expand All @@ -63,17 +66,21 @@ where
}

#[inline(always)]
fn done(&mut self, state: Self::State) -> Self::Done { state }
fn done(&mut self, state: Self::State) -> Self::Done {
let sum = state.0;
let count = state.1 as f64;
B::to_f64(&sum).map(|sum| sum / count).unwrap()
}
}



impl<B> FolderSync<(B, usize)> for MeanFolder<B, StepB>
where
B: iter::Sum<B>
B: iter::Sum<B> + ToPrimitive,
{
type State = (B, usize);
type Done = Self::State;
type Done = f64;

#[inline(always)]
fn zero(&mut self) -> Self::State {
Expand All @@ -91,6 +98,11 @@ where
}

#[inline(always)]
fn done(&mut self, state: Self::State) -> Self::Done { state }
fn done(&mut self, state: Self::State) -> Self::Done {
let sum = state.0;
let count = state.1 as f64;
B::to_f64(&sum).map(|sum| sum / count).unwrap()

}

}

0 comments on commit 9a6965c

Please sign in to comment.