Skip to main content

quantize_slice_dithered

Function quantize_slice_dithered 

Source
pub fn quantize_slice_dithered(
    xs: &mut [f32],
    bits: u32,
    eps: f32,
    source: &mut impl DitherSource,
)
Expand description

Quantize a slice in-place with deterministic dither.

Each element gets an independent dither sample from source.

§Example

use ruvector_dither::{GoldenRatioDither, quantize_slice_dithered};
let mut vals = vec![0.1_f32, 0.5, -0.3, 0.9, -0.8];
let mut d = GoldenRatioDither::new(0.0);
quantize_slice_dithered(&mut vals, 5, 0.5, &mut d);
for &v in &vals {
    assert!(v >= -1.0 && v <= 1.0);
}