@@ -222,21 +222,22 @@ static void msgToCovariance(
222222}
223223
224224/* *
225- * \brief Check is a matrix M is symmetric, i.e. M' M = Id or low(M) = up(M)
225+ * \brief Check is a matrix M is symmetric, i.e. M' M == Id or low(M) = = up(M)
226226 * where low and up are the lower and upper triangular matrices of M
227227 * \param [in] M Square matrix
228228 * \return True if the matrix is symmetric
229229 */
230230template <typename T, int N>
231- bool isSymmetric (const Eigen::Matrix<T, N, N>& M)
231+ bool isSymmetric (const Eigen::Matrix<T, N, N>& M,
232+ const double eps = std::numeric_limits<T>::epsilon())
232233{
233- // Note that triangularView doesn't help to much to simplify the check,
234- // so we iterate on the lower and upper triangular matrixes directly:
234+ // Note that triangularView doesn't help too much to simplify the check,
235+ // so we iterate on the lower and upper triangular matrices directly:
235236 for (size_t i = 0 ; i < N - 1 ; ++i)
236237 {
237238 for (size_t j = i + 1 ; j < N; ++j)
238239 {
239- if (std::abs (M (i, j) - M (j, i)) > std::numeric_limits<T>:: epsilon () )
240+ if (std::abs (M (i, j) - M (j, i)) > eps )
240241 {
241242 return false ;
242243 }
@@ -339,7 +340,9 @@ T conditionNumber(const Eigen::Matrix<T, N, N>& M)
339340
340341 const T s_min = svd.singularValues ().minCoeff ();
341342
342- return s_min == 0 ?
343+ // Note that the singular values computed with Jacobi SVD are all positive, so
344+ // we don't need to use abs().
345+ return s_min == T (0 ) ?
343346 std::numeric_limits<T>::infinity () :
344347 svd.singularValues ().maxCoeff () / s_min;
345348}
0 commit comments