use crate::slice;
pub fn dispatch_gemv(
weights: &[u8],
scales: &[f32],
block_size: usize,
x: &[f32],
out: &mut [f32],
rows: usize,
cols: usize,
) {
assert_eq!(out.len(), rows, "Output vector length must match matrix rows");
assert_eq!(x.len(), cols, "Input vector length must match matrix cols");
for r in 0..rows {
let mut sum = 0.0f32;
let row_offset = r * cols;
for c in 0..cols {
let global_idx = row_offset + c;
let block_idx = global_idx / block_size;
let scale = scales[block_idx];
if let Some(nibble) = slice::get(weights, global_idx) {
let weight_val = (nibble.value() as f32 - 8.0) * scale;
sum += weight_val * x[c];
}
}
out[r] = sum;
}
}
pub fn dispatch_dot(weights: &[u8], scale: f32, x: &[f32]) -> f32 {
let mut sum = 0.0f32;
let len = slice::len(weights).min(x.len());
for i in 0..len {
if let Some(nibble) = slice::get(weights, i) {
let weight_val = (nibble.value() as f32 - 8.0) * scale;
sum += weight_val * x[i];
}
}
sum
}