Commit ae9546cb authored by Davis King's avatar Davis King

Made svd3 faster when working on small matrices.

parent f9fac06e
...@@ -1541,16 +1541,21 @@ convergence: ...@@ -1541,16 +1541,21 @@ convergence:
COMPILE_TIME_ASSERT(wX == 0 || wX == 1); COMPILE_TIME_ASSERT(wX == 0 || wX == 1);
#ifdef DLIB_USE_LAPACK #ifdef DLIB_USE_LAPACK
matrix<typename matrix_exp<EXP>::type, uNR, uNC,MM1,L1> temp(m); // use LAPACK but only if it isn't a really small matrix we are taking the SVD of.
lapack::gesvd('S','A', temp, w, u, v); if (NR*NC == 0 || NR*NC > 3*3)
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<T>(m.nc()-u.nc(),1)); matrix<typename matrix_exp<EXP>::type, uNR, uNC,MM1,L1> temp(m);
u = join_rows(u, zeros_matrix<T>(u.nr(), m.nc()-u.nc())); 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<T>(m.nc()-u.nc(),1));
u = join_rows(u, zeros_matrix<T>(u.nr(), m.nc()-u.nc()));
}
return;
} }
#else #endif
v.set_size(m.nc(),m.nc()); v.set_size(m.nc(),m.nc());
u = m; u = m;
...@@ -1558,7 +1563,6 @@ convergence: ...@@ -1558,7 +1563,6 @@ convergence:
w.set_size(m.nc(),1); w.set_size(m.nc(),1);
matrix<T,matrix_exp<EXP>::NC,1,MM1> rv1(m.nc(),1); matrix<T,matrix_exp<EXP>::NC,1,MM1> rv1(m.nc(),1);
nric::svdcmp(u,w,v,rv1); nric::svdcmp(u,w,v,rv1);
#endif
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
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