Struct Edges

Source
pub struct Edges<A: Ord + Send> { /* private fields */ }
Expand description

A sorted collection of type A elements used to represent the boundaries of intervals, i.e. Bins on a 1-dimensional axis.

Note that all intervals are left-closed and right-open. See examples below.

§Examples

use ndarray_histogram::{
	histogram::{Bins, Edges},
	o64,
};

let unit_edges = Edges::from(vec![o64(0.), o64(1.)]);
let unit_interval = Bins::new(unit_edges);
// left-closed
assert_eq!(unit_interval.range_of(&o64(0.)).unwrap(), o64(0.)..o64(1.),);
// right-open
assert_eq!(unit_interval.range_of(&o64(1.)), None);

Implementations§

Source§

impl<A: Ord + Send> Edges<A>

Source

pub fn len(&self) -> usize

Returns the number of edges in self.

§Examples
use ndarray_histogram::{histogram::Edges, o64};

let edges = Edges::from(vec![o64(0.), o64(1.), o64(3.)]);
assert_eq!(edges.len(), 3);
Source

pub fn is_empty(&self) -> bool

Returns true if self contains no edges.

§Examples
use ndarray_histogram::{O64, histogram::Edges, o64};

let edges = Edges::<O64>::from(vec![]);
assert_eq!(edges.is_empty(), true);

let edges = Edges::from(vec![o64(0.), o64(2.), o64(5.)]);
assert_eq!(edges.is_empty(), false);
Source

pub fn as_array_view(&self) -> ArrayView1<'_, A>

Returns an immutable 1-dimensional array view of edges.

§Examples
use ndarray::array;
use ndarray_histogram::histogram::Edges;

let edges = Edges::from(vec![0, 5, 3]);
assert_eq!(edges.as_array_view(), array![0, 3, 5].view());
Source

pub fn indices_of(&self, value: &A) -> Option<(usize, usize)>

Returns indices of two consecutive edges in self, if the interval they represent contains the given value, or returns None otherwise.

That is to say, it returns

  • Some((left, right)),

where left and right are the indices of two consecutive edges in self and right == left + 1, if self[left] <= value < self[right] it returns

  • None,

else otherwise.

§Examples
use ndarray_histogram::histogram::Edges;

let edges = Edges::from(vec![0, 2, 3]);
// `1` is in the interval [0, 2), whose indices are (0, 1)
assert_eq!(edges.indices_of(&1), Some((0, 1)));
// `5` is not in any of intervals
assert_eq!(edges.indices_of(&5), None);
Source

pub fn iter(&self) -> impl Iterator<Item = &A>

Returns an iterator over the edges in self.

Trait Implementations§

Source§

impl<A: Clone + Ord + Send> Clone for Edges<A>

Source§

fn clone(&self) -> Edges<A>

Returns a duplicate 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<A: Debug + Ord + Send> Debug for Edges<A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<A: Ord + Send + Clone> From<ArrayBase<OwnedRepr<A>, Dim<[usize; 1]>>> for Edges<A>

Source§

fn from(edges: Array1<A>) -> Self

Converts an Array1<A> into an Edges<A>, consuming the 1-dimensional array. The array will be sorted in increasing order using an unstable sorting algorithm, with duplicates removed.

§Current implementation

The current sorting algorithm is the same as std::slice::sort_unstable(), which is based on pattern-defeating quicksort.

This sort is unstable (i.e., may reorder equal elements), in-place (i.e., does not allocate) , and O(n log n) worst-case.

§Examples
use ndarray_histogram::histogram::Edges;

let edges = Edges::from(vec![1, 15, 10, 20]);
// The vec gets sorted!
assert_eq!(edges[1], 10);
Source§

impl<A: Ord + Send> From<Vec<A>> for Edges<A>

Source§

fn from(edges: Vec<A>) -> Self

Converts a Vec<A> into an Edges<A>, consuming the edges. The vector will be sorted in increasing order using an unstable sorting algorithm, with duplicates removed.

§Current implementation

The current sorting algorithm is the same as std::slice::sort_unstable(), which is based on pattern-defeating quicksort.

This sort is unstable (i.e., may reorder equal elements), in-place (i.e., does not allocate) , and O(n log n) worst-case.

§Examples
use ndarray::array;
use ndarray_histogram::histogram::Edges;

let edges = Edges::from(array![1, 15, 10, 10, 20]);
// The array gets sorted!
assert_eq!(edges[2], 15);
Source§

impl<A: Ord + Send> Index<usize> for Edges<A>

Source§

fn index(&self, i: usize) -> &Self::Output

Returns a reference to the i-th edge in self.

§Panics

Panics if the index i is out of bounds.

§Examples
use ndarray_histogram::histogram::Edges;

let edges = Edges::from(vec![1, 5, 10, 20]);
assert_eq!(edges[1], 5);
Source§

type Output = A

The returned type after indexing.
Source§

impl<A: PartialEq + Ord + Send> PartialEq for Edges<A>

Source§

fn eq(&self, other: &Edges<A>) -> 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<A: Eq + Ord + Send> Eq for Edges<A>

Source§

impl<A: Ord + Send> StructuralPartialEq for Edges<A>

Auto Trait Implementations§

§

impl<A> Freeze for Edges<A>

§

impl<A> RefUnwindSafe for Edges<A>
where A: RefUnwindSafe,

§

impl<A> Send for Edges<A>

§

impl<A> Sync for Edges<A>
where A: Sync,

§

impl<A> Unpin for Edges<A>
where A: Unpin,

§

impl<A> UnwindSafe for Edges<A>
where A: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.