1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- #include "is_symmetric.h"
- #include "find.h"
- template <typename T>
- IGL_INLINE bool igl::is_symmetric(const Eigen::SparseMatrix<T>& A)
- {
- if(A.rows() != A.cols())
- {
- return false;
- }
- Eigen::SparseMatrix<T> AT = A.transpose();
- Eigen::SparseMatrix<T> 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;
- }
- 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;
- }
- template <typename AType, typename epsilonT>
- IGL_INLINE bool igl::is_symmetric(
- const Eigen::SparseMatrix<AType>& A,
- const epsilonT epsilon)
- {
- using namespace Eigen;
- using namespace igl;
- if(A.rows() != A.cols())
- {
- return false;
- }
- SparseMatrix<AType> AT = A.transpose();
- SparseMatrix<AType> AmAT = A-AT;
- VectorXi AmATI,AmATJ;
- Matrix<AType,Dynamic,1> AmATV;
- find(AmAT,AmATI,AmATJ,AmATV);
-
- return AmATV.maxCoeff() < epsilon && AmATV.minCoeff() > -epsilon;
- }
- #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&);
- template bool igl::is_symmetric<double, double>(Eigen::SparseMatrix<double, 0, int> const&, double);
- template bool igl::is_symmetric<double, int>(Eigen::SparseMatrix<double, 0, int> const&, int);
- #endif
|