Struct HistogramInt

Source
pub struct HistogramInt<T> { /* private fields */ }
๐Ÿ‘ŽDeprecated since 0.2.0: Use GenericHist of BinningWithWidth instead
Expand description

ยงGeneric Histogram for integer types

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>

Implementationsยง

Sourceยง

impl<T> HistogramInt<T>

Source

pub fn borders(&self) -> &Vec<T>

similar to self.borders_clone but does not allocate memory

Source

pub fn bin_iter(&self) -> impl Iterator<Item = &[T; 2]>

ยงIterator over all the bins

In HistogramInt a bin is defined by two values: The left border (inclusive) and the right border (exclusive)

Here you get an iterator which iterates over said borders. The Iterator returns a borrowed Array of length two, where the first value is the left (inclusive) border and the second value is the right (exclusive) border

ยงExample
use sampling::histogram::*;
 
let hist = HistI8::new(0, 8, 4).unwrap();
let mut bin_iter = hist.bin_iter();

assert_eq!(bin_iter.next(), Some(&[0_i8, 2]));
assert_eq!(bin_iter.next(), Some(&[2, 4]));
assert_eq!(bin_iter.next(), Some(&[4, 6]));
assert_eq!(bin_iter.next(), Some(&[6, 8]));
assert_eq!(bin_iter.next(), None);
Source

pub fn bin_hits_iter(&self) -> impl Iterator<Item = (&[T; 2], usize)>

ยงIterate over all bins

In HistogramInt a bin is defined by two values: The left border (inclusive) and the right border (exclusive)

This iterates over these values as well as the corresponding hit count (i.e. how often the corresponding bin was hit)

ยงItem of Iterator

(&[left_border, right_border], number_of_hits)

ยงExample
use sampling::histogram::*;
 
let mut hist = HistUsize::new(0, 6, 3).unwrap();
 
hist.increment(0).unwrap();
hist.increment(5).unwrap();
hist.increment(4).unwrap();
 
let mut iter = hist.bin_hits_iter();
assert_eq!(
    iter.next(),
    Some(
        (&[0, 2], 1)
    )
);
assert_eq!(
    iter.next(),
    Some(
        (&[2, 4], 0)
    )
);
assert_eq!(
    iter.next(),
    Some(
        (&[4, 6], 2)
    )
);
assert_eq!(iter.next(), None);
Sourceยง

impl<T> HistogramInt<T>
where T: Sub<T, Output = T> + Add<T, Output = T> + Ord + One + Copy + NumCast,

Source

pub fn increment<V: Borrow<T>>(&mut self, val: V) -> Result<usize, HistErrors>

ยงIncrement hit count

If val is inside the histogram, the corresponding bin count will be increased by 1 and the index corresponding to the bin in returned: Ok(index). Otherwise an Error is returned

ยงNote

This is the same as HistogramVal::count_val

Source

pub fn increment_quiet<V: Borrow<T>>(&mut self, val: V)

ยงIncrement hit count

Increments the hit count of the bin corresponding to val. If no bin corresponding to val exists, nothing happens

Sourceยง

impl<T> HistogramInt<T>
where T: PartialOrd + ToPrimitive + FromPrimitive + CheckedAdd + One + HasUnsignedVersion + Bounded + Sub<T, Output = T> + Mul<T, Output = T> + Zero + Copy, RangeInclusive<T>: Iterator<Item = T>, T::Unsigned: Bounded + HasUnsignedVersion<LeBytes = T::LeBytes, Unsigned = T::Unsigned> + WrappingAdd + ToPrimitive + Sub<Output = T::Unsigned> + Rem<Output = T::Unsigned> + FromPrimitive + Zero + Eq + Div<Output = T::Unsigned> + Ord + Mul<Output = T::Unsigned> + WrappingSub + Copy, RangeInclusive<T::Unsigned>: Iterator<Item = T::Unsigned>,

Source

pub fn new(left: T, right: T, bins: usize) -> Result<Self, HistErrors>

ยงCreate a new histogram
  • right: exclusive border
  • left: inclusive border
  • bins: how many bins do you need?
ยงNote
  • (right - left) % bins == 0 has to be true, otherwise the bins cannot all have the same length!
Source

pub fn new_inclusive(left: T, right: T, bins: usize) -> Result<Self, HistErrors>

ยงCreate a new histogram
ยงNote:
  • Due to implementation details, right cannot be T::MAX - if you try, you will get Err(HistErrors::Overflow)

Trait Implementationsยง

Sourceยง

impl<T: Clone> Clone for HistogramInt<T>

Sourceยง

fn clone(&self) -> HistogramInt<T>

Returns a copy of the value. Read more
1.0.0 ยท Sourceยง

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Sourceยง

impl<T: Debug> Debug for HistogramInt<T>

Sourceยง

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Sourceยง

impl<'de, T> Deserialize<'de> for HistogramInt<T>
where T: Deserialize<'de>,

Sourceยง

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Sourceยง

impl<T> Histogram for HistogramInt<T>

Sourceยง

fn bin_count(&self) -> usize

How many bins the histogram contains Read more
Sourceยง

