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 more