Skip to content

Commit 10a13a2

Browse files
committed
🧹 allow panic if thread pool cannot be created
1 parent 1c78216 commit 10a13a2

File tree

2 files changed

+8
-31
lines changed

2 files changed

+8
-31
lines changed

downsample_rs/src/m4/generic.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub(crate) fn m4_generic_parallel<T: Copy + PartialOrd + Send + Sync>(
8282
.num_threads(n_threads)
8383
.build();
8484

85-
let mut zip_func = || {
85+
let zip_func = || {
8686
Zip::from(sampled_indices.exact_chunks_mut(4)).par_for_each(|mut sampled_index| {
8787
let i: f64 = unsafe { *sampled_index.uget(0) >> 2 } as f64;
8888
let start_idx: usize = (block_size * i) as usize + (i != 0.0) as usize;
@@ -105,13 +105,7 @@ pub(crate) fn m4_generic_parallel<T: Copy + PartialOrd + Send + Sync>(
105105
})
106106
};
107107

108-
if let Ok(pool) = pool {
109-
pool.install(zip_func)
110-
} else {
111-
// if a pool, for some reason, could not be created, we fall back to default Rayon
112-
// behaviour. (Question: Should this be the behaviour in this case?)
113-
zip_func()
114-
}
108+
pool.unwrap().install(zip_func); // allow panic if pool could not be created
115109

116110
sampled_indices
117111
}
@@ -228,11 +222,6 @@ pub(crate) fn m4_generic_with_x_parallel<T: Copy + PartialOrd + Send + Sync>(
228222
.collect::<Vec<usize>>(),
229223
)
230224
};
231-
if let Ok(pool) = pool {
232-
pool.install(iter_func)
233-
} else {
234-
// if a pool, for some reason, could not be created, we fall back to default Rayon
235-
// behaviour. (Question: Should this be the behaviour in this case?)
236-
iter_func()
237-
}
225+
226+
pool.unwrap().install(iter_func) // allow panic if pool could not be created
238227
}

downsample_rs/src/minmax/generic.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub(crate) fn min_max_generic_parallel<T: Copy + PartialOrd + Send + Sync>(
7474
.num_threads(n_threads)
7575
.build();
7676

77-
let mut zip_func = || {
77+
let zip_func = || {
7878
Zip::from(sampled_indices.exact_chunks_mut(2)).par_for_each(|mut sampled_index| {
7979
let i: f64 = unsafe { *sampled_index.uget(0) >> 1 } as f64;
8080
let start_idx: usize = (block_size * i) as usize + (i != 0.0) as usize;
@@ -95,13 +95,7 @@ pub(crate) fn min_max_generic_parallel<T: Copy + PartialOrd + Send + Sync>(
9595
});
9696
};
9797

98-
if let Ok(pool) = pool {
99-
pool.install(zip_func);
100-
} else {
101-
// if a pool, for some reason, could not be created, we fall back to default Rayon
102-
// behaviour. (Question: Should this be the behaviour in this case?)
103-
zip_func();
104-
}
98+
pool.unwrap().install(zip_func); // allow panic if pool could not be created
10599

106100
sampled_indices
107101
}
@@ -170,7 +164,7 @@ pub(crate) fn min_max_generic_with_x_parallel<T: Copy + Send + Sync>(
170164
.num_threads(n_threads)
171165
.build();
172166

173-
let iterator_func = || {
167+
let iter_func = || {
174168
Array1::from_vec(
175169
bin_idx_iterator
176170
.flat_map(|bin_idx_iterator| {
@@ -211,11 +205,5 @@ pub(crate) fn min_max_generic_with_x_parallel<T: Copy + Send + Sync>(
211205
)
212206
};
213207

214-
if let Ok(pool) = pool {
215-
pool.install(iterator_func)
216-
} else {
217-
// if a pool, for some reason, could not be created, we fall back to default Rayon
218-
// behaviour. (Question: Should this be the behaviour in this case?)
219-
iterator_func()
220-
}
208+
pool.unwrap().install(iter_func) // allow panic if pool could not be created
221209
}

0 commit comments

Comments
 (0)