2 #ifndef vnl_convolve_hxx_ 3 #define vnl_convolve_hxx_ 10 # include <vcl_msvc_warnings.h> 13 template <
class T1,
class T2,
class U>
18 unsigned int n = v1.
size();
20 typedef std::complex<double> C;
21 vnl_vector<C> w1(n, C(0));
for (
unsigned i=0; i<n; ++i) w1[i]=v1[i];
22 vnl_vector<C> w2(n, C(0));
for (
unsigned i=0; i<n; ++i) w2[i]=v2[i];
25 for (
unsigned int i=0; i<n; ++i) w1[i] *= w2[i];
28 std::cout << w1 << std::endl;
32 for (
unsigned int i = 0; i<n; ++i)
33 r[i] = U(std::real(w1[i]) / n);
35 for (
unsigned int i = 0; i<n; ++i)
36 assert(std::imag(w1[i]) == 0);
41 template <
class T1,
class T2,
class U>
45 unsigned int n = v1.
size();
55 for (
unsigned int k=0; k<n; ++k)
57 for (
unsigned int i=0; i<=k; ++i)
58 ret[k] += U(v1[k-i]) * U(v2[i]);
59 for (
unsigned int i=k+1; i<n; ++i)
60 ret[k] += U(v1[n+k-i]) * U(v2[i]);
68 if (n <= 1)
return true;
69 while (n%2 == 0) n /= 2;
70 while (n%3 == 0) n /= 3;
71 while (n%5 == 0) n /= 5;
75 template <
class T1,
class T2,
class U>
97 if (v1.
size() == 0 || v2.
size() == 0)
99 if (v1.
size() == 1)
return v2*v1[0];
100 if (v2.
size() == 1)
return v1*v2[0];
105 unsigned int n = v1.
size() + v2.
size() - 1;
107 for (
unsigned int k=0; k<v1.
size(); ++k)
108 for (
unsigned int i=0; i<=k && i<v2.
size(); ++i)
109 ret[k] += v1[k-i] * v2[i];
110 for (
unsigned int k=v1.
size(); k<n; ++k)
111 for (
unsigned int i=k+1-v1.
size(); i<=k && i<v2.
size(); ++i)
112 ret[k] += v1[k-i] * v2[i];
117 template <
class T1,
class T2,
class U>
121 if (v1.
size() == 0 || v2.
size() == 0)
127 unsigned int n = v1.
size() + v2.
size() - 1;
129 for (
unsigned int k=0; k<v1.
size(); ++k)
130 for (
unsigned int i=0; i<=k && i<v2.
size(); ++i)
131 ret[k] += U(v1[k-i]) * U(v2[i]);
132 for (
unsigned int k=v1.
size(); k<n; ++k)
133 for (
unsigned int i=k+1-v1.
size(); i<=k && i<v2.
size(); ++i)
134 ret[k] += U(v1[k-i]) * U(v2[i]);
139 #undef VNL_CONVOLVE_INSTANTIATE 140 #define VNL_CONVOLVE_INSTANTIATE_2(T,U) \ 141 template vnl_vector<U > vnl_convolve(vnl_vector<T > const&, vnl_vector<U > const&, U*, int); \ 142 template vnl_vector<U > vnl_convolve_cyclic(vnl_vector<T > const&, vnl_vector<U > const&, U*, bool) 144 #define VNL_CONVOLVE_INSTANTIATE(T,U) \ 145 VNL_CONVOLVE_INSTANTIATE_2(T,U); \ 146 template vnl_vector<T > vnl_convolve(vnl_vector<T > const&, vnl_vector<T > const&, int) 148 #endif // vnl_convolve_hxx_ vnl_vector< U > vnl_convolve_cyclic_using_fft(vnl_vector< T1 > const &v1, vnl_vector< T2 > const &v2, U *)
bool has_only_primefactors_2_3_5(unsigned int n)
size_t size() const
Return the length, number of elements, dimension of this vector.
T const * data_block() const
Access the contiguous block storing the elements in the vector. O(1).
vnl_vector< U > vnl_convolve_using_fft(vnl_vector< T1 > const &v1, vnl_vector< T2 > const &v2, U *, int n)
In-place 1D fast Fourier transform.
VNL_EXPORT vnl_vector< T > vnl_convolve(vnl_vector< T > const &v1, vnl_vector< T > const &v2, int use_fft=0)
Convolve two vnl_vector<T>'s, with the same base type T.
void bwd_transform(std::vector< std::complex< T > > &signal)
backward (inverse) FFT.
Mathematical vector class, templated by type of element.
Templated 1D and 2D convolution.
void fwd_transform(std::vector< std::complex< T > > &signal)
forward FFT.
VNL_EXPORT vnl_vector< U > vnl_convolve_cyclic(vnl_vector< T1 > const &v1, vnl_vector< T2 > const &v2, U *, bool use_fft=false)
Cyclically convolve two vnl_vector<T>'s of the same length.
In-place 1D fast Fourier transform.