is_symmetric.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. template <typename DerivedA>
  18. IGL_INLINE bool igl::is_symmetric(
  19. const Eigen::PlainObjectBase<DerivedA>& A)
  20. {
  21. if(A.rows() != A.cols())
  22. {
  23. return false;
  24. }
  25. const typename Eigen::PlainObjectBase<DerivedA>& AT = A.transpose();
  26. const typename Eigen::PlainObjectBase<DerivedA>& AmAT = A-AT;
  27. //// Eigen screws up something with LLT if you try to do
  28. //SparseMatrix<T> AmAT = A-A.transpose();
  29. //// Eigen crashes at runtime if you try to do
  30. // return (A-A.transpose()).nonZeros() == 0;
  31. return AmAT.nonZeros() == 0;
  32. }
  33. #ifndef IGL_HEADER_ONLY
  34. // Explicit template specialization
  35. // generated by autoexplicit.sh
  36. template bool igl::is_symmetric<Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&);
  37. // generated by autoexplicit.sh
  38. template bool igl::is_symmetric<double>(Eigen::SparseMatrix<double, 0, int> const&);
  39. #endif