Created
December 27, 2013 01:53
-
-
Save richard-uk1/8141373 to your computer and use it in GitHub Desktop.
dot product
This file contains hidden or 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 dot<T: Add<T, T> + Mul<T, T> + Zero>(u: ~[T], v: ~[T]) -> T { | |
let mut acc = Zero::zero(); | |
let mut it = u.iter().zip(v.iter()); | |
loop { | |
match it.next() { | |
Some((u, v)) => { acc = acc + *u * *v } | |
_ => { break; } | |
} | |
} | |
acc | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment