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

Function test_sparse_matrix_vector_multiplies

dlib/test/sparse_vector.cpp:19–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17 dlib::logger dlog("test.sparse_vector");
18
19 void test_sparse_matrix_vector_multiplies()
20 {
21 dlib::rand rnd;
22
23 const long size = 30;
24
25 for (int iter = 0; iter < 10; ++iter)
26 {
27 print_spinner();
28
29 std::vector<sample_pair> edges;
30 std::vector<ordered_sample_pair> oedges;
31 matrix<double> M(size,size);
32 M = 0;
33 for (long i = 0; i < M.size()/3; ++i)
34 {
35 const long r = rnd.get_random_32bit_number()%M.nr();
36 const long c = rnd.get_random_32bit_number()%M.nc();
37 const double d = rnd.get_random_gaussian()*10;
38 M(r,c) += d;
39 oedges.push_back(ordered_sample_pair(r,c,d));
40 }
41
42 matrix<double> SM(size,size);
43 SM = 0;
44 for (long i = 0; i < SM.size()/3; ++i)
45 {
46 const long r = rnd.get_random_32bit_number()%SM.nr();
47 const long c = rnd.get_random_32bit_number()%SM.nc();
48 const double d = rnd.get_random_gaussian()*10;
49 SM(r,c) += d;
50 if (r != c)
51 SM(c,r) += d;
52 edges.push_back(sample_pair(r,c,d));
53 }
54
55 const matrix<double> v = randm(size,1);
56
57 matrix<double> result;
58
59 sparse_matrix_vector_multiply(oedges, v, result);
60 DLIB_TEST_MSG(length(M*v - result) < 1e-12, length(M*v - result));
61
62 sparse_matrix_vector_multiply(edges, v, result);
63 DLIB_TEST_MSG(length(SM*v - result) < 1e-12, length(SM*v - result));
64
65 }
66 }
67
68// ----------------------------------------------------------------------------------------
69

Callers 1

perform_testMethod · 0.85

Calls 12

print_spinnerFunction · 0.85
get_random_gaussianMethod · 0.80
randmFunction · 0.70
ordered_sample_pairClass · 0.50
sample_pairClass · 0.50
lengthFunction · 0.50
sizeMethod · 0.45
nrMethod · 0.45
ncMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected