| 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 |
nothing calls this directly
no test coverage detected