pub struct UniformCyclic<T = f64> { /* private fields */ }
Expand description
A wrap-around axis with equal-sized bins.
An axis with N
equally-spaced, equal-sized bins, in [low, high)
.
Entries outside this interval get wrapped around.
There are no overflow bins so this axis has exactly N
bins.
§Examples
1D histogram with 4 bins distributed around a circle.
use ndhistogram::{ndhistogram, Histogram};
use ndhistogram::axis::{Axis, BinInterval, UniformCyclic};
let mut hist = ndhistogram!(UniformCyclic::new(4, 0.0, 360.0)?);
hist.fill(& 45.0 ); // Add entry at 45 degrees
hist.fill(&(45.0 + 360.0)); // Add entry at 45 degrees + one whole turn
hist.fill(&(45.0 - 360.0)); // Add entry at 45 degrees + one whole turn backwards
// All 3 above entries end up in the same bin
assert_eq!(hist.value(&45.0), Some(&3.0));
// Lookup also wraps around
assert_eq!(hist.value(&(45.0 + 360.0)), Some(&3.0));
assert_eq!(hist.value(&(45.0 - 360.0)), Some(&3.0));
Time of day
use ndhistogram::{ndhistogram, Histogram};
use ndhistogram::axis::{Axis, BinInterval, UniformCyclic};
let bins_per_day = 24;
let hours_per_bin = 1;
let start_at_zero = 0;
let four_pm = 16;
let mut hist = ndhistogram!(UniformCyclic::with_step_size(
bins_per_day, start_at_zero, hours_per_bin
)?);
hist.fill(&40); // The 40th hour of the week ...
assert_eq!(hist.value(&four_pm), Some(&1.0)); // ... is at 4 pm.
Implementations§
Source§impl<T> UniformCyclic<T>
impl<T> UniformCyclic<T>
Sourcepub fn new(nbins: usize, low: T, high: T) -> Result<Self, AxisError>where
T: Float,
pub fn new(nbins: usize, low: T, high: T) -> Result<Self, AxisError>where
T: Float,
Create a wrap-around axis with nbins
uniformly-spaced bins in the range [low, high)
.
Only implemented for Float. Use UniformCyclic::with_step_size for integers.
For floating point types, infinities and NaN do not map to any bin.
The parameters have the same constraints as UniformNoFlow::new, otherwise an error in returned.
Sourcepub fn with_step_size(nbins: usize, low: T, step: T) -> Result<Self, AxisError>
pub fn with_step_size(nbins: usize, low: T, step: T) -> Result<Self, AxisError>
Create a wrap-around axis with nbins
uniformly-spaced bins in the range [low, low+num*step)
.
The parameters have the same constraints as UniformNoFlow::new, otherwise an error is returned.
Trait Implementations§
Source§impl<T: PartialOrd + Num + NumCast + NumOps + Copy> Axis for UniformCyclic<T>
impl<T: PartialOrd + Num + NumCast + NumOps + Copy> Axis for UniformCyclic<T>
Source§type Coordinate = T
type Coordinate = T
Source§type BinInterval = BinInterval<T>
type BinInterval = BinInterval<T>
Source§fn index(&self, coordinate: &Self::Coordinate) -> Option<usize>
fn index(&self, coordinate: &Self::Coordinate) -> Option<usize>
Source§fn num_bins(&self) -> usize
fn num_bins(&self) -> usize
Source§fn bin(&self, index: usize) -> Option<<Self as Axis>::BinInterval>
fn bin(&self, index: usize) -> Option<<Self as Axis>::BinInterval>
Source§fn iter(&self) -> Box<dyn Iterator<Item = (usize, Self::BinInterval)> + '_>
fn iter(&self) -> Box<dyn Iterator<Item = (usize, Self::BinInterval)> + '_>
Source§impl<T: Clone> Clone for UniformCyclic<T>
impl<T: Clone> Clone for UniformCyclic<T>
Source§fn clone(&self) -> UniformCyclic<T>
fn clone(&self) -> UniformCyclic<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<T: Debug> Debug for UniformCyclic<T>
impl<T: Debug> Debug for UniformCyclic<T>
Source§impl<T: Default> Default for UniformCyclic<T>
impl<T: Default> Default for UniformCyclic<T>
Source§fn default() -> UniformCyclic<T>
fn default() -> UniformCyclic<T>
Source§impl<'de, T> Deserialize<'de> for UniformCyclic<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for UniformCyclic<T>where
T: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<T> Display for UniformCyclic<T>
impl<T> Display for UniformCyclic<T>
Source§impl<T: Hash> Hash for UniformCyclic<T>
impl<T: Hash> Hash for UniformCyclic<T>
Source§impl<'a, T> IntoIterator for &'a UniformCyclic<T>where
UniformCyclic<T>: Axis,
impl<'a, T> IntoIterator for &'a UniformCyclic<T>where
UniformCyclic<T>: Axis,
Source§type Item = (usize, <UniformCyclic<T> as Axis>::BinInterval)
type Item = (usize, <UniformCyclic<T> as Axis>::BinInterval)
Source§type IntoIter = Box<dyn Iterator<Item = <&'a UniformCyclic<T> as IntoIterator>::Item> + 'a>
type IntoIter = Box<dyn Iterator<Item = <&'a UniformCyclic<T> as IntoIterator>::Item> + 'a>
Source§impl<T: Ord> Ord for UniformCyclic<T>
impl<T: Ord> Ord for UniformCyclic<T>
Source§fn cmp(&self, other: &UniformCyclic<T>) -> Ordering
fn cmp(&self, other: &UniformCyclic<T>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T: PartialEq> PartialEq for UniformCyclic<T>
impl<T: PartialEq> PartialEq for UniformCyclic<T>
Source§impl<T: PartialOrd> PartialOrd for UniformCyclic<T>
impl<T: PartialOrd> PartialOrd for UniformCyclic<T>
Source§impl<T> Serialize for UniformCyclic<T>where
T: Serialize,
impl<T> Serialize for UniformCyclic<T>where
T: Serialize,
impl<T: Eq> Eq for UniformCyclic<T>
impl<T> StructuralPartialEq for UniformCyclic<T>
Auto Trait Implementations§
impl<T> Freeze for UniformCyclic<T>where
T: Freeze,
impl<T> RefUnwindSafe for UniformCyclic<T>where
T: RefUnwindSafe,
impl<T> Send for UniformCyclic<T>where
T: Send,
impl<T> Sync for UniformCyclic<T>where
T: Sync,
impl<T> Unpin for UniformCyclic<T>where
T: Unpin,
impl<T> UnwindSafe for UniformCyclic<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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