From bd48df23f8b22feeff5374e92029c82f127cee22 Mon Sep 17 00:00:00 2001 From: Yannick Feld Date: Mon, 6 Jan 2025 16:14:06 +0100 Subject: [PATCH] deprecate old hist --- benches/bench.rs | 11 +-- src/histogram/atomic_generic_hist.rs | 4 ++ src/histogram/binning/binning_int_multi.rs | 2 + src/histogram/generic_hist.rs | 4 ++ src/histogram/histogram_int.rs | 84 ++++++++++++++++++---- 5 files changed, 85 insertions(+), 20 deletions(-) diff --git a/benches/bench.rs b/benches/bench.rs index 6a5e8252..6eab899a 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -188,10 +188,11 @@ pub fn bench_hists(c: &mut Criterion){ use rand::prelude::*; use rand_pcg::Pcg64; - let mut hist = HistI16::new_inclusive(0, 10000, 10001) + let max_val = 100; + let mut hist = HistI16::new_inclusive(0, max_val, (max_val+1) as usize) .unwrap(); - let uniform = Uniform::new_inclusive(0, 10000); + let uniform = Uniform::new_inclusive(0, max_val); let mut rng = Pcg64::seed_from_u64(23894623987612); c.bench_function( @@ -211,7 +212,7 @@ pub fn bench_hists(c: &mut Criterion){ let mut hist = BinningI16::new_inclusive( 0, - 10001, + max_val, 1 ).unwrap() .to_generic_hist(); @@ -235,7 +236,7 @@ pub fn bench_hists(c: &mut Criterion){ let mut hist = FastBinningI16::new_inclusive( 0, - 10001, + max_val, ).to_generic_hist(); let mut rng = Pcg64::seed_from_u64(23894623987612); @@ -257,7 +258,7 @@ pub fn bench_hists(c: &mut Criterion){ let mut hist = HistI16Fast::new_inclusive( 0, - 10001, + max_val, ).unwrap(); let mut rng = Pcg64::seed_from_u64(23894623987612); diff --git a/src/histogram/atomic_generic_hist.rs b/src/histogram/atomic_generic_hist.rs index 6c94e237..b0e6121f 100644 --- a/src/histogram/atomic_generic_hist.rs +++ b/src/histogram/atomic_generic_hist.rs @@ -8,9 +8,13 @@ use std::{ } }; +#[cfg(feature = "serde_support")] +use serde::{Serialize, Deserialize}; + /// # Provides Histogram functionality /// * Is automatically implemented for any type that implements Binning +#[cfg_attr(feature = "serde_support", derive(Serialize, Deserialize))] pub struct AtomicGenericHist{ /// The binning pub(crate) binning: B, diff --git a/src/histogram/binning/binning_int_multi.rs b/src/histogram/binning/binning_int_multi.rs index 6a9cae88..f98b807b 100644 --- a/src/histogram/binning/binning_int_multi.rs +++ b/src/histogram/binning/binning_int_multi.rs @@ -356,6 +356,7 @@ mod tests{ assert_eq!(&vec, &[(-128..=-128), (-127..=-127), (-126..=-126)]); } + #[allow(deprecated)] #[test] fn other_binning_hist_test() { @@ -389,6 +390,7 @@ mod tests{ } + #[allow(deprecated)] #[test] fn other_binning_hist_test2() { diff --git a/src/histogram/generic_hist.rs b/src/histogram/generic_hist.rs index aedfb9fe..8c002ccc 100644 --- a/src/histogram/generic_hist.rs +++ b/src/histogram/generic_hist.rs @@ -5,9 +5,13 @@ use std::{ sync::atomic::AtomicUsize }; +#[cfg(feature = "serde_support")] +use serde::{Serialize, Deserialize}; /// # Provides Histogram functionality /// * Is automatically implemented for any type that implements Binning +#[derive(Clone)] +#[cfg_attr(feature = "serde_support", derive(Serialize, Deserialize))] pub struct GenericHist{ /// The binning pub(crate) binning: B, diff --git a/src/histogram/histogram_int.rs b/src/histogram/histogram_int.rs index 98eb405c..076c3260 100644 --- a/src/histogram/histogram_int.rs +++ b/src/histogram/histogram_int.rs @@ -1,3 +1,4 @@ +#![allow(deprecated)] use{ crate::histogram::*, num_traits::{ @@ -22,10 +23,11 @@ use serde::{Serialize, Deserialize}; /// # Generic Histogram for integer types /// -/// If possible, consider using [GenericHist] with [FastBinningI8] etc or, -/// if your binwidth is not 1, with [BinningI8] etc instead. +/// If possible, consider using [GenericHist] with [FastSingleIntBinning] or, +/// if your bin width is not 1, with [BinningWithWidth] instead (see [Binning::to_generic_hist]). /// This will likely be faster than using `HistogramInt` #[derive(Debug, Clone)] +#[deprecated(since="0.2.0", note="Use GenericHist of BinningWithWidth instead")] #[cfg_attr(feature = "serde_support", derive(Serialize, Deserialize))] pub struct HistogramInt { @@ -411,41 +413,89 @@ where T: Ord /// # Histogram for binning `usize` - alias for `HistogramInt` -/// * you should use `HistUsizeFast` instead, if your bins are `[left, left+1,..., right]` +/// * you should use [HistUsizeFast] or [GenericHist] of [FastBinningUSIZE] instead, if your bin width is 1 +/// * Otherwise use [GenericHist] of [BinningUSIZE] instead (see [Binning::to_generic_hist]) +/// * This type still works fine, but is slower than the alternative. +/// * This type alias might be removed in future releases +#[deprecated(since="0.2.0", note="Use GenericHist of BinningUSIZE instead")] pub type HistUsize = HistogramInt; /// # Histogram for binning `u128` - alias for `HistogramInt` -/// * you should use `HistU128Fast` instead, if your bins are `[left, left+1,..., right]` +/// * you should use [HistU128Fast] or [GenericHist] of [FastBinningU128] instead, if your bin width is 1 +/// * Otherwise use [GenericHist] of [BinningU128] instead (see [Binning::to_generic_hist]) +/// * This type still works fine, but is slower than the alternative. +/// * This type alias might be removed in future releases +#[deprecated(since="0.2.0", note="Use GenericHist of BinningU128 instead")] pub type HistU128 = HistogramInt; /// # Histogram for binning `u64` - alias for `HistogramInt` -/// * you should use `HistU64Fast` instead, if your bins are `[left, left+1,..., right]` +/// * you should use [HistU64Fast] or [GenericHist] of [FastBinningU64] instead, if your bin width is 1 +/// * Otherwise use [GenericHist] of [BinningU64] instead (see [Binning::to_generic_hist]) +/// * This type still works fine, but is slower than the alternative. +/// * This type alias might be removed in future releases +#[deprecated(since="0.2.0", note="Use GenericHist of BinningU64 instead")] pub type HistU64 = HistogramInt; /// # Histogram for binning `u32` - alias for `HistogramInt` -/// * you should use `HistU32Fast` instead, if your bins are `[left, left+1,..., right]` +/// * you should use [HistU32Fast] or [GenericHist] of [FastBinningU32] instead, if your bin width is 1 +/// * Otherwise use [GenericHist] of [BinningU32] instead (see [Binning::to_generic_hist]) +/// * This type still works fine, but is slower than the alternative. +/// * This type alias might be removed in future releases +#[deprecated(since="0.2.0", note="Use GenericHist of BinningU32 instead")] pub type HistU32 = HistogramInt; /// # Histogram for binning `u16` - alias for `HistogramInt` -/// * you should use `HistU16Fast` instead, if your bins are `[left, left+1,..., right]` +/// * you should use [HistU16Fast] or [GenericHist] of [FastBinningU16] instead, if your bin width is 1 +/// * Otherwise use [GenericHist] of [BinningU16] instead (see [Binning::to_generic_hist]) +/// * This type still works fine, but is slower than the alternative. +/// * This type alias might be removed in future releases +#[deprecated(since="0.2.0", note="Use GenericHist of BinningU16 instead")] pub type HistU16 = HistogramInt; /// # Histogram for binning `u8` - alias for `HistogramInt` -/// * you should use `HistU8Fast` instead, if your bins are `[left, left+1,..., right]` +/// * you should use [HistU8Fast] or [GenericHist] of [FastBinningU8] instead, if your bin width is 1 +/// * Otherwise use [GenericHist] of [BinningU8] instead (see [Binning::to_generic_hist]) +/// * This type still works fine, but is slower than the alternative. +/// * This type alias might be removed in future releases +#[deprecated(since="0.2.0", note="Use GenericHist of BinningU8 instead")] pub type HistU8 = HistogramInt; /// # Histogram for binning `isize` - alias for `HistogramInt` -/// * you should use `HistIsizeFast` instead, if your bins are `[left, left+1,..., right]` +/// * you should use [HistIsizeFast] or [GenericHist] of [FastBinningISIZE] instead, if your bin width is 1 +/// * Otherwise use [GenericHist] of [BinningISIZE] instead (see [Binning::to_generic_hist]) +/// * This type still works fine, but is slower than the alternative. +/// * This type alias might be removed in future releases +#[deprecated(since="0.2.0", note="Use GenericHist of BinningISIZE instead")] pub type HistIsize = HistogramInt; /// # Histogram for binning `i128` - alias for `HistogramInt` -/// * you should use `HistI128Fast` instead, if your bins are `[left, left+1,..., right]` +/// * you should use [HistI128Fast] or [GenericHist] of [FastBinningI128] instead, if your bin width is 1 +/// * Otherwise use [GenericHist] of [BinningI128] instead (see [Binning::to_generic_hist]) +/// * This type still works fine, but is slower than the alternative. +/// * This type alias might be removed in future releases +#[deprecated(since="0.2.0", note="Use GenericHist of BinningI128 instead")] pub type HistI128 = HistogramInt; /// # Histogram for binning `i64` - alias for `HistogramInt` -/// * you should use `HistI64Fast` instead, if your bins are `[left, left+1,..., right]` +/// * you should use [HistI64Fast] or [GenericHist] of [FastBinningI64] instead, if your bin width is 1 +/// * Otherwise use [GenericHist] of [BinningI64] instead (see [Binning::to_generic_hist]) +/// * This type still works fine, but is slower than the alternative. +/// * This type alias might be removed in future releases +#[deprecated(since="0.2.0", note="Use GenericHist of BinningI64 instead")] pub type HistI64 = HistogramInt; /// # Histogram for binning `i32` - alias for `HistogramInt` -/// * you should use `HistI32Fast` instead, if your bins are `[left, left+1,..., right]` +/// * you should use [HistI32Fast] or [GenericHist] of [FastBinningI32] instead, if your bin width is 1 +/// * Otherwise use [GenericHist] of [BinningI32] instead (see [Binning::to_generic_hist]) +/// * This type still works fine, but is slower than the alternative. +/// * This type alias might be removed in future releases +#[deprecated(since="0.2.0", note="Use GenericHist of BinningI32 instead")] pub type HistI32 = HistogramInt; /// # Histogram for binning `i16` - alias for `HistogramInt` -/// * you should use `HistI16Fast` instead, if your bins are `[left, left+1,..., right]` +/// * you should use [HistI16Fast] or [GenericHist] of [FastBinningI16] instead, if your bin width is 1 +/// * Otherwise use [GenericHist] of [BinningI16] instead (see [Binning::to_generic_hist]) +/// * This type still works fine, but is slower than the alternative. +/// * This type alias might be removed in future releases +#[deprecated(since="0.2.0", note="Use GenericHist of BinningI16 instead")] pub type HistI16 = HistogramInt; -/// # Histogram for binning `i8` - alias for `HistogramIntiu8>` -/// * you should use `HistI8Fast` instead, if your bins are `[left, left+1,..., right]` +/// # Histogram for binning `i8` - alias for `HistogramInt` +/// * you should use [HistI8Fast] or [GenericHist] of [FastBinningI8] instead, if your bin width is 1 +/// * Otherwise use [GenericHist] of [BinningI8] instead (see [Binning::to_generic_hist]) +/// * This type still works fine, but is slower than the alternative. +/// * This type alias might be removed in future releases +#[deprecated(since="0.2.0", note="Use GenericHist of BinningI8 instead")] pub type HistI8 = HistogramInt; #[cfg(test)] @@ -539,6 +589,7 @@ mod tests{ /// This test makes sure, that HistogramInt and HistogramFast return the same partitions, /// when the histograms are equivalent + #[allow(deprecated)] #[test] fn overlapping_partition_test() { @@ -638,6 +689,7 @@ mod tests{ } /// Check, that the range of the overlapping intervals contain the whole original interval + #[allow(deprecated)] #[test] fn overlapping_partition_test2() { @@ -681,6 +733,7 @@ mod tests{ /// Check, that the range of the overlapping intervals contain the whole original interval /// Different binsize than the other test + #[allow(deprecated)] #[test] fn overlapping_partition_test3() { @@ -729,6 +782,7 @@ mod tests{ } + #[allow(deprecated)] #[test] fn bin_iter_test() {