Skip to content

Commit fb77592

Browse files
committed
replace Zip::apply with Zip::for_each in benches and docs
1 parent aff9b03 commit fb77592

File tree

9 files changed

+33
-33
lines changed

9 files changed

+33
-33
lines changed

benches/bench1.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ fn add_2d_zip(bench: &mut test::Bencher) {
255255
let mut a = Array::<i32, _>::zeros((ADD2DSZ, ADD2DSZ));
256256
let b = Array::<i32, _>::zeros((ADD2DSZ, ADD2DSZ));
257257
bench.iter(|| {
258-
Zip::from(&mut a).and(&b).apply(|a, &b| *a += b);
258+
Zip::from(&mut a).and(&b).for_each(|a, &b| *a += b);
259259
});
260260
}
261261

@@ -284,7 +284,7 @@ fn add_2d_alloc_zip_collect(bench: &mut test::Bencher) {
284284
let a = Array::<i32, _>::zeros((ADD2DSZ, ADD2DSZ));
285285
let b = Array::<i32, _>::zeros((ADD2DSZ, ADD2DSZ));
286286
bench.iter(|| {
287-
Zip::from(&a).and(&b).apply_collect(|&x, &y| x + y)
287+
Zip::from(&a).and(&b).map_collect(|&x, &y| x + y)
288288
});
289289
}
290290

