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

Function matrix_test

dlib/test/matrix.cpp:110–779  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

108 }
109
110 void matrix_test (
111 )
112 /*!
113 ensures
114 - runs tests on the matrix stuff compliance with the specs
115 !*/
116 {
117 typedef memory_manager_stateless<char>::kernel_2_2a MM;
118 print_spinner();
119
120
121 {
122 matrix<complex<double>,2,2,MM> m;
123 set_all_elements(m,complex<double>(1,2));
124 DLIB_TEST((conj(m) == uniform_matrix<complex<double>,2,2>(conj(m(0,0)))));
125 DLIB_TEST((real(m) == uniform_matrix<double,2,2>(1)));
126 DLIB_TEST((imag(m) == uniform_matrix<double,2,2>(2)));
127 DLIB_TEST_MSG((sum(abs(norm(m) - uniform_matrix<double,2,2>(5))) < 1e-10 ),norm(m));
128
129 }
130
131 {
132 matrix<double,5,5,MM,column_major_layout> m(5,5);
133
134 for (long r = 0; r < m.nr(); ++r)
135 {
136 for (long c = 0; c < m.nc(); ++c)
137 {
138 m(r,c) = r*c;
139 }
140 }
141
142 m = cos(exp(m));
143
144
145 matrix<double> mi = pinv(m );
146 DLIB_TEST(mi.nr() == m.nc());
147 DLIB_TEST(mi.nc() == m.nr());
148 DLIB_TEST((equal(round_zeros(mi*m,0.000001) , identity_matrix<double,5>())));
149 DLIB_TEST((equal(round_zeros(m*mi,0.000001) , identity_matrix<double,5>())));
150 DLIB_TEST((equal(round_zeros(mi*m,0.000001) , identity_matrix(m))));
151 DLIB_TEST((equal(round_zeros(m*mi,0.000001) , identity_matrix(m))));
152
153 mi = pinv(m,1e-12);
154 DLIB_TEST(mi.nr() == m.nc());
155 DLIB_TEST(mi.nc() == m.nr());
156 DLIB_TEST((equal(round_zeros(mi*m,0.000001) , identity_matrix<double,5>())));
157 DLIB_TEST((equal(round_zeros(m*mi,0.000001) , identity_matrix<double,5>())));
158 DLIB_TEST((equal(round_zeros(mi*m,0.000001) , identity_matrix(m))));
159 DLIB_TEST((equal(round_zeros(m*mi,0.000001) , identity_matrix(m))));
160
161 m = diagm(diag(m));
162 mi = pinv(diagm(diag(m)),1e-12);
163 DLIB_TEST(mi.nr() == m.nc());
164 DLIB_TEST(mi.nc() == m.nr());
165 DLIB_TEST((equal(round_zeros(mi*m,0.000001) , identity_matrix<double,5>())));
166 DLIB_TEST((equal(round_zeros(m*mi,0.000001) , identity_matrix<double,5>())));
167 DLIB_TEST((equal(round_zeros(mi*m,0.000001) , identity_matrix(m))));

Callers 1

perform_testMethod · 0.70

Calls 15

print_spinnerFunction · 0.85
set_all_elementsFunction · 0.85
realFunction · 0.85
imagFunction · 0.85
absFunction · 0.85
normFunction · 0.85
expFunction · 0.85
pinvFunction · 0.85
round_zerosFunction · 0.85
identity_matrixFunction · 0.85
diagmFunction · 0.85
get_rectFunction · 0.85

Tested by

no test coverage detected