Browse Source

is sparse and full templtated to work even if already full

Former-commit-id: 9dd059142b2d4b992218c86db8bfbc524aedd178
Alec Jacobson (jalec 12 năm trước cách đây
mục cha
commit
dd6d4ac69b

+ 2 - 2
Makefile

@@ -1,8 +1,8 @@
 .PHONY: all
 all: lib extras examples
 
-#GG=g++
-GG=clang++
+GG=g++
+#GG=clang++
 #GG=/usr/bin/g++     17s
 #GG=/usr/bin/clang++ 14s
 #GG=g++-mp-4.3       15.5s

+ 10 - 0
include/igl/full.cpp

@@ -17,8 +17,18 @@ IGL_INLINE void igl::full(
   }
 }
 
+template <typename DerivedA,typename DerivedB>
+IGL_INLINE bool igl::full(
+  const Eigen::PlainObjectBase<DerivedA>& A,
+  Eigen::PlainObjectBase<DerivedB>& B)
+{
+  B = A;
+}
+
 #ifndef IGL_HEADER_ONLY
 // Explicit template specialization
 // generated by autoexplicit.sh
+template bool igl::full<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
+// generated by autoexplicit.sh
 template void igl::full<double>(Eigen::SparseMatrix<double, 0, int> const&, Eigen::Matrix<double, -1, -1, 0, -1, -1>&);
 #endif

+ 5 - 0
include/igl/full.h

@@ -17,6 +17,11 @@ namespace igl
   IGL_INLINE void full(
     const Eigen::SparseMatrix<T> & A,
     Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & B);
+  // If already full then this will just be a copy by assignment
+  template <typename DerivedA,typename DerivedB>
+  IGL_INLINE bool full(
+    const Eigen::PlainObjectBase<DerivedA>& A,
+    Eigen::PlainObjectBase<DerivedB>& B);
 }
 
 #ifdef IGL_HEADER_ONLY

+ 21 - 0
include/igl/is_sparse.cpp

@@ -0,0 +1,21 @@
+#include "is_sparse.h"
+template <typename T>
+IGL_INLINE bool igl::is_sparse(
+  const Eigen::SparseMatrix<T> & A)
+{
+  return true;
+}
+template <typename DerivedA>
+IGL_INLINE bool igl::is_sparse(
+  const Eigen::PlainObjectBase<DerivedA>& A)
+{
+  return false;
+}
+
+#ifndef IGL_HEADER_ONLY
+// Explicit template specialization
+// generated by autoexplicit.sh
+template bool igl::is_sparse<double>(Eigen::SparseMatrix<double, 0, int> const&);
+// generated by autoexplicit.sh
+template bool igl::is_sparse<Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&);
+#endif

+ 29 - 0
include/igl/is_sparse.h

@@ -0,0 +1,29 @@
+#ifndef IGL_IS_SPARSE_H
+#define IGL_IS_SPARSE_H
+#include "igl_inline.h"
+#define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
+#include <Eigen/Dense>
+#include <Eigen/Sparse>
+namespace igl
+{
+  // Determine if a matrix A is sparse
+  //
+  // Template:
+  //   T,DerivedA defines scalar type
+  // Inputs:
+  //   A  matrix in question
+  // Returns true if A is represented with a sparse matrix
+  template <typename T>
+  IGL_INLINE bool is_sparse(
+    const Eigen::SparseMatrix<T> & A);
+  template <typename DerivedA>
+  IGL_INLINE bool is_sparse(
+    const Eigen::PlainObjectBase<DerivedA>& A);
+}
+
+#ifdef IGL_HEADER_ONLY
+#  include "is_sparse.cpp"
+#endif
+
+#endif
+

+ 19 - 0
include/igl/is_symmetric.cpp

@@ -16,8 +16,27 @@ IGL_INLINE bool igl::is_symmetric(const Eigen::SparseMatrix<T>& A)
   return AmAT.nonZeros() == 0;
 }
 
+template <typename DerivedA>
+IGL_INLINE bool igl::is_symmetric(
+  const Eigen::PlainObjectBase<DerivedA>& A)
+{
+  if(A.rows() != A.cols())
+  {
+    return false;
+  }
+  const typename Eigen::PlainObjectBase<DerivedA>& AT = A.transpose();
+  const typename Eigen::PlainObjectBase<DerivedA>& AmAT = A-AT;
+  //// Eigen screws up something with LLT if you try to do
+  //SparseMatrix<T> AmAT = A-A.transpose();
+  //// Eigen crashes at runtime if you try to do
+  // return (A-A.transpose()).nonZeros() == 0;
+  return AmAT.nonZeros() == 0;
+}
+
 #ifndef IGL_HEADER_ONLY
 // Explicit template specialization
 // generated by autoexplicit.sh
+template bool igl::is_symmetric<Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&);
+// generated by autoexplicit.sh
 template bool igl::is_symmetric<double>(Eigen::SparseMatrix<double, 0, int> const&);
 #endif

+ 3 - 0
include/igl/is_symmetric.h

@@ -11,6 +11,9 @@ namespace igl
   // Returns true if the matrix is square and symmetric
   template <typename T>
   IGL_INLINE bool is_symmetric(const Eigen::SparseMatrix<T>& A);
+  template <typename DerivedA>
+  IGL_INLINE bool is_symmetric(
+    const Eigen::PlainObjectBase<DerivedA>& A);
 }
 
 #ifdef IGL_HEADER_ONLY