Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::ops::*;
- pub fn convolve<A, B, C>(signal: &[A], kernel: &[B], mode: &str) -> Vec<f64>
- where A: Mul<B>,
- <A as Mul<B>>::Output: Add<C>
- {
- let y: Vec<f64> = signal.windows(kernel.len()).map(|window| {
- window.iter().zip(kernel.iter().rev()).map(|(x,y)|x*y).sum()
- }).collect();
- match mode {
- "full" => println!("full"),
- "same" => println!("same"),
- "valid" => println!("valid"),
- _ => println!("none"),
- };
- return y;
- }
- fn main() {
- let a = vec![1,2,3,4];
- let b = vec![1,1,1];
- let conv = convolve(&a, &b, "full");
- }
Add Comment
Please, Sign In to add comment