IterativeSolverBase.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017, Justin Carpentier, LAAS-CNRS
3  *
4  * This file is part of eigenpy.
5  * eigenpy is free software: you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public License
7  * as published by the Free Software Foundation, either version 3 of
8  * the License, or (at your option) any later version.
9  * eigenpy is distributed in the hope that it will be
10  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
11  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details. You should
13  * have received a copy of the GNU Lesser General Public License along
14  * with eigenpy. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef __eigenpy_iterative_solver_base_hpp__
18 #define __eigenpy_iterative_solver_base_hpp__
19 
20 #include "eigenpy/fwd.hpp"
22 
23 namespace eigenpy {
24 
25 template <typename IterativeSolver>
26 struct IterativeSolverVisitor : public boost::python::def_visitor<
27  IterativeSolverVisitor<IterativeSolver> > {
28  typedef typename IterativeSolver::MatrixType MatrixType;
29  typedef typename IterativeSolver::Preconditioner Preconditioner;
30  typedef Eigen::VectorXd VectorType;
31 
32  template <class PyClass>
33  void visit(PyClass& cl) const {
34  typedef IterativeSolver IS;
35 
36  cl.def(SparseSolverVisitor<IS>())
37  .def("error", &IS::error,
38  "Returns the tolerance error reached during the last solve.\n"
39  "It is a close approximation of the true relative residual error "
40  "|Ax-b|/|b|.")
41  .def("info", &IS::info,
42  "Returns success if the iterations converged, and NoConvergence "
43  "otherwise.")
44  .def(
45  "iterations", &IS::iterations,
46  "Returns the number of iterations performed during the last solve.")
47  .def("maxIterations", &IS::maxIterations,
48  "Returns the max number of iterations.\n"
49  "It is either the value setted by setMaxIterations or, by "
50  "default, twice the number of columns of the matrix.")
51  .def("setMaxIterations", &IS::setMaxIterations,
52  "Sets the max number of iterations.\n"
53  "Default is twice the number of columns of the matrix.",
54  bp::return_value_policy<bp::reference_existing_object>())
55  .def("tolerance", &IS::tolerance,
56  "Returns he tolerance threshold used by the stopping criteria.")
57  .def("setTolerance", &IS::setTolerance,
58  "Sets the tolerance threshold used by the stopping criteria.\n"
59  "This value is used as an upper bound to the relative residual "
60  "error: |Ax-b|/|b|. The default value is the machine precision.",
61  bp::return_value_policy<bp::reference_existing_object>())
62  .def("analyzePattern", &analyzePattern, bp::arg("A"),
63  "Initializes the iterative solver for the sparsity pattern of the "
64  "matrix A for further solving Ax=b problems.\n"
65  "Currently, this function mostly calls analyzePattern on the "
66  "preconditioner.\n"
67  "In the future we might, for instance, implement column "
68  "reordering for faster matrix vector products.",
69  bp::return_value_policy<bp::reference_existing_object>())
70  .def("factorize", &factorize, bp::arg("A"),
71  "Initializes the iterative solver with the numerical values of "
72  "the matrix A for further solving Ax=b problems.\n"
73  "Currently, this function mostly calls factorize on the "
74  "preconditioner.",
75  bp::return_value_policy<bp::reference_existing_object>())
76  .def("compute", &compute, bp::arg("A"),
77  "Initializes the iterative solver with the numerical values of "
78  "the matrix A for further solving Ax=b problems.\n"
79  "Currently, this function mostly calls factorize on the "
80  "preconditioner.\n"
81  "In the future we might, for instance, implement column "
82  "reordering for faster matrix vector products.",
83  bp::return_value_policy<bp::reference_existing_object>())
84  .def("solveWithGuess", &solveWithGuess, bp::args("b", "x0"),
85  "Returns the solution x of Ax = b using the current decomposition "
86  "of A and x0 as an initial solution.")
87  .def("preconditioner",
88  (Preconditioner & (IS::*)(void)) & IS::preconditioner,
89  "Returns a read-write reference to the preconditioner for custom "
90  "configuration.",
91  bp::return_internal_reference<>());
92  }
93 
94  private:
95  static IterativeSolver& factorize(IterativeSolver& self,
96  const MatrixType& m) {
97  return self.factorize(m);
98  }
99 
100  static IterativeSolver& compute(IterativeSolver& self, const MatrixType& m) {
101  return self.compute(m);
102  }
103 
104  static IterativeSolver& analyzePattern(IterativeSolver& self,
105  const MatrixType& m) {
106  return self.analyzePattern(m);
107  }
108 
109  static VectorType solveWithGuess(IterativeSolver& self,
110  const Eigen::VectorXd& b,
111  const Eigen::VectorXd& x0) {
112  return self.solveWithGuess(b, x0);
113  }
114 };
115 
116 } // namespace eigenpy
117 
118 #endif // ifndef __eigenpy_iterative_solver_base_hpp__
static IterativeSolver & analyzePattern(IterativeSolver &self, const MatrixType &m)
IterativeSolver::Preconditioner Preconditioner
static IterativeSolver & factorize(IterativeSolver &self, const MatrixType &m)
IterativeSolver::MatrixType MatrixType
static IterativeSolver & compute(IterativeSolver &self, const MatrixType &m)
static VectorType solveWithGuess(IterativeSolver &self, const Eigen::VectorXd &b, const Eigen::VectorXd &x0)


eigenpy
Author(s): Justin Carpentier, Nicolas Mansard
autogenerated on Fri Jun 2 2023 02:10:26