daily pastebin goal
59%
SHARE
TWEET

Untitled

a guest Jan 23rd, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fn subc(a: usize, b: usize) -> usize {
  2.     if a >= b { a - b } else { 0 }
  3. }
  4.  
  5. fn convolve(a: &[f32], b: &[f32]) -> Vec<f32> {
  6.     use std::cmp::min;
  7.     let N = a.len() - 1;
  8.     (0..2*N+1).map(|k|
  9.         (subc(k, N) .. min(k+1, N+1)).map(|i|
  10.             a[i]*b[k-i]
  11.         ).sum()
  12.     ).collect()
  13. }
  14.  
  15. fn main() {
  16.     let v1 = vec![1.0, 2.0, 3.0];
  17.     let v2 = vec![0.0, 1.0, 0.5];
  18.     let v3 = convolve(&v1, &v2);
  19.     println!("{:?} * {:?} = {:?}", v1, v2, v3);
  20. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top