MCPcopy Create free account
hub / github.com/davisking/dlib / test_linearity_complex

Function test_linearity_complex

dlib/test/fft.cpp:230–272  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

228
229 template<typename R>
230 void test_linearity_complex()
231 {
232 static constexpr double tol = std::is_same<R,double>::value ? 1e-15 : 5e-2;
233 static constexpr const char* typelabel = std::is_same<R,double>::value ? "double" : "float";
234
235 int test = 0;
236
237 auto func = [&](long nr, long nc)
238 {
239 if (++test % 100 == 0)
240 print_spinner();
241
242 const matrix<complex<R>> m1 = rand_complex<R>(nr,nc);
243 const matrix<complex<R>> m2 = rand_complex<R>(nr,nc);
244 const R a1 = rnd.get_double_in_range(-10.0, 10.0);
245 const R a2 = rnd.get_double_in_range(-10.0, 10.0);
246 const matrix<complex<R>> m3 = a1*m1 + a2*m2;
247
248 const matrix<complex<R>> f1 = fft(m1);
249 const matrix<complex<R>> f2 = fft(m2);
250 const matrix<complex<R>> f3 = fft(m3);
251
252 R diff = max(norm(f3 - a1*f1 - a2*f2));
253 DLIB_TEST_MSG(diff < tol, "diff " << diff << " not within tol " << tol << " where (nr,nc) = (" << nr << "," << nc << ")" << " type " << typelabel);
254
255 const matrix<complex<R>> m4 = ifft(f3);
256
257 diff = max(norm(m4 - m3));
258 DLIB_TEST_MSG(diff < tol, "diff " << diff << " not within tol " << tol << " where (nr,nc) = (" << nr << "," << nc << ")" << " type " << typelabel);
259 };
260
261 for (int nr = 1; nr <= 64; nr++)
262 {
263 for (int nc = 1; nc <= 64; nc++)
264 {
265 func(nr,nc);
266 }
267 }
268
269 //some odd balls...
270 func(3, 131); print_spinner();
271 func(123, 103); print_spinner();
272 }
273
274// ----------------------------------------------------------------------------------------
275

Callers

nothing calls this directly

Calls 6

print_spinnerFunction · 0.85
normFunction · 0.85
ifftFunction · 0.85
get_double_in_rangeMethod · 0.80
fftFunction · 0.50
maxFunction · 0.50

Tested by

no test coverage detected