pub struct CompressionManager<T: Float + Debug + ScalarOperand + Send + Sync + 'static> { /* private fields */ }Expand description
Compression manager
Implementations§
Source§impl<T: Float + Debug + ScalarOperand + Send + Sync + 'static> CompressionManager<T>
impl<T: Float + Debug + ScalarOperand + Send + Sync + 'static> CompressionManager<T>
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
A quantizing compression manager.
There is no configurable target ratio: Self::compress always
quantizes to 8-bit codes, so the achieved ratio is fixed by
size_of::<T>() and reported per payload by
CompressedData::compression_ratio. The compression_ratio this used
to accept was stored and never consulted by the quantizer, which made it
a knob that silently did nothing.
Sourcepub fn compress(&self, tensor: &Array2<T>) -> Result<CompressedData<T>>
pub fn compress(&self, tensor: &Array2<T>) -> Result<CompressedData<T>>
Compress a tensor by affine 8-bit quantization.
Every element is mapped to a u8 code by
code = round((x - min) / step) with step = (max - min) / 255, and the
payload is those codes plus the two f64 parameters min and step.
compressed_size is therefore the real byte count of what is stored:
codes.len() + 2·size_of::<f64>() + shape metadata.
This replaces a version that stored the input verbatim as Vec<T> and
reported compressed_size = bytes / 2 — a fabricated 50% ratio for a
payload that had not shrunk at all.
Quantization is lossy; the reconstruction error is bounded by step / 2
per element, which CompressedData::max_reconstruction_error reports. A constant
tensor (max == min) has step = 0 and round-trips exactly.
§Errors
Returns Err when the tensor is empty or contains a non-finite value
(there is no finite quantization range for NaN/inf).
Sourcepub fn decompress(&self, compressed: &CompressedData<T>) -> Result<Array2<T>>
pub fn decompress(&self, compressed: &CompressedData<T>) -> Result<Array2<T>>
Reconstruct a quantized tensor: x̂ = min + code · step.
§Errors
Returns Err when the stored shape is not two-dimensional or does not
match the number of stored codes.
pub fn store( &mut self, key: String, compressed: CompressedData<T>, ) -> Result<()>
pub fn retrieve(&self, key: &str) -> Result<Option<CompressedData<T>>>
pub fn remove(&mut self, key: &str) -> Result<bool>
pub fn clear(&mut self) -> Result<()>
pub fn get_memory_usage(&self) -> usize
pub fn optimize_compression_ratios( &mut self, _patterns: &AccessPatterns, ) -> Result<()>
Auto Trait Implementations§
impl<T> Freeze for CompressionManager<T>
impl<T> RefUnwindSafe for CompressionManager<T>
impl<T> Send for CompressionManager<T>
impl<T> Sync for CompressionManager<T>
impl<T> Unpin for CompressionManager<T>
impl<T> UnsafeUnpin for CompressionManager<T>
impl<T> UnwindSafe for CompressionManager<T>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.