#ifndef IGL_IS_SYMMETRIC_H #define IGL_IS_SYMMETRIC_H namespace igl { // Returns true if the given matrix is symmetric // Inputs: // A m by m matrix // Returns true if the matrix is square and symmetric template inline bool is_symmetric(const Eigen::SparseMatrix& A); } // Implementation template inline bool igl::is_symmetric(const Eigen::SparseMatrix& A) { if(A.rows() != A.cols()) { return false; } SparseMatrix AT = A.transpose(); SparseMatrix AmAT = A-AT; //// Eigen screws up something with LLT if you try to do //SparseMatrix AmAT = A-A.transpose(); //// Eigen crashes at runtime if you try to do // return (A-A.transpose()).nonZeros() == 0; return AmAT.nonZeros() == 0; } #endif