Commit a7eb6b61 authored by Davis King's avatar Davis King

Fixed a compile time bug in the offset_kernel. Also fixed some

bugs in the sparse vector operations and added a few more new
operations as well.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402952
parent 028c67ed
......@@ -370,7 +370,7 @@ namespace dlib
offset_kernel(const T& k, const scalar_type& offset_
) : kernel(k), offset(offset_) {}
offset_kernel() : offset(0.01) {}
offset_kernel() : kernel(T()), offset(0.01) {}
offset_kernel(
const offset_kernel& k
) : kernel(k.kernel), offset(k.offset) {}
......
......@@ -57,15 +57,28 @@ namespace dlib
while (ai != a.end())
{
sum += ai->second*ai->second;
++ai;
}
while (bi != b.end())
{
sum += bi->second*bi->second;
++bi;
}
return sum;
}
// ------------------------------------------------------------------------------------
template <typename T, typename U>
typename T::value_type::second_type distance (
const T& a,
const U& b
)
{
return std::sqrt(distance_squared(a,b));
}
// ------------------------------------------------------------------------------------
template <typename T, typename U>
......@@ -113,10 +126,11 @@ namespace dlib
{
typedef typename T::value_type::second_type scalar_type;
typename T::const_iterator i = a.begin();
typename T::const_iterator i;
scalar_type sum = 0;
while (i != a.end())
for (i = a.begin(); i != a.end(); ++i)
{
sum += i->second * i->second;
}
......@@ -124,6 +138,16 @@ namespace dlib
return sum;
}
// ------------------------------------------------------------------------------------
template <typename T>
typename T::value_type::second_type length (
const T& a
)
{
return std::sqrt(length_squared(a));
}
}
// ----------------------------------------------------------------------------------------
......
......@@ -47,6 +47,22 @@ namespace dlib
a and b
!*/
// ----------------------------------------------------------------------------------------
template <typename T, typename U>
typename T::value_type::second_type distance (
const T& a,
const U& b
);
/*!
requires
- a is a sorted range of std::pair objects
- b is a sorted range of std::pair objects
ensures
- returns the distance between the vectors
a and b. (i.e. std::sqrt(distance_squared(a,b)))
!*/
// ----------------------------------------------------------------------------------------
template <typename T, typename U>
......@@ -76,6 +92,20 @@ namespace dlib
- returns dot(a,a)
!*/
// ----------------------------------------------------------------------------------------
template <typename T>
typename T::value_type::second_type length (
const T& a
);
/*!
requires
- a is a sorted range of std::pair objects
- b is a sorted range of std::pair objects
ensures
- returns std::sqrt(length_squared(a,a))
!*/
}
// ----------------------------------------------------------------------------------------
......
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