is_symmetric.cpp 671 B

1234567891011121314151617181920212223
  1. #include "is_symmetric.h"
  2. template <typename T>
  3. IGL_INLINE bool igl::is_symmetric(const Eigen::SparseMatrix<T>& A)
  4. {
  5. if(A.rows() != A.cols())
  6. {
  7. return false;
  8. }
  9. Eigen::SparseMatrix<T> AT = A.transpose();
  10. Eigen::SparseMatrix<T> AmAT = A-AT;
  11. //// Eigen screws up something with LLT if you try to do
  12. //SparseMatrix<T> AmAT = A-A.transpose();
  13. //// Eigen crashes at runtime if you try to do
  14. // return (A-A.transpose()).nonZeros() == 0;
  15. return AmAT.nonZeros() == 0;
  16. }
  17. #ifndef IGL_HEADER_ONLY
  18. // Explicit template specialization
  19. // generated by autoexplicit.sh
  20. template bool igl::is_symmetric<double>(Eigen::SparseMatrix<double, 0, int> const&);
  21. #endif