is_symmetric.h 769 B

123456789101112131415161718192021222324252627282930
  1. #ifndef IGL_IS_SYMMETRIC_H
  2. #define IGL_IS_SYMMETRIC_H
  3. namespace igl
  4. {
  5. // Returns true if the given matrix is symmetric
  6. // Inputs:
  7. // A m by m matrix
  8. // Returns true if the matrix is square and symmetric
  9. template <typename T>
  10. inline bool is_symmetric(const Eigen::SparseMatrix<T>& A);
  11. }
  12. // Implementation
  13. template <typename T>
  14. inline bool igl::is_symmetric(const Eigen::SparseMatrix<T>& A)
  15. {
  16. if(A.rows() != A.cols())
  17. {
  18. return false;
  19. }
  20. SparseMatrix<T> AT = A.transpose();
  21. SparseMatrix<T> AmAT = A-AT;
  22. //// Eigen screws up something with LLT if you try to do
  23. //SparseMatrix<T> AmAT = A-A.transpose();
  24. //// Eigen crashes at runtime if you try to do
  25. // return (A-A.transpose()).nonZeros() == 0;
  26. return AmAT.nonZeros() == 0;
  27. }
  28. #endif