mirror of https://github.com/davisking/dlib.git
This change was just to avoid a warning from gcc. The code still
computes exactly the same thing as before. --HG-- extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403519
This commit is contained in:
parent
e5d719e20a
commit
b77ee4307a
|
@ -16,6 +16,45 @@
|
|||
namespace dlib
|
||||
{
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
template <typename T>
|
||||
typename enable_if<is_matrix<typename T::type>,unsigned long>::type num_dimensions_in_samples (
|
||||
const T& samples
|
||||
)
|
||||
{
|
||||
if (samples.size() > 0)
|
||||
return samples(0).size();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename disable_if<is_matrix<typename T::type>,unsigned long>::type num_dimensions_in_samples (
|
||||
const T& samples
|
||||
)
|
||||
/*!
|
||||
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)
|
||||
{
|
||||
if (samples(i).size() > 0)
|
||||
max_dim = std::max<unsigned long>(max_dim, (--samples(i).end())->first + 1);
|
||||
}
|
||||
|
||||
return max_dim;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
template <
|
||||
|
@ -203,7 +242,7 @@ namespace dlib
|
|||
const matrix_exp<EXP>& sample
|
||||
) const
|
||||
{
|
||||
return dot(colm(w,0,w.size()-1), sample);
|
||||
return dot(colm(w,0,sample.size()), sample);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -219,43 +258,6 @@ namespace dlib
|
|||
return temp;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename enable_if<is_matrix<typename T::type>,unsigned long>::type num_dimensions_in_samples (
|
||||
const T& samples
|
||||
) const
|
||||
{
|
||||
if (samples.size() > 0)
|
||||
return samples(0).size();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename disable_if<is_matrix<typename T::type>,unsigned long>::type num_dimensions_in_samples (
|
||||
const T& samples
|
||||
) const
|
||||
/*!
|
||||
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)
|
||||
{
|
||||
if (samples(i).size() > 0)
|
||||
max_dim = std::max<unsigned long>(max_dim, (--samples(i).end())->first + 1);
|
||||
}
|
||||
|
||||
return max_dim;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
|
@ -619,7 +621,10 @@ namespace dlib
|
|||
df.basis_vectors.set_size(1);
|
||||
// Copy the plane normal into the output basis vector. The output vector might be a
|
||||
// sparse vector container so we need to use this special kind of copy to handle that case.
|
||||
sparse_vector::assign_dense_to_sparse(df.basis_vectors(0), matrix_cast<scalar_type>(colm(w, 0, w.size()-1)));
|
||||
// As an aside, the reason for using num_dimensions_in_samples() and not just w.size()-1 is because
|
||||
// doing it this way avoids an inane warning from gcc that can occur in some cases.
|
||||
const long out_size = num_dimensions_in_samples(x);
|
||||
sparse_vector::assign_dense_to_sparse(df.basis_vectors(0), matrix_cast<scalar_type>(colm(w, 0, out_size)));
|
||||
df.alpha.set_size(1);
|
||||
df.alpha(0) = 1;
|
||||
|
||||
|
|
Loading…
Reference in New Issue