fn hist(&self) -> &Vec<usize>

the created histogram Read more
Sourceยง

fn increment_index_by( &mut self, index: usize, count: usize, ) -> Result<(), HistErrors>

self.hist[index] += count, Err() if index out of bounds Read more
Sourceยง

fn reset(&mut self)

reset the histogram to zero
Sourceยง

fn increment_index(&mut self, index: usize) -> Result<(), HistErrors>

self.hist[index] += 1, Err() if index out of bounds Read more
Sourceยง

fn any_bin_zero(&self) -> bool

check if any bin was not hit yet
Sourceยง

impl<T> HistogramIntervalDistance<T> for HistogramInt<T>
where T: Ord + Sub<T, Output = T> + Add<T, Output = T> + One + NumCast + Copy,

Sourceยง

fn interval_distance_overlap<V: Borrow<T>>( &self, val: V, overlap: NonZeroUsize, ) -> usize

Distance metric for how far a value is from a valid interval Read more
Sourceยง

impl<T> HistogramPartition for HistogramInt<T>
where T: Clone + Debug,

Sourceยง

fn overlapping_partition( &self, n: NonZeroUsize, overlap: usize, ) -> Result<Vec<Self>, HistErrors>

partition the interval Read more
Sourceยง

impl<T> HistogramVal<T> for HistogramInt<T>
where T: Ord + Sub<T, Output = T> + Add<T, Output = T> + One + NumCast + Copy,

Sourceยง

fn get_bin_index<V: Borrow<T>>(&self, val: V) -> Result<usize, HistErrors>

None if not inside Hist covered zone

Sourceยง

fn bin_enum_iter(&self) -> Box<dyn Iterator<Item = Bin<T>> + '_>

ยงconsider using self.bin_iter() instead
  • this will return an iterator over the bins for displaying purposes
  • all bins are defined via an inclusive and an exclusive border
  • It is more efficient to use self.bin_iter()instead
Sourceยง

fn count_val<V: Borrow<T>>(&mut self, val: V) -> Result<usize, HistErrors>

count val. Ok(index), if inside of hist, Err(_) if val is invalid
Sourceยง

fn distance<V: Borrow<T>>(&self, val: V) -> f64

calculates some sort of absolute distance to the nearest valid bin Read more
Sourceยง

fn first_border(&self) -> T

get the left most border (inclusive)
Sourceยง

fn last_border(&self) -> T

get last border from the right Read more
Sourceยง

fn last_border_is_inclusive(&self) -> bool

True if last border is inclusive, false otherwise Read more
Sourceยง

fn is_inside<V: Borrow<T>>(&self, val: V) -> bool

does a value correspond to a valid bin?
Sourceยง

fn not_inside<V: Borrow<T>>(&self, val: V) -> bool

opposite of is_inside
Sourceยง

impl<T> IntervalOrder for HistogramInt<T>
where T: Ord,

Sourceยง

fn left_compare(&self, other: &Self) -> Ordering

Will compare leftest bin first. if they are equal: will compare right bin
Sourceยง

impl<T> Serialize for HistogramInt<T>
where T: Serialize,

Sourceยง

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementationsยง

ยง

impl<T> Freeze for HistogramInt<T>

ยง

impl<T> RefUnwindSafe for HistogramInt<T>
where T: RefUnwindSafe,

ยง

impl<T> Send for HistogramInt<T>
where T: Send,

ยง

impl<T> Sync for HistogramInt<T>
where T: Sync,

ยง

impl<T> Unpin for HistogramInt<T>
where T: Unpin,

ยง

impl<T> UnwindSafe for HistogramInt<T>
where T: UnwindSafe,

Blanket Implementationsยง

Sourceยง

impl<T> Any for T
where T: 'static + ?Sized,

Sourceยง

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Sourceยง

impl<T> Borrow<T> for T
where T: ?Sized,

Sourceยง

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Sourceยง

impl<T> BorrowMut<T> for T
where T: ?Sized,

Sourceยง

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Sourceยง

impl<T> CloneToUninit for T
where T: Clone,

Sourceยง

unsafe fn clone_to_uninit(&self, dst: *mut u8)

๐Ÿ”ฌThis is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Sourceยง

impl<T> From<T> for T

Sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

Sourceยง

impl<T, U> Into<U> for T
where U: From<T>,

Sourceยง

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Sourceยง

impl<T> IntoEither for T

Sourceยง

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Sourceยง

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
ยง

impl<T> Pointable for T

ยง

const ALIGN: usize

The alignment of pointer.
ยง

type Init = T

The type for initializers.
ยง

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
ยง

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
ยง

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
ยง

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Sourceยง

impl<T> ToOwned for T
where T: Clone,

Sourceยง

type Owned = T

The resulting type after obtaining ownership.
Sourceยง

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Sourceยง

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Sourceยง

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Sourceยง

type Error = Infallible

The type returned in the event of a conversion error.
Sourceยง

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Sourceยง

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Sourceยง

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Sourceยง

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
ยง

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

ยง

fn vzip(self) -> V

Sourceยง

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,