From 3c6d9d958612fb4a83e340879faf3d5df8eaf359 Mon Sep 17 00:00:00 2001 From: jvdd Date: Tue, 23 Jan 2024 18:00:03 +0100 Subject: [PATCH] :broom: remove threaded --- downsample_rs/src/m4.rs | 49 ++++++++-------- downsample_rs/src/minmax.rs | 49 ++++++++-------- downsample_rs/src/minmaxlttb.rs | 99 +++++++++++++++++++-------------- src/lib.rs | 6 +- 4 files changed, 113 insertions(+), 90 deletions(-) diff --git a/downsample_rs/src/m4.rs b/downsample_rs/src/m4.rs index 71d5689..75ce224 100644 --- a/downsample_rs/src/m4.rs +++ b/downsample_rs/src/m4.rs @@ -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(x: &[Tx], arr: &[Ty], n_out: usize) -> Vec where for<'a> &'a [Ty]: $trait, @@ -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) } }; } @@ -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(arr: &[T], n_out: usize) -> Vec 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) } }; } @@ -52,15 +52,19 @@ m4_without_x!(m4_without_x_nan, NaNArgMinMax, |arr| arr.nanargminmax()); // ----------- WITH X -pub fn m4_with_x_parallel(x: &[Tx], arr: &[Ty], n_out: usize) -> Vec -where - for<'a> &'a [Ty]: ArgMinMax, - Tx: Num + FromPrimitive + AsPrimitive + 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(x: &[Tx], arr: &[Ty], n_out: usize) -> Vec + where + for<'a> &'a [Ty]: $trait, + Tx: Num + FromPrimitive + AsPrimitive + 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()); @@ -69,15 +73,16 @@ m4_with_x_parallel!(m4_with_x_parallel_nan, NaNArgMinMax, |arr| arr // ----------- WITHOUT X -pub fn m4_without_x_parallel( - arr: &[T], - n_out: usize, -) -> Vec -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(arr: &[T], n_out: usize) -> Vec + 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()); diff --git a/downsample_rs/src/minmax.rs b/downsample_rs/src/minmax.rs index dc50849..12553d2 100644 --- a/downsample_rs/src/minmax.rs +++ b/downsample_rs/src/minmax.rs @@ -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(x: &[Tx], arr: &[Ty], n_out: usize) -> Vec where for<'a> &'a [Ty]: $trait, @@ -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) } }; } @@ -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(arr: &[T], n_out: usize) -> Vec 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) } }; } @@ -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(x: &[Tx], arr: &[Ty], n_out: usize) -> Vec -where - for<'a> &'a [Ty]: ArgMinMax, - Tx: Num + FromPrimitive + AsPrimitive + 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(x: &[Tx], arr: &[Ty], n_out: usize) -> Vec + where + for<'a> &'a [Ty]: $trait, + Tx: Num + FromPrimitive + AsPrimitive + 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()); @@ -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( - arr: &[T], - n_out: usize, -) -> Vec -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(arr: &[T], n_out: usize) -> Vec + 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()); diff --git a/downsample_rs/src/minmaxlttb.rs b/downsample_rs/src/minmaxlttb.rs index 1654fa4..959694b 100644 --- a/downsample_rs/src/minmaxlttb.rs +++ b/downsample_rs/src/minmaxlttb.rs @@ -10,16 +10,22 @@ use num_traits::{AsPrimitive, FromPrimitive}; // ----------- WITH X -pub fn minmaxlttb_with_x + FromPrimitive, Ty: Num + AsPrimitive>( - x: &[Tx], - y: &[Ty], - n_out: usize, - minmax_ratio: usize, -) -> Vec -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( + x: &[Tx], + y: &[Ty], + n_out: usize, + minmax_ratio: usize, + ) -> Vec + where + for<'a> &'a [Ty]: $trait, + Tx: Num + AsPrimitive + FromPrimitive, + Ty: Num + AsPrimitive, + { + minmaxlttb_generic(x, y, n_out, minmax_ratio, $f_minmax) + } + }; } minmaxlttb_with_x!(minmaxlttb_with_x, ArgMinMax, minmax::min_max_with_x); @@ -31,15 +37,19 @@ minmaxlttb_with_x!( // ----------- WITHOUT X -pub fn minmaxlttb_without_x>( - y: &[Ty], - n_out: usize, - minmax_ratio: usize, -) -> Vec -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>( + y: &[Ty], + n_out: usize, + minmax_ratio: usize, + ) -> Vec + 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); @@ -53,19 +63,22 @@ minmaxlttb_without_x!( // ----------- WITH X -pub fn minmaxlttb_with_x_parallel< - Tx: Num + AsPrimitive + FromPrimitive + Send + Sync, - Ty: Num + AsPrimitive + Send + Sync, ->( - x: &[Tx], - y: &[Ty], - n_out: usize, - minmax_ratio: usize, -) -> Vec -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( + x: &[Tx], + y: &[Ty], + n_out: usize, + minmax_ratio: usize, + ) -> Vec + where + for<'a> &'a [Ty]: $trait, + Tx: Num + AsPrimitive + FromPrimitive + Send + Sync, + Ty: Num + AsPrimitive + Send + Sync, + { + minmaxlttb_generic(x, y, n_out, minmax_ratio, $f_minmax) + } + }; } minmaxlttb_with_x_parallel!( @@ -81,15 +94,19 @@ minmaxlttb_with_x_parallel!( // ----------- WITHOUT X -pub fn minmaxlttb_without_x_parallel + Send + Sync>( - y: &[Ty], - n_out: usize, - minmax_ratio: usize, -) -> Vec -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 + Send + Sync>( + y: &[Ty], + n_out: usize, + minmax_ratio: usize, + ) -> Vec + where + for<'a> &'a [Ty]: $trait, + { + minmaxlttb_generic_without_x(y, n_out, minmax_ratio, $f_minmax) + } + }; } minmaxlttb_without_x_parallel!( diff --git a/src/lib.rs b/src/lib.rs index 19967c0..213578f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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, @@ -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, @@ -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); }; @@ -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, @@ -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