pub type BinningI8 = BinningWithWidth<i8>;
Expand description
Efficient binning for i8
with bins of width 1
Aliased Type§
struct BinningI8 { /* private fields */ }
Implementations§
source§impl BinningI8
impl BinningI8
sourcepub fn new_inclusive(
start: i8,
end_inclusive: i8,
bin_width: i8
) -> Result<Self, <i8 as HasUnsignedVersion>::Unsigned>
pub fn new_inclusive( start: i8, end_inclusive: i8, bin_width: i8 ) -> Result<Self, <i8 as HasUnsignedVersion>::Unsigned>
Create a new Binning
- both borders are inclusive
- each bin has width 1
Panics
- if
start
is smaller thanend_inclusive
- if bin_width <= 0
sourcepub const fn range_inclusive(&self) -> RangeInclusive<i8>
pub const fn range_inclusive(&self) -> RangeInclusive<i8>
sourcepub fn multi_valued_bin_iter(&self) -> impl Iterator<Item = (i8, i8)>
pub fn multi_valued_bin_iter(&self) -> impl Iterator<Item = (i8, i8)>
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::BinningI8;
let binning = BinningI8::new_inclusive(2,7,2).unwrap();
let vec: Vec<_> = binning.multi_valued_bin_iter().collect();
assert_eq!(&vec, &[(2, 3), (4, 5), (6, 7)]);
sourcepub fn bins_m1(&self) -> <i8 as HasUnsignedVersion>::Unsigned
pub fn bins_m1(&self) -> <i8 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
sourcepub fn get_bin_index_native<V: Borrow<i8>>(
&self,
val: V
) -> Option<<i8 as HasUnsignedVersion>::Unsigned>
pub fn get_bin_index_native<V: Borrow<i8>>( &self, val: V ) -> Option<<i8 as HasUnsignedVersion>::Unsigned>
Trait Implementations§
source§impl Binning<i8> for BinningI8
impl Binning<i8> for BinningI8
source§fn get_bin_index<V: Borrow<i8>>(&self, val: V) -> Option<usize>
fn get_bin_index<V: Borrow<i8>>(&self, val: V) -> Option<usize>
Get the respective bin index
- Note: Obviously this breaks when the bin index cannot be represented as
usize
source§fn not_inside<V: Borrow<i8>>(&self, val: V) -> bool
fn not_inside<V: Borrow<i8>>(&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) -> i8
fn first_border(&self) -> i8
get the left most border (inclusive)
source§fn distance<V: Borrow<i8>>(&self, v: V) -> f64
fn distance<V: Borrow<i8>>(&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<i8>>>
fn bin_iter(&self) -> Box<dyn Iterator<Item = Bin<i8>>>
Iterates over all bins
- Note: This implementation usees a more efficient representations of the bins underneath, but is capable of returning the bins in this representation on request
- Note also that this
Binning
implements another method for the bin borders, i.e.,multi_valued_bin_iter
. Consider using that instead, as it is more efficient
source§fn get_bin_len(&self) -> usize
fn get_bin_len(&self) -> usize
Get the number of underlying bins Read more
source§fn last_border(&self) -> i8
fn last_border(&self) -> i8
get last border from the rightNote: this border might be inclusive or exclusive Read more
source§fn last_border_is_inclusive(&self) -> bool
fn last_border_is_inclusive(&self) -> bool
True if last border is inclusive, false otherwise Read more