pub struct HashHistogram<A, V> { /* private fields */ }
Expand description
A sparse N-dimensional Histogram that stores its values in a HashMap.
Only bins that are filled will consume memory. This makes high-dimensional, many-binned (but mostly empty) histograms possible. If memory usage is not a concern, see VecHistogram.
See crate::sparsehistogram for examples of its use.
Implementations§
Source§impl<A: Axis, V> HashHistogram<A, V>
impl<A: Axis, V> HashHistogram<A, V>
Sourcepub fn new(axes: A) -> Self
pub fn new(axes: A) -> Self
Factory method for HashHistogram. It is recommended to use the sparsehistogram macro instead.
Source§impl<A, V> HashHistogram<A, V>
impl<A, V> HashHistogram<A, V>
Sourcepub fn par_values(&self) -> impl ParallelIterator<Item = &V>where
V: Sync,
pub fn par_values(&self) -> impl ParallelIterator<Item = &V>where
V: Sync,
An immutable rayon parallel iterator over the histogram values.
It only iterates over filled bins in the sparse histogram. This requires the “rayon” crate feature to be enabled.
Sourcepub fn par_values_mut(&mut self) -> impl ParallelIterator<Item = &mut V>where
V: Send,
pub fn par_values_mut(&mut self) -> impl ParallelIterator<Item = &mut V>where
V: Send,
A mutable rayon parallel iterator over the histogram values.
It only iterates over filled bins in the sparse histogram. This requires the “rayon” crate feature to be enabled.
Sourcepub fn par_iter(
&self,
) -> impl ParallelIterator<Item = Item<<A as Axis>::BinInterval, &V>>
pub fn par_iter( &self, ) -> impl ParallelIterator<Item = Item<<A as Axis>::BinInterval, &V>>
An immutable rayon parallel iterator over bin indices, bin interval and bin values.
It only iterates over filled bins in the sparse histogram. This requires the “rayon” crate feature to be enabled.
Sourcepub fn par_iter_mut(
&mut self,
) -> impl ParallelIterator<Item = Item<<A as Axis>::BinInterval, &mut V>>
pub fn par_iter_mut( &mut self, ) -> impl ParallelIterator<Item = Item<<A as Axis>::BinInterval, &mut V>>
An mutable rayon parallel iterator over bin indices, bin interval and bin values.
It only iterates over filled bins in the sparse histogram. This requires the “rayon” crate feature to be enabled.
Trait Implementations§
Source§impl<A: Axis + PartialEq + Clone, V> Add<&HashHistogram<A, V>> for &HashHistogram<A, V>
impl<A: Axis + PartialEq + Clone, V> Add<&HashHistogram<A, V>> for &HashHistogram<A, V>
Source§fn add(self, rhs: &HashHistogram<A, V>) -> Self::Output
fn add(self, rhs: &HashHistogram<A, V>) -> Self::Output
Combine the right-hand histogram with the left-hand histogram, returning a copy, and leaving the original histograms intact.
If the input histograms have incompatible axes, this operation will return a crate::error::BinaryOperationError.
§Examples
use ndhistogram::{Histogram, sparsehistogram, axis::Uniform};
let mut hist1 = sparsehistogram!(Uniform::<f64>::new(10, -5.0, 5.0)?);
let mut hist2 = sparsehistogram!(Uniform::<f64>::new(10, -5.0, 5.0)?);
hist1.fill_with(&0.0, 2.0);
hist2.fill(&0.0);
let combined_hist = (&hist1 + &hist2).expect("Axes are compatible");
assert_eq!(combined_hist.value(&0.0).unwrap(), &3.0);
Source§type Output = Result<HashHistogram<A, V>, BinaryOperationError>
type Output = Result<HashHistogram<A, V>, BinaryOperationError>
+
operator.Source§impl<A: Axis + PartialEq + Clone, V> Add<&HashHistogram<A, V>> for HashHistogram<A, V>
impl<A: Axis + PartialEq + Clone, V> Add<&HashHistogram<A, V>> for HashHistogram<A, V>
Source§fn add(self, rhs: &HashHistogram<A, V>) -> Self::Output
fn add(self, rhs: &HashHistogram<A, V>) -> Self::Output
Combine the right-hand histogram with the left-hand histogram, consuming the left-hand histogram and returning a new value. As this avoids making copies of the histograms, this is the recommended method to merge histograms.
If the input histograms have incompatible axes, this operation will return a crate::error::BinaryOperationError.
§Examples
use ndhistogram::{Histogram, sparsehistogram, axis::Uniform};
let mut hist1 = sparsehistogram!(Uniform::<f64>::new(10, -5.0, 5.0)?);
let mut hist2 = sparsehistogram!(Uniform::<f64>::new(10, -5.0, 5.0)?);
hist1.fill_with(&0.0, 2.0);
hist2.fill(&0.0);
let combined_hist = (hist1 + &hist2).expect("Axes are compatible");
assert_eq!(combined_hist.value(&0.0).unwrap(), &3.0);
Source§type Output = Result<HashHistogram<A, V>, BinaryOperationError>
type Output = Result<HashHistogram<A, V>, BinaryOperationError>
+
operator.Source§impl<A: Axis + PartialEq, V> AddAssign<&HashHistogram<A, V>> for HashHistogram<A, V>
impl<A: Axis + PartialEq, V> AddAssign<&HashHistogram<A, V>> for HashHistogram<A, V>
Source§fn add_assign(&mut self, rhs: &HashHistogram<A, V>)
fn add_assign(&mut self, rhs: &HashHistogram<A, V>)
Combine the right-hand histogram with the left-hand histogram, mutating the left-hand histogram.
§Panics
Panics if the histograms have incompatible axes. To handle this failure mode at runtime, use the non-assign version of this operation, which returns an Result.
§Examples
use ndhistogram::{Histogram, sparsehistogram, axis::Uniform};
let mut hist1 = sparsehistogram!(Uniform::<f64>::new(10, -5.0, 5.0)?);
let mut hist2 = sparsehistogram!(Uniform::<f64>::new(10, -5.0, 5.0)?);
hist1.fill_with(&0.0, 2.0);
hist2.fill(&0.0);
hist1 += &hist2;
assert_eq!(hist1.value(&0.0).unwrap(), &3.0);
Source§impl<A: Clone, V: Clone> Clone for HashHistogram<A, V>
impl<A: Clone, V: Clone> Clone for HashHistogram<A, V>
Source§fn clone(&self) -> HashHistogram<A, V>
fn clone(&self) -> HashHistogram<A, V>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<A: Default, V: Default> Default for HashHistogram<A, V>
impl<A: Default, V: Default> Default for HashHistogram<A, V>
Source§fn default() -> HashHistogram<A, V>
fn default() -> HashHistogram<A, V>
Source§impl<'de, A, V> Deserialize<'de> for HashHistogram<A, V>where
A: Deserialize<'de>,
V: Deserialize<'de>,
impl<'de, A, V> Deserialize<'de> for HashHistogram<A, V>where
A: Deserialize<'de>,
V: 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<A: Axis, V> Display for HashHistogram<A, V>
impl<A: Axis, V> Display for HashHistogram<A, V>
Source§impl<A: Axis + PartialEq + Clone, V> Div<&HashHistogram<A, V>> for &HashHistogram<A, V>
impl<A: Axis + PartialEq + Clone, V> Div<&HashHistogram<A, V>> for &HashHistogram<A, V>
Source§fn div(self, rhs: &HashHistogram<A, V>) -> Self::Output
fn div(self, rhs: &HashHistogram<A, V>) -> Self::Output
Combine the right-hand histogram with the left-hand histogram, returning a copy, and leaving the original histograms intact.
If the input histograms have incompatible axes, this operation will return a crate::error::BinaryOperationError.
§Examples
use ndhistogram::{Histogram, sparsehistogram, axis::Uniform};
let mut hist1 = sparsehistogram!(Uniform::<f64>::new(10, -5.0, 5.0)?);
let mut hist2 = sparsehistogram!(Uniform::<f64>::new(10, -5.0, 5.0)?);
hist1.fill_with(&0.0, 2.0);
hist2.fill(&0.0);
let combined_hist = (&hist1 / &hist2).expect("Axes are compatible");
assert_eq!(combined_hist.value(&0.0).unwrap(), &2.0);
Source§type Output = Result<HashHistogram<A, V>, BinaryOperationError>
type Output = Result<HashHistogram<A, V>, BinaryOperationError>
/
operator.Source§impl<A: Axis + PartialEq + Clone, V> Div<&HashHistogram<A, V>> for HashHistogram<A, V>
impl<A: Axis + PartialEq + Clone, V> Div<&HashHistogram<A, V>> for HashHistogram<A, V>
Source§fn div(self, rhs: &HashHistogram<A, V>) -> Self::Output
fn div(self, rhs: &HashHistogram<A, V>) -> Self::Output
Combine the right-hand histogram with the left-hand histogram, consuming the left-hand histogram and returning a new value. As this avoids making copies of the histograms, this is the recommended method to merge histograms.
If the input histograms have incompatible axes, this operation will return a crate::error::BinaryOperationError.
§Examples
use ndhistogram::{Histogram, sparsehistogram, axis::Uniform};
let mut hist1 = sparsehistogram!(Uniform::<f64>::new(10, -5.0, 5.0)?);
let mut hist2 = sparsehistogram!(Uniform::<f64>::new(10, -5.0, 5.0)?);
hist1.fill_with(&0.0, 2.0);
hist2.fill(&0.0);
let combined_hist = (hist1 / &hist2).expect("Axes are compatible");
assert_eq!(combined_hist.value(&0.0).unwrap(), &2.0);
Source§type Output = Result<HashHistogram<A, V>, BinaryOperationError>
type Output = Result<HashHistogram<A, V>, BinaryOperationError>
/
operator.Source§impl<A: Axis + PartialEq, V> DivAssign<&HashHistogram<A, V>> for HashHistogram<A, V>
impl<A: Axis + PartialEq, V> DivAssign<&HashHistogram<A, V>> for HashHistogram<A, V>
Source§fn div_assign(&mut self, rhs: &HashHistogram<A, V>)
fn div_assign(&mut self, rhs: &HashHistogram<A, V>)
Combine the right-hand histogram with the left-hand histogram, mutating the left-hand histogram.
§Panics
Panics if the histograms have incompatible axes. To handle this failure mode at runtime, use the non-assign version of this operation, which returns an Result.
§Examples
use ndhistogram::{Histogram, sparsehistogram, axis::Uniform};
let mut hist1 = sparsehistogram!(Uniform::<f64>::new(10, -5.0, 5.0)?);
let mut hist2 = sparsehistogram!(Uniform::<f64>::new(10, -5.0, 5.0)?);
hist1.fill_with(&0.0, 2.0);
hist2.fill(&0.0);
hist1 /= &hist2;
assert_eq!(hist1.value(&0.0).unwrap(), &2.0);
Source§impl<A: Axis, V: Default> Histogram<A, V> for HashHistogram<A, V>
impl<A: Axis, V: Default> Histogram<A, V> for HashHistogram<A, V>
Source§fn value_at_index(&self, index: usize) -> Option<&V>
fn value_at_index(&self, index: usize) -> Option<&V>
Source§fn iter(
&self,
) -> Box<dyn Iterator<Item = Item<<A as Axis>::BinInterval, &'_ V>> + '_>
fn iter( &self, ) -> Box<dyn Iterator<Item = Item<<A as Axis>::BinInterval, &'_ V>> + '_>
Source§fn value_at_index_mut(&mut self, index: usize) -> Option<&mut V>
fn value_at_index_mut(&mut self, index: usize) -> Option<&mut V>
Source§fn values_mut(&mut self) -> Box<dyn Iterator<Item = &'_ mut V> + '_>
fn values_mut(&mut self) -> Box<dyn Iterator<Item = &'_ mut V> + '_>
Source§fn iter_mut(
&mut self,
) -> Box<dyn Iterator<Item = Item<<A as Axis>::BinInterval, &'_ mut V>> + '_>
fn iter_mut( &mut self, ) -> Box<dyn Iterator<Item = Item<<A as Axis>::BinInterval, &'_ mut V>> + '_>
Source§fn fill(&mut self, coordinate: &A::Coordinate)where
V: Fill,
fn fill(&mut self, coordinate: &A::Coordinate)where
V: Fill,
Source§fn fill_with<D>(&mut self, coordinate: &A::Coordinate, data: D)where
V: FillWith<D>,
fn fill_with<D>(&mut self, coordinate: &A::Coordinate, data: D)where
V: FillWith<D>,
Source§fn fill_with_weighted<D, W>(
&mut self,
coordinate: &A::Coordinate,
data: D,
weight: W,
)where
V: FillWithWeighted<D, W>,
fn fill_with_weighted<D, W>(
&mut self,
coordinate: &A::Coordinate,
data: D,
weight: W,
)where
V: FillWithWeighted<D, W>,
Source§impl<'a, A: Axis, V> IntoIterator for &'a HashHistogram<A, V>where
HashHistogram<A, V>: Histogram<A, V>,
impl<'a, A: Axis, V> IntoIterator for &'a HashHistogram<A, V>where
HashHistogram<A, V>: Histogram<A, V>,
Source§impl<'a, A: Axis, V: 'a> IntoIterator for &'a mut HashHistogram<A, V>where
HashHistogram<A, V>: Histogram<A, V>,
impl<'a, A: Axis, V: 'a> IntoIterator for &'a mut HashHistogram<A, V>where
HashHistogram<A, V>: Histogram<A, V>,
Source§impl<A: Axis + PartialEq + Clone, V> Mul<&HashHistogram<A, V>> for &HashHistogram<A, V>
impl<A: Axis + PartialEq + Clone, V> Mul<&HashHistogram<A, V>> for &HashHistogram<A, V>
Source§fn mul(self, rhs: &HashHistogram<A, V>) -> Self::Output
fn mul(self, rhs: &HashHistogram<A, V>) -> Self::Output
Combine the right-hand histogram with the left-hand histogram, returning a copy, and leaving the original histograms intact.
If the input histograms have incompatible axes, this operation will return a crate::error::BinaryOperationError.
§Examples
use ndhistogram::{Histogram, sparsehistogram, axis::Uniform};
let mut hist1 = sparsehistogram!(Uniform::<f64>::new(10, -5.0, 5.0)?);
let mut hist2 = sparsehistogram!(Uniform::<f64>::new(10, -5.0, 5.0)?);
hist1.fill_with(&0.0, 2.0);
hist2.fill(&0.0);
let combined_hist = (&hist1 * &hist2).expect("Axes are compatible");
assert_eq!(combined_hist.value(&0.0).unwrap(), &2.0);
Source§type Output = Result<HashHistogram<A, V>, BinaryOperationError>
type Output = Result<HashHistogram<A, V>, BinaryOperationError>
*
operator.Source§impl<A: Axis + PartialEq + Clone, V> Mul<&HashHistogram<A, V>> for HashHistogram<A, V>
impl<A: Axis + PartialEq + Clone, V> Mul<&HashHistogram<A, V>> for HashHistogram<A, V>
Source§fn mul(self, rhs: &HashHistogram<A, V>) -> Self::Output
fn mul(self, rhs: &HashHistogram<A, V>) -> Self::Output
Combine the right-hand histogram with the left-hand histogram, consuming the left-hand histogram and returning a new value. As this avoids making copies of the histograms, this is the recommended method to merge histograms.
If the input histograms have incompatible axes, this operation will return a crate::error::BinaryOperationError.
§Examples
use ndhistogram::{Histogram, sparsehistogram, axis::Uniform};
let mut hist1 = sparsehistogram!(Uniform::<f64>::new(10, -5.0, 5.0)?);
let mut hist2 = sparsehistogram!(Uniform::<f64>::new(10, -5.0, 5.0)?);
hist1.fill_with(&0.0, 2.0);
hist2.fill(&0.0);
let combined_hist = (hist1 * &hist2).expect("Axes are compatible");
assert_eq!(combined_hist.value(&0.0).unwrap(), &2.0);
Source§type Output = Result<HashHistogram<A, V>, BinaryOperationError>
type Output = Result<HashHistogram<A, V>, BinaryOperationError>
*
operator.Source§impl<A: Axis + PartialEq, V> MulAssign<&HashHistogram<A, V>> for HashHistogram<A, V>
impl<A: Axis + PartialEq, V> MulAssign<&HashHistogram<A, V>> for HashHistogram<A, V>
Source§fn mul_assign(&mut self, rhs: &HashHistogram<A, V>)
fn mul_assign(&mut self, rhs: &HashHistogram<A, V>)
Combine the right-hand histogram with the left-hand histogram, mutating the left-hand histogram.
§Panics
Panics if the histograms have incompatible axes. To handle this failure mode at runtime, use the non-assign version of this operation, which returns an Result.
§Examples
use ndhistogram::{Histogram, sparsehistogram, axis::Uniform};
let mut hist1 = sparsehistogram!(Uniform::<f64>::new(10, -5.0, 5.0)?);
let mut hist2 = sparsehistogram!(Uniform::<f64>::new(10, -5.0, 5.0)?);
hist1.fill_with(&0.0, 2.0);
hist2.fill(&0.0);
hist1 *= &hist2;
assert_eq!(hist1.value(&0.0).unwrap(), &2.0);
Source§impl<A, V> Serialize for HashHistogram<A, V>
impl<A, V> Serialize for HashHistogram<A, V>
Source§impl<A: Axis + PartialEq + Clone, V> Sub<&HashHistogram<A, V>> for &HashHistogram<A, V>
impl<A: Axis + PartialEq + Clone, V> Sub<&HashHistogram<A, V>> for &HashHistogram<A, V>
Source§fn sub(self, rhs: &HashHistogram<A, V>) -> Self::Output
fn sub(self, rhs: &HashHistogram<A, V>) -> Self::Output
Combine the right-hand histogram with the left-hand histogram, returning a copy, and leaving the original histograms intact.
If the input histograms have incompatible axes, this operation will return a crate::error::BinaryOperationError.
§Examples
use ndhistogram::{Histogram, sparsehistogram, axis::Uniform};
let mut hist1 = sparsehistogram!(Uniform::<f64>::new(10, -5.0, 5.0)?);
let mut hist2 = sparsehistogram!(Uniform::<f64>::new(10, -5.0, 5.0)?);
hist1.fill_with(&0.0, 2.0);
hist2.fill(&0.0);
let combined_hist = (&hist1 - &hist2).expect("Axes are compatible");
assert_eq!(combined_hist.value(&0.0).unwrap(), &1.0);
Source§type Output = Result<HashHistogram<A, V>, BinaryOperationError>
type Output = Result<HashHistogram<A, V>, BinaryOperationError>
-
operator.Source§impl<A: Axis + PartialEq + Clone, V> Sub<&HashHistogram<A, V>> for HashHistogram<A, V>
impl<A: Axis + PartialEq + Clone, V> Sub<&HashHistogram<A, V>> for HashHistogram<A, V>
Source§fn sub(self, rhs: &HashHistogram<A, V>) -> Self::Output
fn sub(self, rhs: &HashHistogram<A, V>) -> Self::Output
Combine the right-hand histogram with the left-hand histogram, consuming the left-hand histogram and returning a new value. As this avoids making copies of the histograms, this is the recommended method to merge histograms.
If the input histograms have incompatible axes, this operation will return a crate::error::BinaryOperationError.
§Examples
use ndhistogram::{Histogram, sparsehistogram, axis::Uniform};
let mut hist1 = sparsehistogram!(Uniform::<f64>::new(10, -5.0, 5.0)?);
let mut hist2 = sparsehistogram!(Uniform::<f64>::new(10, -5.0, 5.0)?);
hist1.fill_with(&0.0, 2.0);
hist2.fill(&0.0);
let combined_hist = (hist1 - &hist2).expect("Axes are compatible");
assert_eq!(combined_hist.value(&0.0).unwrap(), &1.0);
Source§type Output = Result<HashHistogram<A, V>, BinaryOperationError>
type Output = Result<HashHistogram<A, V>, BinaryOperationError>
-
operator.Source§impl<A: Axis + PartialEq, V> SubAssign<&HashHistogram<A, V>> for HashHistogram<A, V>
impl<A: Axis + PartialEq, V> SubAssign<&HashHistogram<A, V>> for HashHistogram<A, V>
Source§fn sub_assign(&mut self, rhs: &HashHistogram<A, V>)
fn sub_assign(&mut self, rhs: &HashHistogram<A, V>)
Combine the right-hand histogram with the left-hand histogram, mutating the left-hand histogram.
§Panics
Panics if the histograms have incompatible axes. To handle this failure mode at runtime, use the non-assign version of this operation, which returns an Result.
§Examples
use ndhistogram::{Histogram, sparsehistogram, axis::Uniform};
let mut hist1 = sparsehistogram!(Uniform::<f64>::new(10, -5.0, 5.0)?);
let mut hist2 = sparsehistogram!(Uniform::<f64>::new(10, -5.0, 5.0)?);
hist1.fill_with(&0.0, 2.0);
hist2.fill(&0.0);
hist1 -= &hist2;
assert_eq!(hist1.value(&0.0).unwrap(), &1.0);
impl<A: Eq, V: Eq> Eq for HashHistogram<A, V>
impl<A, V> StructuralPartialEq for HashHistogram<A, V>
Auto Trait Implementations§
impl<A, V> Freeze for HashHistogram<A, V>where
A: Freeze,
impl<A, V> RefUnwindSafe for HashHistogram<A, V>where
A: RefUnwindSafe,
V: RefUnwindSafe,
impl<A, V> Send for HashHistogram<A, V>
impl<A, V> Sync for HashHistogram<A, V>
impl<A, V> Unpin for HashHistogram<A, V>
impl<A, V> UnwindSafe for HashHistogram<A, V>where
A: UnwindSafe,
V: 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