فهرست منبع

better asserts and output

Former-commit-id: 7e3a5fe33b8af553b20d63edf5c80b528f1135c1
Alec Jacobson (jalec 11 سال پیش
والد
کامیت
64b2825610

+ 9 - 6
include/igl/active_set.cpp

@@ -131,14 +131,17 @@ IGL_INLINE igl::SolverStatus igl::active_set(
           as_ux(z) = TRUE;
         }
       }
-      PlainObjectBase<DerivedZ> AieqZ;
-      AieqZ = Aieq*Z;
-      for(int a = 0;a<Aieq.rows();a++)
+      if(Aieq.rows() > 0)
       {
-        if(AieqZ(a) > Bieq(a))
+        PlainObjectBase<DerivedZ> AieqZ;
+        AieqZ = Aieq*Z;
+        for(int a = 0;a<Aieq.rows();a++)
         {
-          new_as_ieq += (as_ieq(a)?0:1);
-          as_ieq(a) = TRUE;
+          if(AieqZ(a) > Bieq(a))
+          {
+            new_as_ieq += (as_ieq(a)?0:1);
+            as_ieq(a) = TRUE;
+          }
         }
       }
 #ifdef ACTIVE_SET_CPP_DEBUG

+ 3 - 1
include/igl/colon.cpp

@@ -18,6 +18,7 @@ IGL_INLINE void igl::colon(
         (double)low,
         (double)hi,
         (double)step);
+      assert(false && "low<hi but step<0");
       return;
     }
   }
@@ -26,10 +27,11 @@ IGL_INLINE void igl::colon(
     if(step > 0)
     {
       I.resize(0);
-      fprintf(stderr,"Error: colon() low(%g)>hi(%g) but step(%g)<0\n",
+      fprintf(stderr,"Error: colon() low(%g)>hi(%g) but step(%g)>0\n",
         (double)low,
         (double)hi,
         (double)step);
+      assert(false && "low>hi but step<0");
       return;
     }
   }

+ 52 - 1
include/igl/matlab/MatlabWorkspace.h

@@ -112,6 +112,12 @@ namespace igl
       IGL_INLINE bool find( 
         const std::string & name,
         Eigen::SparseMatrix<MT>& M);
+      IGL_INLINE bool find( 
+        const std::string & name,
+        double & d);
+      IGL_INLINE bool find( 
+        const std::string & name,
+        int & v);
       // Subtracts 1 from all entries
       template <typename DerivedM>
       IGL_INLINE bool find_index( 
@@ -371,7 +377,6 @@ IGL_INLINE bool igl::MatlabWorkspace::find(
   //cout<<name<<": "<<mxGetM(mx_data)<<" "<<mxGetN(mx_data)<<endl;
   const int m = mxGetM(mx_data);
   const int n = mxGetN(mx_data);
-
   // Handle vectors
   if(DerivedM::IsVectorAtCompileTime)
   {
@@ -442,6 +447,52 @@ IGL_INLINE bool igl::MatlabWorkspace::find(
 
 }
 
+IGL_INLINE bool igl::MatlabWorkspace::find( 
+  const std::string & name,
+  int & v)
+{
+  using namespace std;
+  const int i = std::find(names.begin(), names.end(), name)-names.begin();
+  if(i>=(int)names.size())
+  {
+    return false;
+  }
+  assert(i<=(int)data.size());
+  mxArray * mx_data = data[i];
+  assert(!mxIsSparse(mx_data));
+  assert(mxGetNumberOfDimensions(mx_data) == 2);
+  //cout<<name<<": "<<mxGetM(mx_data)<<" "<<mxGetN(mx_data)<<endl;
+  assert(mxGetNumberOfElements(mx_data) == 1);
+  copy(
+    mxGetPr(mx_data),
+    mxGetPr(mx_data)+mxGetNumberOfElements(mx_data),
+    &v);
+  return true;
+}
+
+IGL_INLINE bool igl::MatlabWorkspace::find( 
+  const std::string & name,
+  double & d)
+{
+  using namespace std;
+  const int i = std::find(names.begin(), names.end(), name)-names.begin();
+  if(i>=(int)names.size())
+  {
+    return false;
+  }
+  assert(i<=(int)data.size());
+  mxArray * mx_data = data[i];
+  assert(!mxIsSparse(mx_data));
+  assert(mxGetNumberOfDimensions(mx_data) == 2);
+  //cout<<name<<": "<<mxGetM(mx_data)<<" "<<mxGetN(mx_data)<<endl;
+  assert(mxGetNumberOfElements(mx_data) == 1);
+  copy(
+    mxGetPr(mx_data),
+    mxGetPr(mx_data)+mxGetNumberOfElements(mx_data),
+    &d);
+  return true;
+}
+
 template <typename DerivedM>
 IGL_INLINE bool igl::MatlabWorkspace::find_index( 
   const std::string & name,

+ 3 - 1
include/igl/min_quad_with_fixed.cpp

@@ -96,7 +96,9 @@ IGL_INLINE bool igl::min_quad_with_fixed_precompute(
   {
     // PD implies symmetric
     data.Auu_sym = true;
-    assert(is_symmetric(Auu,EPS<double>()));
+    // This is an annoying assertion unless EPS can be chosen in a nicer way.
+    //assert(is_symmetric(Auu,EPS<double>()));
+    assert(is_symmetric(Auu,1.0));
   }else
   {
     // determine if A(unknown,unknown) is symmetric and/or positive definite

+ 6 - 0
include/igl/mosek/bbw.cpp

@@ -132,6 +132,12 @@ IGL_INLINE bool igl::bbw(
       }
       W.col(i) = Wi;
     }
+    const double min_rowsum = W.rowwise().sum().array().abs().minCoeff();
+    if(min_rowsum < 0.1)
+    {
+      cerr<<"bbw.cpp: Warning, row sum is very low. Consider more iterations "
+        "or enforcing partition of unity."<<endl;
+    }
     // Need to normalize
     igl::normalize_row_sums(W,W); 
   }

+ 12 - 1
include/igl/slice.cpp

@@ -76,14 +76,25 @@ IGL_INLINE void igl::slice(
   const int dim,
   Eigen::SparseMatrix<T>& Y)
 {
-  
   Eigen::VectorXi C;
   switch(dim)
   {
     case 1:
+      // boring base case
+      if(X.cols() == 0)
+      {
+        Y.resize(R.size(),0);
+        return;
+      }
       igl::colon(0,X.cols()-1,C);
       return slice(X,R,C,Y);
     case 2:
+      // boring base case
+      if(X.rows() == 0)
+      {
+        Y.resize(0,R.size());
+        return;
+      }
       igl::colon(0,X.rows()-1,C);
       return slice(X,C,R,Y);
     default: