pub struct Codebook {
pub bits: u8,
pub centroids: &'static [f32],
pub boundaries: &'static [f32],
}Expand description
A scalar quantizer codebook for a given bit-width.
Fields§
§bits: u8Bit-width (1-4).
centroids: &'static [f32]Reconstruction centroids in ascending order (2^b values).
boundaries: &'static [f32]Decision boundaries (2^b - 1 midpoints between consecutive centroids).
Implementations§
Source§impl Codebook
impl Codebook
Sourcepub fn for_bits(bits: u8) -> Result<&'static Codebook, QuantError>
pub fn for_bits(bits: u8) -> Result<&'static Codebook, QuantError>
Get the codebook for a given bit-width.
Sourcepub fn quantize_scalar(&self, x: f32) -> u8
pub fn quantize_scalar(&self, x: f32) -> u8
Find the index of the nearest centroid for a scalar value.
Sourcepub fn dequantize_scalar(&self, idx: u8) -> f32
pub fn dequantize_scalar(&self, idx: u8) -> f32
Look up the centroid for a given index.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Codebook
impl RefUnwindSafe for Codebook
impl Send for Codebook
impl Sync for Codebook
impl Unpin for Codebook
impl UnsafeUnpin for Codebook
impl UnwindSafe for Codebook
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more