Skip to content

Commit 1451c72

Browse files
committed
module: extend is_approx for sparse matrices
1 parent 2564070 commit 1451c72

File tree

1 file changed

+34
-12
lines changed

1 file changed

+34
-12
lines changed

python/main.cpp

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright 2014-2019, CNRS
3-
* Copyright 2018-2023, INRIA
3+
* Copyright 2018-2024, INRIA
44
*/
55

66
#include <boost/python/scope.hpp>
@@ -17,6 +17,37 @@
1717

1818
using namespace eigenpy;
1919

20+
template <typename Scalar>
21+
void exposeIsApprox() {
22+
enum { Options = 0 };
23+
EIGENPY_MAKE_TYPEDEFS(Scalar, Options, s, Eigen::Dynamic, X);
24+
EIGENPY_UNUSED_TYPE(VectorXs);
25+
EIGENPY_UNUSED_TYPE(RowVectorXs);
26+
typedef Eigen::SparseMatrix<Scalar, Options> SparseMatrixXs;
27+
typedef typename MatrixXs::RealScalar RealScalar;
28+
29+
using namespace Eigen;
30+
const RealScalar dummy_precision =
31+
Eigen::NumTraits<RealScalar>::dummy_precision();
32+
33+
bp::def("is_approx",
34+
(bool (*)(const Eigen::MatrixBase<MatrixXs> &,
35+
const Eigen::MatrixBase<MatrixXs> &, const RealScalar &)) &
36+
is_approx,
37+
(bp::arg("A"), bp::arg("B"), bp::arg("prec") = dummy_precision),
38+
"Returns True if A is approximately equal to B, within the "
39+
"precision determined by prec.");
40+
41+
bp::def("is_approx",
42+
(bool (*)(const Eigen::SparseMatrixBase<SparseMatrixXs> &,
43+
const Eigen::SparseMatrixBase<SparseMatrixXs> &,
44+
const RealScalar &)) &
45+
is_approx,
46+
(bp::arg("A"), bp::arg("B"), bp::arg("prec") = dummy_precision),
47+
"Returns True if A is approximately equal to B, within the "
48+
"precision determined by prec.");
49+
}
50+
2051
BOOST_PYTHON_MODULE(eigenpy_pywrap) {
2152
enableEigenPy();
2253

@@ -46,17 +77,8 @@ BOOST_PYTHON_MODULE(eigenpy_pywrap) {
4677
register_symbolic_link_to_registered_type<Eigen::ComputationInfo>();
4778
}
4879

49-
{
50-
using namespace Eigen;
51-
52-
bp::def("is_approx",
53-
(bool (*)(const Eigen::MatrixBase<MatrixXd> &,
54-
const Eigen::MatrixBase<MatrixXd> &, const double &)) &
55-
is_approx<MatrixXd, MatrixXd>,
56-
(bp::arg("A"), bp::arg("B"), bp::arg("prec") = 1e-12),
57-
"Returns True if A is approximately equal to B, within the "
58-
"precision determined by prec.");
59-
}
80+
exposeIsApprox<double>();
81+
exposeIsApprox<std::complex<double> >();
6082

6183
exposeDecompositions();
6284
}

0 commit comments

Comments
 (0)