Browse Source

add svd version

Former-commit-id: e21270fdafefc6f336d5289c74a87eae6f457daa
Alec Jacobson 8 years ago
parent
commit
0faf24a294
3 changed files with 53 additions and 85 deletions
  1. 0 48
      include/igl/for_each.cpp
  2. 53 5
      include/igl/for_each.h
  3. 0 32
      include/igl/redux.cpp

+ 0 - 48
include/igl/for_each.cpp

@@ -1,48 +0,0 @@
-#include "for_each.h"
-
-template <typename AType, typename Func>
-IGL_INLINE void igl::for_each(
-  const Eigen::SparseMatrix<AType> & A,
-  const Func & func)
-{
-  // Can **not** use parallel for because this must be _in order_
-  // Iterate over outside
-  for(int k=0; k<A.outerSize(); ++k)
-  {
-    // Iterate over inside
-    for(typename Eigen::SparseMatrix<AType>::InnerIterator it (A,k); it; ++it)
-    {
-      func(it.row(),it.col(),it.value());
-    }
-  }
-}
-
-template <typename DerivedA, typename Func>
-IGL_INLINE void igl::for_each(
-  const Eigen::DenseBase<DerivedA> & A,
-  const Func & func)
-{
-  // Can **not** use parallel for because this must be _in order_
-  if(A.IsRowMajor)
-  {
-    for(typename DerivedA::Index i = 0;i<A.rows();i++)
-    {
-      for(typename DerivedA::Index j = 0;j<A.cols();j++)
-      {
-        func(i,j,A(i,j));
-      }
-    }
-  }else
-  {
-    for(typename DerivedA::Index j = 0;j<A.cols();j++)
-    {
-      for(typename DerivedA::Index i = 0;i<A.rows();i++)
-      {
-        func(i,j,A(i,j));
-      }
-    }
-  }
-  
-}
-
-#include <functional>

+ 53 - 5
include/igl/for_each.h

@@ -16,15 +16,63 @@ namespace igl
   //
   // See also: std::for_each
   template <typename AType, typename Func>
-  IGL_INLINE void for_each(
+  inline void for_each(
     const Eigen::SparseMatrix<AType> & A,
     const Func & func);
   template <typename DerivedA, typename Func>
-  IGL_INLINE void for_each(
+  inline void for_each(
     const Eigen::DenseBase<DerivedA> & A,
     const Func & func);
 }
-#ifndef IGL_STATIC_LIBRARY
-#  include "for_each.cpp"
-#endif
+
+// Implementation
+
+template <typename AType, typename Func>
+inline void igl::for_each(
+  const Eigen::SparseMatrix<AType> & A,
+  const Func & func)
+{
+  // Can **not** use parallel for because this must be _in order_
+  // Iterate over outside
+  for(int k=0; k<A.outerSize(); ++k)
+  {
+    // Iterate over inside
+    for(typename Eigen::SparseMatrix<AType>::InnerIterator it (A,k); it; ++it)
+    {
+      func(it.row(),it.col(),it.value());
+    }
+  }
+}
+
+template <typename DerivedA, typename Func>
+inline void igl::for_each(
+  const Eigen::DenseBase<DerivedA> & A,
+  const Func & func)
+{
+  // Can **not** use parallel for because this must be _in order_
+  if(A.IsRowMajor)
+  {
+    for(typename DerivedA::Index i = 0;i<A.rows();i++)
+    {
+      for(typename DerivedA::Index j = 0;j<A.cols();j++)
+      {
+        func(i,j,A(i,j));
+      }
+    }
+  }else
+  {
+    for(typename DerivedA::Index j = 0;j<A.cols();j++)
+    {
+      for(typename DerivedA::Index i = 0;i<A.rows();i++)
+      {
+        func(i,j,A(i,j));
+      }
+    }
+  }
+  
+}
+
+//#ifndef IGL_STATIC_LIBRARY
+//#  include "for_each.cpp"
+//#endif
 #endif

+ 0 - 32
include/igl/redux.cpp

@@ -1,32 +0,0 @@
-#include "redux.h"
-#include "for_each.h"
-
-template <typename AType, typename Func, typename DerivedB>
-IGL_INLINE void igl::redux(
-  const Eigen::SparseMatrix<AType> & A,
-  const int dim,
-  const Func & func,
-  Eigen::PlainObjectBase<DerivedB> & B)
-{
-  assert((dim == 1 || dim == 2) && "dim must be 2 or 1");
-  // Get size of input
-  int m = A.rows();
-  int n = A.cols();
-  // resize output
-  B = DerivedB::Zero(dim==1?n:m);
-  const auto func_wrap = [&func,&B,&dim](const int i, const int j, const int v)
-  {
-    if(dim == 1)
-    {
-      B(j) = i == 0? v : func(B(j),v);
-    }else
-    {
-      B(i) = j == 0? v : func(B(i),v);
-    }
-  };
-  for_each(A,func_wrap);
-}
-
-#ifdef IGL_STATIC_LIBRARY
-// Explicit template specialization
-#endif