Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
f3b154df
Commit
f3b154df
authored
Nov 24, 2012
by
Davis King
Browse files
Added some sparse_matrix_vector_multiply() unit tests.
parent
6b2b213d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
0 deletions
+46
-0
dlib/test/sparse_vector.cpp
dlib/test/sparse_vector.cpp
+46
-0
No files found.
dlib/test/sparse_vector.cpp
View file @
f3b154df
...
@@ -67,6 +67,50 @@ namespace
...
@@ -67,6 +67,50 @@ namespace
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
void
test_sparse_matrix_vector_multiply1
()
{
print_spinner
();
std
::
map
<
unsigned
long
,
double
>
sv
;
sv
[
2
]
=
8
;
sv
[
6
]
=
2.3
;
matrix
<
double
,
10
,
1
>
v
;
v
=
0
;
v
(
2
)
=
8
;
v
(
6
)
=
2.3
;
matrix
<
double
,
0
,
1
>
r1
,
r2
;
r1
=
gaussian_randm
(
4
,
10
)
*
v
;
r2
=
sparse_matrix_vector_multiply
(
gaussian_randm
(
4
,
std
::
numeric_limits
<
long
>::
max
()),
sv
);
DLIB_TEST
(
max
(
abs
(
r1
-
r2
))
<
1e-15
);
}
// ----------------------------------------------------------------------------------------
void
test_sparse_matrix_vector_multiply2
()
{
std
::
vector
<
std
::
pair
<
unsigned
long
,
double
>
>
sv
;
sv
.
push_back
(
make_pair
(
6
,
1.42
));
sv
.
push_back
(
make_pair
(
3
,
5
));
matrix
<
double
,
9
,
1
>
v
;
v
=
0
;
v
(
3
)
=
5
;
v
(
6
)
=
1.42
;
matrix
<
double
,
0
,
1
>
r1
,
r2
;
r1
=
gaussian_randm
(
3
,
9
)
*
v
;
r2
=
sparse_matrix_vector_multiply
(
gaussian_randm
(
3
,
std
::
numeric_limits
<
long
>::
max
()),
sv
);
DLIB_TEST
(
max
(
abs
(
r1
-
r2
))
<
1e-15
);
}
// ----------------------------------------------------------------------------------------
class
sparse_vector_tester
:
public
tester
class
sparse_vector_tester
:
public
tester
{
{
...
@@ -194,6 +238,8 @@ namespace
...
@@ -194,6 +238,8 @@ namespace
}
}
test_sparse_matrix_vector_multiplies
();
test_sparse_matrix_vector_multiplies
();
test_sparse_matrix_vector_multiply1
();
test_sparse_matrix_vector_multiply2
();
}
}
};
};
...
...
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