| 46 | } |
| 47 | |
| 48 | void matrix_test ( |
| 49 | ) |
| 50 | /*! |
| 51 | ensures |
| 52 | - runs tests on the matrix stuff compliance with the specs |
| 53 | !*/ |
| 54 | { |
| 55 | typedef memory_manager_stateless<char>::kernel_2_2a MM; |
| 56 | print_spinner(); |
| 57 | |
| 58 | |
| 59 | { |
| 60 | matrix<complex<double>,2,2,MM> m; |
| 61 | set_all_elements(m,complex<double>(1,2)); |
| 62 | DLIB_TEST((conj(m) == uniform_matrix<complex<double>,2,2>(conj(m(0,0))))); |
| 63 | DLIB_TEST((real(m) == uniform_matrix<double,2,2>(1))); |
| 64 | DLIB_TEST((imag(m) == uniform_matrix<double,2,2>(2))); |
| 65 | DLIB_TEST_MSG((sum(abs(norm(m) - uniform_matrix<double,2,2>(5))) < 1e-10 ),norm(m)); |
| 66 | |
| 67 | } |
| 68 | |
| 69 | { |
| 70 | matrix<double,5,5,MM,column_major_layout> m(5,5); |
| 71 | |
| 72 | for (long r = 0; r < m.nr(); ++r) |
| 73 | { |
| 74 | for (long c = 0; c < m.nc(); ++c) |
| 75 | { |
| 76 | m(r,c) = r*c; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | m = cos(exp(m)); |
| 81 | |
| 82 | |
| 83 | matrix<double> mi = pinv(m ); |
| 84 | DLIB_TEST(mi.nr() == m.nc()); |
| 85 | DLIB_TEST(mi.nc() == m.nr()); |
| 86 | DLIB_TEST((equal(round_zeros(mi*m,0.000001) , identity_matrix<double,5>()))); |
| 87 | DLIB_TEST((equal(round_zeros(m*mi,0.000001) , identity_matrix<double,5>()))); |
| 88 | DLIB_TEST((equal(round_zeros(mi*m,0.000001) , identity_matrix(m)))); |
| 89 | DLIB_TEST((equal(round_zeros(m*mi,0.000001) , identity_matrix(m)))); |
| 90 | |
| 91 | mi = pinv(m,1e-12); |
| 92 | DLIB_TEST(mi.nr() == m.nc()); |
| 93 | DLIB_TEST(mi.nc() == m.nr()); |
| 94 | DLIB_TEST((equal(round_zeros(mi*m,0.000001) , identity_matrix<double,5>()))); |
| 95 | DLIB_TEST((equal(round_zeros(m*mi,0.000001) , identity_matrix<double,5>()))); |
| 96 | DLIB_TEST((equal(round_zeros(mi*m,0.000001) , identity_matrix(m)))); |
| 97 | DLIB_TEST((equal(round_zeros(m*mi,0.000001) , identity_matrix(m)))); |
| 98 | |
| 99 | m = diagm(diag(m)); |
| 100 | mi = pinv(diagm(diag(m)),1e-12); |
| 101 | DLIB_TEST(mi.nr() == m.nc()); |
| 102 | DLIB_TEST(mi.nc() == m.nr()); |
| 103 | DLIB_TEST((equal(round_zeros(mi*m,0.000001) , identity_matrix<double,5>()))); |
| 104 | DLIB_TEST((equal(round_zeros(m*mi,0.000001) , identity_matrix<double,5>()))); |
| 105 | DLIB_TEST((equal(round_zeros(mi*m,0.000001) , identity_matrix(m)))); |
no test coverage detected