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
7f434061
Commit
7f434061
authored
Apr 30, 2012
by
Davis King
Browse files
Added functions for finding the min and max elements of a sparse vector.
parent
0a8da5ed
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
0 deletions
+64
-0
dlib/svm/sparse_vector.h
dlib/svm/sparse_vector.h
+36
-0
dlib/svm/sparse_vector_abstract.h
dlib/svm/sparse_vector_abstract.h
+28
-0
No files found.
dlib/svm/sparse_vector.h
View file @
7f434061
...
@@ -564,6 +564,42 @@ namespace dlib
...
@@ -564,6 +564,42 @@ namespace dlib
dest
(
i
->
first
)
-=
C
*
i
->
second
;
dest
(
i
->
first
)
-=
C
*
i
->
second
;
}
}
// ------------------------------------------------------------------------------------
template
<
typename
T
>
typename
T
::
value_type
::
second_type
min
(
const
T
&
a
)
{
typedef
typename
T
::
value_type
::
second_type
type
;
type
temp
=
0
;
for
(
typename
T
::
const_iterator
i
=
a
.
begin
();
i
!=
a
.
end
();
++
i
)
{
if
(
temp
>
i
->
second
)
temp
=
i
->
second
;
}
return
temp
;
}
// ------------------------------------------------------------------------------------
template
<
typename
T
>
typename
T
::
value_type
::
second_type
max
(
const
T
&
a
)
{
typedef
typename
T
::
value_type
::
second_type
type
;
type
temp
=
0
;
for
(
typename
T
::
const_iterator
i
=
a
.
begin
();
i
!=
a
.
end
();
++
i
)
{
if
(
temp
<
i
->
second
)
temp
=
i
->
second
;
}
return
temp
;
}
// ------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------
}
}
...
...
dlib/svm/sparse_vector_abstract.h
View file @
7f434061
...
@@ -308,6 +308,34 @@ namespace dlib
...
@@ -308,6 +308,34 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
typename
T
::
value_type
::
second_type
min
(
const
T
&
vect
);
/*!
requires
- T == an unsorted sparse vector
ensures
- returns the minimum value in the sparse vector vect. Note that
this value is always <= 0 since a sparse vector has an unlimited number
of 0 elements.
!*/
// ------------------------------------------------------------------------------------
template
<
typename
T
>
typename
T
::
value_type
::
second_type
max
(
const
T
&
vect
);
/*!
requires
- T == an unsorted sparse vector
ensures
- returns the maximum value in the sparse vector vect. Note that
this value is always >= 0 since a sparse vector has an unlimited number
of 0 elements.
!*/
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
...
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