pub struct Edges<A: Ord> { /* 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_stats::histogram::{Bins, Edges};
use noisy_float::types::n64;

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

Implementations

Returns the number of edges in self.

Examples
use ndarray_stats::histogram::Edges;
use noisy_float::types::n64;

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

Returns true if self contains no edges.

Examples
use ndarray_stats::histogram::Edges;
use noisy_float::types::{N64, n64};

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

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

Returns an immutable 1-dimensional array view of edges.

Examples
use ndarray::array;
use ndarray_stats::histogram::Edges;

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

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];
  • None, otherwise.
Examples
use ndarray_stats::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
);

Returns an iterator over the edges in self.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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_stats::histogram::Edges;

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

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_stats::histogram::Edges;

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

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

Panics

Panics if the index i is out of bounds.

Examples
use ndarray_stats::histogram::Edges;

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

The returned type after indexing.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Compare self to key and return true if they are equal.

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.