forked from rajasekarv/vega
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:rajasekarv/native_spark
- Loading branch information
Showing
22 changed files
with
430 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use std::sync::Arc; | ||
use vega::*; | ||
|
||
fn main() -> Result<()> { | ||
let sc = Context::new()?; | ||
let col1 = vec![1, 2, 3, 4, 5, 10, 12, 13, 19, 0]; | ||
|
||
let col2 = vec![3, 4, 5, 6, 7, 8, 11, 13]; | ||
|
||
let first = sc.parallelize(col1, 4); | ||
let second = sc.parallelize(col2, 4); | ||
let ans = first.subtract(Arc::new(second)); | ||
|
||
for elem in ans.collect().iter() { | ||
println!("{:?}", elem); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use std::collections::HashMap; | ||
use std::hash::Hash; | ||
|
||
use crate::partial::{ | ||
approximate_evaluator::ApproximateEvaluator, bounded_double::BoundedDouble, | ||
count_evaluator::bound, | ||
}; | ||
use crate::serializable_traits::Data; | ||
|
||
/// An ApproximateEvaluator for counts by key. Returns a map of key to confidence interval. | ||
pub(crate) struct GroupedCountEvaluator<T> | ||
where | ||
T: Eq + Hash, | ||
{ | ||
total_outputs: usize, | ||
confidence: f64, | ||
outputs_merged: usize, | ||
sums: HashMap<T, usize>, | ||
} | ||
|
||
impl<T: Eq + Hash> GroupedCountEvaluator<T> { | ||
pub fn new(total_outputs: usize, confidence: f64) -> Self { | ||
GroupedCountEvaluator { | ||
total_outputs, | ||
confidence, | ||
outputs_merged: 0, | ||
sums: HashMap::new(), | ||
} | ||
} | ||
} | ||
|
||
impl<T: Data + Eq + Hash> ApproximateEvaluator<HashMap<T, usize>, HashMap<T, BoundedDouble>> | ||
for GroupedCountEvaluator<T> | ||
{ | ||
fn merge(&mut self, _output_id: usize, task_result: &HashMap<T, usize>) { | ||
self.outputs_merged += 1; | ||
task_result.iter().for_each(|(k, v)| { | ||
*self.sums.entry(k.clone()).or_insert(0) += v; | ||
}); | ||
} | ||
|
||
fn current_result(&self) -> HashMap<T, BoundedDouble> { | ||
if self.outputs_merged == 0 { | ||
HashMap::new() | ||
} else if self.outputs_merged == self.total_outputs { | ||
self.sums | ||
.iter() | ||
.map(|(k, sum)| { | ||
let sum = *sum as f64; | ||
(k.clone(), BoundedDouble::from((sum, 1.0, sum, sum))) | ||
}) | ||
.collect() | ||
} else { | ||
let p = self.outputs_merged as f64 / self.total_outputs as f64; | ||
self.sums | ||
.iter() | ||
.map(|(k, sum)| (k.clone(), bound(self.confidence, *sum as f64, p))) | ||
.collect() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.