Type Alias FastBinningISIZE

Source
pub type FastBinningISIZE = FastSingleIntBinning<isize>;
Expand description

Efficient binning for isize with bins of width 1

Aliased Type§

struct FastBinningISIZE { /* private fields */ }

Implementations§

Source§

impl FastBinningISIZE

Source

pub const fn new_inclusive(start: isize, end_inclusive: isize) -> Self

§Create a new Binning
  • both borders are inclusive
  • each bin has width 1
§Panics
  • if start is smaller than end_inclusive
Source

pub const fn left(&self) -> isize

Get left border, inclusive

Source

pub const fn right(&self) -> isize

Get right border, inclusive

Source

pub const fn range_inclusive(&self) -> RangeInclusive<isize>

§Returns the range covered by the bins as a RangeInclusive<T>
Source

pub fn native_bin_iter(&self) -> impl Iterator<Item = isize>

§Iterator over all the bins

Since the bins have width 1, a bin can be defined by its corresponding value which we can iterate over.

§Example
use sampling::histogram::FastBinningISIZE;
let binning = FastBinningISIZE::new_inclusive(2,5);
let vec: Vec<_> = binning.native_bin_iter().collect();
assert_eq!(&vec, &[2, 3, 4, 5]);
Source

pub fn bins_m1(&self) -> <isize as HasUnsignedVersion>::Unsigned

§The amount of bins -1
  • minus 1 because if the bins are going over the entire range of the type, then I cannot represent the number of bins as this type
§Example

If we look at an u8 and the range from 0 to 255, then this is 256 bins, which cannot be represented as u8. To combat this, I return bins - 1. This works, because we always have at least 1 bin

Source§

impl FastBinningISIZE

Source

pub fn get_bin_index_native<V: Borrow<isize>>( &self, val: V, ) -> Option<<isize as HasUnsignedVersion>::Unsigned>

§Get the respective bin index
  • Similar to get_bin_index, but without the cast to usize. This means that large types are not at a risk of overflow here

Trait Implementations§

Source§

impl Binning<isize> for FastBinningISIZE

Source§

fn get_bin_index<V: Borrow<isize>>(&self, val: V) -> Option<usize>

§Get the respective bin index
  • Note: Obviously this breaks when the bin index cannot be represented as usize, in that case Some(usize::MAX) will be returned
Source§

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

Does a value correspond to a valid bin?

Source§

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

§Opposite of is_inside
  • I could also have called this is_outside, but I didn’t
Source§

fn first_border(&self) -> isize

get the left most border (inclusive)

Source§

fn distance<V: Borrow<isize>>(&self, v: V) -> f64

§calculates some sort of absolute distance to the nearest valid bin
  • if a value corresponds to a valid bin, the distance is zero
Source§

fn bin_iter(&self) -> Box<dyn Iterator<Item = Bin<isize>>>

§Iterates over all bins
  • Note: This implementation use more efficient representations of the bins underneath, but are capable of returning the bins in this representation on request
  • Note also that this Binning implements another method for the bin borders, i.e., native_bin_iter. Consider using that instead, as it is more efficient
Source§

fn get_bin_len(&self) -> usize

Get the number of underlying bins Read more
Source§

fn last_border(&self) -> isize

If the last border is inclusive, this returns the largest value that is still inside the binning.If the last border is exclusive, this is the first value which is not inside the binning. Read more
Source§

fn last_border_is_inclusive(&self) -> bool

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

fn to_generic_hist(self) -> GenericHist<Self, T>
where Self: Sized,

Convert binning into GenericHist Read more
Source§

fn to_generic_atomic_hist(self) -> AtomicGenericHist<Self, T>
where Self: Sized,

Convert binning into a AtomicGenericHist Read more
Source§

impl HistogramPartition for FastBinningISIZE

Source§

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

§partition the interval
  • returns Vector of n Binnings. Though n will be limited by the max value that isize can hold. ## parameter
  • n number of resulting intervals.
  • overlap How much overlap should there be?
§To understand overlap, we have to look at the formula for the i_th interval in the result vector:

let left be the left border of self and right be the right border of self

  • left border of interval i = left + i * (right - left) / (n + overlap)
  • right border of interval i = left + (i + overlap) * (right - left) / (n + overlap)
§What is it for?
  • This is intended to create multiple overlapping intervals, e.g., for a Wang-Landau simulation
§Note
  • Will fail if overlap + n are not representable as isize
Source§

impl<T: Clone> Clone for FastSingleIntBinning<T>

Source§

fn clone(&self) -> FastSingleIntBinning<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 FastSingleIntBinning<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 FastSingleIntBinning<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: Ord> Ord for FastSingleIntBinning<T>

Source§

fn cmp(&self, other: &FastSingleIntBinning<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: PartialEq> PartialEq for FastSingleIntBinning<T>

Source§

fn eq(&self, other: &FastSingleIntBinning<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd> PartialOrd for FastSingleIntBinning<T>

Source§

fn partial_cmp(&self, other: &FastSingleIntBinning<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> Serialize for FastSingleIntBinning<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
Source§

impl<T: Copy> Copy for FastSingleIntBinning<T>

Source§

impl<T: Eq> Eq for FastSingleIntBinning<T>

Source§

impl<T> StructuralPartialEq for FastSingleIntBinning<T>