Last active
July 2, 2024 16:49
-
-
Save ChillFish8/5e1fc739949bae7acffbc0bfc3eda80a to your computer and use it in GitHub Desktop.
A simple f32 vector dot product.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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