diff --git a/dlib/svm/krls.h b/dlib/svm/krls.h index f18db21db..77cf17587 100644 --- a/dlib/svm/krls.h +++ b/dlib/svm/krls.h @@ -115,40 +115,24 @@ namespace dlib // update K_inv by computing the new one in the temp matrix (equation 3.14) matrix temp(K_inv.nr()+1, K_inv.nc()+1); - for (long r = 0; r < K_inv.nr(); ++r) - { - for (long c = 0; c < K_inv.nc(); ++c) - { - temp(r,c) = (K_inv + a*trans(a)/delta)(r,c); - } - } + // update the middle part of the matrix + set_subm(temp, get_rect(K_inv)) = K_inv + a*trans(a)/delta; + // update the right column of the matrix + set_subm(temp, 0, K_inv.nr(),K_inv.nr(),1) = -a/delta; + // update the bottom row of the matrix + set_subm(temp, K_inv.nr(), 0, 1, K_inv.nr()) = trans(-a/delta); + // update the bottom right corner of the matrix temp(K_inv.nr(), K_inv.nc()) = 1/delta; - - // update the new sides of K_inv - for (long i = 0; i < K_inv.nr(); ++i) - { - temp(K_inv.nr(),i) = -a(i)/delta; - temp(i,K_inv.nr()) = -a(i)/delta; - } // put temp into K_inv temp.swap(K_inv); // Now update the P matrix (equation 3.15) temp.set_size(P.nr()+1, P.nc()+1); - for (long r = 0; r < P.nr(); ++r) - { - for (long c = 0; c < P.nc(); ++c) - { - temp(r,c) = P(r,c); - } - } + set_subm(temp, get_rect(P)) = P; // initialize the new sides of P - for (long i = 0; i < P.nr(); ++i) - { - temp(P.nr(),i) = 0; - temp(i,P.nc()) = 0; - } + set_rowm(temp,P.nr()) = 0; + set_colm(temp,P.nr()) = 0; temp(P.nr(), P.nc()) = 1; temp.swap(P);