6 #ifndef __eigenpy_basic_preconditioners_hpp__
7 #define __eigenpy_basic_preconditioners_hpp__
9 #include <Eigen/IterativeLinearSolvers>
15 template <
typename Preconditioner>
17 :
public bp::def_visitor<PreconditionerBaseVisitor<Preconditioner> > {
21 template <
class PyClass>
23 cl.def(bp::init<>(
"Default constructor"))
24 .def(bp::init<MatrixType>(bp::args(
"self",
"A"),
25 "Initialize the preconditioner with matrix A "
26 "for further Az=b solving."))
27 #if EIGEN_VERSION_AT_LEAST(3, 3, 0)
28 .def(
"info", &Preconditioner::info,
29 "Returns success if the Preconditioner has been well initialized.")
31 .def(
"solve", &
solve, bp::arg(
"b"),
32 "Returns the solution A * z = b where the preconditioner is an "
35 .def(
"compute", &Preconditioner::template compute<MatrixType>,
37 "Initialize the preconditioner from the matrix value.",
38 bp::return_value_policy<bp::reference_existing_object>())
39 .def(
"factorize", &Preconditioner::template factorize<MatrixType>,
41 "Initialize the preconditioner from the matrix value, i.e "
42 "factorize the mat given as input to approximate its inverse.",
43 bp::return_value_policy<bp::reference_existing_object>());
52 template <
typename Scalar>
55 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>
MatrixType;
58 template <
class PyClass>
62 "Returns the number of rows in the preconditioner.")
64 "Returns the number of cols in the preconditioner.");
68 bp::class_<Preconditioner>(
69 "DiagonalPreconditioner",
70 "A preconditioner based on the digonal entrie.\n"
71 "This class allows to approximately solve for A.x = b problems "
72 "assuming A is a diagonal matrix.",
78 #if EIGEN_VERSION_AT_LEAST(3, 3, 5)
79 template <
typename Scalar>
80 struct LeastSquareDiagonalPreconditionerVisitor
81 : PreconditionerBaseVisitor<
82 Eigen::LeastSquareDiagonalPreconditioner<Scalar> > {
83 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> MatrixType;
84 typedef Eigen::LeastSquareDiagonalPreconditioner<Scalar> Preconditioner;
86 template <
class PyClass>
87 void visit(PyClass&)
const {}
90 bp::class_<Preconditioner>(
91 "LeastSquareDiagonalPreconditioner",
92 "Jacobi preconditioner for LeastSquaresConjugateGradient.\n"
93 "his class allows to approximately solve for A' A x = A' b problems "
94 "assuming A' A is a diagonal matrix.",
96 .def(DiagonalPreconditionerVisitor<Scalar>())
97 .def(IdVisitor<Preconditioner>());
106 template <
class PyClass>
110 bp::class_<Preconditioner>(
"IdentityPreconditioner", bp::no_init)
118 #endif // ifndef __eigenpy_basic_preconditioners_hpp__