.. _program_listing_file__tmp_ws_src_eigenpy_include_eigenpy_solvers_BasicPreconditioners.hpp: Program Listing for File BasicPreconditioners.hpp ================================================= |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/eigenpy/include/eigenpy/solvers/BasicPreconditioners.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /* * Copyright 2017, Justin Carpentier, LAAS-CNRS * * This file is part of eigenpy. * eigenpy is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation, either version 3 of * the License, or (at your option) any later version. * eigenpy is distributed in the hope that it will be * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. You should * have received a copy of the GNU Lesser General Public License along * with eigenpy. If not, see . */ #ifndef __eigenpy_basic_preconditioners_hpp__ #define __eigenpy_basic_preconditioners_hpp__ #include #include "eigenpy/fwd.hpp" namespace eigenpy { template struct PreconditionerBaseVisitor : public bp::def_visitor > { typedef Eigen::MatrixXd MatrixType; typedef Eigen::VectorXd VectorType; template void visit(PyClass& cl) const { cl.def(bp::init<>("Default constructor")) .def(bp::init(bp::args("self", "A"), "Initialize the preconditioner with matrix A " "for further Az=b solving.")) #if EIGEN_VERSION_AT_LEAST(3, 3, 0) .def("info", &Preconditioner::info, "Returns success if the Preconditioner has been well initialized.") #endif .def("solve", &solve, bp::arg("b"), "Returns the solution A * z = b where the preconditioner is an " "estimate of A^-1.") .def("compute", &Preconditioner::template compute, bp::arg("mat"), "Initialize the preconditioner from the matrix value.", bp::return_value_policy()) .def("factorize", &Preconditioner::template factorize, bp::arg("mat"), "Initialize the preconditioner from the matrix value, i.e " "factorize the mat given as input to approximate its inverse.", bp::return_value_policy()); } private: static VectorType solve(Preconditioner& self, const VectorType& b) { return self.solve(b); } }; template struct DiagonalPreconditionerVisitor : PreconditionerBaseVisitor > { typedef Eigen::Matrix MatrixType; typedef Eigen::DiagonalPreconditioner Preconditioner; template void visit(PyClass& cl) const { cl.def(PreconditionerBaseVisitor()) .def("rows", &Preconditioner::rows, "Returns the number of rows in the preconditioner.") .def("cols", &Preconditioner::cols, "Returns the number of cols in the preconditioner."); } static void expose() { bp::class_( "DiagonalPreconditioner", "A preconditioner based on the digonal entrie.\n" "This class allows to approximately solve for A.x = b problems " "assuming A is a diagonal matrix.", bp::no_init); } }; #if EIGEN_VERSION_AT_LEAST(3, 3, 5) template struct LeastSquareDiagonalPreconditionerVisitor : PreconditionerBaseVisitor< Eigen::LeastSquareDiagonalPreconditioner > { typedef Eigen::Matrix MatrixType; typedef Eigen::LeastSquareDiagonalPreconditioner Preconditioner; template void visit(PyClass&) const {} static void expose() { bp::class_( "LeastSquareDiagonalPreconditioner", "Jacobi preconditioner for LeastSquaresConjugateGradient.\n" "his class allows to approximately solve for A' A x = A' b problems " "assuming A' A is a diagonal matrix.", bp::no_init) .def(DiagonalPreconditionerVisitor()); } }; #endif struct IdentityPreconditionerVisitor : PreconditionerBaseVisitor { typedef Eigen::IdentityPreconditioner Preconditioner; template void visit(PyClass&) const {} static void expose() { bp::class_("IdentityPreconditioner", bp::no_init) .def(PreconditionerBaseVisitor()); } }; } // namespace eigenpy #endif // ifndef __eigenpy_basic_preconditioners_hpp__