Verified Commit 339241f8 authored by Justin Carpentier's avatar Justin Carpentier
Browse files

utils: add is_approx function and expose it

parent 78e31bec
# #
# Copyright (c) 2014-2019 CNRS # Copyright (c) 2014-2019 CNRS
# Copyright (c) 2018-2019 INRIA # Copyright (c) 2018-2020 INRIA
# #
CMAKE_MINIMUM_REQUIRED(VERSION 2.6) CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
...@@ -73,6 +73,7 @@ SEARCH_FOR_BOOST() ...@@ -73,6 +73,7 @@ SEARCH_FOR_BOOST()
# ---------------------------------------------------- # ----------------------------------------------------
SET(${PROJECT_NAME}_UTILS_HEADERS SET(${PROJECT_NAME}_UTILS_HEADERS
include/eigenpy/utils/scalar-name.hpp include/eigenpy/utils/scalar-name.hpp
include/eigenpy/utils/is-approx.hpp
) )
SET(${PROJECT_NAME}_SOLVERS_HEADERS SET(${PROJECT_NAME}_SOLVERS_HEADERS
......
/*
* Copyright 2020 INRIA
*/
#ifndef __eigenpy_utils_scalar_is_approx_hpp__
#define __eigenpy_utils_scalar_is_approx_hpp__
#include <Eigen/Core>
namespace eigenpy
{
template<typename MatrixType1, typename MatrixType2>
inline bool is_approx(const Eigen::MatrixBase<MatrixType1> & mat1,
const Eigen::MatrixBase<MatrixType2> & mat2,
const typename MatrixType1::Scalar & prec = Eigen::NumTraits<typename MatrixType1::Scalar>::dummy_precision())
{
return mat1.isApprox(mat2,prec);
}
}
#endif // ifndef __eigenpy_utils_scalar_is_approx_hpp__
...@@ -13,10 +13,28 @@ ...@@ -13,10 +13,28 @@
#include "eigenpy/solvers/preconditioners.hpp" #include "eigenpy/solvers/preconditioners.hpp"
#include "eigenpy/decompositions/decompositions.hpp" #include "eigenpy/decompositions/decompositions.hpp"
#include "eigenpy/utils/is-approx.hpp"
#include <boost/python/scope.hpp> #include <boost/python/scope.hpp>
#define DEFINE_IS_APPROX(MatType) \
BOOST_PYTHON_FUNCTION_OVERLOADS(is_approx_overload##MatType,eigenpy::is_approx,2,3)
#define EXPOSE_IS_APPROX(MatType) \
bp::def("is_approx", \
(bool (*)(const Eigen::MatrixBase<MatType> &, \
const Eigen::MatrixBase<MatType> &, \
const MatType::Scalar &))eigenpy::is_approx<MatType,MatType>, \
is_approx_overload##MatType(bp::args("A","B","prec"), \
"Returns True if A is approximately equal to B, within the precision determined by prec."))
using namespace eigenpy; using namespace eigenpy;
DEFINE_IS_APPROX(MatrixXd)
DEFINE_IS_APPROX(MatrixXf)
BOOST_PYTHON_MODULE(eigenpy) BOOST_PYTHON_MODULE(eigenpy)
{ {
namespace bp = boost::python; namespace bp = boost::python;
...@@ -42,5 +60,11 @@ BOOST_PYTHON_MODULE(eigenpy) ...@@ -42,5 +60,11 @@ BOOST_PYTHON_MODULE(eigenpy)
register_symbolic_link_to_registered_type<Eigen::ComputationInfo>(); register_symbolic_link_to_registered_type<Eigen::ComputationInfo>();
} }
{
using namespace Eigen;
EXPOSE_IS_APPROX(MatrixXd);
EXPOSE_IS_APPROX(MatrixXf);
}
exposeDecompositions(); exposeDecompositions();
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment