Commit 7f434061 authored by Davis King's avatar Davis King

Added functions for finding the min and max elements of a sparse vector.

parent 0a8da5ed
...@@ -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;
}
// ------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------
} }
......
...@@ -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.
!*/
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment