pub struct QuantizedTensorGeneric<R: QuantRange> { /* private fields */ }Expand description
Generic quantized tensor, parameterized by bit-width marker.
For INT4 tensors, call QuantizedTensorGeneric::pack to compress two
values per byte for 2× storage savings.
Implementations§
Source§impl<R: QuantRange> QuantizedTensorGeneric<R>
impl<R: QuantRange> QuantizedTensorGeneric<R>
Sourcepub fn params(&self) -> &QuantParamsGeneric<R>
pub fn params(&self) -> &QuantParamsGeneric<R>
Per-tensor quantization parameters (channel-0 if per-channel).
Sourcepub fn is_per_channel(&self) -> bool
pub fn is_per_channel(&self) -> bool
Whether per-channel quantization was used.
Sourcepub fn from_f32(data: &[f32], shape: Vec<usize>) -> Result<Self>
pub fn from_f32(data: &[f32], shape: Vec<usize>) -> Result<Self>
Quantize FP32 data, computing the range from the data.
§Errors
Returns QuantizeError::InvalidTensor if data is empty or shape mismatches.
Sourcepub fn from_f32_with_range(
data: &[f32],
shape: Vec<usize>,
min: f32,
max: f32,
) -> Result<Self>
pub fn from_f32_with_range( data: &[f32], shape: Vec<usize>, min: f32, max: f32, ) -> Result<Self>
Quantize FP32 data using an explicit range (for calibration).
§Errors
Returns QuantizeError::InvalidTensor if data is empty or shape mismatches.
Sourcepub fn from_f32_per_channel(data: &[f32], shape: Vec<usize>) -> Result<Self>
pub fn from_f32_per_channel(data: &[f32], shape: Vec<usize>) -> Result<Self>
Quantize FP32 data with per-channel ranges (axis 0 only).
§Errors
Returns QuantizeError::InvalidTensor if data is empty, shape
mismatches, or the tensor is scalar.
Sourcepub fn size_bytes(&self) -> usize
pub fn size_bytes(&self) -> usize
Size of the quantized data in bytes (packed if available, unpacked otherwise).
Sourcepub fn quantization_error(&self, original: &[f32]) -> f32
pub fn quantization_error(&self, original: &[f32]) -> f32
Mean squared error between the original data and the dequantized values.
Source§impl QuantizedTensorGeneric<Int4Range>
impl QuantizedTensorGeneric<Int4Range>
Sourcepub fn ensure_unpacked(&self) -> Vec<i8>
pub fn ensure_unpacked(&self) -> Vec<i8>
Return unpacked i8 data, decompressing from packed storage if needed.
Sourcepub fn packed_size_bytes(&self) -> usize
pub fn packed_size_bytes(&self) -> usize
Size that the packed representation would occupy (or already occupies).
Sourcepub fn unpacked_size_bytes(&self) -> usize
pub fn unpacked_size_bytes(&self) -> usize
Size of the unpacked representation in bytes.
Trait Implementations§
Source§impl<R: Clone + QuantRange> Clone for QuantizedTensorGeneric<R>
impl<R: Clone + QuantRange> Clone for QuantizedTensorGeneric<R>
Source§fn clone(&self) -> QuantizedTensorGeneric<R>
fn clone(&self) -> QuantizedTensorGeneric<R>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<R> Freeze for QuantizedTensorGeneric<R>
impl<R> RefUnwindSafe for QuantizedTensorGeneric<R>where
R: RefUnwindSafe,
impl<R> Send for QuantizedTensorGeneric<R>
impl<R> Sync for QuantizedTensorGeneric<R>
impl<R> Unpin for QuantizedTensorGeneric<R>where
R: Unpin,
impl<R> UnsafeUnpin for QuantizedTensorGeneric<R>
impl<R> UnwindSafe for QuantizedTensorGeneric<R>where
R: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more