@@ -300,7 +300,7 @@ fn vec_string_collect(bench: &mut test::Bencher) {
300300
fn array_string_collect(bench: &mut test::Bencher) {
301301
let v = Array::from(vec![""; 10240]);
302302
bench.iter(|| {
303-
Zip::from(&v).apply_collect(|s| s.to_owned())
303+
Zip::from(&v).map_collect(|s| s.to_owned())
304304
});
305305
}
306306

@@ -316,7 +316,7 @@ fn vec_f64_collect(bench: &mut test::Bencher) {
316316
fn array_f64_collect(bench: &mut test::Bencher) {
317317
let v = Array::from(vec![1.; 10240]);
318318
bench.iter(|| {
319-
Zip::from(&v).apply_collect(|s| s + 1.)
319+
Zip::from(&v).map_collect(|s| s + 1.)
320320
});
321321
}
322322

@@ -350,7 +350,7 @@ fn add_2d_zip_cutout(bench: &mut test::Bencher) {
350350
let mut acut = a.slice_mut(s![1..-1, 1..-1]);
351351
let b = Array::<i32, _>::zeros((ADD2DSZ, ADD2DSZ));
352352
bench.iter(|| {
353-
Zip::from(&mut acut).and(&b).apply(|a, &b| *a += b);
353+
Zip::from(&mut acut).and(&b).for_each(|a, &b| *a += b);
354354
});
355355
}
356356

@@ -363,7 +363,7 @@ fn add_2d_cutouts_by_4(bench: &mut test::Bencher) {
363363
bench.iter(|| {
364364
Zip::from(a.exact_chunks_mut(chunksz))
365365
.and(b.exact_chunks(chunksz))
366-
.apply(|mut a, b| a += &b);
366+
.for_each(|mut a, b| a += &b);
367367
});
368368
}
369369

@@ -376,7 +376,7 @@ fn add_2d_cutouts_by_16(bench: &mut test::Bencher) {
376376
bench.iter(|| {
377377
Zip::from(a.exact_chunks_mut(chunksz))
378378
.and(b.exact_chunks(chunksz))
379-
.apply(|mut a, b| a += &b);
379+
.for_each(|mut a, b| a += &b);
380380
});
381381
}
382382

@@ -389,7 +389,7 @@ fn add_2d_cutouts_by_32(bench: &mut test::Bencher) {
389389
bench.iter(|| {
390390
Zip::from(a.exact_chunks_mut(chunksz))
391391
.and(b.exact_chunks(chunksz))
392-
.apply(|mut a, b| a += &b);
392+
.for_each(|mut a, b| a += &b);
393393
});
394394
}
395395

@@ -511,7 +511,7 @@ fn add_2d_zip_strided(bench: &mut test::Bencher) {
511511
let mut a = a.slice_mut(s![.., ..;2]);
512512
let b = Array::<i32, _>::zeros((ADD2DSZ, ADD2DSZ));
513513
bench.iter(|| {
514-
Zip::from(&mut a).and(&b).apply(|a, &b| *a += b);
514+
Zip::from(&mut a).and(&b).for_each(|a, &b| *a += b);
515515
});
516516
}
517517

@@ -531,7 +531,7 @@ fn add_2d_zip_one_transposed(bench: &mut test::Bencher) {
531531
a.swap_axes(0, 1);
532532
let b = Array::<i32, _>::zeros((ADD2DSZ, ADD2DSZ));
533533
bench.iter(|| {
534-
Zip::from(&mut a).and(&b).apply(|a, &b| *a += b);
534+
Zip::from(&mut a).and(&b).for_each(|a, &b| *a += b);
535535
});
536536
}
537537

@@ -553,7 +553,7 @@ fn add_2d_zip_both_transposed(bench: &mut test::Bencher) {
553553
let mut b = Array::<i32, _>::zeros((ADD2DSZ, ADD2DSZ));
554554
b.swap_axes(0, 1);
555555
bench.iter(|| {
556-
Zip::from(&mut a).and(&b).apply(|a, &b| *a += b);
556+
Zip::from(&mut a).and(&b).for_each(|a, &b| *a += b);
557557
});
558558
}
559559

benches/iter.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ fn indexed_zip_1d_ix1(bench: &mut Bencher) {
249249
}
250250

251251
bench.iter(|| {
252-
Zip::indexed(&a).apply(|i, &_elt| {
252+
Zip::indexed(&a).for_each(|i, &_elt| {
253253
black_box(i);
254254
//assert!(a[i] == elt);
255255
});
@@ -278,7 +278,7 @@ fn indexed_zip_2d_ix2(bench: &mut Bencher) {
278278
}
279279

280280
bench.iter(|| {
281-
Zip::indexed(&a).apply(|i, &_elt| {
281+
Zip::indexed(&a).for_each(|i, &_elt| {
282282
black_box(i);
283283
//assert!(a[i] == elt);
284284
});
@@ -308,7 +308,7 @@ fn indexed_zip_3d_ix3(bench: &mut Bencher) {
308308
}
309309

310310
bench.iter(|| {
311-
Zip::indexed(&a).apply(|i, &_elt| {
311+
Zip::indexed(&a).for_each(|i, &_elt| {
312312
black_box(i);
313313
//assert!(a[i] == elt);
314314
});

benches/par_rayon.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ fn vec_string_collect(bench: &mut test::Bencher) {
152152
fn array_string_collect(bench: &mut test::Bencher) {
153153
let v = Array::from_elem((COLL_STRING_N, COLL_STRING_N), "");
154154
bench.iter(|| {
155-
Zip::from(&v).par_apply_collect(|s| s.to_owned())
155+
Zip::from(&v).par_map_collect(|s| s.to_owned())
156156
});
157157
}
158158

@@ -168,7 +168,7 @@ fn vec_f64_collect(bench: &mut test::Bencher) {
168168
fn array_f64_collect(bench: &mut test::Bencher) {
169169
let v = Array::from_elem((COLL_F64_N, COLL_F64_N), 1.);
170170
bench.iter(|| {
171-
Zip::from(&v).par_apply_collect(|s| s + 1.)
171+
Zip::from(&v).par_map_collect(|s| s + 1.)
172172
});
173173
}
174174

benches/zip.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub fn zip_copy<'a, A, P, Q>(data: P, out: Q)
1010
Q: IntoNdProducer<Item = &'a mut A, Dim = P::Dim>,
1111
A: Copy + 'a
1212
{
13-
Zip::from(data).and(out).apply(|&i, o| {
13+
Zip::from(data).and(out).for_each(|&i, o| {
1414
*o = i;
1515
});
1616
}
@@ -25,14 +25,14 @@ pub fn zip_copy_split<'a, A, P, Q>(data: P, out: Q)
2525
let (z11, z12) = z1.split();
2626
let (z21, z22) = z2.split();
2727
let f = |&i: &A, o: &mut A| *o = i;
28-
z11.apply(f);
29-
z12.apply(f);
30-
z21.apply(f);
31-
z22.apply(f);
28+
z11.for_each(f);
29+
z12.for_each(f);
30+
z21.for_each(f);
31+
z22.for_each(f);
3232
}
3333

3434
pub fn zip_indexed(data: &Array3<f32>, out: &mut Array3<f32>) {
35-
Zip::indexed(data).and(out).apply(|idx, &i, o| {
35+
Zip::indexed(data).and(out).for_each(|idx, &i, o| {
3636
let _ = black_box(idx);
3737
*o = i;
3838
});

src/impl_constructors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ where
534534
/// A: Clone + 'a
535535
/// {
536536
/// Zip::from(from)
537-
/// .apply_assign_into(to, A::clone);
537+
/// .map_assign_into(to, A::clone);
538538
/// }
539539
///
540540
/// # shift_by_two(&Array2::zeros((8, 8)));

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ pub type Ixs = isize;
447447
///
448448
/// Zip::from(a.rows())
449449
/// .and(&mut b)
450-
/// .apply(|a_row, b_elt| {
450+
/// .for_each(|a_row, b_elt| {
451451
/// *b_elt = a_row[a.ncols() - 1] - a_row[0];
452452
/// });
453453
/// ```

src/parallel/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
//!
2222
//! - [`ArrayBase::par_map_inplace()`]
2323
//! - [`ArrayBase::par_mapv_inplace()`]
24-
//! - [`Zip::par_apply()`] (all arities)
25-
//! - [`Zip::par_apply_collect()`] (all arities)
26-
//! - [`Zip::par_apply_assign_into()`] (all arities)
24+
//! - [`Zip::par_for_each()`] (all arities)
25+
//! - [`Zip::par_map_collect()`] (all arities)
26+
//! - [`Zip::par_map_assign_into()`] (all arities)
2727
//!
2828
//! Note that you can use the parallel iterator for [Zip] to access all other
2929
//! rayon parallel iterator methods.
@@ -115,7 +115,7 @@
115115
//! Zip::from(&mut c)
116116
//! .and(&a)
117117
//! .and(&b)
118-
//! .par_apply(|c, &a, &b| {
118+
//! .par_for_each(|c, &a, &b| {
119119
//! *c += a - b;
120120
//! });
121121
//! }

src/zip/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,9 @@ impl<A, D: Dimension> NdProducer for RawArrayViewMut<A, D> {
571571
/// assert_eq!(totals, a.sum_axis(Axis(1)));
572572
///
573573
///
574-
/// // Example 3: Recreate Example 2 using apply_collect to make a new array
574+
/// // Example 3: Recreate Example 2 using map_collect to make a new array
575575
///
576-
/// let mut totals2 = Zip::from(a.rows()).apply_collect(|row| row.sum());
576+
/// let mut totals2 = Zip::from(a.rows()).map_collect(|row| row.sum());
577577
///
578578
/// // Check the result against the previous example.
579579
/// assert_eq!(totals, totals2);
@@ -722,7 +722,7 @@ where
722722
}
723723
}
724724

725-
/// The innermost loop of the Zip apply methods
725+
/// The innermost loop of the Zip for_each methods
726726
///
727727
/// Run the fold while operation on a stretch of elements with constant strides
728728
///
@@ -1165,7 +1165,7 @@ macro_rules! map_impl {
11651165
$($p: NdProducer<Dim=D> ,)*
11661166
PLast: NdProducer<Dim = D, Item = *mut R, Ptr = *mut R, Stride = isize>,
11671167
{
1168-
/// The inner workings of apply_collect and par_apply_collect
1168+
/// The inner workings of map_collect and par_map_collect
11691169
///
11701170
/// Apply the function and collect the results into the output (last producer)
11711171
/// which should be a raw array view; a Partial that owns the written

tests/par_zip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fn test_zip_index_4() {
7676
fn test_zip_collect() {
7777
use approx::assert_abs_diff_eq;
7878

79-
// test Zip::apply_collect and that it preserves c/f layout.
79+
// test Zip::map_collect and that it preserves c/f layout.
8080

8181
let b = Array::from_shape_fn((M, N), |(i, j)| 1. / (i + 2 * j + 1) as f32);
8282
let c = Array::from_shape_fn((M, N), |(i, j)| f32::ln((1 + i + j) as f32));

0 commit comments

Comments
 (0)