Skip to content

Instantly share code, notes, and snippets.

@ChillFish8
Last active July 2, 2024 16:49
Show Gist options
  • Save ChillFish8/5e1fc739949bae7acffbc0bfc3eda80a to your computer and use it in GitHub Desktop.
Save ChillFish8/5e1fc739949bae7acffbc0bfc3eda80a to your computer and use it in GitHub Desktop.
A simple f32 vector dot product.
fn simple_dot_product(vector_a: &[f32], vector_b: &[f32]) -> f32 {
assert_eq!(vector_a.len(), vector_b.len(), "Vectors must be equal in length");
let dims = vector_a.len();
let mut total = 0.0;
// Quick disclaimer: I'm going to be using while loops here for consistency across
// the code samples.
let mut i = 0;
while i < dims {
let a = vector_a[i];
let b = vector_b[i];
total += a * b;
i += 1;
}
total
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment