This forum will soon be archived and you won't be able to interact with it anymore. Please use KDE Discuss instead.

## Infinite loop in SVD decomposition

eranb
Registered Member
Posts
11
Karma
0

### Infinite loop in SVD decomposition

Mon Nov 18, 2013 10:02 am
In my windows MSVC (both 32bit and 64bit) this code made an infinite loop :
Code: Select all
`#include <extern/eigen/Dense>using namespace Eigen;int main(){   Matrix<double, 3, 3, RowMajor> mat;   mat <<      4.4331978442502944e+307,      -5.8585363752028680e+307,      6.4527017443412964e+307,      3.7841695601406358e+307,      2.4331702789740617e+306,      -3.5235707140272905e+307,      -8.7190887618028355e+307,      -7.3453213709232193e+307,      -2.4367363684472105e+307;   Matrix<double,Dynamic,Dynamic> u,d,v;   JacobiSVD<Matrix<double, Dynamic, Dynamic, RowMajor> > svd(mat, ComputeThinU | ComputeThinV);   return 0;}`

The loop is the inner while of JacobiSVD.h compute method.
The documentation says :
...the computation is guaranteed to terminate in finite (and reasonable) time.

(From http://eigen.tuxfamily.org/dox/classEigen_1_1JacobiSVD.html).
ggael
Moderator
Posts
3447
Karma
19
OS

### Re: Infinite loop in SVD decomposition

Mon Nov 18, 2013 10:50 am
It's very dangerous to work with such high values that are very close to overflow. I guess this explain why it does not converge. Before a proper fix, I suggest you to apply scaling:

Code: Select all
`   double s mat.cwiseAbs().maxCoeff();   mat /= s;   JacobiSVD<MatrixXd> svd(mat, ComputeThinU | ComputeThinV);   VectorXd d = svd.singularValues() * s;`
eranb
Registered Member
Posts
11
Karma
0

### Re: Infinite loop in SVD decomposition

Mon Nov 18, 2013 11:08 am
The source of those numbers is a bug (uninitialized memory), so I don't really need their svd decomposition, but infinite loop is unacceptable...
tnx.
ggael
Moderator
Posts
3447
Karma
19
OS

### Re: Infinite loop in SVD decomposition

Tue Nov 19, 2013 10:54 am
fixed.

https://bitbucket.org/eigen/eigen/commits/9034caa3d917/
Changeset: 9034caa3d917
User: ggael
Date: 2013-11-19 11:53:48
Summary: Add scaling in JacobiSVD to avoid overflows

## Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot], markhm, mickae, sethaaaa, Sogou [Bot], Yahoo [Bot], zolder