split_weighted

Function split_weighted 

Source
pub fn split_weighted(
    total: usize,
    weights: Vec<usize>,
) -> Result<Vec<NonZeroUsize>, String>
Expand description

Splits the total based on provided weights for each batch.

§Arguments

  • total - The total number to be split.
  • weights - A vector of weights for each batch.

§Returns

A Result containing a vector of NonZeroUsize representing the size of each batch.

§Errors

Returns an error if:

  • The total is zero.
  • The weights vector is empty.
  • Any weight is zero.

§Examples

use batch_maestro::split_weighted;
use std::num::NonZeroUsize;

let batch_sizes = split_weighted(100, vec![1, 2, 3]).unwrap();
assert_eq!(batch_sizes, vec![NonZeroUsize::new(17).unwrap(), NonZeroUsize::new(33).unwrap(), NonZeroUsize::new(50).unwrap()]);