Skip to main content

QuantizedMatrix

Struct QuantizedMatrix 

Source
pub struct QuantizedMatrix { /* private fields */ }
Expand description

A row-quantized f32 matrix: one i8 code per element plus one f32 scale per row.

Implementations§

Source§

impl QuantizedMatrix

Source

pub fn data(&self) -> &Array2<i8>

The (n_rows, n_cols) int8 code matrix.

Source

pub fn scales(&self) -> &Array1<f32>

The per-row f32 scales (len == n_rows).

Source

pub fn nrows(&self) -> usize

Number of rows.

Source

pub fn ncols(&self) -> usize

Number of columns.

Source

pub fn dequantize(&self) -> Array2<f32>

Reconstruct (decode) the approximate f32 matrix as code * scale[row].

Source

pub fn from_parts( data: Array2<i8>, scales: Array1<f32>, ) -> Result<Self, EmbeddingError>

Construct a QuantizedMatrix from existing codes and scales (for example, decoded from a wire format).

§Errors

Returns EmbeddingError::EmptyInput when data is empty and EmbeddingError::DimensionMismatch when scales.len() != data.nrows().

Source

pub fn query_corpus_scores_quantized( &self, corpus: &QuantizedMatrix, metric: Metric, ) -> Result<Array2<f32>, EmbeddingError>

Score this quantized matrix as queries against a quantized corpus under metric.

Implemented as dequantize-then-existing-kernel: both operands are decoded to f32 and scored with query_corpus_scores. Results approximate the full-precision path within the quantization tolerance.

§Errors

Returns the same errors as query_corpus_scores (empty input, dimension mismatch, or cosine zero-norm rows).

Trait Implementations§

Source§

impl Clone for QuantizedMatrix

Source§

fn clone(&self) -> QuantizedMatrix

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for QuantizedMatrix

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for QuantizedMatrix

Source§

fn eq(&self, other: &QuantizedMatrix) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for QuantizedMatrix

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V