Skip to content

Commit 1f5b8d5

Browse files
committed
API: Rename apply_collect, apply_collect_into to map_collect, map_collect_into
1 parent f4dfa50 commit 1f5b8d5

File tree

6 files changed

+70
-22
lines changed

6 files changed

+70
-22
lines changed

src/parallel/impl_par_methods.rs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ macro_rules! zip_impl {
8686

8787
expand_if!(@bool [$notlast]
8888

89-
/// Apply and collect the results into a new array, which has the same size as the
89+
/// Map and collect the results into a new array, which has the same size as the
9090
/// inputs.
9191
///
9292
/// If all inputs are c- or f-order respectively, that is preserved in the output.
93-
pub fn par_apply_collect<R>(self, f: impl Fn($($p::Item,)* ) -> R + Sync + Send)
93+
pub fn par_map_collect<R>(self, f: impl Fn($($p::Item,)* ) -> R + Sync + Send)
9494
-> Array<R, D>
9595
where R: Send
9696
{
@@ -135,12 +135,24 @@ macro_rules! zip_impl {
135135
}
136136
}
137137

138-
/// Apply and assign the results into the producer `into`, which should have the same
138+
/// Map and collect the results into a new array, which has the same size as the
139+
/// inputs.
140+
///
141+
/// If all inputs are c- or f-order respectively, that is preserved in the output.
142+
#[deprecated(note="Renamed to .par_map_collect()", since="0.15.0")]
143+
pub fn par_apply_collect<R>(self, f: impl Fn($($p::Item,)* ) -> R + Sync + Send)
144+
-> Array<R, D>
145+
where R: Send
146+
{
147+
self.par_map_collect(f)
148+
}
149+
150+
/// Map and assign the results into the producer `into`, which should have the same
139151
/// size as the other inputs.
140152
///
141153
/// The producer should have assignable items as dictated by the `AssignElem` trait,
142154
/// for example `&mut R`.
143-
pub fn par_apply_assign_into<R, Q>(self, into: Q, f: impl Fn($($p::Item,)* ) -> R + Sync + Send)
155+
pub fn par_map_assign_into<R, Q>(self, into: Q, f: impl Fn($($p::Item,)* ) -> R + Sync + Send)
144156
where Q: IntoNdProducer<Dim=D>,
145157
Q::Item: AssignElem<R> + Send,
146158
Q::Output: Send,
@@ -150,6 +162,21 @@ macro_rules! zip_impl {
150162
output_.assign_elem(f($($p ),*));
151163
});
152164
}
165+
166+
/// Apply and assign the results into the producer `into`, which should have the same
167+
/// size as the other inputs.
168+
///
169+
/// The producer should have assignable items as dictated by the `AssignElem` trait,
170+
/// for example `&mut R`.
171+
#[deprecated(note="Renamed to .par_map_assign_into()", since="0.15.0")]
172+
pub fn par_apply_assign_into<R, Q>(self, into: Q, f: impl Fn($($p::Item,)* ) -> R + Sync + Send)
173+
where Q: IntoNdProducer<Dim=D>,
174+
Q::Item: AssignElem<R> + Send,
175+
Q::Output: Send,
176+
{
177+
self.par_map_assign_into(into, f)
178+
}
179+
153180
);
154181
}
155182
)+

src/traversal_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ pub(crate) fn assign_to<'a, P1, P2, A>(from: P1, to: P2)
2121
A: Clone + 'a
2222
{
2323
Zip::from(from)
24-
.apply_assign_into(to, A::clone);
24+
.map_assign_into(to, A::clone);
2525
}
2626

src/zip/mod.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,12 +1074,11 @@ macro_rules! map_impl {
10741074
}
10751075
}
10761076

