Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::ops::{Add, Mul};
- fn dot<N>(v1: &[N], v2: &[N]) -> N
- where
- N: Add<Output = N> + Mul<Output = N> + Default + Copy,
- {
- let mut total = N::default();
- for i in 0..v1.len() {
- total = total + v1[i] * v2[i];
- }
- total
- }
- #[test]
- fn test_dot() {
- assert_eq!(dot(&[1, 2, 3, 4], &[1, 1, 1, 1]), 10);
- assert_eq!(dot(&[53.0, 7.0], &[1.0, 5.0]), 88.0);
- }
- fn main() {
- let a = 5;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement