Skip to content

Commit f6a3205

Browse files
authored
Expand Zip to up to 9 producers (#1559)
As has been discussed in #1175, I expanded `Zip` for up to 9 producers (including `azip!`, `par_azip!`). Previously, it was only working for up to 6 producers. I also added two simple tests with 9 producers.
1 parent 2cf23d6 commit f6a3205

File tree

5 files changed

+56
-3
lines changed

5 files changed

+56
-3
lines changed

src/parallel/impl_par_methods.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,5 +196,8 @@ zip_impl! {
196196
[true P1 P2 P3],
197197
[true P1 P2 P3 P4],
198198
[true P1 P2 P3 P4 P5],
199-
[false P1 P2 P3 P4 P5 P6],
199+
[true P1 P2 P3 P4 P5 P6],
200+
[true P1 P2 P3 P4 P5 P6 P7],
201+
[true P1 P2 P3 P4 P5 P6 P7 P8],
202+
[false P1 P2 P3 P4 P5 P6 P7 P8 P9],
200203
}

src/parallel/par.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,9 @@ zip_impl! {
307307
[P1 P2 P3 P4],
308308
[P1 P2 P3 P4 P5],
309309
[P1 P2 P3 P4 P5 P6],
310+
[P1 P2 P3 P4 P5 P6 P7],
311+
[P1 P2 P3 P4 P5 P6 P7 P8],
312+
[P1 P2 P3 P4 P5 P6 P7 P8 P9],
310313
}
311314

312315
impl<D, Parts> Parallel<Zip<Parts, D>>

src/zip/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,9 @@ offset_impl! {
504504
[A B C D][ a b c d],
505505
[A B C D E][ a b c d e],
506506
[A B C D E F][ a b c d e f],
507+
[A B C D E F G][ a b c d e f g],
508+
[A B C D E F G H][ a b c d e f g h],
509+
[A B C D E F G H I][ a b c d e f g h i],
507510
}
508511

509512
macro_rules! zipt_impl {
@@ -563,6 +566,9 @@ zipt_impl! {
563566
[A B C D][ a b c d],
564567
[A B C D E][ a b c d e],
565568
[A B C D E F][ a b c d e f],
569+
[A B C D E F G][ a b c d e f g],
570+
[A B C D E F G H][ a b c d e f g h],
571+
[A B C D E F G H I][ a b c d e f g h i],
566572
}
567573

568574
macro_rules! map_impl {
@@ -914,7 +920,10 @@ map_impl! {
914920
[true P1 P2 P3],
915921
[true P1 P2 P3 P4],
916922
[true P1 P2 P3 P4 P5],
917-
[false P1 P2 P3 P4 P5 P6],
923+
[true P1 P2 P3 P4 P5 P6],
924+
[true P1 P2 P3 P4 P5 P6 P7],
925+
[true P1 P2 P3 P4 P5 P6 P7 P8],
926+
[false P1 P2 P3 P4 P5 P6 P7 P8 P9],
918927
}
919928

920929
/// Value controlling the execution of `.fold_while` on `Zip`.

tests/azip.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,3 +476,22 @@ fn test_zip_all_empty_array()
476476
assert!(Zip::from(&a).and(&b).all(|&_x, &_y| true));
477477
assert!(Zip::from(&a).and(&b).all(|&_x, &_y| false));
478478
}
479+
480+
#[test]
481+
fn test_azip9()
482+
{
483+
let mut a = Array::<i32, _>::zeros(62);
484+
let b = Array::from_shape_fn(a.dim(), |j| j as i32);
485+
let c = Array::from_shape_fn(a.dim(), |j| (j * 2) as i32);
486+
let d = Array::from_shape_fn(a.dim(), |j| (j * 4) as i32);
487+
let e = Array::from_shape_fn(a.dim(), |j| (j * 8) as i32);
488+
let f = Array::from_shape_fn(a.dim(), |j| (j * 16) as i32);
489+
let g = Array::from_shape_fn(a.dim(), |j| (j * 32) as i32);
490+
let h = Array::from_shape_fn(a.dim(), |j| (j * 64) as i32);
491+
let i = Array::from_shape_fn(a.dim(), |j| (j * 128) as i32);
492+
azip!((a in &mut a, &b in &b, &c in &c, &d in &d, &e in &e, &f in &f, &g in &g, &h in &h, &i in &i){
493+
*a = b + c + d + e + f + g + h + i;
494+
});
495+
let x = Array::from_shape_fn(a.dim(), |j| (j * 255) as i32);
496+
assert_equal(cloned(&a), x);
497+
}

tests/par_azip.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![cfg(feature = "rayon")]
22

33
#[cfg(feature = "approx")]
4-
use itertools::enumerate;
4+
use itertools::{assert_equal, cloned, enumerate};
55
use ndarray::parallel::prelude::*;
66
use ndarray::prelude::*;
77
use std::sync::atomic::{AtomicUsize, Ordering};
@@ -71,3 +71,22 @@ fn test_indices_1()
7171
});
7272
assert_eq!(count.load(Ordering::SeqCst), a1.len());
7373
}
74+
75+
#[test]
76+
fn test_par_azip9()
77+
{
78+
let mut a = Array::<i32, _>::zeros(62);
79+
let b = Array::from_shape_fn(a.dim(), |j| j as i32);
80+
let c = Array::from_shape_fn(a.dim(), |j| (j * 2) as i32);
81+
let d = Array::from_shape_fn(a.dim(), |j| (j * 4) as i32);
82+
let e = Array::from_shape_fn(a.dim(), |j| (j * 8) as i32);
83+
let f = Array::from_shape_fn(a.dim(), |j| (j * 16) as i32);
84+
let g = Array::from_shape_fn(a.dim(), |j| (j * 32) as i32);
85+
let h = Array::from_shape_fn(a.dim(), |j| (j * 64) as i32);
86+
let i = Array::from_shape_fn(a.dim(), |j| (j * 128) as i32);
87+
par_azip!((a in &mut a, &b in &b, &c in &c, &d in &d, &e in &e, &f in &f, &g in &g, &h in &h, &i in &i){
88+
*a = b + c + d + e + f + g + h + i;
89+
});
90+
let x = Array::from_shape_fn(a.dim(), |j| (j * 255) as i32);
91+
assert_equal(cloned(&a), x);
92+
}

0 commit comments

Comments
 (0)