Skip to content

Commit 91866cf

Browse files
committed
utils: extend API of is_approx for SparseMatrix
1 parent d5c0a52 commit 91866cf

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed
Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,45 @@
11
/*
2-
* Copyright 2020 INRIA
2+
* Copyright 2020-2024 INRIA
33
*/
44

5-
#ifndef __eigenpy_utils_scalar_is_approx_hpp__
6-
#define __eigenpy_utils_scalar_is_approx_hpp__
5+
#ifndef __eigenpy_utils_is_approx_hpp__
6+
#define __eigenpy_utils_is_approx_hpp__
77

88
#include <Eigen/Core>
9+
#include <Eigen/SparseCore>
910

1011
namespace eigenpy {
1112
template <typename MatrixType1, typename MatrixType2>
12-
inline EIGEN_DONT_INLINE bool is_approx(
13-
const Eigen::MatrixBase<MatrixType1>& mat1,
14-
const Eigen::MatrixBase<MatrixType2>& mat2,
13+
EIGEN_DONT_INLINE bool is_approx(const Eigen::MatrixBase<MatrixType1>& mat1,
14+
const Eigen::MatrixBase<MatrixType2>& mat2,
15+
const typename MatrixType1::Scalar& prec) {
16+
return mat1.isApprox(mat2, prec);
17+
}
18+
19+
template <typename MatrixType1, typename MatrixType2>
20+
EIGEN_DONT_INLINE bool is_approx(const Eigen::MatrixBase<MatrixType1>& mat1,
21+
const Eigen::MatrixBase<MatrixType2>& mat2) {
22+
return is_approx(
23+
mat1, mat2,
24+
Eigen::NumTraits<typename MatrixType1::Scalar>::dummy_precision());
25+
}
26+
27+
template <typename MatrixType1, typename MatrixType2>
28+
EIGEN_DONT_INLINE bool is_approx(
29+
const Eigen::SparseMatrixBase<MatrixType1>& mat1,
30+
const Eigen::SparseMatrixBase<MatrixType2>& mat2,
1531
const typename MatrixType1::Scalar& prec) {
1632
return mat1.isApprox(mat2, prec);
1733
}
1834

1935
template <typename MatrixType1, typename MatrixType2>
20-
inline EIGEN_DONT_INLINE bool is_approx(
21-
const Eigen::MatrixBase<MatrixType1>& mat1,
22-
const Eigen::MatrixBase<MatrixType2>& mat2) {
36+
EIGEN_DONT_INLINE bool is_approx(
37+
const Eigen::SparseMatrixBase<MatrixType1>& mat1,
38+
const Eigen::SparseMatrixBase<MatrixType2>& mat2) {
2339
return is_approx(
2440
mat1, mat2,
2541
Eigen::NumTraits<typename MatrixType1::Scalar>::dummy_precision());
2642
}
2743
} // namespace eigenpy
2844

29-
#endif // ifndef __eigenpy_utils_scalar_is_approx_hpp__
45+
#endif // ifndef __eigenpy_utils_is_approx_hpp__

0 commit comments

Comments
 (0)