From c6da881849734fc8c76a151e60da3bc65ef2e2fd Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 16 Oct 2013 15:25:39 +0200 Subject: [PATCH] Fix bug #674: typo in documentation example for BiCGSTAB. They are now proper snippet files. --- Eigen/src/IterativeLinearSolvers/BiCGSTAB.h | 25 ++------------------- doc/snippets/BiCGSTAB_simple.cpp | 11 +++++++++ doc/snippets/BiCGSTAB_step_by_step.cpp | 14 ++++++++++++ doc/snippets/compile_snippet.cpp.in | 2 +- 4 files changed, 28 insertions(+), 24 deletions(-) create mode 100644 doc/snippets/BiCGSTAB_simple.cpp create mode 100644 doc/snippets/BiCGSTAB_step_by_step.cpp diff --git a/Eigen/src/IterativeLinearSolvers/BiCGSTAB.h b/Eigen/src/IterativeLinearSolvers/BiCGSTAB.h index 6fc6ab852..7a46b51fa 100644 --- a/Eigen/src/IterativeLinearSolvers/BiCGSTAB.h +++ b/Eigen/src/IterativeLinearSolvers/BiCGSTAB.h @@ -136,34 +136,13 @@ struct traits > * and NumTraits::epsilon() for the tolerance. * * This class can be used as the direct solver classes. Here is a typical usage example: - * \code - * int n = 10000; - * VectorXd x(n), b(n); - * SparseMatrix A(n,n); - * // fill A and b - * BiCGSTAB > solver; - * solver(A); - * x = solver.solve(b); - * std::cout << "#iterations: " << solver.iterations() << std::endl; - * std::cout << "estimated error: " << solver.error() << std::endl; - * // update b, and solve again - * x = solver.solve(b); - * \endcode + * \include BiCGSTAB_simple.cpp * * By default the iterations start with x=0 as an initial guess of the solution. * One can control the start using the solveWithGuess() method. Here is a step by * step execution example starting with a random guess and printing the evolution * of the estimated error: - * * \code - * x = VectorXd::Random(n); - * solver.setMaxIterations(1); - * int i = 0; - * do { - * x = solver.solveWithGuess(b,x); - * std::cout << i << " : " << solver.error() << std::endl; - * ++i; - * } while (solver.info()!=Success && i<100); - * \endcode + * \include BiCGSTAB_step_by_step.cpp * Note that such a step by step excution is slightly slower. * * \sa class SimplicialCholesky, DiagonalPreconditioner, IdentityPreconditioner diff --git a/doc/snippets/BiCGSTAB_simple.cpp b/doc/snippets/BiCGSTAB_simple.cpp new file mode 100644 index 000000000..5520f4f1f --- /dev/null +++ b/doc/snippets/BiCGSTAB_simple.cpp @@ -0,0 +1,11 @@ + int n = 10000; + VectorXd x(n), b(n); + SparseMatrix A(n,n); + /* ... fill A and b ... */ + BiCGSTAB > solver; + solver.compute(A); + x = solver.solve(b); + std::cout << "#iterations: " << solver.iterations() << std::endl; + std::cout << "estimated error: " << solver.error() << std::endl; + /* ... update b ... */ + x = solver.solve(b); // solve again \ No newline at end of file diff --git a/doc/snippets/BiCGSTAB_step_by_step.cpp b/doc/snippets/BiCGSTAB_step_by_step.cpp new file mode 100644 index 000000000..06147bb81 --- /dev/null +++ b/doc/snippets/BiCGSTAB_step_by_step.cpp @@ -0,0 +1,14 @@ + int n = 10000; + VectorXd x(n), b(n); + SparseMatrix A(n,n); + /* ... fill A and b ... */ + BiCGSTAB > solver(A); + // start from a random solution + x = VectorXd::Random(n); + solver.setMaxIterations(1); + int i = 0; + do { + x = solver.solveWithGuess(b,x); + std::cout << i << " : " << solver.error() << std::endl; + ++i; + } while (solver.info()!=Success && i<100); \ No newline at end of file diff --git a/doc/snippets/compile_snippet.cpp.in b/doc/snippets/compile_snippet.cpp.in index 894cd526c..82ae89162 100644 --- a/doc/snippets/compile_snippet.cpp.in +++ b/doc/snippets/compile_snippet.cpp.in @@ -1,4 +1,4 @@ -#include +#include #include using namespace Eigen;