Commit 4da79d8d authored by Davis King's avatar Davis King

Added an overloaded matrix_assign() that handles symmetric kernel_matrix()

expressions more efficiently by only evaluating the upper triangular part
of the matrix.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403837
parent 69e3f4fe
......@@ -183,6 +183,46 @@ namespace dlib
return matrix_op<op>(op(kern,v,v));
}
// ----------------------------------------------------------------------------------------
template <
typename matrix_dest_type,
typename K,
typename V
>
inline void matrix_assign (
matrix_dest_type& dest,
const matrix_exp<matrix_op<op_kern_mat<K,V,V> > >& src
)
/*!
Overload matrix assignment so that when a kernel_matrix expression
gets assigned it only evaluates half the kernel matrix (since it is symmetric)
!*/
{
// if this is a symmetric kernel matrix
if (&src.ref().op.vect1 == &src.ref().op.vect2)
{
for (long r = 0; r < src.nr(); ++r)
{
for (long c = r; c < src.nc(); ++c)
{
dest(r,c) = dest(c,r) = src(r,c);
}
}
}
else
{
// This isn't a symmetric kernel matrix so just do a normal assignment loop
for (long r = 0; r < src.nr(); ++r)
{
for (long c = 0; c < src.nc(); ++c)
{
dest(r,c) = src(r,c);
}
}
}
}
// ----------------------------------------------------------------------------------------
}
......
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