Skip to content

Commit

Permalink
🧹 remove threaded
Browse files Browse the repository at this point in the history
  • Loading branch information
jvdd committed Jan 23, 2024
1 parent 45fc0d3 commit 3c6d9d9
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 90 deletions.
49 changes: 27 additions & 22 deletions downsample_rs/src/m4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use super::POOL;
// ----------- WITH X

macro_rules! m4_with_x {
($func_name:ident, $trait:path, $func:expr) => {
($func_name:ident, $trait:path, $f_argminmax:expr) => {
pub fn $func_name<Tx, Ty>(x: &[Tx], arr: &[Ty], n_out: usize) -> Vec<usize>
where
for<'a> &'a [Ty]: $trait,
Expand All @@ -23,7 +23,7 @@ macro_rules! m4_with_x {
{
assert_eq!(n_out % 4, 0);
let bin_idx_iterator = get_equidistant_bin_idx_iterator(x, n_out / 4);
m4_generic_with_x(arr, bin_idx_iterator, n_out, $func)
m4_generic_with_x(arr, bin_idx_iterator, n_out, $f_argminmax)
}
};
}
Expand All @@ -34,13 +34,13 @@ m4_with_x!(m4_with_x_nan, NaNArgMinMax, |arr| arr.nanargminmax());
// ----------- WITHOUT X

macro_rules! m4_without_x {
($func_name:ident, $trait:path, $func:expr) => {
($func_name:ident, $trait:path, $f_argminmax:expr) => {
pub fn $func_name<T: Copy + PartialOrd>(arr: &[T], n_out: usize) -> Vec<usize>
where
for<'a> &'a [T]: $trait,
{
assert_eq!(n_out % 4, 0);
m4_generic(arr, n_out, $func)
m4_generic(arr, n_out, $f_argminmax)
}
};
}
Expand All @@ -52,15 +52,19 @@ m4_without_x!(m4_without_x_nan, NaNArgMinMax, |arr| arr.nanargminmax());

// ----------- WITH X

pub fn m4_with_x_parallel<Tx, Ty>(x: &[Tx], arr: &[Ty], n_out: usize) -> Vec<usize>
where
for<'a> &'a [Ty]: ArgMinMax,
Tx: Num + FromPrimitive + AsPrimitive<f64> + Send + Sync,
Ty: Copy + PartialOrd + Send + Sync,
{
assert_eq!(n_out % 4, 0);
let bin_idx_iterator = get_equidistant_bin_idx_iterator_parallel(x, n_out / 4);
m4_generic_with_x_parallel(arr, bin_idx_iterator, n_out, |arr| arr.argminmax())
macro_rules! m4_with_x_parallel {
($func_name:ident, $trait:path, $f_argminmax:expr) => {
pub fn $func_name<Tx, Ty>(x: &[Tx], arr: &[Ty], n_out: usize) -> Vec<usize>
where
for<'a> &'a [Ty]: $trait,
Tx: Num + FromPrimitive + AsPrimitive<f64> + Send + Sync,
Ty: Copy + PartialOrd + Send + Sync,
{
assert_eq!(n_out % 4, 0);
let bin_idx_iterator = get_equidistant_bin_idx_iterator_parallel(x, n_out / 4);
m4_generic_with_x_parallel(arr, bin_idx_iterator, n_out, $f_argminmax)
}
};
}

m4_with_x_parallel!(m4_with_x_parallel, ArgMinMax, |arr| arr.argminmax());
Expand All @@ -69,15 +73,16 @@ m4_with_x_parallel!(m4_with_x_parallel_nan, NaNArgMinMax, |arr| arr

// ----------- WITHOUT X

pub fn m4_without_x_parallel<T: Copy + PartialOrd + Send + Sync>(
arr: &[T],
n_out: usize,
) -> Vec<usize>
where
for<'a> &'a [T]: ArgMinMax,
{
assert_eq!(n_out % 4, 0);
m4_generic_parallel(arr, n_out, |arr| arr.argminmax())
macro_rules! m4_without_x_parallel {
($func_name:ident, $trait:path, $f_argminmax:expr) => {
pub fn $func_name<T: Copy + PartialOrd + Send + Sync>(arr: &[T], n_out: usize) -> Vec<usize>
where
for<'a> &'a [T]: $trait,
{
assert_eq!(n_out % 4, 0);
m4_generic_parallel(arr, n_out, $f_argminmax)
}
};
}

m4_without_x_parallel!(m4_without_x_parallel, ArgMinMax, |arr| arr.argminmax());
Expand Down
49 changes: 27 additions & 22 deletions downsample_rs/src/minmax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use super::POOL;
// ----------- WITH X

macro_rules! min_max_with_x {
($func_name:ident, $trait:path, $func:expr) => {
($func_name:ident, $trait:path, $f_argminmax:expr) => {
pub fn $func_name<Tx, Ty>(x: &[Tx], arr: &[Ty], n_out: usize) -> Vec<usize>
where
for<'a> &'a [Ty]: $trait,
Expand All @@ -24,7 +24,7 @@ macro_rules! min_max_with_x {
{
assert_eq!(n_out % 2, 0);
let bin_idx_iterator = get_equidistant_bin_idx_iterator(x, n_out / 2);
min_max_generic_with_x(arr, bin_idx_iterator, n_out, $func)
min_max_generic_with_x(arr, bin_idx_iterator, n_out, $f_argminmax)
}
};
}
Expand All @@ -35,13 +35,13 @@ min_max_with_x!(min_max_with_x_nan, NaNArgMinMax, |arr| arr.nanargminmax());
// ----------- WITHOUT X

macro_rules! min_max_without_x {
($func_name:ident, $trait:path, $func:expr) => {
($func_name:ident, $trait:path, $f_argminmax:expr) => {
pub fn $func_name<T: Copy + PartialOrd>(arr: &[T], n_out: usize) -> Vec<usize>
where
for<'a> &'a [T]: $trait,
{
assert_eq!(n_out % 2, 0);
min_max_generic(arr, n_out, $func)
min_max_generic(arr, n_out, $f_argminmax)
}
};
}
Expand All @@ -54,15 +54,19 @@ min_max_without_x!(min_max_without_x_nan, NaNArgMinMax, |arr| arr

// ----------- WITH X

pub fn min_max_with_x_parallel<Tx, Ty>(x: &[Tx], arr: &[Ty], n_out: usize) -> Vec<usize>
where
for<'a> &'a [Ty]: ArgMinMax,
Tx: Num + FromPrimitive + AsPrimitive<f64> + Send + Sync,
Ty: Copy + PartialOrd + Send + Sync,
{
assert_eq!(n_out % 2, 0);
let bin_idx_iterator = get_equidistant_bin_idx_iterator_parallel(x, n_out / 2);
min_max_generic_with_x_parallel(arr, bin_idx_iterator, n_out, |arr| arr.argminmax())
macro_rules! min_max_with_x_parallel {
($func_name:ident, $trait:path, $f_argminmax:expr) => {
pub fn $func_name<Tx, Ty>(x: &[Tx], arr: &[Ty], n_out: usize) -> Vec<usize>
where
for<'a> &'a [Ty]: $trait,
Tx: Num + FromPrimitive + AsPrimitive<f64> + Send + Sync,
Ty: Copy + PartialOrd + Send + Sync,
{
assert_eq!(n_out % 2, 0);
let bin_idx_iterator = get_equidistant_bin_idx_iterator_parallel(x, n_out / 2);
min_max_generic_with_x_parallel(arr, bin_idx_iterator, n_out, $f_argminmax)
}
};
}

min_max_with_x_parallel!(min_max_with_x_parallel, ArgMinMax, |arr| arr.argminmax());
Expand All @@ -71,15 +75,16 @@ min_max_with_x_parallel!(min_max_with_x_parallel_nan, NaNArgMinMax, |arr| arr

// ----------- WITHOUT X

pub fn min_max_without_x_parallel<T: Copy + PartialOrd + Send + Sync>(
arr: &[T],
n_out: usize,
) -> Vec<usize>
where
for<'a> &'a [T]: ArgMinMax,
{
assert_eq!(n_out % 2, 0);
min_max_generic_parallel(arr, n_out, |arr| arr.argminmax())
macro_rules! min_max_without_x_parallel {
($func_name:ident, $trait:path, $f_argminmax:expr) => {
pub fn $func_name<T: Copy + PartialOrd + Send + Sync>(arr: &[T], n_out: usize) -> Vec<usize>
where
for<'a> &'a [T]: $trait,
{
assert_eq!(n_out % 2, 0);
min_max_generic_parallel(arr, n_out, $f_argminmax)
}
};
}

min_max_without_x_parallel!(min_max_without_x_parallel, ArgMinMax, |arr| arr.argminmax());
Expand Down
99 changes: 58 additions & 41 deletions downsample_rs/src/minmaxlttb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@ use num_traits::{AsPrimitive, FromPrimitive};

// ----------- WITH X

pub fn minmaxlttb_with_x<Tx: Num + AsPrimitive<f64> + FromPrimitive, Ty: Num + AsPrimitive<f64>>(
x: &[Tx],
y: &[Ty],
n_out: usize,
minmax_ratio: usize,
) -> Vec<usize>
where
for<'a> &'a [Ty]: ArgMinMax,
{
minmaxlttb_generic(x, y, n_out, minmax_ratio, minmax::min_max_with_x)
macro_rules! minmaxlttb_with_x {
($func_name:ident, $trait:ident, $f_minmax:expr) => {
pub fn $func_name<Tx, Ty>(
x: &[Tx],
y: &[Ty],
n_out: usize,
minmax_ratio: usize,
) -> Vec<usize>
where
for<'a> &'a [Ty]: $trait,
Tx: Num + AsPrimitive<f64> + FromPrimitive,
Ty: Num + AsPrimitive<f64>,
{
minmaxlttb_generic(x, y, n_out, minmax_ratio, $f_minmax)
}
};
}

minmaxlttb_with_x!(minmaxlttb_with_x, ArgMinMax, minmax::min_max_with_x);
Expand All @@ -31,15 +37,19 @@ minmaxlttb_with_x!(

// ----------- WITHOUT X

pub fn minmaxlttb_without_x<Ty: Num + AsPrimitive<f64>>(
y: &[Ty],
n_out: usize,
minmax_ratio: usize,
) -> Vec<usize>
where
for<'a> &'a [Ty]: ArgMinMax,
{
minmaxlttb_generic_without_x(y, n_out, minmax_ratio, minmax::min_max_without_x)
macro_rules! minmaxlttb_without_x {
($func_name:ident, $trait:ident, $f_minmax:expr) => {
pub fn $func_name<Ty: Num + AsPrimitive<f64>>(
y: &[Ty],
n_out: usize,
minmax_ratio: usize,
) -> Vec<usize>
where
for<'a> &'a [Ty]: $trait,
{
minmaxlttb_generic_without_x(y, n_out, minmax_ratio, $f_minmax)
}
};
}

minmaxlttb_without_x!(minmaxlttb_without_x, ArgMinMax, minmax::min_max_without_x);
Expand All @@ -53,19 +63,22 @@ minmaxlttb_without_x!(

// ----------- WITH X

pub fn minmaxlttb_with_x_parallel<
Tx: Num + AsPrimitive<f64> + FromPrimitive + Send + Sync,
Ty: Num + AsPrimitive<f64> + Send + Sync,
>(
x: &[Tx],
y: &[Ty],
n_out: usize,
minmax_ratio: usize,
) -> Vec<usize>
where
for<'a> &'a [Ty]: ArgMinMax,
{
minmaxlttb_generic(x, y, n_out, minmax_ratio, minmax::min_max_with_x_parallel)
macro_rules! minmaxlttb_with_x_parallel {
($func_name:ident, $trait:ident, $f_minmax:expr) => {
pub fn $func_name<Tx, Ty>(
x: &[Tx],
y: &[Ty],
n_out: usize,
minmax_ratio: usize,
) -> Vec<usize>
where
for<'a> &'a [Ty]: $trait,
Tx: Num + AsPrimitive<f64> + FromPrimitive + Send + Sync,
Ty: Num + AsPrimitive<f64> + Send + Sync,
{
minmaxlttb_generic(x, y, n_out, minmax_ratio, $f_minmax)
}
};
}

minmaxlttb_with_x_parallel!(
Expand All @@ -81,15 +94,19 @@ minmaxlttb_with_x_parallel!(

// ----------- WITHOUT X

pub fn minmaxlttb_without_x_parallel<Ty: Num + AsPrimitive<f64> + Send + Sync>(
y: &[Ty],
n_out: usize,
minmax_ratio: usize,
) -> Vec<usize>
where
for<'a> &'a [Ty]: ArgMinMax,
{
minmaxlttb_generic_without_x(y, n_out, minmax_ratio, minmax::min_max_without_x_parallel)
macro_rules! minmaxlttb_without_x_parallel {
($func_name:ident, $trait:ident, $f_minmax:expr) => {
pub fn $func_name<Ty: Num + AsPrimitive<f64> + Send + Sync>(
y: &[Ty],
n_out: usize,
minmax_ratio: usize,
) -> Vec<usize>
where
for<'a> &'a [Ty]: $trait,
{
minmaxlttb_generic_without_x(y, n_out, minmax_ratio, $f_minmax)
}
};
}

minmaxlttb_without_x_parallel!(
Expand Down
6 changes: 1 addition & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ macro_rules! _create_pyfuncs_without_x_helper {
}

macro_rules! create_pyfuncs_without_x {
// Use @threaded to differentiate between the single and multithreaded versions
($resample_mod:ident, $resample_fn:ident, $mod:ident) => {
_create_pyfuncs_without_x_helper!(
_create_pyfunc_without_x,
Expand All @@ -205,7 +204,6 @@ macro_rules! create_pyfuncs_without_x {
}

macro_rules! create_pyfuncs_without_x_with_ratio {
// Use @threaded to differentiate between the single and multithreaded versions
($resample_mod:ident, $resample_fn:ident, $mod:ident) => {
_create_pyfuncs_without_x_helper!(
_create_pyfunc_without_x_with_ratio,
Expand Down Expand Up @@ -234,7 +232,6 @@ macro_rules! _create_pyfuncs_with_x_helper {
}

macro_rules! create_pyfuncs_with_x {
// Use @threaded to differentiate between the single and multithreaded versions
($resample_mod:ident, $resample_fn:ident, $mod:ident) => {
_create_pyfuncs_with_x_helper!(_create_pyfunc_with_x, $resample_mod, $resample_fn, $mod);
};
Expand All @@ -244,7 +241,6 @@ macro_rules! create_pyfuncs_with_x {
}

macro_rules! create_pyfuncs_with_x_with_ratio {
// Use @threaded to differentiate between the single and multithreaded versions
($resample_mod:ident, $resample_fn:ident, $mod:ident) => {
_create_pyfuncs_with_x_helper!(
_create_pyfunc_with_x_with_ratio,
Expand Down Expand Up @@ -417,7 +413,7 @@ fn minmaxlttb(_py: Python, m: &PyModule) -> PyResult<()> {
minmaxlttb_without_x_parallel,
parallel_mod
);
create_pyfuncs_without_x_with_ratio!(@nan @threaded
create_pyfuncs_without_x_with_ratio!(@nan
minmaxlttb_mod,
minmaxlttb_without_x_parallel,
parallel_mod
Expand Down

0 comments on commit 3c6d9d9

Please sign in to comment.