Guest User

Untitled

a guest
Jan 23rd, 2019
85
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use std::ops::*;
  2.  
  3. pub fn convolve<A, B, C>(signal: &[A], kernel: &[B], mode: &str) -> Vec<f64>
  4. where A: Mul<B>,
  5. <A as Mul<B>>::Output: Add<C>
  6. {
  7. let y: Vec<f64> = signal.windows(kernel.len()).map(|window| {
  8. window.iter().zip(kernel.iter().rev()).map(|(x,y)|x*y).sum()
  9. }).collect();
  10.  
  11. match mode {
  12. "full" => println!("full"),
  13. "same" => println!("same"),
  14. "valid" => println!("valid"),
  15. _ => println!("none"),
  16. };
  17. return y;
  18. }
  19.  
  20. fn main() {
  21.  
  22. let a = vec![1,2,3,4];
  23. let b = vec![1,1,1];
  24. let conv = convolve(&a, &b, "full");
  25.  
  26. }
RAW Paste Data