| 780 | |
| 781 | |
| 782 | void matrix_test2() |
| 783 | { |
| 784 | print_spinner(); |
| 785 | |
| 786 | |
| 787 | { |
| 788 | |
| 789 | const double stuff[] = { |
| 790 | 1, 2, 3, |
| 791 | 6, 3, 3, |
| 792 | 7, 3, 9}; |
| 793 | |
| 794 | matrix<double,3,3> m(stuff); |
| 795 | |
| 796 | // make m be symmetric |
| 797 | m = m*trans(m); |
| 798 | |
| 799 | matrix<double> L = chol(m); |
| 800 | DLIB_TEST(equal(L*trans(L), m)); |
| 801 | |
| 802 | DLIB_TEST_MSG(equal(inv(m), inv_upper_triangular(trans(L))*inv_lower_triangular((L))), ""); |
| 803 | DLIB_TEST(equal(round_zeros(inv_upper_triangular(trans(L))*trans(L),1e-10), identity_matrix<double>(3), 1e-10)); |
| 804 | DLIB_TEST(equal(round_zeros(inv_lower_triangular((L))*(L),1e-10) ,identity_matrix<double>(3),1e-10)); |
| 805 | |
| 806 | } |
| 807 | |
| 808 | { |
| 809 | |
| 810 | const double stuff[] = { |
| 811 | 1, 2, 3, 6, 3, 4, |
| 812 | 6, 3, 3, 1, 2, 3, |
| 813 | 7, 3, 9, 54.3, 5, 3, |
| 814 | -6, 3, -3, 1, 2, 3, |
| 815 | 1, 2, 3, 5, -3, 3, |
| 816 | 7, 3, -9, 54.3, 5, 3 |
| 817 | }; |
| 818 | |
| 819 | matrix<double,6,6> m(stuff); |
| 820 | |
| 821 | // make m be symmetric |
| 822 | m = m*trans(m); |
| 823 | |
| 824 | matrix<double> L = chol(m); |
| 825 | DLIB_TEST_MSG(equal(L*trans(L), m, 1e-10), L*trans(L)-m); |
| 826 | |
| 827 | DLIB_TEST_MSG(equal(inv(m), inv_upper_triangular(trans(L))*inv_lower_triangular((L))), ""); |
| 828 | DLIB_TEST_MSG(equal(inv(m), trans(inv_lower_triangular(L))*inv_lower_triangular((L))), ""); |
| 829 | DLIB_TEST_MSG(equal(inv(m), trans(inv_lower_triangular(L))*trans(inv_upper_triangular(trans(L)))), ""); |
| 830 | DLIB_TEST_MSG(equal(round_zeros(inv_upper_triangular(trans(L))*trans(L),1e-10) , identity_matrix<double>(6), 1e-10), |
| 831 | round_zeros(inv_upper_triangular(trans(L))*trans(L),1e-10)); |
| 832 | DLIB_TEST_MSG(equal(round_zeros(inv_lower_triangular((L))*(L),1e-10) ,identity_matrix<double>(6), 1e-10), |
| 833 | round_zeros(inv_lower_triangular((L))*(L),1e-10)); |
| 834 | |
| 835 | } |
| 836 | |
| 837 | { |
| 838 | // Test band chol |
| 839 | matrix<double> m = rand_sp_banded<double>(10, 3); |
no test coverage detected