Function smartnoise_runtime::components::digitize::bin_index [−][src]
pub fn bin_index<T: PartialOrd + Clone>(
datum: &T,
edges: &[T],
inclusive_left: bool
) -> Option<usize>
Given datum and bin definition, finds index of appropriate bin.
Bins will be of the form [lower, upper) or (lower, upper] and are constructed
from edges
and inclusive_left
.
Arguments
data
- Data to be binned.edges
- Values representing the edges of bins.inclusive_left
- Whether or not the left edge of the bin is inclusive, i.e. the bins are of the form [lower, upper).
Return
Index of appropriate bin.
Example
use smartnoise_runtime::components::digitize::bin_index; let data = vec![1.1, 2., 2.9, 4.1, 6.4]; let edges = vec![0., 1., 2., 3., 4., 5.]; let index1 = bin_index(&data[1], &edges, true); assert_eq!(index1, Some(2)); let index2 = bin_index(&data[1], &edges, false); assert_eq!(index2, Some(1)); let index3 = bin_index(&data[4], &edges, true); assert!(index3.is_none());