QuantizedMatrixFreeOp

Struct QuantizedMatrixFreeOp 

Source
pub struct QuantizedMatrixFreeOp<F>
where F: Float + NumAssign + Zero + Sum + One + ScalarOperand + Send + Sync + Debug + 'static,
{ /* private fields */ }
Expand description

A matrix-free operator that represents a quantized matrix

Implementations§

Source§

impl<F> QuantizedMatrixFreeOp<F>

Source

pub fn new<O>( rows: usize, cols: usize, bits: u8, method: QuantizationMethod, op_fn: O, ) -> LinalgResult<Self>
where O: Fn(&ArrayView1<'_, F>) -> LinalgResult<Array1<F>> + Send + Sync + 'static,

Create a new quantized matrix-free operator from a function

This allows direct specification of how the operator acts on vectors without materializing the quantized matrix.

§Arguments
  • rows - Number of rows in the matrix
  • cols - Number of columns in the matrix
  • bits - Bit width for quantization
  • method - Quantization method
  • op_fn - Function that implements the matrix-vector product in the quantized domain
§Returns

A new QuantizedMatrixFreeOp instance

Source

pub fn frommatrix( matrix: &ArrayView2<'_, F>, bits: u8, method: QuantizationMethod, ) -> LinalgResult<Self>

Create a quantized matrix-free operator from an explicit matrix

This quantizes the matrix and creates a matrix-free operator that applies the quantized matrix without materializing it for each operation.

§Arguments
  • matrix - Matrix to quantize
  • bits - Bit width for quantization
  • method - Quantization method
§Returns

A new QuantizedMatrixFreeOp instance

Source

pub fn symmetric(self) -> Self

Mark the operator as symmetric

§Returns

Self with the symmetric flag set to true

Source

pub fn positive_definite(self) -> Self

Mark the operator as positive definite

§Returns

Self with the positive_definite flag set to true

Source

pub fn params(&self) -> &QuantizationParams

Get the quantization parameters

Source

pub fn block_diagonal( blocks: Vec<ArrayView2<'_, F>>, bits: u8, method: QuantizationMethod, ) -> LinalgResult<Self>

Create a memory-efficient operator for block-diagonal matrices

This is particularly useful for large models with block structure, as it avoids materializing the full matrix.

§Arguments
  • blocks - A vector of smaller matrices to place on the diagonal
  • bits - Bit width for quantization
  • method - Quantization method
§Returns

A new QuantizedMatrixFreeOp instance

Source

pub fn sparse( rows: usize, cols: usize, indices: Vec<(usize, usize)>, values: &ArrayView1<'_, F>, bits: u8, method: QuantizationMethod, ) -> LinalgResult<Self>

Create a memory-efficient operator for structured sparse matrices

This is particularly useful for large sparse models, as it stores only the non-zero elements and their indices.

§Arguments
  • rows - Number of rows in the matrix
  • cols - Number of columns in the matrix
  • indices - Pairs of (row, column) indices for non-zero elements
  • values - Values at the corresponding indices
  • bits - Bit width for quantization
  • method - Quantization method
§Returns

A new QuantizedMatrixFreeOp instance

Source

pub fn banded( n: usize, bands: Vec<(isize, ArrayView1<'_, F>)>, bits: u8, method: QuantizationMethod, ) -> LinalgResult<Self>

Create a memory-efficient operator for a banded matrix

This is particularly useful for banded matrices like tridiagonal or pentadiagonal matrices, as it stores only the bands.

§Arguments
  • n - Size of the square matrix
  • bands - Vector of (offset, band_values) pairs, where offset is the diagonal offset (0 for main diagonal, 1 for first super-diagonal, -1 for first sub-diagonal)
  • bits - Bit width for quantization
  • method - Quantization method
§Returns

A new QuantizedMatrixFreeOp instance

Trait Implementations§

Source§

impl<F> Clone for QuantizedMatrixFreeOp<F>
where F: Float + NumAssign + Zero + Sum + One + ScalarOperand + Send + Sync + Debug + 'static,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<F> MatrixFreeOp<F> for QuantizedMatrixFreeOp<F>
where F: Float + NumAssign + Zero + Sum + One + ScalarOperand + Send + Sync + Debug + 'static,

Source§

fn apply(&self, x: &ArrayView1<'_, F>) -> LinalgResult<Array1<F>>

Apply the linear operator to a vector
Source§

fn nrows(&self) -> usize

Get the number of rows in the linear operator
Source§

fn ncols(&self) -> usize

Get the number of columns in the linear operator
Source§

fn is_symmetric(&self) -> bool

Check if the linear operator is symmetric
Source§

fn is_positive_definite(&self) -> bool

Check if the linear operator is positive definite

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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