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