Function smartnoise_runtime::components::digitize::digitize[][src]

pub fn digitize<T: PartialOrd + Clone + Div<T, Output = T> + Add<T, Output = T> + Copy + Default>(
    data: ArrayD<T>,
    edges: Vec<Vec<T>>,
    inclusive_left: ArrayD<bool>,
    null: ArrayD<Integer>
) -> Result<ArrayD<Integer>>

Maps data in bins to digits.

Bins will be of the form [lower, upper) or (lower, upper].

Arguments

Return

Binned data.

Example

use ndarray::{ArrayD, arr2, arr1};
use smartnoise_runtime::components::digitize::{bin_index, digitize};
use smartnoise_validator::utilities::standardize_float_argument;
use smartnoise_runtime::utilities::get_num_columns;
use smartnoise_validator::Float;

let data: ArrayD<Float> = arr1(&[1.1, 2., 2.9, 4.1, 6.4]).into_dyn();
let edges = vec![vec![0., 1., 2., 3., 4., 5.]];
let inclusive_left = arr1(&[true]).into_dyn();
let null = arr1(&[-1]).into_dyn();


let num_columns = get_num_columns(&data).unwrap();
let edges = standardize_float_argument(edges, num_columns).unwrap();

let digitization = digitize(data, edges, inclusive_left, null).unwrap();
println!("digitize {:?}", digitization);
assert_eq!(digitization, arr1(&[1, 2, 2, 4, -1]).into_dyn());