Commit f5801c15 authored by Davis King's avatar Davis King

Fixed a runtime bug in the distance_function's + and - operators which triggered when

distance_functions with no basis vectors in them were added or subtracted.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%404128
parent e7ac1871
......@@ -523,6 +523,11 @@ namespace dlib
<< "\n\t You can only add two distance_functions together if they use the same kernel."
);
if (alpha.size() == 0)
return rhs;
else if (rhs.alpha.size() == 0)
return *this;
else
return distance_function(join_cols(alpha, rhs.alpha),
b + rhs.b + 2*trans(alpha)*kernel_matrix(kernel_function,basis_vectors,rhs.basis_vectors)*rhs.alpha,
kernel_function,
......@@ -539,6 +544,13 @@ namespace dlib
<< "\n\t You can only subtract two distance_functions if they use the same kernel."
);
if (alpha.size() == 0 && rhs.alpha.size() == 0)
return distance_function(kernel_function);
else if (alpha.size() != 0 && rhs.alpha.size() == 0)
return *this;
else if (alpha.size() == 0 && rhs.alpha.size() != 0)
return -1*rhs;
else
return distance_function(join_cols(alpha, -rhs.alpha),
b + rhs.b - 2*trans(alpha)*kernel_matrix(kernel_function,basis_vectors,rhs.basis_vectors)*rhs.alpha,
kernel_function,
......
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