1077-
/// Apply and collect the results into a new array, which has the same size as the
1077+
/// Map and collect the results into a new array, which has the same size as the
10781078
/// inputs.
10791079
///
10801080
/// If all inputs are c- or f-order respectively, that is preserved in the output.
1081-
pub fn apply_collect<R>(self, f: impl FnMut($($p::Item,)* ) -> R) -> Array<R, D>
1082-
{
1081+
pub fn map_collect<R>(self, f: impl FnMut($($p::Item,)* ) -> R) -> Array<R, D> {
10831082
// Make uninit result
10841083
let mut output = self.uninitalized_for_current_layout::<R>();
10851084

@@ -1095,12 +1094,21 @@ macro_rules! map_impl {
10951094
}
10961095
}
10971096

1098-
/// Apply and assign the results into the producer `into`, which should have the same
1097+
/// Map and collect the results into a new array, which has the same size as the
1098+
/// inputs.
1099+
///
1100+
/// If all inputs are c- or f-order respectively, that is preserved in the output.
1101+
#[deprecated(note="Renamed to .map_collect()", since="0.15.0")]
1102+
pub fn apply_collect<R>(self, f: impl FnMut($($p::Item,)* ) -> R) -> Array<R, D> {
1103+
self.map_collect(f)
1104+
}
1105+
1106+
/// Map and assign the results into the producer `into`, which should have the same
10991107
/// size as the other inputs.
11001108
///
11011109
/// The producer should have assignable items as dictated by the `AssignElem` trait,
11021110
/// for example `&mut R`.
1103-
pub fn apply_assign_into<R, Q>(self, into: Q, mut f: impl FnMut($($p::Item,)* ) -> R)
1111+
pub fn map_assign_into<R, Q>(self, into: Q, mut f: impl FnMut($($p::Item,)* ) -> R)
11041112
where Q: IntoNdProducer<Dim=D>,
11051113
Q::Item: AssignElem<R>
11061114
{
@@ -1110,6 +1118,19 @@ macro_rules! map_impl {
11101118
});
11111119
}
11121120

1121+
/// Map and assign the results into the producer `into`, which should have the same
1122+
/// size as the other inputs.
1123+
///
1124+
/// The producer should have assignable items as dictated by the `AssignElem` trait,
1125+
/// for example `&mut R`.
1126+
#[deprecated(note="Renamed to .map_assign_into()", since="0.15.0")]
1127+
pub fn apply_assign_into<R, Q>(self, into: Q, f: impl FnMut($($p::Item,)* ) -> R)
1128+
where Q: IntoNdProducer<Dim=D>,
1129+
Q::Item: AssignElem<R>
1130+
{
1131+
self.map_assign_into(into, f)
1132+
}
1133+
11131134

11141135
);
11151136

