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

Function test_linearity_real

dlib/test/fft.cpp:277–324  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

275
276 template<typename R>
277 void test_linearity_real()
278 {
279 static constexpr double tol = std::is_same<R,double>::value ? 1e-15 : 1e-3;
280 static constexpr const char* typelabel = std::is_same<R,double>::value ? "double" : "float";
281
282 int test = 0;
283
284 auto func = [&](long nr, long nc)
285 {
286 if (++test % 100 == 0)
287 print_spinner();
288
289 const matrix<R> m1 = rand_real<R>(nr,nc);
290 const matrix<R> m2 = rand_real<R>(nr,nc);
291 const R a1 = rnd.get_double_in_range(-10.0, 10.0);
292 const R a2 = rnd.get_double_in_range(-10.0, 10.0);
293 const matrix<R> m3 = a1*m1 + a2*m2;
294
295 const matrix<complex<R>> f1 = fftr(m1);
296 const matrix<complex<R>> f2 = fftr(m2);
297 const matrix<complex<R>> f3 = fftr(m3);
298
299 DLIB_TEST(f1.nr() == m1.nr());
300 DLIB_TEST(f1.nc() == fftr_nc_size(m1.nc()));
301
302 R diff = max(norm(f3 - a1*f1 - a2*f2));
303 DLIB_TEST_MSG(diff < tol, "diff " << diff << " not within tol " << tol << " where (nr,nc) = (" << nr << "," << nc << ")" << " type " << typelabel);
304
305 const matrix<R> m4 = ifftr(f3);
306 DLIB_TEST(m4.nr() == f3.nr());
307 DLIB_TEST(m4.nc() == ifftr_nc_size(f3.nc()));
308
309 diff = max(squared(m4 - m3));
310 DLIB_TEST_MSG(diff < tol, "diff " << diff << " not within tol " << tol << " where (nr,nc) = (" << nr << "," << nc << ")" << " type " << typelabel);
311 };
312
313 for (int nr = 2; nr <= 64; nr += 2)
314 {
315 for (int nc = 2; nc <= 64; nc += 2)
316 {
317 func(nr,nc);
318 }
319 }
320
321 //some odd balls...
322 func(89, 102); print_spinner();
323 func(123, 48); print_spinner();
324 }
325
326// ----------------------------------------------------------------------------------------
327

Callers

nothing calls this directly

Calls 11

print_spinnerFunction · 0.85
fftr_nc_sizeFunction · 0.85
normFunction · 0.85
ifftr_nc_sizeFunction · 0.85
squaredFunction · 0.85
get_double_in_rangeMethod · 0.80
fftrFunction · 0.50
maxFunction · 0.50
ifftrFunction · 0.50
nrMethod · 0.45
ncMethod · 0.45

Tested by

no test coverage detected