Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
43b5e2d4
Commit
43b5e2d4
authored
Nov 04, 2012
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added unit tests for sparse_matrix_vector_multiply()
parent
4138b15a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
0 deletions
+54
-0
sparse_vector.cpp
dlib/test/sparse_vector.cpp
+54
-0
No files found.
dlib/test/sparse_vector.cpp
View file @
43b5e2d4
...
...
@@ -16,6 +16,57 @@ namespace
using
namespace
std
;
dlib
::
logger
dlog
(
"test.sparse_vector"
);
void
test_sparse_matrix_vector_multiplies
()
{
dlib
::
rand
rnd
;
const
long
size
=
30
;
for
(
int
iter
=
0
;
iter
<
10
;
++
iter
)
{
print_spinner
();
std
::
vector
<
sample_pair
>
edges
;
std
::
vector
<
ordered_sample_pair
>
oedges
;
matrix
<
double
>
M
(
size
,
size
);
M
=
0
;
for
(
long
i
=
0
;
i
<
M
.
size
()
/
3
;
++
i
)
{
const
long
r
=
rnd
.
get_random_32bit_number
()
%
M
.
nr
();
const
long
c
=
rnd
.
get_random_32bit_number
()
%
M
.
nc
();
const
double
d
=
rnd
.
get_random_gaussian
()
*
10
;
M
(
r
,
c
)
+=
d
;
oedges
.
push_back
(
ordered_sample_pair
(
r
,
c
,
d
));
}
matrix
<
double
>
SM
(
size
,
size
);
SM
=
0
;
for
(
long
i
=
0
;
i
<
SM
.
size
()
/
3
;
++
i
)
{
const
long
r
=
rnd
.
get_random_32bit_number
()
%
SM
.
nr
();
const
long
c
=
rnd
.
get_random_32bit_number
()
%
SM
.
nc
();
const
double
d
=
rnd
.
get_random_gaussian
()
*
10
;
SM
(
r
,
c
)
+=
d
;
if
(
r
!=
c
)
SM
(
c
,
r
)
+=
d
;
edges
.
push_back
(
sample_pair
(
r
,
c
,
d
));
}
const
matrix
<
double
>
v
=
randm
(
size
,
1
);
matrix
<
double
>
result
;
sparse_matrix_vector_multiply
(
oedges
,
v
,
result
);
DLIB_TEST_MSG
(
length
(
M
*
v
-
result
)
<
1e-12
,
length
(
M
*
v
-
result
));
sparse_matrix_vector_multiply
(
edges
,
v
,
result
);
DLIB_TEST_MSG
(
length
(
SM
*
v
-
result
)
<
1e-12
,
length
(
SM
*
v
-
result
));
}
}
// ----------------------------------------------------------------------------------------
class
sparse_vector_tester
:
public
tester
{
...
...
@@ -141,6 +192,9 @@ namespace
DLIB_TEST
(
cc
[
2
].
second
==
-
5
);
}
test_sparse_matrix_vector_multiplies
();
}
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment