17 #ifndef __eigenpy_basic_preconditioners_hpp__ 18 #define __eigenpy_basic_preconditioners_hpp__ 20 #include <Eigen/IterativeLinearSolvers> 26 template <
typename Preconditioner>
28 :
public bp::def_visitor<PreconditionerBaseVisitor<Preconditioner> > {
32 template <
class PyClass>
34 cl.def(bp::init<>(
"Default constructor"))
35 .def(bp::init<MatrixType>(bp::args(
"self",
"A"),
36 "Initialize the preconditioner with matrix A " 37 "for further Az=b solving."))
38 #if EIGEN_VERSION_AT_LEAST(3, 3, 0) 39 .def(
"info", &Preconditioner::info,
40 "Returns success if the Preconditioner has been well initialized.")
42 .def(
"solve", &
solve, bp::arg(
"b"),
43 "Returns the solution A * z = b where the preconditioner is an " 46 .def(
"compute", &Preconditioner::template compute<MatrixType>,
48 "Initialize the preconditioner from the matrix value.",
49 bp::return_value_policy<bp::reference_existing_object>())
50 .def(
"factorize", &Preconditioner::template factorize<MatrixType>,
52 "Initialize the preconditioner from the matrix value, i.e " 53 "factorize the mat given as input to approximate its inverse.",
54 bp::return_value_policy<bp::reference_existing_object>());
58 static VectorType
solve(Preconditioner&
self,
const VectorType& b) {
63 template <
typename Scalar>
66 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>
MatrixType;
69 template <
class PyClass>
73 "Returns the number of rows in the preconditioner.")
75 "Returns the number of cols in the preconditioner.");
79 bp::class_<Preconditioner>(
80 "DiagonalPreconditioner",
81 "A preconditioner based on the digonal entrie.\n" 82 "This class allows to approximately solve for A.x = b problems " 83 "assuming A is a diagonal matrix.",
88 #if EIGEN_VERSION_AT_LEAST(3, 3, 5) 89 template <
typename Scalar>
90 struct LeastSquareDiagonalPreconditionerVisitor
92 Eigen::LeastSquareDiagonalPreconditioner<Scalar> > {
93 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>
MatrixType;
94 typedef Eigen::LeastSquareDiagonalPreconditioner<Scalar>
Preconditioner;
96 template <
class PyClass>
97 void visit(PyClass&)
const {}
100 bp::class_<Preconditioner>(
101 "LeastSquareDiagonalPreconditioner",
102 "Jacobi preconditioner for LeastSquaresConjugateGradient.\n" 103 "his class allows to approximately solve for A' A x = A' b problems " 104 "assuming A' A is a diagonal matrix.",
115 template <
class PyClass>
119 bp::class_<Preconditioner>(
"IdentityPreconditioner", bp::no_init)
126 #endif // ifndef __eigenpy_basic_preconditioners_hpp__ Eigen::IdentityPreconditioner Preconditioner
Eigen::VectorXd VectorType
Eigen::DiagonalPreconditioner< Scalar > Preconditioner
Eigen::MatrixXd MatrixType
void visit(PyClass &cl) const
void expose()
Call the expose function of a given type T.
void visit(PyClass &cl) const
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > MatrixType
void visit(PyClass &) const
static VectorType solve(Preconditioner &self, const VectorType &b)