tests/azip.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ fn test_azip2_3() {
5454
fn test_zip_collect() {
5555
use approx::assert_abs_diff_eq;
5656

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

5959
let b = Array::from_shape_fn((5, 10), |(i, j)| 1. / (i + 2 * j + 1) as f32);
6060
let c = Array::from_shape_fn((5, 10), |(i, j)| f32::exp((i + j) as f32));
6161

6262
{
63-
let a = Zip::from(&b).and(&c).apply_collect(|x, y| x + y);
63+
let a = Zip::from(&b).and(&c).map_collect(|x, y| x + y);
6464

6565
assert_abs_diff_eq!(a, &b + &c, epsilon = 1e-6);
6666
assert_eq!(a.strides(), b.strides());
@@ -70,7 +70,7 @@ fn test_zip_collect() {
7070
let b = b.t();
7171
let c = c.t();
7272

73-
let a = Zip::from(&b).and(&c).apply_collect(|x, y| x + y);
73+
let a = Zip::from(&b).and(&c).map_collect(|x, y| x + y);
7474

7575
assert_abs_diff_eq!(a, &b + &c, epsilon = 1e-6);
7676
assert_eq!(a.strides(), b.strides());
@@ -86,7 +86,7 @@ fn test_zip_assign_into() {
8686
let b = Array::from_shape_fn((5, 10), |(i, j)| 1. / (i + 2 * j + 1) as f32);
8787
let c = Array::from_shape_fn((5, 10), |(i, j)| f32::exp((i + j) as f32));
8888

89-
Zip::from(&b).and(&c).apply_assign_into(&mut a, |x, y| x + y);
89+
Zip::from(&b).and(&c).map_assign_into(&mut a, |x, y| x + y);
9090

9191
assert_abs_diff_eq!(a, &b + &c, epsilon = 1e-6);
9292
}
@@ -101,7 +101,7 @@ fn test_zip_assign_into_cell() {
101101
let b = Array::from_shape_fn((5, 10), |(i, j)| 1. / (i + 2 * j + 1) as f32);
102102
let c = Array::from_shape_fn((5, 10), |(i, j)| f32::exp((i + j) as f32));
103103

104-
Zip::from(&b).and(&c).apply_assign_into(&a, |x, y| x + y);
104+
Zip::from(&b).and(&c).map_assign_into(&a, |x, y| x + y);
105105
let a2 = a.mapv(|elt| elt.get());
106106

107107
assert_abs_diff_eq!(a2, &b + &c, epsilon = 1e-6);
@@ -154,7 +154,7 @@ fn test_zip_collect_drop() {
154154
}
155155

156156
let _result = panic::catch_unwind(panic::AssertUnwindSafe(|| {
157-
Zip::from(&a).and(&b).apply_collect(|&elt, _| {
157+
Zip::from(&a).and(&b).map_collect(|&elt, _| {
158158
if elt.0 > 3 && will_panic {
159159
panic!();
160160
}
@@ -308,7 +308,7 @@ fn test_indices_0() {
308308
let a1 = arr0(3);
309309

310310
let mut count = 0;
311-
Zip::indexed(&a1).apply(|i, elt| {
311+
Zip::indexed(&a1).for_each(|i, elt| {
312312
count += 1;
313313
assert_eq!(i, ());
314314
assert_eq!(*elt, 3);

tests/par_zip.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ fn test_zip_collect() {
8282
let c = Array::from_shape_fn((M, N), |(i, j)| f32::ln((1 + i + j) as f32));
8383

8484
{
85-
let a = Zip::from(&b).and(&c).par_apply_collect(|x, y| x + y);
85+
let a = Zip::from(&b).and(&c).par_map_collect(|x, y| x + y);
8686

8787
assert_abs_diff_eq!(a, &b + &c, epsilon = 1e-6);
8888
assert_eq!(a.strides(), b.strides());
@@ -92,7 +92,7 @@ fn test_zip_collect() {
9292
let b = b.t();
9393
let c = c.t();
9494

95-
let a = Zip::from(&b).and(&c).par_apply_collect(|x, y| x + y);
95+
let a = Zip::from(&b).and(&c).par_map_collect(|x, y| x + y);
9696

9797
assert_abs_diff_eq!(a, &b + &c, epsilon = 1e-6);
9898
assert_eq!(a.strides(), b.strides());
@@ -112,7 +112,7 @@ fn test_zip_small_collect() {
112112
let c = Array::from_shape_fn(dim, |(i, j)| f32::ln((1 + i + j) as f32));
113113

114114
{
115-
let a = Zip::from(&b).and(&c).par_apply_collect(|x, y| x + y);
115+
let a = Zip::from(&b).and(&c).par_map_collect(|x, y| x + y);
116116

117117
assert_abs_diff_eq!(a, &b + &c, epsilon = 1e-6);
118118
assert_eq!(a.strides(), b.strides());
@@ -130,7 +130,7 @@ fn test_zip_assign_into() {
130130
let b = Array::from_shape_fn((M, N), |(i, j)| 1. / (i + 2 * j + 1) as f32);
131131
let c = Array::from_shape_fn((M, N), |(i, j)| f32::ln((1 + i + j) as f32));
132132

133-
Zip::from(&b).and(&c).par_apply_assign_into(&mut a, |x, y| x + y);
133+
Zip::from(&b).and(&c).par_map_assign_into(&mut a, |x, y| x + y);
134134

135135
assert_abs_diff_eq!(a, &b + &c, epsilon = 1e-6);
136136
}

tests/views.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn cell_view() {
1010
let cv1 = a.cell_view();
1111
let cv2 = cv1;
1212

13-
Zip::from(cv1).and(cv2).apply(|a, b| a.set(b.get() + 1.));
13+
Zip::from(cv1).and(cv2).for_each(|a, b| a.set(b.get() + 1.));
1414
}
1515
assert_eq!(a, answer);
1616
}

0 commit comments

Comments
 (0)