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

Function test_time_shift

dlib/test/fft.cpp:367–409  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

365
366 template<typename R>
367 void test_time_shift()
368 {
369 static constexpr double tol = std::is_same<R,double>::value ? 1e-15 : 1e-1;
370 static constexpr const char* typelabel = std::is_same<R,double>::value ? "double" : "float";
371
372 int test = 0;
373
374 auto func = [&](size_t size, size_t time_shift)
375 {
376 if (++test % 100 == 0)
377 print_spinner();
378
379 matrix<complex<R>> x1 = rand_complex<R>(1,size, 1.0);
380 matrix<complex<R>> x2 = x1;
381 std::rotate(x2.begin(), x2.begin() + time_shift, x2.end());
382
383 matrix<complex<R>> f1 = fft(x1);
384 matrix<complex<R>> f2 = fft(x2);
385 matrix<complex<R>> f2_expected = f1;
386
387 for (long i = 0 ; i < f1.size() ; i++)
388 f2_expected(i) = f1(i)*std::polar<R>(R(1), R(6.283185307179586476925286766559005768394338798*time_shift*i / size));
389
390 const auto diff_real = max(squared(real(f2) - real(f2_expected)));
391 const auto diff_imag = max(squared(imag(f2) - imag(f2_expected)));
392
393 DLIB_TEST_MSG(diff_real < tol, typelabel << " diff_real " << diff_real << " size " << size << " shift " << time_shift);
394 DLIB_TEST_MSG(diff_imag < tol, typelabel << " diff_real " << diff_imag << " size " << size << " shift " << time_shift);
395 };
396
397 for (size_t size = 16 ; size < 64 ; size++)
398 {
399 for (size_t time_shift = 10 ; time_shift < size/2 + 1 ; time_shift += 10)
400 {
401 func(size, time_shift);
402 }
403 }
404
405 //some odd balls...
406 func(3,1);
407 func(123,16);
408 func(123,122);
409 }
410
411// ----------------------------------------------------------------------------------------
412

Callers

nothing calls this directly

Calls 10

print_spinnerFunction · 0.85
rotateFunction · 0.85
squaredFunction · 0.85
realFunction · 0.85
imagFunction · 0.85
fftFunction · 0.50
maxFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected