pub struct QuantizedMatrixFreeOp<F>{ /* private fields */ }
Expand description
A matrix-free operator that represents a quantized matrix
Implementations§
Source§impl<F> QuantizedMatrixFreeOp<F>where
F: Float + NumAssign + Zero + Sum + One + ScalarOperand + Send + Sync + Debug + FromPrimitive + AsPrimitive<f32> + 'static,
f32: AsPrimitive<F>,
impl<F> QuantizedMatrixFreeOp<F>where
F: Float + NumAssign + Zero + Sum + One + ScalarOperand + Send + Sync + Debug + FromPrimitive + AsPrimitive<f32> + 'static,
f32: AsPrimitive<F>,
Sourcepub fn new<O>(
rows: usize,
cols: usize,
bits: u8,
method: QuantizationMethod,
op_fn: O,
) -> LinalgResult<Self>
pub fn new<O>( rows: usize, cols: usize, bits: u8, method: QuantizationMethod, op_fn: O, ) -> LinalgResult<Self>
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 matrixcols
- Number of columns in the matrixbits
- Bit width for quantizationmethod
- Quantization methodop_fn
- Function that implements the matrix-vector product in the quantized domain
§Returns
A new QuantizedMatrixFreeOp
instance
Sourcepub fn frommatrix(
matrix: &ArrayView2<'_, F>,
bits: u8,
method: QuantizationMethod,
) -> LinalgResult<Self>
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 quantizebits
- Bit width for quantizationmethod
- Quantization method
§Returns
A new QuantizedMatrixFreeOp
instance
Sourcepub fn positive_definite(self) -> Self
pub fn positive_definite(self) -> Self
Sourcepub fn params(&self) -> &QuantizationParams
pub fn params(&self) -> &QuantizationParams
Get the quantization parameters
Sourcepub fn block_diagonal(
blocks: Vec<ArrayView2<'_, F>>,
bits: u8,
method: QuantizationMethod,
) -> LinalgResult<Self>
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 diagonalbits
- Bit width for quantizationmethod
- Quantization method
§Returns
A new QuantizedMatrixFreeOp
instance
Sourcepub fn sparse(
rows: usize,
cols: usize,
indices: Vec<(usize, usize)>,
values: &ArrayView1<'_, F>,
bits: u8,
method: QuantizationMethod,
) -> LinalgResult<Self>
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 matrixcols
- Number of columns in the matrixindices
- Pairs of (row, column) indices for non-zero elementsvalues
- Values at the corresponding indicesbits
- Bit width for quantizationmethod
- Quantization method
§Returns
A new QuantizedMatrixFreeOp
instance
Sourcepub fn banded(
n: usize,
bands: Vec<(isize, ArrayView1<'_, F>)>,
bits: u8,
method: QuantizationMethod,
) -> LinalgResult<Self>
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 matrixbands
- 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 quantizationmethod
- Quantization method
§Returns
A new QuantizedMatrixFreeOp
instance
Trait Implementations§
Source§impl<F> Clone for QuantizedMatrixFreeOp<F>
impl<F> Clone for QuantizedMatrixFreeOp<F>
Source§impl<F> MatrixFreeOp<F> for QuantizedMatrixFreeOp<F>
impl<F> MatrixFreeOp<F> for QuantizedMatrixFreeOp<F>
Source§fn apply(&self, x: &ArrayView1<'_, F>) -> LinalgResult<Array1<F>>
fn apply(&self, x: &ArrayView1<'_, F>) -> LinalgResult<Array1<F>>
Source§fn is_symmetric(&self) -> bool
fn is_symmetric(&self) -> bool
Source§fn is_positive_definite(&self) -> bool
fn is_positive_definite(&self) -> bool
Auto Trait Implementations§
impl<F> Freeze for QuantizedMatrixFreeOp<F>
impl<F> !RefUnwindSafe for QuantizedMatrixFreeOp<F>
impl<F> Send for QuantizedMatrixFreeOp<F>
impl<F> Sync for QuantizedMatrixFreeOp<F>
impl<F> Unpin for QuantizedMatrixFreeOp<F>
impl<F> !UnwindSafe for QuantizedMatrixFreeOp<F>
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> 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