Skip to content

Instantly share code, notes, and snippets.

@mralfarrakhan
Created March 6, 2022 15:08
Show Gist options
  • Select an option

  • Save mralfarrakhan/0631eae2ac9364cfe3f3adc2380b26d9 to your computer and use it in GitHub Desktop.

Select an option

Save mralfarrakhan/0631eae2ac9364cfe3f3adc2380b26d9 to your computer and use it in GitHub Desktop.
Basic 1D convolution function
#include <vector>
template<typename T>
auto convolve(std::vector<T> v1, std::vector<T> v2){
std::vector<T> res(v1.size() + v2.size() - 1);
for(int i = 0; i < v1.size(); i++){
int j = i;
for(const auto &ev2 : v2){
res[j++] += v1[i]*ev2;
}
}
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment