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
6b2b213d
Commit
6b2b213d
authored
Nov 24, 2012
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added an overload of sparse_matrix_vector_multiply() that multiplies a dense
matrix with a sparse vector.
parent
aee36c3d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
2 deletions
+95
-2
sparse_vector.h
dlib/svm/sparse_vector.h
+52
-2
sparse_vector_abstract.h
dlib/svm/sparse_vector_abstract.h
+43
-0
No files found.
dlib/svm/sparse_vector.h
View file @
6b2b213d
...
...
@@ -1003,10 +1003,60 @@ namespace dlib
// ----------------------------------------------------------------------------------------
}
template
<
typename
EXP
,
typename
sparse_vector_type
,
typename
T
,
long
NR
,
long
NC
,
typename
MM
,
typename
L
>
void
sparse_matrix_vector_multiply
(
const
matrix_exp
<
EXP
>&
m
,
const
sparse_vector_type
&
v
,
matrix
<
T
,
NR
,
NC
,
MM
,
L
>&
result
)
{
// make sure requires clause is not broken
DLIB_ASSERT
(
max_index_plus_one
(
v
)
<=
(
unsigned
long
)
m
.
nc
(),
"
\t
void sparse_matrix_vector_multiply()"
<<
"
\n\t
Invalid inputs were given to this function"
<<
"
\n\t
max_index_plus_one(v): "
<<
max_index_plus_one
(
v
)
<<
"
\n\t
m.size(): "
<<
m
.
size
()
);
#endif // DLIB_SVm_SPARSE_VECTOR
result
.
set_size
(
m
.
nr
(),
1
);
result
=
0
;
for
(
typename
sparse_vector_type
::
const_iterator
i
=
v
.
begin
();
i
!=
v
.
end
();
++
i
)
{
for
(
long
r
=
0
;
r
<
result
.
nr
();
++
r
)
{
result
(
r
)
+=
m
(
r
,
i
->
first
)
*
i
->
second
;
}
}
}
// ----------------------------------------------------------------------------------------
template
<
typename
EXP
,
typename
sparse_vector_type
>
matrix
<
typename
EXP
::
type
,
0
,
1
>
sparse_matrix_vector_multiply
(
const
matrix_exp
<
EXP
>&
m
,
const
sparse_vector_type
&
v
)
{
matrix
<
typename
EXP
::
type
,
0
,
1
>
result
;
sparse_matrix_vector_multiply
(
m
,
v
,
result
);
return
result
;
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_SVm_SPARSE_VECTOR
dlib/svm/sparse_vector_abstract.h
View file @
6b2b213d
...
...
@@ -618,6 +618,49 @@ namespace dlib
// ----------------------------------------------------------------------------------------
template
<
typename
EXP
,
typename
sparse_vector_type
,
typename
T
,
long
NR
,
long
NC
,
typename
MM
,
typename
L
>
void
sparse_matrix_vector_multiply
(
const
matrix_exp
<
EXP
>&
m
,
const
sparse_vector_type
&
v
,
matrix
<
T
,
NR
,
NC
,
MM
,
L
>&
result
);
/*!
requires
- max_index_plus_one(v) < m.nc()
- v == an unsorted sparse vector
ensures
- #result == m*v
(i.e. multiply m by the vector v and store the output in result)
!*/
// ----------------------------------------------------------------------------------------
template
<
typename
EXP
,
typename
sparse_vector_type
>
matrix
<
typename
EXP
::
type
,
0
,
1
>
sparse_matrix_vector_multiply
(
const
matrix_exp
<
EXP
>&
m
,
const
sparse_vector_type
&
v
);
/*!
requires
- max_index_plus_one(v) < m.nc()
- v == an unsorted sparse vector
ensures
- returns m*v
(i.e. multiply m by the vector v and return the resulting vector)
!*/
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_SVm_SPARSE_VECTOR_ABSTRACT_
...
...
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