Skip to content
Snippets Groups Projects
Unverified Commit 4b122107 authored by Justin Carpentier's avatar Justin Carpentier Committed by GitHub
Browse files

Merge pull request #274 from jcarpent/devel

Apply pre-commit on all the project
parents 4a44fac2 ff48cba0
No related branches found
No related tags found
No related merge requests found
Showing
with 1942 additions and 1913 deletions
repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v13.0.1
hooks:
- id: clang-format
args: [-i, --style=Google]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: trailing-whitespace
Subproject commit 7a5475bcbac62643eb5c03744f1ee16f83607fe2
Subproject commit 332976cc4d5305256c79a479e55ad7ab2ecc42f1
......@@ -45,8 +45,8 @@ a:link {
color:#0066CC
}
a:hover, a:active {
text-decoration: underline;
a:hover, a:active {
text-decoration: underline;
color: #3C9A35;
}
......@@ -57,7 +57,7 @@ a:visited {
}
DIV.memitem
{
{
spacing: 10px;
width:100%;
background:#FFFFFF;
......@@ -70,7 +70,7 @@ DIV.memitem
}
DIV.memproto
{
{
width:100%;
background:#F0F0F0;
font-size:100%;
......@@ -82,7 +82,7 @@ DIV.memproto
}
DIV.memdoc
{
{
padding: 10px;
width:100%;
font-size:100%;
......@@ -189,7 +189,7 @@ DIV.nav
}
DIV.groupHeader
{
{
padding-top: 30px;
padding-bottom: 20px;
background : none;
......@@ -201,23 +201,23 @@ DIV.groupHeader
color:#0066CC;
}
.directory p
{
margin: 0px;
white-space: nowrap;
.directory p
{
margin: 0px;
white-space: nowrap;
font-family: 'Lucida Grande','Lucida Sans Unicode',Verdana,Sans-Serif;
font-size: 10pt;
font-weight: normal;
}
.directory h3
{
.directory h3
{
font-family: 'Lucida Grande','Lucida Sans Unicode',Verdana,Sans-Serif;
margin: 0px;
margin-top: 1em;
margin: 0px;
margin-top: 1em;
padding-bottom: 20px;
font-size: 12pt;
font-size: 12pt;
font-variant: small-caps;
text-align: center;
}
......
......@@ -5,147 +5,133 @@
#ifndef __eigenpy_angle_axis_hpp__
#define __eigenpy_angle_axis_hpp__
#include "eigenpy/eigenpy.hpp"
#include <Eigen/Core>
#include <Eigen/Geometry>
namespace eigenpy
{
namespace bp = boost::python;
template<typename AngleAxis> class AngleAxisVisitor;
template<typename Scalar>
struct call< Eigen::AngleAxis<Scalar> >
{
typedef Eigen::AngleAxis<Scalar> AngleAxis;
static inline void expose()
{
AngleAxisVisitor<AngleAxis>::expose();
}
static inline bool isApprox(const AngleAxis & self, const AngleAxis & other,
const Scalar & prec = Eigen::NumTraits<Scalar>::dummy_precision())
{
return self.isApprox(other,prec);
}
};
template<typename AngleAxis>
class AngleAxisVisitor
: public bp::def_visitor< AngleAxisVisitor<AngleAxis> >
{
typedef typename AngleAxis::Scalar Scalar;
typedef typename AngleAxis::Vector3 Vector3;
typedef typename AngleAxis::Matrix3 Matrix3;
typedef typename Eigen::Quaternion<Scalar,0> Quaternion;
typedef Eigen::RotationBase<AngleAxis,3> RotationBase;
BOOST_PYTHON_FUNCTION_OVERLOADS(isApproxAngleAxis_overload,call<AngleAxis>::isApprox,2,3)
public:
template<class PyClass>
void visit(PyClass& cl) const
{
cl
.def(bp::init<>(bp::arg("self"),"Default constructor"))
.def(bp::init<Scalar,Vector3>
((bp::arg("self"),bp::arg("angle"),bp::arg("axis")),
#include "eigenpy/eigenpy.hpp"
namespace eigenpy {
namespace bp = boost::python;
template <typename AngleAxis>
class AngleAxisVisitor;
template <typename Scalar>
struct call<Eigen::AngleAxis<Scalar> > {
typedef Eigen::AngleAxis<Scalar> AngleAxis;
static inline void expose() { AngleAxisVisitor<AngleAxis>::expose(); }
static inline bool isApprox(
const AngleAxis& self, const AngleAxis& other,
const Scalar& prec = Eigen::NumTraits<Scalar>::dummy_precision()) {
return self.isApprox(other, prec);
}
};
template <typename AngleAxis>
class AngleAxisVisitor : public bp::def_visitor<AngleAxisVisitor<AngleAxis> > {
typedef typename AngleAxis::Scalar Scalar;
typedef typename AngleAxis::Vector3 Vector3;
typedef typename AngleAxis::Matrix3 Matrix3;
typedef typename Eigen::Quaternion<Scalar, 0> Quaternion;
typedef Eigen::RotationBase<AngleAxis, 3> RotationBase;
BOOST_PYTHON_FUNCTION_OVERLOADS(isApproxAngleAxis_overload,
call<AngleAxis>::isApprox, 2, 3)
public:
template <class PyClass>
void visit(PyClass& cl) const {
cl.def(bp::init<>(bp::arg("self"), "Default constructor"))
.def(bp::init<Scalar, Vector3>(
(bp::arg("self"), bp::arg("angle"), bp::arg("axis")),
"Initialize from angle and axis."))
.def(bp::init<Matrix3>
((bp::arg("self"),bp::arg("R")),
"Initialize from a rotation matrix"))
.def(bp::init<Quaternion>((bp::arg("self"),bp::arg("quaternion")),
"Initialize from a quaternion."))
.def(bp::init<AngleAxis>((bp::arg("self"),bp::arg("copy")),
"Copy constructor."))
/* --- Properties --- */
.add_property("axis",
bp::make_function((Vector3 & (AngleAxis::*)())&AngleAxis::axis,
bp::return_internal_reference<>()),
&AngleAxisVisitor::setAxis,"The rotation axis.")
.add_property("angle",
(Scalar (AngleAxis::*)()const)&AngleAxis::angle,
&AngleAxisVisitor::setAngle,"The rotation angle.")
/* --- Methods --- */
.def("inverse",&AngleAxis::inverse,
bp::arg("self"),
"Return the inverse rotation.")
.def("fromRotationMatrix",&AngleAxis::template fromRotationMatrix<Matrix3>,
(bp::arg("self"),bp::arg("rotation matrix")),
"Sets *this from a 3x3 rotation matrix",
bp::return_self<>())
.def("toRotationMatrix",
&AngleAxis::toRotationMatrix,
// bp::arg("self"),
"Constructs and returns an equivalent rotation matrix.")
.def("matrix",&AngleAxis::matrix,
bp::arg("self"),
"Returns an equivalent rotation matrix.")
.def("isApprox",
&call<AngleAxis>::isApprox,
isApproxAngleAxis_overload(bp::args("self","other","prec"),
"Returns true if *this is approximately equal to other, within the precision determined by prec."))
/* --- Operators --- */
.def(bp::self * bp::other<Vector3>())
.def(bp::self * bp::other<Quaternion>())
.def(bp::self * bp::self)
.def("__eq__",&AngleAxisVisitor::__eq__)
.def("__ne__",&AngleAxisVisitor::__ne__)
.def("__str__",&print)
.def("__repr__",&print)
;
}
private:
static void setAxis(AngleAxis & self, const Vector3 & axis)
{ self.axis() = axis; }
static void setAngle( AngleAxis & self, const Scalar & angle)
{ self.angle() = angle; }
static bool __eq__(const AngleAxis & u, const AngleAxis & v)
{ return u.axis() == v.axis() && v.angle() == u.angle(); }
static bool __ne__(const AngleAxis & u, const AngleAxis & v)
{ return !__eq__(u,v); }
static std::string print(const AngleAxis & self)
{
std::stringstream ss;
ss << "angle: " << self.angle() << std::endl;
ss << "axis: " << self.axis().transpose() << std::endl;
return ss.str();
}
public:
static void expose()
{
bp::class_<AngleAxis>("AngleAxis",
"AngleAxis representation of a rotation.\n\n",
bp::no_init)
.def(AngleAxisVisitor<AngleAxis>());
// Cast to Eigen::RotationBase
bp::implicitly_convertible<AngleAxis,RotationBase>();
}
};
} // namespace eigenpy
#endif //ifndef __eigenpy_angle_axis_hpp__
.def(bp::init<Matrix3>((bp::arg("self"), bp::arg("R")),
"Initialize from a rotation matrix"))
.def(bp::init<Quaternion>((bp::arg("self"), bp::arg("quaternion")),
"Initialize from a quaternion."))
.def(bp::init<AngleAxis>((bp::arg("self"), bp::arg("copy")),
"Copy constructor."))
/* --- Properties --- */
.add_property(
"axis",
bp::make_function((Vector3 & (AngleAxis::*)()) & AngleAxis::axis,
bp::return_internal_reference<>()),
&AngleAxisVisitor::setAxis, "The rotation axis.")
.add_property("angle",
(Scalar(AngleAxis::*)() const) & AngleAxis::angle,
&AngleAxisVisitor::setAngle, "The rotation angle.")
/* --- Methods --- */
.def("inverse", &AngleAxis::inverse, bp::arg("self"),
"Return the inverse rotation.")
.def("fromRotationMatrix",
&AngleAxis::template fromRotationMatrix<Matrix3>,
(bp::arg("self"), bp::arg("rotation matrix")),
"Sets *this from a 3x3 rotation matrix", bp::return_self<>())
.def("toRotationMatrix", &AngleAxis::toRotationMatrix,
// bp::arg("self"),
"Constructs and returns an equivalent rotation matrix.")
.def("matrix", &AngleAxis::matrix, bp::arg("self"),
"Returns an equivalent rotation matrix.")
.def("isApprox", &call<AngleAxis>::isApprox,
isApproxAngleAxis_overload(
bp::args("self", "other", "prec"),
"Returns true if *this is approximately equal to other, "
"within the precision determined by prec."))
/* --- Operators --- */
.def(bp::self * bp::other<Vector3>())
.def(bp::self * bp::other<Quaternion>())
.def(bp::self * bp::self)
.def("__eq__", &AngleAxisVisitor::__eq__)
.def("__ne__", &AngleAxisVisitor::__ne__)
.def("__str__", &print)
.def("__repr__", &print);
}
private:
static void setAxis(AngleAxis& self, const Vector3& axis) {
self.axis() = axis;
}
static void setAngle(AngleAxis& self, const Scalar& angle) {
self.angle() = angle;
}
static bool __eq__(const AngleAxis& u, const AngleAxis& v) {
return u.axis() == v.axis() && v.angle() == u.angle();
}
static bool __ne__(const AngleAxis& u, const AngleAxis& v) {
return !__eq__(u, v);
}
static std::string print(const AngleAxis& self) {
std::stringstream ss;
ss << "angle: " << self.angle() << std::endl;
ss << "axis: " << self.axis().transpose() << std::endl;
return ss.str();
}
public:
static void expose() {
bp::class_<AngleAxis>(
"AngleAxis", "AngleAxis representation of a rotation.\n\n", bp::no_init)
.def(AngleAxisVisitor<AngleAxis>());
// Cast to Eigen::RotationBase
bp::implicitly_convertible<AngleAxis, RotationBase>();
}
};
} // namespace eigenpy
#endif // ifndef __eigenpy_angle_axis_hpp__
......@@ -7,17 +7,14 @@
#include "eigenpy/fwd.hpp"
namespace eigenpy
{
inline void exposeComputationInfo()
{
boost::python::enum_<Eigen::ComputationInfo>("ComputationInfo")
.value("Success",Eigen::Success)
.value("NumericalIssue",Eigen::NumericalIssue)
.value("NoConvergence",Eigen::NoConvergence)
.value("InvalidInput",Eigen::InvalidInput)
;
}
} // namespace eigenpy
namespace eigenpy {
inline void exposeComputationInfo() {
boost::python::enum_<Eigen::ComputationInfo>("ComputationInfo")
.value("Success", Eigen::Success)
.value("NumericalIssue", Eigen::NumericalIssue)
.value("NoConvergence", Eigen::NoConvergence)
.value("InvalidInput", Eigen::InvalidInput);
}
} // namespace eigenpy
#endif // define __eigenpy_decompositions_computation_info_hpp__
#endif // define __eigenpy_decompositions_computation_info_hpp__
......@@ -5,94 +5,89 @@
#ifndef __eigenpy_decomposition_eigen_solver_hpp__
#define __eigenpy_decomposition_eigen_solver_hpp__
#include "eigenpy/eigenpy.hpp"
#include "eigenpy/eigen-to-python.hpp"
#include <Eigen/Core>
#include <Eigen/Eigenvalues>
#include "eigenpy/eigen-to-python.hpp"
#include "eigenpy/eigenpy.hpp"
#include "eigenpy/utils/scalar-name.hpp"
namespace eigenpy
{
template<typename _MatrixType>
struct EigenSolverVisitor
: public boost::python::def_visitor< EigenSolverVisitor<_MatrixType> >
{
typedef _MatrixType MatrixType;
typedef typename MatrixType::Scalar Scalar;
typedef Eigen::EigenSolver<MatrixType> Solver;
template<class PyClass>
void visit(PyClass& cl) const
{
namespace bp = boost::python;
cl
.def(bp::init<>("Default constructor"))
.def(bp::init<Eigen::DenseIndex>(bp::arg("size"),
"Default constructor with memory preallocation"))
.def(bp::init<MatrixType,bp::optional<bool> >(bp::args("matrix","compute_eigen_vectors"),
"Computes eigendecomposition of given matrix"))
.def("eigenvalues",&Solver::eigenvalues,bp::arg("self"),
"Returns the eigenvalues of given matrix.",
bp::return_internal_reference<>())
.def("eigenvectors",&Solver::eigenvectors,bp::arg("self"),
"Returns the eigenvectors of given matrix.")
.def("compute",&EigenSolverVisitor::compute_proxy<MatrixType>,
bp::args("self","matrix"),
"Computes the eigendecomposition of given matrix.",
bp::return_self<>())
.def("compute",(Solver & (Solver::*)(const Eigen::EigenBase<MatrixType> & matrix, bool))&Solver::compute,
bp::args("self","matrix","compute_eigen_vectors"),
"Computes the eigendecomposition of given matrix.",
bp::return_self<>())
.def("getMaxIterations",&Solver::getMaxIterations,bp::arg("self"),
"Returns the maximum number of iterations.")
.def("setMaxIterations",&Solver::setMaxIterations,bp::args("self","max_iter"),
"Sets the maximum number of iterations allowed.",
bp::return_self<>())
.def("pseudoEigenvalueMatrix",&Solver::pseudoEigenvalueMatrix,bp::arg("self"),
"Returns the block-diagonal matrix in the pseudo-eigendecomposition.")
.def("pseudoEigenvectors",&Solver::pseudoEigenvectors ,bp::arg("self"),
"Returns the pseudo-eigenvectors of given matrix.",
bp::return_internal_reference<>())
.def("info",&Solver::info,bp::arg("self"),
"NumericalIssue if the input contains INF or NaN values or overflow occured. Returns Success otherwise.")
;
}
static void expose()
{
static const std::string classname = "EigenSolver" + scalar_name<Scalar>::shortname();
expose(classname);
}
static void expose(const std::string & name)
{
namespace bp = boost::python;
bp::class_<Solver>(name.c_str(),
bp::no_init)
.def(EigenSolverVisitor());
}
private:
template<typename MatrixType>
static Solver & compute_proxy(Solver & self, const Eigen::EigenBase<MatrixType> & matrix)
{
return self.compute(matrix);
}
};
} // namespace eigenpy
#endif // ifndef __eigenpy_decomposition_eigen_solver_hpp__
namespace eigenpy {
template <typename _MatrixType>
struct EigenSolverVisitor
: public boost::python::def_visitor<EigenSolverVisitor<_MatrixType> > {
typedef _MatrixType MatrixType;
typedef typename MatrixType::Scalar Scalar;
typedef Eigen::EigenSolver<MatrixType> Solver;
template <class PyClass>
void visit(PyClass& cl) const {
namespace bp = boost::python;
cl.def(bp::init<>("Default constructor"))
.def(bp::init<Eigen::DenseIndex>(
bp::arg("size"), "Default constructor with memory preallocation"))
.def(bp::init<MatrixType, bp::optional<bool> >(
bp::args("matrix", "compute_eigen_vectors"),
"Computes eigendecomposition of given matrix"))
.def("eigenvalues", &Solver::eigenvalues, bp::arg("self"),
"Returns the eigenvalues of given matrix.",
bp::return_internal_reference<>())
.def("eigenvectors", &Solver::eigenvectors, bp::arg("self"),
"Returns the eigenvectors of given matrix.")
.def("compute", &EigenSolverVisitor::compute_proxy<MatrixType>,
bp::args("self", "matrix"),
"Computes the eigendecomposition of given matrix.",
bp::return_self<>())
.def("compute",
(Solver &
(Solver::*)(const Eigen::EigenBase<MatrixType>& matrix, bool)) &
Solver::compute,
bp::args("self", "matrix", "compute_eigen_vectors"),
"Computes the eigendecomposition of given matrix.",
bp::return_self<>())
.def("getMaxIterations", &Solver::getMaxIterations, bp::arg("self"),
"Returns the maximum number of iterations.")
.def("setMaxIterations", &Solver::setMaxIterations,
bp::args("self", "max_iter"),
"Sets the maximum number of iterations allowed.",
bp::return_self<>())
.def("pseudoEigenvalueMatrix", &Solver::pseudoEigenvalueMatrix,
bp::arg("self"),
"Returns the block-diagonal matrix in the "
"pseudo-eigendecomposition.")
.def("pseudoEigenvectors", &Solver::pseudoEigenvectors, bp::arg("self"),
"Returns the pseudo-eigenvectors of given matrix.",
bp::return_internal_reference<>())
.def("info", &Solver::info, bp::arg("self"),
"NumericalIssue if the input contains INF or NaN values or "
"overflow occured. Returns Success otherwise.");
}
static void expose() {
static const std::string classname =
"EigenSolver" + scalar_name<Scalar>::shortname();
expose(classname);
}
static void expose(const std::string& name) {
namespace bp = boost::python;
bp::class_<Solver>(name.c_str(), bp::no_init).def(EigenSolverVisitor());
}
private:
template <typename MatrixType>
static Solver& compute_proxy(Solver& self,
const Eigen::EigenBase<MatrixType>& matrix) {
return self.compute(matrix);
}
};
} // namespace eigenpy
#endif // ifndef __eigenpy_decomposition_eigen_solver_hpp__
......@@ -5,126 +5,137 @@
#ifndef __eigenpy_decomposition_ldlt_hpp__
#define __eigenpy_decomposition_ldlt_hpp__
#include "eigenpy/eigenpy.hpp"
#include <Eigen/Core>
#include <Eigen/Cholesky>
#include <Eigen/Core>
#include "eigenpy/eigenpy.hpp"
#include "eigenpy/utils/scalar-name.hpp"
namespace eigenpy
{
template<typename _MatrixType>
struct LDLTSolverVisitor
: public boost::python::def_visitor< LDLTSolverVisitor<_MatrixType> >
{
typedef _MatrixType MatrixType;
typedef typename MatrixType::Scalar Scalar;
typedef typename MatrixType::RealScalar RealScalar;
typedef Eigen::Matrix<Scalar,Eigen::Dynamic,1,MatrixType::Options> VectorXs;
typedef Eigen::Matrix<Scalar,Eigen::Dynamic,Eigen::Dynamic,MatrixType::Options> MatrixXs;
typedef Eigen::LDLT<MatrixType> Solver;
template<class PyClass>
void visit(PyClass& cl) const
{
namespace bp = boost::python;
cl
.def(bp::init<>("Default constructor"))
.def(bp::init<Eigen::DenseIndex>(bp::arg("size"),
"Default constructor with memory preallocation"))
.def(bp::init<MatrixType>(bp::arg("matrix"),
"Constructs a LDLT factorization from a given matrix."))
.def("isNegative",&Solver::isNegative,bp::arg("self"),
"Returns true if the matrix is negative (semidefinite).")
.def("isPositive",&Solver::isPositive,bp::arg("self"),
"Returns true if the matrix is positive (semidefinite).")
.def("matrixL",&matrixL,bp::arg("self"),
"Returns the lower triangular matrix L.")
.def("matrixU",&matrixU,bp::arg("self"),
"Returns the upper triangular matrix U.")
.def("vectorD",&vectorD,bp::arg("self"),
"Returns the coefficients of the diagonal matrix D.")
.def("transpositionsP",&transpositionsP,bp::arg("self"),
"Returns the permutation matrix P.")
.def("matrixLDLT",&Solver::matrixLDLT,bp::arg("self"),
"Returns the LDLT decomposition matrix.",
bp::return_internal_reference<>())
.def("rankUpdate",(Solver & (Solver::*)(const Eigen::MatrixBase<VectorXs> &, const RealScalar &))&Solver::template rankUpdate<VectorXs>,
bp::args("self","vector","sigma"),
bp::return_self<>())
#if EIGEN_VERSION_AT_LEAST(3,3,0)
.def("adjoint",&Solver::adjoint,bp::arg("self"),
"Returns the adjoint, that is, a reference to the decomposition itself as if the underlying matrix is self-adjoint.",
bp::return_self<>())
namespace eigenpy {
template <typename _MatrixType>
struct LDLTSolverVisitor
: public boost::python::def_visitor<LDLTSolverVisitor<_MatrixType> > {
typedef _MatrixType MatrixType;
typedef typename MatrixType::Scalar Scalar;
typedef typename MatrixType::RealScalar RealScalar;
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1, MatrixType::Options>
VectorXs;
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic,
MatrixType::Options>
MatrixXs;
typedef Eigen::LDLT<MatrixType> Solver;
template <class PyClass>
void visit(PyClass &cl) const {
namespace bp = boost::python;
cl.def(bp::init<>("Default constructor"))
.def(bp::init<Eigen::DenseIndex>(
bp::arg("size"), "Default constructor with memory preallocation"))
.def(bp::init<MatrixType>(
bp::arg("matrix"),
"Constructs a LDLT factorization from a given matrix."))
.def("isNegative", &Solver::isNegative, bp::arg("self"),
"Returns true if the matrix is negative (semidefinite).")
.def("isPositive", &Solver::isPositive, bp::arg("self"),
"Returns true if the matrix is positive (semidefinite).")
.def("matrixL", &matrixL, bp::arg("self"),
"Returns the lower triangular matrix L.")
.def("matrixU", &matrixU, bp::arg("self"),
"Returns the upper triangular matrix U.")
.def("vectorD", &vectorD, bp::arg("self"),
"Returns the coefficients of the diagonal matrix D.")
.def("transpositionsP", &transpositionsP, bp::arg("self"),
"Returns the permutation matrix P.")
.def("matrixLDLT", &Solver::matrixLDLT, bp::arg("self"),
"Returns the LDLT decomposition matrix.",
bp::return_internal_reference<>())
.def("rankUpdate",
(Solver & (Solver::*)(const Eigen::MatrixBase<VectorXs> &,
const RealScalar &)) &
Solver::template rankUpdate<VectorXs>,
bp::args("self", "vector", "sigma"), bp::return_self<>())
#if EIGEN_VERSION_AT_LEAST(3, 3, 0)
.def("adjoint", &Solver::adjoint, bp::arg("self"),
"Returns the adjoint, that is, a reference to the decomposition "
"itself as if the underlying matrix is self-adjoint.",
bp::return_self<>())
#endif
.def("compute",(Solver & (Solver::*)(const Eigen::EigenBase<MatrixType> & matrix))&Solver::compute,
bp::args("self","matrix"),
"Computes the LDLT of given matrix.",
bp::return_self<>())
.def("info",&Solver::info,bp::arg("self"),
"NumericalIssue if the input contains INF or NaN values or overflow occured. Returns Success otherwise.")
#if EIGEN_VERSION_AT_LEAST(3,3,0)
.def("rcond",&Solver::rcond,bp::arg("self"),
"Returns an estimate of the reciprocal condition number of the matrix.")
.def(
"compute",
(Solver & (Solver::*)(const Eigen::EigenBase<MatrixType> &matrix)) &
Solver::compute,
bp::args("self", "matrix"), "Computes the LDLT of given matrix.",
bp::return_self<>())
.def("info", &Solver::info, bp::arg("self"),
"NumericalIssue if the input contains INF or NaN values or "
"overflow occured. Returns Success otherwise.")
#if EIGEN_VERSION_AT_LEAST(3, 3, 0)
.def("rcond", &Solver::rcond, bp::arg("self"),
"Returns an estimate of the reciprocal condition number of the "
"matrix.")
#endif
.def("reconstructedMatrix",&Solver::reconstructedMatrix,bp::arg("self"),
"Returns the matrix represented by the decomposition, i.e., it returns the product: L L^*. This function is provided for debug purpose.")
.def("solve",&solve<VectorXs>,bp::args("self","b"),
"Returns the solution x of A x = b using the current decomposition of A.")
.def("solve",&solve<MatrixXs>,bp::args("self","B"),
"Returns the solution X of A X = B using the current decomposition of A where B is a right hand side matrix.")
.def("setZero",&Solver::setZero,bp::arg("self"),
"Clear any existing decomposition.")
;
}
static void expose()
{
static const std::string classname = "LDLT" + scalar_name<Scalar>::shortname();
expose(classname);
}
static void expose(const std::string & name)
{
namespace bp = boost::python;
bp::class_<Solver>(name.c_str(),
"Robust Cholesky decomposition of a matrix with pivoting.\n\n"
"Perform a robust Cholesky decomposition of a positive semidefinite or negative semidefinite matrix $ A $ such that $ A = P^TLDL^*P $, where P is a permutation matrix, L is lower triangular with a unit diagonal and D is a diagonal matrix.\n\n"
"The decomposition uses pivoting to ensure stability, so that L will have zeros in the bottom right rank(A) - n submatrix. Avoiding the square root on D also stabilizes the computation.",
bp::no_init)
.def(LDLTSolverVisitor());
}
private:
static MatrixType matrixL(const Solver & self) { return self.matrixL(); }
static MatrixType matrixU(const Solver & self) { return self.matrixU(); }
static VectorXs vectorD(const Solver & self) { return self.vectorD(); }
static MatrixType transpositionsP(const Solver & self)
{
return self.transpositionsP() * MatrixType::Identity(self.matrixL().rows(),
self.matrixL().rows());
}
template<typename MatrixOrVector>
static MatrixOrVector solve(const Solver & self, const MatrixOrVector & vec)
{
return self.solve(vec);
}
};
} // namespace eigenpy
#endif // ifndef __eigenpy_decomposition_ldlt_hpp__
.def("reconstructedMatrix", &Solver::reconstructedMatrix,
bp::arg("self"),
"Returns the matrix represented by the decomposition, i.e., it "
"returns the product: L L^*. This function is provided for debug "
"purpose.")
.def("solve", &solve<VectorXs>, bp::args("self", "b"),
"Returns the solution x of A x = b using the current "
"decomposition of A.")
.def("solve", &solve<MatrixXs>, bp::args("self", "B"),
"Returns the solution X of A X = B using the current "
"decomposition of A where B is a right hand side matrix.")
.def("setZero", &Solver::setZero, bp::arg("self"),
"Clear any existing decomposition.");
}
static void expose() {
static const std::string classname =
"LDLT" + scalar_name<Scalar>::shortname();
expose(classname);
}
static void expose(const std::string &name) {
namespace bp = boost::python;
bp::class_<Solver>(
name.c_str(),
"Robust Cholesky decomposition of a matrix with pivoting.\n\n"
"Perform a robust Cholesky decomposition of a positive semidefinite or "
"negative semidefinite matrix $ A $ such that $ A = P^TLDL^*P $, where "
"P is a permutation matrix, L is lower triangular with a unit diagonal "
"and D is a diagonal matrix.\n\n"
"The decomposition uses pivoting to ensure stability, so that L will "
"have zeros in the bottom right rank(A) - n submatrix. Avoiding the "
"square root on D also stabilizes the computation.",
bp::no_init)
.def(LDLTSolverVisitor());
}
private:
static MatrixType matrixL(const Solver &self) { return self.matrixL(); }
static MatrixType matrixU(const Solver &self) { return self.matrixU(); }
static VectorXs vectorD(const Solver &self) { return self.vectorD(); }
static MatrixType transpositionsP(const Solver &self) {
return self.transpositionsP() *
MatrixType::Identity(self.matrixL().rows(), self.matrixL().rows());
}
template <typename MatrixOrVector>
static MatrixOrVector solve(const Solver &self, const MatrixOrVector &vec) {
return self.solve(vec);
}
};
} // namespace eigenpy
#endif // ifndef __eigenpy_decomposition_ldlt_hpp__
......@@ -5,110 +5,127 @@
#ifndef __eigenpy_decomposition_llt_hpp__
#define __eigenpy_decomposition_llt_hpp__
#include "eigenpy/eigenpy.hpp"
#include <Eigen/Core>
#include <Eigen/Cholesky>
#include <Eigen/Core>
#include "eigenpy/eigenpy.hpp"
#include "eigenpy/utils/scalar-name.hpp"
namespace eigenpy
{
template<typename _MatrixType>
struct LLTSolverVisitor
: public boost::python::def_visitor< LLTSolverVisitor<_MatrixType> >
{
typedef _MatrixType MatrixType;
typedef typename MatrixType::Scalar Scalar;
typedef typename MatrixType::RealScalar RealScalar;
typedef Eigen::Matrix<Scalar,Eigen::Dynamic,1,MatrixType::Options> VectorXs;
typedef Eigen::Matrix<Scalar,Eigen::Dynamic,Eigen::Dynamic,MatrixType::Options> MatrixXs;
typedef Eigen::LLT<MatrixType> Solver;
template<class PyClass>
void visit(PyClass& cl) const
{
namespace bp = boost::python;
cl
.def(bp::init<>("Default constructor"))
.def(bp::init<Eigen::DenseIndex>(bp::arg("size"),
"Default constructor with memory preallocation"))
.def(bp::init<MatrixType>(bp::arg("matrix"),
"Constructs a LLT factorization from a given matrix."))
.def("matrixL",&matrixL,bp::arg("self"),
"Returns the lower triangular matrix L.")
.def("matrixU",&matrixU,bp::arg("self"),
"Returns the upper triangular matrix U.")
.def("matrixLLT",&Solver::matrixLLT,bp::arg("self"),
"Returns the LLT decomposition matrix.",
bp::return_internal_reference<>())
#if EIGEN_VERSION_AT_LEAST(3,3,90)
.def("rankUpdate",(Solver& (Solver::*)(const VectorXs &, const RealScalar &))&Solver::template rankUpdate<VectorXs>,
bp::args("self","vector","sigma"), bp::return_self<>())
namespace eigenpy {
template <typename _MatrixType>
struct LLTSolverVisitor
: public boost::python::def_visitor<LLTSolverVisitor<_MatrixType> > {
typedef _MatrixType MatrixType;
typedef typename MatrixType::Scalar Scalar;
typedef typename MatrixType::RealScalar RealScalar;
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1, MatrixType::Options>
VectorXs;
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic,
MatrixType::Options>
MatrixXs;
typedef Eigen::LLT<MatrixType> Solver;
template <class PyClass>
void visit(PyClass &cl) const {
namespace bp = boost::python;
cl.def(bp::init<>("Default constructor"))
.def(bp::init<Eigen::DenseIndex>(
bp::arg("size"), "Default constructor with memory preallocation"))
.def(bp::init<MatrixType>(
bp::arg("matrix"),
"Constructs a LLT factorization from a given matrix."))
.def("matrixL", &matrixL, bp::arg("self"),
"Returns the lower triangular matrix L.")
.def("matrixU", &matrixU, bp::arg("self"),
"Returns the upper triangular matrix U.")
.def("matrixLLT", &Solver::matrixLLT, bp::arg("self"),
"Returns the LLT decomposition matrix.",
bp::return_internal_reference<>())
#if EIGEN_VERSION_AT_LEAST(3, 3, 90)
.def("rankUpdate",
(Solver & (Solver::*)(const VectorXs &, const RealScalar &)) &
Solver::template rankUpdate<VectorXs>,
bp::args("self", "vector", "sigma"), bp::return_self<>())
#else
.def("rankUpdate",(Solver (Solver::*)(const VectorXs &, const RealScalar &))&Solver::template rankUpdate<VectorXs>,
bp::args("self","vector","sigma"))
.def("rankUpdate",
(Solver(Solver::*)(const VectorXs &, const RealScalar &)) &
Solver::template rankUpdate<VectorXs>,
bp::args("self", "vector", "sigma"))
#endif
#if EIGEN_VERSION_AT_LEAST(3,3,0)
.def("adjoint",&Solver::adjoint,bp::arg("self"),
"Returns the adjoint, that is, a reference to the decomposition itself as if the underlying matrix is self-adjoint.",
bp::return_self<>())
#if EIGEN_VERSION_AT_LEAST(3, 3, 0)
.def("adjoint", &Solver::adjoint, bp::arg("self"),
"Returns the adjoint, that is, a reference to the decomposition "
"itself as if the underlying matrix is self-adjoint.",
bp::return_self<>())
#endif
.def("compute",(Solver & (Solver::*)(const Eigen::EigenBase<MatrixType> & matrix))&Solver::compute,
bp::args("self","matrix"),
"Computes the LLT of given matrix.",
bp::return_self<>())
.def("info",&Solver::info,bp::arg("self"),
"NumericalIssue if the input contains INF or NaN values or overflow occured. Returns Success otherwise.")
#if EIGEN_VERSION_AT_LEAST(3,3,0)
.def("rcond",&Solver::rcond,bp::arg("self"),
"Returns an estimate of the reciprocal condition number of the matrix.")
.def(
"compute",
(Solver & (Solver::*)(const Eigen::EigenBase<MatrixType> &matrix)) &
Solver::compute,
bp::args("self", "matrix"), "Computes the LLT of given matrix.",
bp::return_self<>())
.def("info", &Solver::info, bp::arg("self"),
"NumericalIssue if the input contains INF or NaN values or "
"overflow occured. Returns Success otherwise.")
#if EIGEN_VERSION_AT_LEAST(3, 3, 0)
.def("rcond", &Solver::rcond, bp::arg("self"),
"Returns an estimate of the reciprocal condition number of the "
"matrix.")
#endif
.def("reconstructedMatrix",&Solver::reconstructedMatrix,bp::arg("self"),
"Returns the matrix represented by the decomposition, i.e., it returns the product: L L^*. This function is provided for debug purpose.")
.def("solve",&solve<VectorXs>,bp::args("self","b"),
"Returns the solution x of A x = b using the current decomposition of A.")
.def("solve",&solve<MatrixXs>,bp::args("self","B"),
"Returns the solution X of A X = B using the current decomposition of A where B is a right hand side matrix.")
;
}
static void expose()
{
static const std::string classname = "LLT" + scalar_name<Scalar>::shortname();
expose(classname);
}
static void expose(const std::string & name)
{
namespace bp = boost::python;
bp::class_<Solver>(name.c_str(),
"Standard Cholesky decomposition (LL^T) of a matrix and associated features.\n\n"
"This class performs a LL^T Cholesky decomposition of a symmetric, positive definite matrix A such that A = LL^* = U^*U, where L is lower triangular.\n\n"
"While the Cholesky decomposition is particularly useful to solve selfadjoint problems like D^*D x = b, for that purpose, we recommend the Cholesky decomposition without square root which is more stable and even faster. Nevertheless, this standard Cholesky decomposition remains useful in many other situations like generalised eigen problems with hermitian matrices.",
bp::no_init)
.def(LLTSolverVisitor());
}
private:
static MatrixType matrixL(const Solver & self) { return self.matrixL(); }
static MatrixType matrixU(const Solver & self) { return self.matrixU(); }
template<typename MatrixOrVector>
static MatrixOrVector solve(const Solver & self, const MatrixOrVector & vec)
{
return self.solve(vec);
}
};
} // namespace eigenpy
#endif // ifndef __eigenpy_decomposition_llt_hpp__
.def("reconstructedMatrix", &Solver::reconstructedMatrix,
bp::arg("self"),
"Returns the matrix represented by the decomposition, i.e., it "
"returns the product: L L^*. This function is provided for debug "
"purpose.")
.def("solve", &solve<VectorXs>, bp::args("self", "b"),
"Returns the solution x of A x = b using the current "
"decomposition of A.")
.def("solve", &solve<MatrixXs>, bp::args("self", "B"),
"Returns the solution X of A X = B using the current "
"decomposition of A where B is a right hand side matrix.");
}
static void expose() {
static const std::string classname =
"LLT" + scalar_name<Scalar>::shortname();
expose(classname);
}
static void expose(const std::string &name) {
namespace bp = boost::python;
bp::class_<Solver>(
name.c_str(),
"Standard Cholesky decomposition (LL^T) of a matrix and associated "
"features.\n\n"
"This class performs a LL^T Cholesky decomposition of a symmetric, "
"positive definite matrix A such that A = LL^* = U^*U, where L is "
"lower triangular.\n\n"
"While the Cholesky decomposition is particularly useful to solve "
"selfadjoint problems like D^*D x = b, for that purpose, we recommend "
"the Cholesky decomposition without square root which is more stable "
"and even faster. Nevertheless, this standard Cholesky decomposition "
"remains useful in many other situations like generalised eigen "
"problems with hermitian matrices.",
bp::no_init)
.def(LLTSolverVisitor());
}
private:
static MatrixType matrixL(const Solver &self) { return self.matrixL(); }
static MatrixType matrixU(const Solver &self) { return self.matrixU(); }
template <typename MatrixOrVector>
static MatrixOrVector solve(const Solver &self, const MatrixOrVector &vec) {
return self.solve(vec);
}
};
} // namespace eigenpy
#endif // ifndef __eigenpy_decomposition_llt_hpp__
......@@ -5,103 +5,101 @@
#ifndef __eigenpy_decomposition_self_adjoint_eigen_solver_hpp__
#define __eigenpy_decomposition_self_adjoint_eigen_solver_hpp__
#include "eigenpy/eigenpy.hpp"
#include "eigenpy/eigen-to-python.hpp"
#include <Eigen/Core>
#include <Eigen/Eigenvalues>
#include "eigenpy/eigen-to-python.hpp"
#include "eigenpy/eigenpy.hpp"
#include "eigenpy/utils/scalar-name.hpp"
namespace eigenpy
{
template<typename _MatrixType>
struct SelfAdjointEigenSolverVisitor
: public boost::python::def_visitor< SelfAdjointEigenSolverVisitor<_MatrixType> >
{
typedef _MatrixType MatrixType;
typedef typename MatrixType::Scalar Scalar;
typedef Eigen::SelfAdjointEigenSolver<MatrixType> Solver;
template<class PyClass>
void visit(PyClass& cl) const
{
namespace bp = boost::python;
cl
.def(bp::init<>("Default constructor"))
.def(bp::init<Eigen::DenseIndex>(bp::arg("size"),
"Default constructor with memory preallocation"))
.def(bp::init<MatrixType,bp::optional<int> >(bp::args("matrix","options"),
"Computes eigendecomposition of given matrix"))
.def("eigenvalues",&Solver::eigenvalues,bp::arg("self"),
"Returns the eigenvalues of given matrix.",
bp::return_internal_reference<>())
.def("eigenvectors",&Solver::eigenvectors,bp::arg("self"),
"Returns the eigenvectors of given matrix.",
bp::return_internal_reference<>())
.def("compute",&SelfAdjointEigenSolverVisitor::compute_proxy<MatrixType>,
bp::args("self","matrix"),
"Computes the eigendecomposition of given matrix.",
bp::return_value_policy<bp::reference_existing_object>())
.def("compute",(Solver & (Solver::*)(const Eigen::EigenBase<MatrixType> & matrix, int options))&Solver::compute,
bp::args("self","matrix","options"),
"Computes the eigendecomposition of given matrix.",
bp::return_self<>())
.def("computeDirect",&SelfAdjointEigenSolverVisitor::computeDirect_proxy,
bp::args("self","matrix"),
"Computes eigendecomposition of given matrix using a closed-form algorithm.",
bp::return_self<>())
.def("computeDirect",(Solver & (Solver::*)(const MatrixType & matrix, int options))&Solver::computeDirect,
bp::args("self","matrix","options"),
"Computes eigendecomposition of given matrix using a closed-form algorithm.",
bp::return_self<>())
.def("operatorInverseSqrt",&Solver::operatorInverseSqrt,bp::arg("self"),
"Computes the inverse square root of the matrix.")
.def("operatorSqrt",&Solver::operatorSqrt,bp::arg("self"),
"Computes the inverse square root of the matrix.")
.def("info",&Solver::info,bp::arg("self"),
"NumericalIssue if the input contains INF or NaN values or overflow occured. Returns Success otherwise.")
;
}
static void expose()
{
static const std::string classname = "SelfAdjointEigenSolver" + scalar_name<Scalar>::shortname();
expose(classname);
}
static void expose(const std::string & name)
{
namespace bp = boost::python;
bp::class_<Solver>(name.c_str(),
bp::no_init)
.def(SelfAdjointEigenSolverVisitor());
}
private:
template<typename MatrixType>
static Solver & compute_proxy(Solver & self, const Eigen::EigenBase<MatrixType> & matrix)
{
return self.compute(matrix);
}
static Solver & computeDirect_proxy(Solver & self, const MatrixType & matrix)
{
return self.computeDirect(matrix);
}
};
} // namespace eigenpy
#endif // ifndef __eigenpy_decomposition_self_adjoint_eigen_solver_hpp__
namespace eigenpy {
template <typename _MatrixType>
struct SelfAdjointEigenSolverVisitor
: public boost::python::def_visitor<
SelfAdjointEigenSolverVisitor<_MatrixType> > {
typedef _MatrixType MatrixType;
typedef typename MatrixType::Scalar Scalar;
typedef Eigen::SelfAdjointEigenSolver<MatrixType> Solver;
template <class PyClass>
void visit(PyClass& cl) const {
namespace bp = boost::python;
cl.def(bp::init<>("Default constructor"))
.def(bp::init<Eigen::DenseIndex>(
bp::arg("size"), "Default constructor with memory preallocation"))
.def(bp::init<MatrixType, bp::optional<int> >(
bp::args("matrix", "options"),
"Computes eigendecomposition of given matrix"))
.def("eigenvalues", &Solver::eigenvalues, bp::arg("self"),
"Returns the eigenvalues of given matrix.",
bp::return_internal_reference<>())
.def("eigenvectors", &Solver::eigenvectors, bp::arg("self"),
"Returns the eigenvectors of given matrix.",
bp::return_internal_reference<>())
.def("compute",
&SelfAdjointEigenSolverVisitor::compute_proxy<MatrixType>,
bp::args("self", "matrix"),
"Computes the eigendecomposition of given matrix.",
bp::return_value_policy<bp::reference_existing_object>())
.def("compute",
(Solver & (Solver::*)(const Eigen::EigenBase<MatrixType>& matrix,
int options)) &
Solver::compute,
bp::args("self", "matrix", "options"),
"Computes the eigendecomposition of given matrix.",
bp::return_self<>())
.def("computeDirect",
&SelfAdjointEigenSolverVisitor::computeDirect_proxy,
bp::args("self", "matrix"),
"Computes eigendecomposition of given matrix using a closed-form "
"algorithm.",
bp::return_self<>())
.def("computeDirect",
(Solver & (Solver::*)(const MatrixType& matrix, int options)) &
Solver::computeDirect,
bp::args("self", "matrix", "options"),
"Computes eigendecomposition of given matrix using a closed-form "
"algorithm.",
bp::return_self<>())
.def("operatorInverseSqrt", &Solver::operatorInverseSqrt,
bp::arg("self"), "Computes the inverse square root of the matrix.")
.def("operatorSqrt", &Solver::operatorSqrt, bp::arg("self"),
"Computes the inverse square root of the matrix.")
.def("info", &Solver::info, bp::arg("self"),
"NumericalIssue if the input contains INF or NaN values or "
"overflow occured. Returns Success otherwise.");
}
static void expose() {
static const std::string classname =
"SelfAdjointEigenSolver" + scalar_name<Scalar>::shortname();
expose(classname);
}
static void expose(const std::string& name) {
namespace bp = boost::python;
bp::class_<Solver>(name.c_str(), bp::no_init)
.def(SelfAdjointEigenSolverVisitor());
}
private:
template <typename MatrixType>
static Solver& compute_proxy(Solver& self,
const Eigen::EigenBase<MatrixType>& matrix) {
return self.compute(matrix);
}
static Solver& computeDirect_proxy(Solver& self, const MatrixType& matrix) {
return self.computeDirect(matrix);
}
};
} // namespace eigenpy
#endif // ifndef __eigenpy_decomposition_self_adjoint_eigen_solver_hpp__
......@@ -7,9 +7,8 @@
#include "eigenpy/config.hpp"
namespace eigenpy
{
void EIGENPY_DLLAPI exposeDecompositions();
} // namespace eigenpy
namespace eigenpy {
void EIGENPY_DLLAPI exposeDecompositions();
} // namespace eigenpy
#endif // define __eigenpy_decompositions_decompositions_hpp__
#endif // define __eigenpy_decompositions_decompositions_hpp__
......@@ -5,154 +5,179 @@
#ifndef __eigenpy_decomposition_minres_hpp__
#define __eigenpy_decomposition_minres_hpp__
#include "eigenpy/eigenpy.hpp"
#include <iostream>
#include <Eigen/Core>
#include <iostream>
#include <unsupported/Eigen/IterativeSolvers>
#include "eigenpy/eigenpy.hpp"
#include "eigenpy/utils/scalar-name.hpp"
namespace eigenpy
{
template<typename _Solver>
struct IterativeSolverBaseVisitor
: public boost::python::def_visitor< IterativeSolverBaseVisitor<_Solver> >
{
typedef _Solver Solver;
typedef typename Solver::MatrixType MatrixType;
typedef typename Solver::Preconditioner Preconditioner;
typedef typename Solver::Scalar Scalar;
typedef typename Solver::RealScalar RealScalar;
typedef Eigen::Matrix<Scalar,Eigen::Dynamic,Eigen::Dynamic,MatrixType::Options> MatrixXs;
template<class PyClass>
void visit(PyClass& cl) const
{
namespace bp = boost::python;
cl
.def("analyzePattern",
(Solver & (Solver::*)(const Eigen::EigenBase<MatrixType> & matrix))&Solver::analyzePattern,
bp::args("self","A"),
"Initializes the iterative solver for the sparsity pattern of the matrix A for further solving Ax=b problems.",
bp::return_self<>())
.def("factorize",
(Solver & (Solver::*)(const Eigen::EigenBase<MatrixType> & matrix))&Solver::factorize,
bp::args("self","A"),
"Initializes the iterative solver with the numerical values of the matrix A for further solving Ax=b problems.",
bp::return_self<>())
.def("compute",
(Solver & (Solver::*)(const Eigen::EigenBase<MatrixType> & matrix))&Solver::compute,
bp::args("self","A"),
"Initializes the iterative solver with the matrix A for further solving Ax=b problems.",
bp::return_self<>())
namespace eigenpy {
template <typename _Solver>
struct IterativeSolverBaseVisitor
: public boost::python::def_visitor<IterativeSolverBaseVisitor<_Solver> > {
typedef _Solver Solver;
typedef typename Solver::MatrixType MatrixType;
typedef typename Solver::Preconditioner Preconditioner;
typedef typename Solver::Scalar Scalar;
typedef typename Solver::RealScalar RealScalar;
.def("rows",&Solver::rows,bp::arg("self"),"Returns the number of rows.")
.def("cols",&Solver::cols,bp::arg("self"),"Returns the number of columns.")
.def("tolerance",&Solver::tolerance,bp::arg("self"),
"Returns the tolerance threshold used by the stopping criteria.")
.def("setTolerance",&Solver::setTolerance,bp::args("self","tolerance"),
"Sets the tolerance threshold used by the stopping criteria.\n"
"This value is used as an upper bound to the relative residual error: |Ax-b|/|b|.\n"
"The default value is the machine precision given by NumTraits<Scalar>::epsilon().",
bp::return_self<>())
.def("preconditioner",(Preconditioner & (Solver::*)())&Solver::preconditioner,bp::arg("self"),
"Returns a read-write reference to the preconditioner for custom configuration.",
bp::return_internal_reference<>())
.def("maxIterations",&Solver::maxIterations,bp::arg("self"),
"Returns the max number of iterations.\n"
"It is either the value setted by setMaxIterations or, by default, twice the number of columns of the matrix.")
.def("setMaxIterations",&Solver::setMaxIterations,bp::args("self","max_iterations"),
"Sets the max number of iterations.\n"
"Default is twice the number of columns of the matrix.",
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic,
MatrixType::Options>
MatrixXs;
template <class PyClass>
void visit(PyClass& cl) const {
namespace bp = boost::python;
cl.def("analyzePattern",
(Solver & (Solver::*)(const Eigen::EigenBase<MatrixType>& matrix)) &
Solver::analyzePattern,
bp::args("self", "A"),
"Initializes the iterative solver for the sparsity pattern of the "
"matrix A for further solving Ax=b problems.",
bp::return_self<>())
.def("iterations",&Solver::iterations,bp::arg("self"),
"Returns the number of iterations performed during the last solve.")
.def("error",&Solver::error,bp::arg("self"),
"Returns the tolerance error reached during the last solve.\n"
"It is a close approximation of the true relative residual error |Ax-b|/|b|.")
.def("info",&Solver::error,bp::arg("info"),
"Returns Success if the iterations converged, and NoConvergence otherwise.")
.def("solveWithGuess",&solveWithGuess<MatrixXs,MatrixXs>,bp::args("self","b","x0"),
"Returns the solution x of A x = b using the current decomposition of A and x0 as an initial solution.")
.def("solve",&solve<MatrixXs>,bp::args("self","b"),
"Returns the solution x of A x = b using the current decomposition of A where b is a right hand side matrix or vector.")
;
}
private:
template<typename MatrixOrVector1, typename MatrixOrVector2>
static MatrixOrVector1 solveWithGuess(const Solver & self, const MatrixOrVector1 & b, const MatrixOrVector2 & guess)
{
return self.solveWithGuess(b,guess);
}
template<typename MatrixOrVector>
static MatrixOrVector solve(const Solver & self, const MatrixOrVector & mat_or_vec)
{
MatrixOrVector res = self.solve(mat_or_vec);
return res;
}
};
template<typename _MatrixType>
struct MINRESSolverVisitor
: public boost::python::def_visitor< MINRESSolverVisitor<_MatrixType> >
{
typedef _MatrixType MatrixType;
typedef typename MatrixType::Scalar Scalar;
typedef typename MatrixType::RealScalar RealScalar;
typedef Eigen::Matrix<Scalar,Eigen::Dynamic,1,MatrixType::Options> VectorXs;
typedef Eigen::Matrix<Scalar,Eigen::Dynamic,Eigen::Dynamic,MatrixType::Options> MatrixXs;
typedef Eigen::MINRES<MatrixType> Solver;
template<class PyClass>
void visit(PyClass& cl) const
{
namespace bp = boost::python;
cl
.def(bp::init<>("Default constructor"))
.def(bp::init<MatrixType>(bp::arg("matrix"),
"Initialize the solver with matrix A for further Ax=b solving.\n"
"This constructor is a shortcut for the default constructor followed by a call to compute()."))
.def(IterativeSolverBaseVisitor<Solver>())
;
}
static void expose()
{
static const std::string classname = "MINRES" + scalar_name<Scalar>::shortname();
expose(classname);
}
static void expose(const std::string & name)
{
namespace bp = boost::python;
bp::class_<Solver, boost::noncopyable>(name.c_str(),
"A minimal residual solver for sparse symmetric problems.\n"
"This class allows to solve for A.x = b sparse linear problems using the MINRES algorithm of Paige and Saunders (1975). The sparse matrix A must be symmetric (possibly indefinite). The vectors x and b can be either dense or sparse.\n"
"The maximal number of iterations and tolerance value can be controlled via the setMaxIterations() and setTolerance() methods. The defaults are the size of the problem for the maximal number of iterations and NumTraits<Scalar>::epsilon() for the tolerance.\n",
bp::no_init)
.def(MINRESSolverVisitor());
}
private:
template<typename MatrixOrVector>
static MatrixOrVector solve(const Solver & self, const MatrixOrVector & vec)
{
return self.solve(vec);
}
};
} // namespace eigenpy
#endif // ifndef __eigenpy_decomposition_minres_hpp__
.def(
"factorize",
(Solver & (Solver::*)(const Eigen::EigenBase<MatrixType>& matrix)) &
Solver::factorize,
bp::args("self", "A"),
"Initializes the iterative solver with the numerical values of the "
"matrix A for further solving Ax=b problems.",
bp::return_self<>())
.def(
"compute",
(Solver & (Solver::*)(const Eigen::EigenBase<MatrixType>& matrix)) &
Solver::compute,
bp::args("self", "A"),
"Initializes the iterative solver with the matrix A for further "
"solving Ax=b problems.",
bp::return_self<>())
.def("rows", &Solver::rows, bp::arg("self"),
"Returns the number of rows.")
.def("cols", &Solver::cols, bp::arg("self"),
"Returns the number of columns.")
.def("tolerance", &Solver::tolerance, bp::arg("self"),
"Returns the tolerance threshold used by the stopping criteria.")
.def("setTolerance", &Solver::setTolerance,
bp::args("self", "tolerance"),
"Sets the tolerance threshold used by the stopping criteria.\n"
"This value is used as an upper bound to the relative residual "
"error: |Ax-b|/|b|.\n"
"The default value is the machine precision given by "
"NumTraits<Scalar>::epsilon().",
bp::return_self<>())
.def("preconditioner",
(Preconditioner & (Solver::*)()) & Solver::preconditioner,
bp::arg("self"),
"Returns a read-write reference to the preconditioner for custom "
"configuration.",
bp::return_internal_reference<>())
.def("maxIterations", &Solver::maxIterations, bp::arg("self"),
"Returns the max number of iterations.\n"
"It is either the value setted by setMaxIterations or, by "
"default, twice the number of columns of the matrix.")
.def("setMaxIterations", &Solver::setMaxIterations,
bp::args("self", "max_iterations"),
"Sets the max number of iterations.\n"
"Default is twice the number of columns of the matrix.",
bp::return_self<>())
.def(
"iterations", &Solver::iterations, bp::arg("self"),
"Returns the number of iterations performed during the last solve.")
.def("error", &Solver::error, bp::arg("self"),
"Returns the tolerance error reached during the last solve.\n"
"It is a close approximation of the true relative residual error "
"|Ax-b|/|b|.")
.def("info", &Solver::error, bp::arg("info"),
"Returns Success if the iterations converged, and NoConvergence "
"otherwise.")
.def("solveWithGuess", &solveWithGuess<MatrixXs, MatrixXs>,
bp::args("self", "b", "x0"),
"Returns the solution x of A x = b using the current "
"decomposition of A and x0 as an initial solution.")
.def(
"solve", &solve<MatrixXs>, bp::args("self", "b"),
"Returns the solution x of A x = b using the current decomposition "
"of A where b is a right hand side matrix or vector.");
}
private:
template <typename MatrixOrVector1, typename MatrixOrVector2>
static MatrixOrVector1 solveWithGuess(const Solver& self,
const MatrixOrVector1& b,
const MatrixOrVector2& guess) {
return self.solveWithGuess(b, guess);
}
template <typename MatrixOrVector>
static MatrixOrVector solve(const Solver& self,
const MatrixOrVector& mat_or_vec) {
MatrixOrVector res = self.solve(mat_or_vec);
return res;
}
};
template <typename _MatrixType>
struct MINRESSolverVisitor
: public boost::python::def_visitor<MINRESSolverVisitor<_MatrixType> > {
typedef _MatrixType MatrixType;
typedef typename MatrixType::Scalar Scalar;
typedef typename MatrixType::RealScalar RealScalar;
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1, MatrixType::Options>
VectorXs;
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic,
MatrixType::Options>
MatrixXs;
typedef Eigen::MINRES<MatrixType> Solver;
template <class PyClass>
void visit(PyClass& cl) const {
namespace bp = boost::python;
cl.def(bp::init<>("Default constructor"))
.def(bp::init<MatrixType>(
bp::arg("matrix"),
"Initialize the solver with matrix A for further Ax=b solving.\n"
"This constructor is a shortcut for the default constructor "
"followed by a call to compute()."))
.def(IterativeSolverBaseVisitor<Solver>());
}
static void expose() {
static const std::string classname =
"MINRES" + scalar_name<Scalar>::shortname();
expose(classname);
}
static void expose(const std::string& name) {
namespace bp = boost::python;
bp::class_<Solver, boost::noncopyable>(
name.c_str(),
"A minimal residual solver for sparse symmetric problems.\n"
"This class allows to solve for A.x = b sparse linear problems using "
"the MINRES algorithm of Paige and Saunders (1975). The sparse matrix "
"A must be symmetric (possibly indefinite). The vectors x and b can be "
"either dense or sparse.\n"
"The maximal number of iterations and tolerance value can be "
"controlled via the setMaxIterations() and setTolerance() methods. The "
"defaults are the size of the problem for the maximal number of "
"iterations and NumTraits<Scalar>::epsilon() for the tolerance.\n",
bp::no_init)
.def(MINRESSolverVisitor());
}
private:
template <typename MatrixOrVector>
static MatrixOrVector solve(const Solver& self, const MatrixOrVector& vec) {
return self.solve(vec);
}
};
} // namespace eigenpy
#endif // ifndef __eigenpy_decomposition_minres_hpp__
......@@ -6,89 +6,74 @@
#ifndef __eigenpy_details_hpp__
#define __eigenpy_details_hpp__
#include "eigenpy/fwd.hpp"
#include "eigenpy/eigenpy.hpp"
#include "eigenpy/numpy-type.hpp"
#include "eigenpy/scalar-conversion.hpp"
#include "eigenpy/eigen-allocator.hpp"
#include "eigenpy/eigen-to-python.hpp"
#include "eigenpy/eigen-from-python.hpp"
#include "eigenpy/registration.hpp"
#include "eigenpy/eigen-to-python.hpp"
#include "eigenpy/eigenpy.hpp"
#include "eigenpy/exception.hpp"
#include "eigenpy/fwd.hpp"
#include "eigenpy/numpy-type.hpp"
#include "eigenpy/registration.hpp"
#include "eigenpy/scalar-conversion.hpp"
namespace boost { namespace python { namespace detail {
template<class MatType>
struct referent_size<Eigen::MatrixBase<MatType>&>
{
BOOST_STATIC_CONSTANT(
std::size_t, value = sizeof(MatType));
};
template<class MatType>
struct referent_size<Eigen::MatrixBase<MatType> >
{
BOOST_STATIC_CONSTANT(
std::size_t, value = sizeof(MatType));
};
template<class MatType>
struct referent_size<Eigen::EigenBase<MatType>&>
{
BOOST_STATIC_CONSTANT(
std::size_t, value = sizeof(MatType));
};
template<class MatType>
struct referent_size<Eigen::EigenBase<MatType> >
{
BOOST_STATIC_CONSTANT(
std::size_t, value = sizeof(MatType));
};
template<class MatType>
struct referent_size<Eigen::PlainObjectBase<MatType>&>
{
BOOST_STATIC_CONSTANT(
std::size_t, value = sizeof(MatType));
};
template<class MatType>
struct referent_size<Eigen::PlainObjectBase<MatType> >
{
BOOST_STATIC_CONSTANT(
std::size_t, value = sizeof(MatType));
};
}}}
namespace eigenpy
{
template<typename MatType,typename EigenEquivalentType>
EIGENPY_DEPRECATED
void enableEigenPySpecific()
{
enableEigenPySpecific<MatType>();
}
template<typename MatType>
void enableEigenPySpecific()
{
if(check_registration<MatType>()) return;
// to-python
EigenToPyConverter<MatType>::registration();
#if EIGEN_VERSION_AT_LEAST(3,2,0)
EigenToPyConverter< Eigen::Ref<MatType> >::registration();
namespace boost {
namespace python {
namespace detail {
template <class MatType>
struct referent_size<Eigen::MatrixBase<MatType>&> {
BOOST_STATIC_CONSTANT(std::size_t, value = sizeof(MatType));
};
template <class MatType>
struct referent_size<Eigen::MatrixBase<MatType> > {
BOOST_STATIC_CONSTANT(std::size_t, value = sizeof(MatType));
};
template <class MatType>
struct referent_size<Eigen::EigenBase<MatType>&> {
BOOST_STATIC_CONSTANT(std::size_t, value = sizeof(MatType));
};
template <class MatType>
struct referent_size<Eigen::EigenBase<MatType> > {
BOOST_STATIC_CONSTANT(std::size_t, value = sizeof(MatType));
};
template <class MatType>
struct referent_size<Eigen::PlainObjectBase<MatType>&> {
BOOST_STATIC_CONSTANT(std::size_t, value = sizeof(MatType));
};
template <class MatType>
struct referent_size<Eigen::PlainObjectBase<MatType> > {
BOOST_STATIC_CONSTANT(std::size_t, value = sizeof(MatType));
};
} // namespace detail
} // namespace python
} // namespace boost
namespace eigenpy {
template <typename MatType, typename EigenEquivalentType>
EIGENPY_DEPRECATED void enableEigenPySpecific() {
enableEigenPySpecific<MatType>();
}
template <typename MatType>
void enableEigenPySpecific() {
if (check_registration<MatType>()) return;
// to-python
EigenToPyConverter<MatType>::registration();
#if EIGEN_VERSION_AT_LEAST(3, 2, 0)
EigenToPyConverter<Eigen::Ref<MatType> >::registration();
#endif
// from-python
EigenFromPyConverter<MatType>::registration();
}
} // namespace eigenpy
// from-python
EigenFromPyConverter<MatType>::registration();
}
} // namespace eigenpy
#endif // ifndef __eigenpy_details_hpp__
#endif // ifndef __eigenpy_details_hpp__
This diff is collapsed.
This diff is collapsed.
......@@ -5,131 +5,134 @@
#ifndef __eigenpy_eigen_to_python_hpp__
#define __eigenpy_eigen_to_python_hpp__
#include "eigenpy/fwd.hpp"
#include "eigenpy/numpy-type.hpp"
#include <boost/type_traits.hpp>
#include "eigenpy/eigen-allocator.hpp"
#include "eigenpy/fwd.hpp"
#include "eigenpy/numpy-allocator.hpp"
#include "eigenpy/numpy-type.hpp"
#include <boost/type_traits.hpp>
namespace boost {
namespace python {
namespace boost { namespace python {
template <typename MatrixRef, class MakeHolder>
struct to_python_indirect_eigen {
template <class U>
inline PyObject* operator()(U const& mat) const {
return eigenpy::EigenToPy<MatrixRef>::convert(const_cast<U&>(mat));
}
template<typename MatrixRef, class MakeHolder>
struct to_python_indirect_eigen
{
template <class U>
inline PyObject* operator()(U const& mat) const
{
return eigenpy::EigenToPy<MatrixRef>::convert(const_cast<U&>(mat));
}
#ifndef BOOST_PYTHON_NO_PY_SIGNATURES
inline PyTypeObject const*
get_pytype() const
{
return converter::registered_pytype<MatrixRef>::get_pytype();
}
inline PyTypeObject const* get_pytype() const {
return converter::registered_pytype<MatrixRef>::get_pytype();
}
#endif
};
template <typename Scalar, int RowsAtCompileTime, int ColsAtCompileTime, int Options, int MaxRowsAtCompileTime, int MaxColsAtCompileTime, class MakeHolder>
struct to_python_indirect<Eigen::Matrix<Scalar,RowsAtCompileTime,ColsAtCompileTime,Options,MaxRowsAtCompileTime,MaxColsAtCompileTime>&,MakeHolder>
: to_python_indirect_eigen<Eigen::Matrix<Scalar,RowsAtCompileTime,ColsAtCompileTime,Options,MaxRowsAtCompileTime,MaxColsAtCompileTime>&,MakeHolder>
{
};
template <typename Scalar, int RowsAtCompileTime, int ColsAtCompileTime, int Options, int MaxRowsAtCompileTime, int MaxColsAtCompileTime, class MakeHolder>
struct to_python_indirect<const Eigen::Matrix<Scalar,RowsAtCompileTime,ColsAtCompileTime,Options,MaxRowsAtCompileTime,MaxColsAtCompileTime>&,MakeHolder>
: to_python_indirect_eigen<const Eigen::Matrix<Scalar,RowsAtCompileTime,ColsAtCompileTime,Options,MaxRowsAtCompileTime,MaxColsAtCompileTime>&,MakeHolder>
{
};
}}
namespace eigenpy
{
namespace bp = boost::python;
template<typename MatType, typename _Scalar>
struct EigenToPy
{
static PyObject* convert(typename boost::add_reference<typename boost::add_const<MatType>::type>::type mat)
{
typedef typename boost::remove_const<typename boost::remove_reference<MatType>::type>::type MatrixDerived;
assert( (mat.rows()<INT_MAX) && (mat.cols()<INT_MAX)
&& "Matrix range larger than int ... should never happen." );
const npy_intp R = (npy_intp)mat.rows(), C = (npy_intp)mat.cols();
PyArrayObject* pyArray;
// Allocate Python memory
if( ( ((!(C == 1) != !(R == 1)) && !MatrixDerived::IsVectorAtCompileTime) || MatrixDerived::IsVectorAtCompileTime)
&& NumpyType::getType() == ARRAY_TYPE) // Handle array with a single dimension
{
npy_intp shape[1] = { C == 1 ? R : C };
pyArray = NumpyAllocator<MatType>::allocate(const_cast<MatrixDerived &>(mat.derived()),
1,shape);
}
else
{
npy_intp shape[2] = { R,C };
pyArray = NumpyAllocator<MatType>::allocate(const_cast<MatrixDerived &>(mat.derived()),
2,shape);
}
// Create an instance (either np.array or np.matrix)
return NumpyType::make(pyArray).ptr();
}
static PyTypeObject const *get_pytype()
{
return getPyArrayType();
}
};
};
template<typename MatType, int Options, typename Stride, typename _Scalar>
struct EigenToPy< Eigen::Ref<MatType,Options,Stride>,_Scalar >
{
static PyObject* convert(const Eigen::Ref<MatType,Options,Stride> & mat)
{
typedef Eigen::Ref<MatType,Options,Stride> EigenRef;
assert( (mat.rows()<INT_MAX) && (mat.cols()<INT_MAX)
&& "Matrix range larger than int ... should never happen." );
const npy_intp R = (npy_intp)mat.rows(), C = (npy_intp)mat.cols();
PyArrayObject* pyArray;
// Allocate Python memory
if( ( ((!(C == 1) != !(R == 1)) && !MatType::IsVectorAtCompileTime) || MatType::IsVectorAtCompileTime)
&& NumpyType::getType() == ARRAY_TYPE) // Handle array with a single dimension
{
npy_intp shape[1] = { C == 1 ? R : C };
pyArray = NumpyAllocator<EigenRef>::allocate(const_cast<EigenRef &>(mat),1,shape);
}
else
{
npy_intp shape[2] = { R,C };
pyArray = NumpyAllocator<EigenRef>::allocate(const_cast<EigenRef &>(mat),2,shape);
}
// Create an instance (either np.array or np.matrix)
return NumpyType::make(pyArray).ptr();
}
static PyTypeObject const *get_pytype()
template <typename Scalar, int RowsAtCompileTime, int ColsAtCompileTime,
int Options, int MaxRowsAtCompileTime, int MaxColsAtCompileTime,
class MakeHolder>
struct to_python_indirect<
Eigen::Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime, Options,
MaxRowsAtCompileTime, MaxColsAtCompileTime>&,
MakeHolder>
: to_python_indirect_eigen<
Eigen::Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime, Options,
MaxRowsAtCompileTime, MaxColsAtCompileTime>&,
MakeHolder> {};
template <typename Scalar, int RowsAtCompileTime, int ColsAtCompileTime,
int Options, int MaxRowsAtCompileTime, int MaxColsAtCompileTime,
class MakeHolder>
struct to_python_indirect<
const Eigen::Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime, Options,
MaxRowsAtCompileTime, MaxColsAtCompileTime>&,
MakeHolder>
: to_python_indirect_eigen<
const Eigen::Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime,
Options, MaxRowsAtCompileTime,
MaxColsAtCompileTime>&,
MakeHolder> {};
} // namespace python
} // namespace boost
namespace eigenpy {
namespace bp = boost::python;
template <typename MatType, typename _Scalar>
struct EigenToPy {
static PyObject* convert(
typename boost::add_reference<
typename boost::add_const<MatType>::type>::type mat) {
typedef typename boost::remove_const<
typename boost::remove_reference<MatType>::type>::type MatrixDerived;
assert((mat.rows() < INT_MAX) && (mat.cols() < INT_MAX) &&
"Matrix range larger than int ... should never happen.");
const npy_intp R = (npy_intp)mat.rows(), C = (npy_intp)mat.cols();
PyArrayObject* pyArray;
// Allocate Python memory
if ((((!(C == 1) != !(R == 1)) && !MatrixDerived::IsVectorAtCompileTime) ||
MatrixDerived::IsVectorAtCompileTime) &&
NumpyType::getType() ==
ARRAY_TYPE) // Handle array with a single dimension
{
return getPyArrayType();
npy_intp shape[1] = {C == 1 ? R : C};
pyArray = NumpyAllocator<MatType>::allocate(
const_cast<MatrixDerived&>(mat.derived()), 1, shape);
} else {
npy_intp shape[2] = {R, C};
pyArray = NumpyAllocator<MatType>::allocate(
const_cast<MatrixDerived&>(mat.derived()), 2, shape);
}
};
template<typename MatType>
struct EigenToPyConverter
{
static void registration()
// Create an instance (either np.array or np.matrix)
return NumpyType::make(pyArray).ptr();
}
static PyTypeObject const* get_pytype() { return getPyArrayType(); }
};
template <typename MatType, int Options, typename Stride, typename _Scalar>
struct EigenToPy<Eigen::Ref<MatType, Options, Stride>, _Scalar> {
static PyObject* convert(const Eigen::Ref<MatType, Options, Stride>& mat) {
typedef Eigen::Ref<MatType, Options, Stride> EigenRef;
assert((mat.rows() < INT_MAX) && (mat.cols() < INT_MAX) &&
"Matrix range larger than int ... should never happen.");
const npy_intp R = (npy_intp)mat.rows(), C = (npy_intp)mat.cols();
PyArrayObject* pyArray;
// Allocate Python memory
if ((((!(C == 1) != !(R == 1)) && !MatType::IsVectorAtCompileTime) ||
MatType::IsVectorAtCompileTime) &&
NumpyType::getType() ==
ARRAY_TYPE) // Handle array with a single dimension
{
bp::to_python_converter<MatType,EigenToPy<MatType>, true>();
npy_intp shape[1] = {C == 1 ? R : C};
pyArray = NumpyAllocator<EigenRef>::allocate(const_cast<EigenRef&>(mat),
1, shape);
} else {
npy_intp shape[2] = {R, C};
pyArray = NumpyAllocator<EigenRef>::allocate(const_cast<EigenRef&>(mat),
2, shape);
}
};
}
#endif // __eigenpy_eigen_to_python_hpp__
// Create an instance (either np.array or np.matrix)
return NumpyType::make(pyArray).ptr();
}
static PyTypeObject const* get_pytype() { return getPyArrayType(); }
};
template <typename MatType>
struct EigenToPyConverter {
static void registration() {
bp::to_python_converter<MatType, EigenToPy<MatType>, true>();
}
};
} // namespace eigenpy
#endif // __eigenpy_eigen_to_python_hpp__
......@@ -7,27 +7,30 @@
#include "eigenpy/fwd.hpp"
#define EIGENPY_MAKE_TYPEDEFS(Type, Options, TypeSuffix, Size, SizeSuffix) \
/** \ingroup matrixtypedefs */ \
typedef Eigen::Matrix<Type, Size, Size, Options> Matrix##SizeSuffix##TypeSuffix; \
/** \ingroup matrixtypedefs */ \
typedef Eigen::Matrix<Type, Size, 1> Vector##SizeSuffix##TypeSuffix; \
/** \ingroup matrixtypedefs */ \
typedef Eigen::Matrix<Type, 1, Size> RowVector##SizeSuffix##TypeSuffix;
#define EIGENPY_MAKE_TYPEDEFS(Type, Options, TypeSuffix, Size, SizeSuffix) \
/** \ingroup matrixtypedefs */ \
typedef Eigen::Matrix<Type, Size, Size, Options> \
Matrix##SizeSuffix##TypeSuffix; \
/** \ingroup matrixtypedefs */ \
typedef Eigen::Matrix<Type, Size, 1> Vector##SizeSuffix##TypeSuffix; \
/** \ingroup matrixtypedefs */ \
typedef Eigen::Matrix<Type, 1, Size> RowVector##SizeSuffix##TypeSuffix;
#define EIGENPY_MAKE_FIXED_TYPEDEFS(Type, Options, TypeSuffix, Size) \
/** \ingroup matrixtypedefs */ \
typedef Eigen::Matrix<Type, Size, Eigen::Dynamic, Options> Matrix##Size##X##TypeSuffix; \
/** \ingroup matrixtypedefs */ \
typedef Eigen::Matrix<Type, Eigen::Dynamic, Size, Options> Matrix##X##Size##TypeSuffix;
#define EIGENPY_MAKE_FIXED_TYPEDEFS(Type, Options, TypeSuffix, Size) \
/** \ingroup matrixtypedefs */ \
typedef Eigen::Matrix<Type, Size, Eigen::Dynamic, Options> \
Matrix##Size##X##TypeSuffix; \
/** \ingroup matrixtypedefs */ \
typedef Eigen::Matrix<Type, Eigen::Dynamic, Size, Options> \
Matrix##X##Size##TypeSuffix;
#define EIGENPY_MAKE_TYPEDEFS_ALL_SIZES(Type, Options, TypeSuffix) \
EIGENPY_MAKE_TYPEDEFS(Type, Options, TypeSuffix, 2, 2) \
EIGENPY_MAKE_TYPEDEFS(Type, Options, TypeSuffix, 3, 3) \
EIGENPY_MAKE_TYPEDEFS(Type, Options, TypeSuffix, 4, 4) \
#define EIGENPY_MAKE_TYPEDEFS_ALL_SIZES(Type, Options, TypeSuffix) \
EIGENPY_MAKE_TYPEDEFS(Type, Options, TypeSuffix, 2, 2) \
EIGENPY_MAKE_TYPEDEFS(Type, Options, TypeSuffix, 3, 3) \
EIGENPY_MAKE_TYPEDEFS(Type, Options, TypeSuffix, 4, 4) \
EIGENPY_MAKE_TYPEDEFS(Type, Options, TypeSuffix, Eigen::Dynamic, X) \
EIGENPY_MAKE_FIXED_TYPEDEFS(Type, Options, TypeSuffix, 2) \
EIGENPY_MAKE_FIXED_TYPEDEFS(Type, Options, TypeSuffix, 3) \
EIGENPY_MAKE_FIXED_TYPEDEFS(Type, Options, TypeSuffix, 2) \
EIGENPY_MAKE_FIXED_TYPEDEFS(Type, Options, TypeSuffix, 3) \
EIGENPY_MAKE_FIXED_TYPEDEFS(Type, Options, TypeSuffix, 4)
#endif // ifndef __eigenpy_eigen_typedef_hpp__
#endif // ifndef __eigenpy_eigen_typedef_hpp__
......@@ -6,67 +6,65 @@
#ifndef __eigenpy_eigenpy_hpp__
#define __eigenpy_eigenpy_hpp__
#include "eigenpy/fwd.hpp"
#include "eigenpy/deprecated.hpp"
#include "eigenpy/eigen-typedef.hpp"
#include "eigenpy/fwd.hpp"
#define ENABLE_SPECIFIC_MATRIX_TYPE(TYPE) \
::eigenpy::enableEigenPySpecific<TYPE>();
namespace eigenpy
{
/* Enable Eigen-Numpy serialization for a set of standard MatrixBase instance. */
void EIGENPY_DLLAPI enableEigenPy();
/* Enable the Eigen--Numpy serialization for the templated MatrixBase class.
* The second template argument is used for inheritance of Eigen classes. If
* using a native Eigen::MatrixBase, simply repeat the same arg twice. */
template<typename MatType>
void enableEigenPySpecific();
/* Enable the Eigen--Numpy serialization for the templated MatrixBase class.
* The second template argument is used for inheritance of Eigen classes. If
* using a native Eigen::MatrixBase, simply repeat the same arg twice. */
template<typename MatType,typename EigenEquivalentType>
EIGENPY_DEPRECATED void enableEigenPySpecific();
template<typename Scalar, int Options>
EIGEN_DONT_INLINE void exposeType()
{
EIGENPY_MAKE_TYPEDEFS_ALL_SIZES(Scalar,Options,s);
ENABLE_SPECIFIC_MATRIX_TYPE(Vector2s);
ENABLE_SPECIFIC_MATRIX_TYPE(RowVector2s);
ENABLE_SPECIFIC_MATRIX_TYPE(Matrix2s);
ENABLE_SPECIFIC_MATRIX_TYPE(Matrix2Xs);
ENABLE_SPECIFIC_MATRIX_TYPE(MatrixX2s);
ENABLE_SPECIFIC_MATRIX_TYPE(Vector3s);
ENABLE_SPECIFIC_MATRIX_TYPE(RowVector3s);
ENABLE_SPECIFIC_MATRIX_TYPE(Matrix3s);
ENABLE_SPECIFIC_MATRIX_TYPE(Matrix3Xs);
ENABLE_SPECIFIC_MATRIX_TYPE(MatrixX3s);
ENABLE_SPECIFIC_MATRIX_TYPE(Vector4s);
ENABLE_SPECIFIC_MATRIX_TYPE(RowVector4s);
ENABLE_SPECIFIC_MATRIX_TYPE(Matrix4s);
ENABLE_SPECIFIC_MATRIX_TYPE(Matrix4Xs);
ENABLE_SPECIFIC_MATRIX_TYPE(MatrixX4s);
ENABLE_SPECIFIC_MATRIX_TYPE(VectorXs);
ENABLE_SPECIFIC_MATRIX_TYPE(RowVectorXs);
ENABLE_SPECIFIC_MATRIX_TYPE(MatrixXs);
}
template<typename Scalar>
EIGEN_DONT_INLINE void exposeType()
{
exposeType<Scalar,0>();
}
} // namespace eigenpy
namespace eigenpy {
/* Enable Eigen-Numpy serialization for a set of standard MatrixBase instance.
*/
void EIGENPY_DLLAPI enableEigenPy();
/* Enable the Eigen--Numpy serialization for the templated MatrixBase class.
* The second template argument is used for inheritance of Eigen classes. If
* using a native Eigen::MatrixBase, simply repeat the same arg twice. */
template <typename MatType>
void enableEigenPySpecific();
/* Enable the Eigen--Numpy serialization for the templated MatrixBase class.
* The second template argument is used for inheritance of Eigen classes. If
* using a native Eigen::MatrixBase, simply repeat the same arg twice. */
template <typename MatType, typename EigenEquivalentType>
EIGENPY_DEPRECATED void enableEigenPySpecific();
template <typename Scalar, int Options>
EIGEN_DONT_INLINE void exposeType() {
EIGENPY_MAKE_TYPEDEFS_ALL_SIZES(Scalar, Options, s);
ENABLE_SPECIFIC_MATRIX_TYPE(Vector2s);
ENABLE_SPECIFIC_MATRIX_TYPE(RowVector2s);
ENABLE_SPECIFIC_MATRIX_TYPE(Matrix2s);
ENABLE_SPECIFIC_MATRIX_TYPE(Matrix2Xs);
ENABLE_SPECIFIC_MATRIX_TYPE(MatrixX2s);
ENABLE_SPECIFIC_MATRIX_TYPE(Vector3s);
ENABLE_SPECIFIC_MATRIX_TYPE(RowVector3s);
ENABLE_SPECIFIC_MATRIX_TYPE(Matrix3s);
ENABLE_SPECIFIC_MATRIX_TYPE(Matrix3Xs);
ENABLE_SPECIFIC_MATRIX_TYPE(MatrixX3s);
ENABLE_SPECIFIC_MATRIX_TYPE(Vector4s);
ENABLE_SPECIFIC_MATRIX_TYPE(RowVector4s);
ENABLE_SPECIFIC_MATRIX_TYPE(Matrix4s);
ENABLE_SPECIFIC_MATRIX_TYPE(Matrix4Xs);
ENABLE_SPECIFIC_MATRIX_TYPE(MatrixX4s);
ENABLE_SPECIFIC_MATRIX_TYPE(VectorXs);
ENABLE_SPECIFIC_MATRIX_TYPE(RowVectorXs);
ENABLE_SPECIFIC_MATRIX_TYPE(MatrixXs);
}
template <typename Scalar>
EIGEN_DONT_INLINE void exposeType() {
exposeType<Scalar, 0>();
}
} // namespace eigenpy
#include "eigenpy/details.hpp"
#endif // ifndef __eigenpy_eigenpy_hpp__
#endif // ifndef __eigenpy_eigenpy_hpp__
......@@ -11,34 +11,32 @@
#include "eigenpy/fwd.hpp"
namespace eigenpy
{
/*
* Eigenpy exception. They can be catch with python (equivalent eigenpy.exception class).
*/
class Exception : public std::exception
{
public:
Exception() : message() {}
Exception(const std::string & msg) : message(msg) {}
const char *what() const throw()
{
return this->getMessage().c_str();
}
~Exception() throw() {}
virtual const std::string & getMessage() const { return message; }
std::string copyMessage() const { return getMessage(); }
/* Call this static function to "enable" the translation of this C++ exception in Python. */
static void registerException();
private:
static void translateException( Exception const & e );
static PyObject * pyType;
protected:
std::string message;
};
} // namespace eigenpy
#endif // ifndef __eigenpy_exception_hpp__
namespace eigenpy {
/*
* Eigenpy exception. They can be catch with python (equivalent
* eigenpy.exception class).
*/
class Exception : public std::exception {
public:
Exception() : message() {}
Exception(const std::string &msg) : message(msg) {}
const char *what() const throw() { return this->getMessage().c_str(); }
~Exception() throw() {}
virtual const std::string &getMessage() const { return message; }
std::string copyMessage() const { return getMessage(); }
/* Call this static function to "enable" the translation of this C++ exception
* in Python. */
static void registerException();
private:
static void translateException(Exception const &e);
static PyObject *pyType;
protected:
std::string message;
};
} // namespace eigenpy
#endif // ifndef __eigenpy_exception_hpp__
......@@ -7,26 +7,22 @@
#include "eigenpy/registration.hpp"
namespace eigenpy
{
///
/// \brief Allows a template specialization.
///
template<typename T>
struct call
{
static inline void expose() { T::expose(); }
};
namespace eigenpy {
///
/// \brief Allows a template specialization.
///
template <typename T>
struct call {
static inline void expose() { T::expose(); }
};
///
/// \brief Call the expose function of a given type T.
///
template<typename T>
inline void expose()
{
if(!register_symbolic_link_to_registered_type<T>())
call<T>::expose();
}
///
/// \brief Call the expose function of a given type T.
///
template <typename T>
inline void expose() {
if (!register_symbolic_link_to_registered_type<T>()) call<T>::expose();
}
} // namespace eigenpy
#endif // ifndef __eigenpy_expose_hpp__
#endif // ifndef __eigenpy_expose_hpp__
......@@ -15,17 +15,17 @@
#include <boost/python/scope.hpp>
#define NO_IMPORT_ARRAY
#include "eigenpy/numpy.hpp"
#include "eigenpy/numpy.hpp"
#undef NO_IMPORT_ARRAY
#undef BOOST_BIND_GLOBAL_PLACEHOLDERS
#include <Eigen/Core>
#if EIGEN_VERSION_AT_LEAST(3,2,90)
#define EIGENPY_DEFAULT_ALIGNMENT_VALUE Eigen::Aligned16
#if EIGEN_VERSION_AT_LEAST(3, 2, 90)
#define EIGENPY_DEFAULT_ALIGNMENT_VALUE Eigen::Aligned16
#else
#define EIGENPY_DEFAULT_ALIGNMENT_VALUE Eigen::Aligned
#define EIGENPY_DEFAULT_ALIGNMENT_VALUE Eigen::Aligned
#endif
#define EIGENPY_NO_ALIGNMENT_VALUE Eigen::Unaligned
......@@ -34,10 +34,15 @@
#include "eigenpy/expose.hpp"
namespace eigenpy
{
template<typename MatType, typename Scalar = typename boost::remove_reference<MatType>::type::Scalar> struct EigenToPy;
template<typename MatType, typename Scalar = typename boost::remove_reference<MatType>::type::Scalar> struct EigenFromPy;
}
#endif // ifndef __eigenpy_fwd_hpp__
namespace eigenpy {
template <typename MatType,
typename Scalar =
typename boost::remove_reference<MatType>::type::Scalar>
struct EigenToPy;
template <typename MatType,
typename Scalar =
typename boost::remove_reference<MatType>::type::Scalar>
struct EigenFromPy;
} // namespace eigenpy
#endif // ifndef __eigenpy_fwd_hpp__
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment