From ae9546cbdccabef39066a8583b2830ab3ad5bb07 Mon Sep 17 00:00:00 2001 From: Davis King Date: Mon, 11 Aug 2014 19:51:05 -0400 Subject: [PATCH] Made svd3 faster when working on small matrices. --- dlib/matrix/matrix_la.h | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/dlib/matrix/matrix_la.h b/dlib/matrix/matrix_la.h index 14dc0cef1..daab0cb94 100644 --- a/dlib/matrix/matrix_la.h +++ b/dlib/matrix/matrix_la.h @@ -1541,16 +1541,21 @@ convergence: COMPILE_TIME_ASSERT(wX == 0 || wX == 1); #ifdef DLIB_USE_LAPACK - matrix::type, uNR, uNC,MM1,L1> temp(m); - lapack::gesvd('S','A', temp, w, u, v); - v = trans(v); - // if u isn't the size we want then pad it (and v) with zeros - if (u.nc() < m.nc()) + // use LAPACK but only if it isn't a really small matrix we are taking the SVD of. + if (NR*NC == 0 || NR*NC > 3*3) { - w = join_cols(w, zeros_matrix(m.nc()-u.nc(),1)); - u = join_rows(u, zeros_matrix(u.nr(), m.nc()-u.nc())); + matrix::type, uNR, uNC,MM1,L1> temp(m); + lapack::gesvd('S','A', temp, w, u, v); + v = trans(v); + // if u isn't the size we want then pad it (and v) with zeros + if (u.nc() < m.nc()) + { + w = join_cols(w, zeros_matrix(m.nc()-u.nc(),1)); + u = join_rows(u, zeros_matrix(u.nr(), m.nc()-u.nc())); + } + return; } -#else +#endif v.set_size(m.nc(),m.nc()); u = m; @@ -1558,7 +1563,6 @@ convergence: w.set_size(m.nc(),1); matrix::NC,1,MM1> rv1(m.nc(),1); nric::svdcmp(u,w,v,rv1); -#endif } // ----------------------------------------------------------------------------------------