Skip to content

Commit

Permalink
deprecate old hist
Browse files Browse the repository at this point in the history
  • Loading branch information
Pardoxa committed Jan 6, 2025
1 parent e72bdb3 commit bd48df2
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 20 deletions.
11 changes: 6 additions & 5 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/histogram/atomic_generic_hist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<B, T>{
/// The binning
pub(crate) binning: B,
Expand Down
2 changes: 2 additions & 0 deletions src/histogram/binning/binning_int_multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ mod tests{
assert_eq!(&vec, &[(-128..=-128), (-127..=-127), (-126..=-126)]);
}

#[allow(deprecated)]
#[test]
fn other_binning_hist_test()
{
Expand Down Expand Up @@ -389,6 +390,7 @@ mod tests{

}

#[allow(deprecated)]
#[test]
fn other_binning_hist_test2()
{
Expand Down
4 changes: 4 additions & 0 deletions src/histogram/generic_hist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<B, T>{
/// The binning
pub(crate) binning: B,
Expand Down
84 changes: 69 additions & 15 deletions src/histogram/histogram_int.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(deprecated)]
use{
crate::histogram::*,
num_traits::{
Expand All @@ -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<T>`
#[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<T>
{
Expand Down Expand Up @@ -411,41 +413,89 @@ where T: Ord


/// # Histogram for binning `usize` - alias for `HistogramInt<usize>`
/// * 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<usize>;
/// # Histogram for binning `u128` - alias for `HistogramInt<u128>`
/// * 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<u128>;
/// # Histogram for binning `u64` - alias for `HistogramInt<u64>`
/// * 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<u64>;
/// # Histogram for binning `u32` - alias for `HistogramInt<u32>`
/// * 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<u32>;
/// # Histogram for binning `u16` - alias for `HistogramInt<u16>`
/// * 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<u16>;
/// # Histogram for binning `u8` - alias for `HistogramInt<u8>`
/// * 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<u8>;

/// # Histogram for binning `isize` - alias for `HistogramInt<isize>`
/// * 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<isize>;
/// # Histogram for binning `i128` - alias for `HistogramInt<i128>`
/// * 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<i128>;
/// # Histogram for binning `i64` - alias for `HistogramInt<i64>`
/// * 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<i64>;
/// # Histogram for binning `i32` - alias for `HistogramInt<i32>`
/// * 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<i32>;
/// # Histogram for binning `i16` - alias for `HistogramInt<i16>`
/// * 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<i16>;
/// # 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<i8>`
/// * 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<i8>;

#[cfg(test)]
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -729,6 +782,7 @@ mod tests{

}

#[allow(deprecated)]
#[test]
fn bin_iter_test()
{
Expand Down

0 comments on commit bd48df2

Please sign in to comment.