pub struct PackedBinaryMatrix { /* private fields */ }Expand description
Row-major 1-bit packed matrix with values in {-1, +1}.
Bit encoding follows upstream quantization/utils/binary_packer.py (lsb_first):
+1maps to bit0-1maps to bit1- Rows are padded on the right to multiples of 32 with
+1(bit0) - Each 32-bit chunk is stored as a signed
i32word (LSB = lowest column index)
Implementations§
Source§impl PackedBinaryMatrix
impl PackedBinaryMatrix
Sourcepub fn from_words(rows: usize, cols: usize, data: Vec<i32>) -> Result<Self>
pub fn from_words(rows: usize, cols: usize, data: Vec<i32>) -> Result<Self>
Construct from pre-packed row-major 32-bit words after validating dimensions.
§Errors
Returns LittleBitError::InvalidShape when data.len() != rows * cols.div_ceil(32).
Sourcepub fn words_per_row(&self) -> usize
pub fn words_per_row(&self) -> usize
Number of i32 words stored per row (cols.div_ceil(32)).
Sourcepub fn memory_bytes(&self) -> usize
pub fn memory_bytes(&self) -> usize
Heap memory footprint in bytes of the packed word storage.
Sourcepub fn unpack_to_i8(&self) -> Vec<i8>
pub fn unpack_to_i8(&self) -> Vec<i8>
Unpack back to row-major Vec<i8> containing only -1 and +1.
Sourcepub fn matmul_transposed_f32(
&self,
x: &[f32],
batch_rows: usize,
) -> Result<Vec<f32>>
pub fn matmul_transposed_f32( &self, x: &[f32], batch_rows: usize, ) -> Result<Vec<f32>>
Compute Y = X @ W^T where X is (batch_rows, cols) in row-major f32
and W (self) is (rows, cols) packed at 1 bit per weight.
Returns a row-major Vec<f32> of shape (batch_rows, rows) without unpacking W.
§Errors
Returns LittleBitError::InvalidShape when x.len() != batch_rows * self.cols.
Sourcepub fn to_tensors(&self, device: &Device) -> Result<(Tensor, Tensor)>
pub fn to_tensors(&self, device: &Device) -> Result<(Tensor, Tensor)>
Convert packed storage into (packed_i32, shape_i64) tensors matching upstream safetensors.
§Errors
Returns an error if tensor creation fails.
Trait Implementations§
Source§impl Clone for PackedBinaryMatrix
impl Clone for PackedBinaryMatrix
Source§impl Debug for PackedBinaryMatrix
impl Debug for PackedBinaryMatrix
impl Eq for PackedBinaryMatrix
Source§impl PartialEq for PackedBinaryMatrix
impl PartialEq for PackedBinaryMatrix
impl StructuralPartialEq for PackedBinaryMatrix
Auto Trait Implementations§
impl Freeze for PackedBinaryMatrix
impl RefUnwindSafe for PackedBinaryMatrix
impl Send for PackedBinaryMatrix
impl Sync for PackedBinaryMatrix
impl Unpin for PackedBinaryMatrix
impl UnsafeUnpin for PackedBinaryMatrix
impl UnwindSafe for PackedBinaryMatrix
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
impl<T, U> Imply<T> for U
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