Skip to content

Commit

Permalink
Add Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
valebes committed Oct 24, 2023
1 parent 4c0e527 commit cf0a522
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions src/templates/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ where
/// vector.
/// In this case, using the OrderedMap template, it is possible
/// to mantain the order of the input in the output.
/// Moreover, using the `build_with_replicas` method,
/// we can create a stage consisting of four map operator,
/// each one composed by 2 worker.
///
/// ```
/// use ppl::{prelude::*, templates::misc::{SourceIter, OrderedSinkVec}, templates::map::OrderedMap};
Expand Down Expand Up @@ -682,6 +685,39 @@ fn simple_map() {
}
}

#[test]
#[serial]
fn simple_map_replicated() {
let mut counter = 1.0;
let numbers: Vec<f64> = vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0];
let mut vector = Vec::new();

for _i in 0..1000 {
vector.push(numbers.clone());
}


let pipe = pipeline![
SourceIter::build(vector.into_iter()),
Map::build_with_replicas(4, 2, |el: f64| square(el)),
SinkVec::build()
];

let res: Vec<Vec<f64>> = pipe.start_and_wait_end().unwrap();

for vec in res {
for el in vec {
assert_eq!(el.sqrt(), counter);
counter += 1.0;
}
counter = 1.0;
}

unsafe {
Orchestrator::delete_global_orchestrator();
}
}

#[test]
#[serial]
fn simple_ordered_map() {
Expand All @@ -698,6 +734,43 @@ fn simple_ordered_map() {
}


let pipe = pipeline![
SourceIter::build(vector.into_iter()),
OrderedMap::build(4, |el: f64| square(el)),
OrderedSinkVec::build()
];

let res: Vec<Vec<f64>> = pipe.start_and_wait_end().unwrap();

counter = 1.0;
for vec in res {
for el in vec {
assert_eq!(el.sqrt(), counter);
counter += 1.0;
}
}

unsafe {
Orchestrator::delete_global_orchestrator();
}
}

#[test]
#[serial]
fn simple_ordered_map_replicated() {
let mut counter = 1.0;
let mut vector = Vec::new();

for _i in 0..1000{
let mut numbers = Vec::new();
for _i in 0..10 {
numbers.push(counter);
counter += 1.0;
}
vector.push(numbers);
}


let pipe = pipeline![
SourceIter::build(vector.into_iter()),
OrderedMap::build_with_replicas(4, 2, |el: f64| square(el)),
Expand Down

0 comments on commit cf0a522

Please sign in to comment.