浏览代码

eigs now working even when there are modes with multiplicity

Former-commit-id: 345527af2ab955695cee26d5df42644503e28b74
Alec Jacobson 8 年之前
父节点
当前提交
2da6128618
共有 1 个文件被更改,包括 9 次插入2 次删除
  1. 9 2
      include/igl/eigs.cpp

+ 9 - 2
include/igl/eigs.cpp

@@ -45,8 +45,10 @@ IGL_INLINE bool igl::eigs(
   Scalar conv = 1e-14;
   int max_iter = 100;
   int i = 0;
+  //std::cout<<"start"<<std::endl;
   while(true)
   {
+    //std::cout<<i<<std::endl;
     // Random initial guess
     VectorXS y = VectorXS::Random(n,1);
     Scalar eff_sigma = 0;
@@ -132,8 +134,13 @@ IGL_INLINE bool igl::eigs(
       cerr<<"Failed to converge."<<endl;
       return false;
     }
-    if(i==0 || (S.head(i).array()-sigma).abs().maxCoeff()>1e-14)
+    if(
+      i==0 || 
+      (S.head(i).array()-sigma).abs().maxCoeff()>1e-14 ||
+      ((S.transpose()*B*x).array().abs()>=1e-7).all()
+      )
     {
+      //cout<<"Found "<<i<<"th mode"<<endl;
       U.col(i) = x;
       S(i) = sigma;
       i++;
@@ -144,7 +151,7 @@ IGL_INLINE bool igl::eigs(
     }else
     {
       // restart with new random guess.
-      cout<<"RESTART!"<<endl;
+      cout<<"igl::eigs RESTART"<<endl;
     }
   }
   // finally sort