Commit 1ef9e918 authored by Davis King's avatar Davis King

Added some compile time checks to make sure that only sparse vectors that

contain unsigned integral keys get used with the svm_c_linear_trainer.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403511
parent b0fb6d54
......@@ -185,6 +185,14 @@ namespace dlib
}
}
// ------------------------------------------------------------------------------------
template <typename T>
struct has_unsigned_keys
{
static const bool value = is_unsigned_type<typename T::value_type::first_type>::value;
};
// ------------------------------------------------------------------------------------
template <typename T, typename U>
......
......@@ -182,6 +182,20 @@ namespace dlib
}
// ----------------------------------------------------------------------------------------
/*!A has_unsigned_keys
This is a template where has_unsigned_keys<T>::value == true when T is a
sparse vector that contains unsigned integral keys and false otherwise.
!*/
template <typename T>
struct has_unsigned_keys
{
static const bool value = is_unsigned_type<typename T::value_type::first_type>::value;
};
// ----------------------------------------------------------------------------------------
}
......
......@@ -238,6 +238,13 @@ namespace dlib
T must be a sparse vector with an integral key type
!*/
{
typedef typename T::type sample_type;
// You are getting this error because you are attempting to use sparse sample vectors with
// the svm_c_linear_trainer object but you aren't using an unsigned integer as your key type
// in the sparse vectors.
COMPILE_TIME_ASSERT(sparse_vector::has_unsigned_keys<sample_type>::value);
// these should be sparse samples so look over all them to find the max dimension.
unsigned long max_dim = 0;
for (long i = 0; i < samples.size(); ++i)
......
......@@ -17,7 +17,8 @@ namespace dlib
{
/*!
REQUIREMENTS ON K
is either linear_kernel or sparse_linear_kernel
Is either linear_kernel or sparse_linear_kernel. If you use a sparse_linear_kernel
then it must operate on sparse vectors that use unsigned integral keys.
WHAT THIS OBJECT REPRESENTS
This object represents a tool for training the C formulation of
......
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