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

Function test_svd_fast

dlib/test/cca.cpp:283–357  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

281// ----------------------------------------------------------------------------------------
282
283 void test_svd_fast(
284 long rank,
285 long m,
286 long n
287 )
288 {
289 print_spinner();
290 matrix<double> A = randm(m,rank,rnd)*randm(rank,n,rnd);
291 matrix<double> u,v;
292 matrix<double,0,1> w;
293
294 dlog << LINFO << "rank: "<< rank;
295 dlog << LINFO << "m: "<< m;
296 dlog << LINFO << "n: "<< n;
297
298 svd_fast(A, u, w, v, rank, 2);
299 DLIB_TEST(u.nr() == m);
300 DLIB_TEST(u.nc() == rank);
301 DLIB_TEST(w.nr() == rank);
302 DLIB_TEST(w.nc() == 1);
303 DLIB_TEST(v.nr() == n);
304 DLIB_TEST(v.nc() == rank);
305 DLIB_TEST(max(abs(trans(u)*u - identity_matrix<double>(u.nc()))) < 1e-13);
306 DLIB_TEST(max(abs(trans(v)*v - identity_matrix<double>(u.nc()))) < 1e-13);
307
308 DLIB_TEST(max(abs(tmp(A - u*diagm(w)*trans(v)))) < 1e-11);
309 svd_fast(mat_to_sparse(A), u, w, v, rank, 2);
310 DLIB_TEST(u.nr() == m);
311 DLIB_TEST(u.nc() == rank);
312 DLIB_TEST(w.nr() == rank);
313 DLIB_TEST(w.nc() == 1);
314 DLIB_TEST(v.nr() == n);
315 DLIB_TEST(v.nc() == rank);
316 DLIB_TEST(max(abs(trans(u)*u - identity_matrix<double>(u.nc()))) < 1e-13);
317 DLIB_TEST(max(abs(trans(v)*v - identity_matrix<double>(u.nc()))) < 1e-13);
318 DLIB_TEST(max(abs(tmp(A - u*diagm(w)*trans(v)))) < 1e-13);
319
320 svd_fast(A, u, w, v, rank, 0);
321 DLIB_TEST(u.nr() == m);
322 DLIB_TEST(u.nc() == rank);
323 DLIB_TEST(w.nr() == rank);
324 DLIB_TEST(w.nc() == 1);
325 DLIB_TEST(v.nr() == n);
326 DLIB_TEST(v.nc() == rank);
327 DLIB_TEST(max(abs(trans(u)*u - identity_matrix<double>(u.nc()))) < 1e-13);
328 DLIB_TEST(max(abs(trans(v)*v - identity_matrix<double>(u.nc()))) < 1e-13);
329 DLIB_TEST_MSG(max(abs(tmp(A - u*diagm(w)*trans(v)))) < 1e-9,max(abs(tmp(A - u*diagm(w)*trans(v)))));
330 svd_fast(mat_to_sparse(A), u, w, v, rank, 0);
331 DLIB_TEST(u.nr() == m);
332 DLIB_TEST(u.nc() == rank);
333 DLIB_TEST(w.nr() == rank);
334 DLIB_TEST(w.nc() == 1);
335 DLIB_TEST(v.nr() == n);
336 DLIB_TEST(v.nc() == rank);
337 DLIB_TEST(max(abs(trans(u)*u - identity_matrix<double>(u.nc()))) < 1e-13);
338 DLIB_TEST(max(abs(trans(v)*v - identity_matrix<double>(u.nc()))) < 1e-13);
339 DLIB_TEST(max(abs(tmp(A - u*diagm(w)*trans(v)))) < 1e-9);
340

Callers 1

perform_testMethod · 0.85

Calls 12

print_spinnerFunction · 0.85
svd_fastFunction · 0.85
absFunction · 0.85
tmpFunction · 0.85
diagmFunction · 0.85
mat_to_sparseFunction · 0.85
randmFunction · 0.70
maxFunction · 0.50
transFunction · 0.50
nrMethod · 0.45
ncMethod · 0.45

Tested by

no test coverage detected