Function smartnoise_runtime::components::partition::partition_ndarray_evenly[][src]

pub fn partition_ndarray_evenly<T: Clone + Default + Debug>(
    data: &ArrayD<T>,
    num_partitions: i64
) -> IndexMap<IndexKey, ArrayD<T>>

Partitions data evenly into num_partitions partitions

The first partitions may have one more element than the latter partitions.

Arguments

Return

Indexmap with data splits.

Example

use ndarray::{ArrayD, arr1, arr2};
use smartnoise_runtime::components::partition::partition_ndarray_evenly;
use smartnoise_validator::base::IndexKey;

let data = arr2(&[ [1, 2], [4, 5], [7, 8], [10, 11] ]).into_dyn();
let partitioned = partition_ndarray_evenly(&data, 3);
assert_eq!(partitioned.get::<IndexKey>(&0.into()).unwrap().clone(), arr2(&[ [1, 2], [4, 5] ]).into_dyn());
assert_eq!(partitioned.get::<IndexKey>(&1.into()).unwrap().clone(), arr2(&[ [7, 8] ]).into_dyn());
assert_eq!(partitioned.get::<IndexKey>(&2.into()).unwrap().clone(), arr2(&[ [10, 11] ]).into_dyn());