Struct ndarray_stats::histogram::GridBuilder

source ·
pub struct GridBuilder<B: BinsBuildingStrategy> { /* private fields */ }
Expand description

A builder used to create Grid instances for histogram computations.

§Examples

Basic usage, creating a Grid with some observations and a given strategy:

use ndarray::Array;
use ndarray_stats::histogram::{strategies::Auto, Bins, Edges, Grid, GridBuilder};

// 1-dimensional observations, as a (n_observations, n_dimension) 2-d matrix
let observations = Array::from_shape_vec(
    (12, 1),
    vec![1, 4, 5, 2, 100, 20, 50, 65, 27, 40, 45, 23],
).unwrap();

// The optimal grid layout is inferred from the data, given a chosen strategy, Auto in this case
let grid = GridBuilder::<Auto<usize>>::from_array(&observations).unwrap().build();
// Equivalently, build a Grid directly
let expected_grid = Grid::from(vec![Bins::new(Edges::from(vec![1, 20, 39, 58, 77, 96, 115]))]);

assert_eq!(grid, expected_grid);

Implementations§

source§

impl<A, B> GridBuilder<B>
where A: Ord, B: BinsBuildingStrategy<Elem = A>,

source

pub fn from_array<S>(array: &ArrayBase<S, Ix2>) -> Result<Self, BinsBuildError>
where S: Data<Elem = A>,

Returns a GridBuilder for building a Grid with a given strategy and some observations in a 2-dimensionalarray with shape (n_observations, n_dimension).

§Errors

It returns BinsBuildError if it is not possible to build a Grid given the observed data according to the chosen strategy.

§Examples

See Trait-level examples for basic usage.

source

pub fn build(&self) -> Grid<A>

Returns a Grid instance, with building parameters infered in from_array, according to the specified strategy and observations provided.

§Examples

See [Trait-level examples] for basic usage.

Auto Trait Implementations§

§

impl<B> Freeze for GridBuilder<B>

§

impl<B> RefUnwindSafe for GridBuilder<B>
where B: RefUnwindSafe,

§

impl<B> Send for GridBuilder<B>
where B: Send,

§

impl<B> Sync for GridBuilder<B>
where B: Sync,

§

impl<B> Unpin for GridBuilder<B>
where B: Unpin,

§

impl<B> UnwindSafe for GridBuilder<B>
where B: 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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V