From 39a6aff16c4da959ca82bb3aab57407961585a88 Mon Sep 17 00:00:00 2001 From: Erik Schultheis Date: Tue, 7 Dec 2021 19:57:38 +0000 Subject: [PATCH] get rid of `using namespace Eigen` in sample code --- doc/examples/Cwise_erf.cpp | 3 +- doc/examples/Cwise_erfc.cpp | 3 +- doc/examples/Cwise_lgamma.cpp | 3 +- doc/examples/DenseBase_middleCols_int.cpp | 11 ++-- doc/examples/DenseBase_middleRows_int.cpp | 11 ++-- .../DenseBase_template_int_middleCols.cpp | 11 ++-- .../DenseBase_template_int_middleRows.cpp | 11 ++-- doc/examples/QuickStart_example2_dynamic.cpp | 8 +-- doc/examples/QuickStart_example2_fixed.cpp | 8 +-- doc/examples/TemplateKeyword_flexible.cpp | 10 ++- doc/examples/TemplateKeyword_simple.cpp | 4 +- doc/examples/TutorialInplaceLU.cpp | 64 +++++++++---------- doc/examples/TutorialLinAlgComputeTwice.cpp | 21 +++--- .../TutorialLinAlgExComputeSolveError.cpp | 5 +- ...torialLinAlgExSolveColPivHouseholderQR.cpp | 15 ++--- doc/examples/TutorialLinAlgExSolveLDLT.cpp | 13 ++-- .../TutorialLinAlgInverseDeterminant.cpp | 11 ++-- doc/examples/TutorialLinAlgRankRevealing.cpp | 19 +++--- doc/examples/TutorialLinAlgSVDSolve.cpp | 15 ++--- .../TutorialLinAlgSelfAdjointEigenSolver.cpp | 17 ++--- doc/examples/TutorialLinAlgSetThreshold.cpp | 11 ++-- .../Tutorial_ArrayClass_accessors.cpp | 9 +-- doc/examples/Tutorial_ArrayClass_addition.cpp | 11 ++-- .../Tutorial_ArrayClass_cwise_other.cpp | 21 +++--- doc/examples/Tutorial_ArrayClass_interop.cpp | 7 +- .../Tutorial_ArrayClass_interop_matrix.cpp | 11 ++-- doc/examples/Tutorial_ArrayClass_mult.cpp | 9 +-- ...orial_BlockOperations_block_assignment.cpp | 13 ++-- doc/examples/Tutorial_PartialLU_solve.cpp | 15 ++--- ...ionsVisitorsBroadcasting_broadcast_1nn.cpp | 9 +-- ...ReductionsVisitorsBroadcasting_maxnorm.cpp | 6 +- ...nsVisitorsBroadcasting_reductions_bool.cpp | 19 +++--- ...nsVisitorsBroadcasting_reductions_norm.cpp | 25 ++++---- ...rsBroadcasting_reductions_operatornorm.cpp | 13 ++-- ...eductionsVisitorsBroadcasting_visitors.cpp | 15 ++--- .../Tutorial_simple_example_dynamic_size.cpp | 6 +- .../Tutorial_simple_example_fixed_size.cpp | 8 +-- doc/examples/class_Block.cpp | 12 ++-- doc/examples/class_CwiseBinaryOp.cpp | 10 +-- doc/examples/class_CwiseUnaryOp.cpp | 6 +- doc/examples/class_CwiseUnaryOp_ptrfun.cpp | 6 +- doc/examples/class_FixedBlock.cpp | 12 ++-- doc/examples/class_FixedReshaped.cpp | 12 ++-- doc/examples/class_FixedVectorBlock.cpp | 12 ++-- doc/examples/class_Reshaped.cpp | 18 +++--- doc/examples/class_VectorBlock.cpp | 12 ++-- doc/examples/function_taking_eigenbase.cpp | 5 +- doc/examples/function_taking_ref.cpp | 16 ++--- doc/examples/make_circulant2.cpp | 12 ++-- doc/examples/nullary_indexing.cpp | 16 ++--- doc/examples/tut_arithmetic_add_sub.cpp | 10 ++- doc/examples/tut_arithmetic_dot_cross.cpp | 12 ++-- doc/examples/tut_arithmetic_matrix_mul.cpp | 5 +- .../tut_arithmetic_scalar_mul_div.cpp | 6 +- .../tut_matrix_coefficient_accessors.cpp | 6 +- doc/examples/tut_matrix_resize.cpp | 6 +- doc/examples/tut_matrix_resize_fixed_size.cpp | 4 +- doc/special_examples/random_cpp11.cpp | 4 +- 58 files changed, 274 insertions(+), 399 deletions(-) diff --git a/doc/examples/Cwise_erf.cpp b/doc/examples/Cwise_erf.cpp index e7cd2c1c0..9ddc57da3 100644 --- a/doc/examples/Cwise_erf.cpp +++ b/doc/examples/Cwise_erf.cpp @@ -1,9 +1,8 @@ #include #include #include -using namespace Eigen; int main() { - Array4d v(-0.5,2,0,-7); + Eigen::Array4d v(-0.5,2,0,-7); std::cout << v.erf() << std::endl; } diff --git a/doc/examples/Cwise_erfc.cpp b/doc/examples/Cwise_erfc.cpp index d8bb04c30..4b7902c6f 100644 --- a/doc/examples/Cwise_erfc.cpp +++ b/doc/examples/Cwise_erfc.cpp @@ -1,9 +1,8 @@ #include #include #include -using namespace Eigen; int main() { - Array4d v(-0.5,2,0,-7); + Eigen::Array4d v(-0.5,2,0,-7); std::cout << v.erfc() << std::endl; } diff --git a/doc/examples/Cwise_lgamma.cpp b/doc/examples/Cwise_lgamma.cpp index 6bfaccbce..f3c9fe610 100644 --- a/doc/examples/Cwise_lgamma.cpp +++ b/doc/examples/Cwise_lgamma.cpp @@ -1,9 +1,8 @@ #include #include #include -using namespace Eigen; int main() { - Array4d v(0.5,10,0,-1); + Eigen::Array4d v(0.5,10,0,-1); std::cout << v.lgamma() << std::endl; } diff --git a/doc/examples/DenseBase_middleCols_int.cpp b/doc/examples/DenseBase_middleCols_int.cpp index 0ebd955ec..d05a552d0 100644 --- a/doc/examples/DenseBase_middleCols_int.cpp +++ b/doc/examples/DenseBase_middleCols_int.cpp @@ -1,15 +1,12 @@ #include #include -using namespace Eigen; -using namespace std; - -int main(void) +int main() { int const N = 5; - MatrixXi A(N,N); + Eigen::MatrixXi A(N,N); A.setRandom(); - cout << "A =\n" << A << '\n' << endl; - cout << "A(1..3,:) =\n" << A.middleCols(1,3) << endl; + std::cout << "A =\n" << A << '\n' << std::endl; + std::cout << "A(1..3,:) =\n" << A.middleCols(1,3) << std::endl; return 0; } diff --git a/doc/examples/DenseBase_middleRows_int.cpp b/doc/examples/DenseBase_middleRows_int.cpp index a6fe9e844..86516295c 100644 --- a/doc/examples/DenseBase_middleRows_int.cpp +++ b/doc/examples/DenseBase_middleRows_int.cpp @@ -1,15 +1,12 @@ #include #include -using namespace Eigen; -using namespace std; - -int main(void) +int main() { int const N = 5; - MatrixXi A(N,N); + Eigen::MatrixXi A(N,N); A.setRandom(); - cout << "A =\n" << A << '\n' << endl; - cout << "A(2..3,:) =\n" << A.middleRows(2,2) << endl; + std::cout << "A =\n" << A << '\n' << std::endl; + std::cout << "A(2..3,:) =\n" << A.middleRows(2,2) << std::endl; return 0; } diff --git a/doc/examples/DenseBase_template_int_middleCols.cpp b/doc/examples/DenseBase_template_int_middleCols.cpp index 6191d79c8..caefabf81 100644 --- a/doc/examples/DenseBase_template_int_middleCols.cpp +++ b/doc/examples/DenseBase_template_int_middleCols.cpp @@ -1,15 +1,12 @@ #include #include -using namespace Eigen; -using namespace std; - -int main(void) +int main() { int const N = 5; - MatrixXi A(N,N); + Eigen::MatrixXi A(N,N); A.setRandom(); - cout << "A =\n" << A << '\n' << endl; - cout << "A(:,1..3) =\n" << A.middleCols<3>(1) << endl; + std::cout << "A =\n" << A << '\n' << std::endl; + std::cout << "A(:,1..3) =\n" << A.middleCols<3>(1) << std::endl; return 0; } diff --git a/doc/examples/DenseBase_template_int_middleRows.cpp b/doc/examples/DenseBase_template_int_middleRows.cpp index 7e8b6573f..ed5b2954c 100644 --- a/doc/examples/DenseBase_template_int_middleRows.cpp +++ b/doc/examples/DenseBase_template_int_middleRows.cpp @@ -1,15 +1,12 @@ #include #include -using namespace Eigen; -using namespace std; - -int main(void) +int main() { int const N = 5; - MatrixXi A(N,N); + Eigen::MatrixXi A(N,N); A.setRandom(); - cout << "A =\n" << A << '\n' << endl; - cout << "A(1..3,:) =\n" << A.middleRows<3>(1) << endl; + std::cout << "A =\n" << A << '\n' << std::endl; + std::cout << "A(1..3,:) =\n" << A.middleRows<3>(1) << std::endl; return 0; } diff --git a/doc/examples/QuickStart_example2_dynamic.cpp b/doc/examples/QuickStart_example2_dynamic.cpp index ff6746e21..bc8d326dd 100644 --- a/doc/examples/QuickStart_example2_dynamic.cpp +++ b/doc/examples/QuickStart_example2_dynamic.cpp @@ -1,15 +1,15 @@ #include #include -using namespace Eigen; -using namespace std; +using Eigen::MatrixXd; +using Eigen::VectorXd; int main() { MatrixXd m = MatrixXd::Random(3,3); m = (m + MatrixXd::Constant(3,3,1.2)) * 50; - cout << "m =" << endl << m << endl; + std::cout << "m =" << std::endl << m << std::endl; VectorXd v(3); v << 1, 2, 3; - cout << "m * v =" << endl << m * v << endl; + std::cout << "m * v =" << std::endl << m * v << std::endl; } diff --git a/doc/examples/QuickStart_example2_fixed.cpp b/doc/examples/QuickStart_example2_fixed.cpp index d91175273..af6f9a984 100644 --- a/doc/examples/QuickStart_example2_fixed.cpp +++ b/doc/examples/QuickStart_example2_fixed.cpp @@ -1,15 +1,15 @@ #include #include -using namespace Eigen; -using namespace std; +using Eigen::Matrix3d; +using Eigen::Vector3d; int main() { Matrix3d m = Matrix3d::Random(); m = (m + Matrix3d::Constant(1.2)) * 50; - cout << "m =" << endl << m << endl; + std::cout << "m =" << std::endl << m << std::endl; Vector3d v(1,2,3); - cout << "m * v =" << endl << m * v << endl; + std::cout << "m * v =" << std::endl << m * v << std::endl; } diff --git a/doc/examples/TemplateKeyword_flexible.cpp b/doc/examples/TemplateKeyword_flexible.cpp index 9d85292dd..efe458bd5 100644 --- a/doc/examples/TemplateKeyword_flexible.cpp +++ b/doc/examples/TemplateKeyword_flexible.cpp @@ -1,19 +1,17 @@ #include #include -using namespace Eigen; - template -void copyUpperTriangularPart(MatrixBase& dst, const MatrixBase& src) +void copyUpperTriangularPart(Eigen::MatrixBase& dst, const Eigen::MatrixBase& src) { /* Note the 'template' keywords in the following line! */ - dst.template triangularView() = src.template triangularView(); + dst.template triangularView() = src.template triangularView(); } int main() { - MatrixXi m1 = MatrixXi::Ones(5,5); - MatrixXi m2 = MatrixXi::Random(4,4); + Eigen::MatrixXi m1 = Eigen::MatrixXi::Ones(5,5); + Eigen::MatrixXi m2 = Eigen::MatrixXi::Random(4,4); std::cout << "m2 before copy:" << std::endl; std::cout << m2 << std::endl << std::endl; copyUpperTriangularPart(m2, m1.topLeftCorner(4,4)); diff --git a/doc/examples/TemplateKeyword_simple.cpp b/doc/examples/TemplateKeyword_simple.cpp index 6998c1769..6b946ad3d 100644 --- a/doc/examples/TemplateKeyword_simple.cpp +++ b/doc/examples/TemplateKeyword_simple.cpp @@ -1,11 +1,11 @@ #include #include -using namespace Eigen; +using Eigen::MatrixXf; void copyUpperTriangularPart(MatrixXf& dst, const MatrixXf& src) { - dst.triangularView() = src.triangularView(); + dst.triangularView() = src.triangularView(); } int main() diff --git a/doc/examples/TutorialInplaceLU.cpp b/doc/examples/TutorialInplaceLU.cpp index cb9c59b60..72bead2a7 100644 --- a/doc/examples/TutorialInplaceLU.cpp +++ b/doc/examples/TutorialInplaceLU.cpp @@ -1,61 +1,57 @@ #include struct init { - init() { std::cout << "[" << "init" << "]" << std::endl; } + init() { std::cout << "[init]\n"; } }; init init_obj; // [init] -#include #include -using namespace std; -using namespace Eigen; - int main() { - MatrixXd A(2,2); + Eigen::MatrixXd A(2,2); A << 2, -1, 1, 3; - cout << "Here is the input matrix A before decomposition:\n" << A << endl; -cout << "[init]" << endl; + std::cout << "Here is the input matrix A before decomposition:\n" << A << "\n"; + std::cout << "[init]\n"; -cout << "[declaration]" << endl; - PartialPivLU > lu(A); - cout << "Here is the input matrix A after decomposition:\n" << A << endl; -cout << "[declaration]" << endl; + std::cout << "[declaration]\n"; + Eigen::PartialPivLU > lu(A); + std::cout << "Here is the input matrix A after decomposition:\n" << A << "\n"; + std::cout << "[declaration]\n"; -cout << "[matrixLU]" << endl; - cout << "Here is the matrix storing the L and U factors:\n" << lu.matrixLU() << endl; -cout << "[matrixLU]" << endl; + std::cout << "[matrixLU]\n"; + std::cout << "Here is the matrix storing the L and U factors:\n" << lu.matrixLU() << "\n"; + std::cout << "[matrixLU]\n"; -cout << "[solve]" << endl; - MatrixXd A0(2,2); A0 << 2, -1, 1, 3; - VectorXd b(2); b << 1, 2; - VectorXd x = lu.solve(b); - cout << "Residual: " << (A0 * x - b).norm() << endl; -cout << "[solve]" << endl; + std::cout << "[solve]\n"; + Eigen::MatrixXd A0(2,2); A0 << 2, -1, 1, 3; + Eigen::VectorXd b(2); b << 1, 2; + Eigen::VectorXd x = lu.solve(b); + std::cout << "Residual: " << (A0 * x - b).norm() << "\n"; + std::cout << "[solve]\n"; -cout << "[modifyA]" << endl; + std::cout << "[modifyA]\n"; A << 3, 4, -2, 1; x = lu.solve(b); - cout << "Residual: " << (A0 * x - b).norm() << endl; -cout << "[modifyA]" << endl; + std::cout << "Residual: " << (A0 * x - b).norm() << "\n"; + std::cout << "[modifyA]\n"; -cout << "[recompute]" << endl; + std::cout << "[recompute]\n"; A0 = A; // save A lu.compute(A); x = lu.solve(b); - cout << "Residual: " << (A0 * x - b).norm() << endl; -cout << "[recompute]" << endl; + std::cout << "Residual: " << (A0 * x - b).norm() << "\n"; + std::cout << "[recompute]\n"; -cout << "[recompute_bis0]" << endl; - MatrixXd A1(2,2); + std::cout << "[recompute_bis0]\n"; + Eigen::MatrixXd A1(2,2); A1 << 5,-2,3,4; lu.compute(A1); - cout << "Here is the input matrix A1 after decomposition:\n" << A1 << endl; -cout << "[recompute_bis0]" << endl; + std::cout << "Here is the input matrix A1 after decomposition:\n" << A1 << "\n"; + std::cout << "[recompute_bis0]\n"; -cout << "[recompute_bis1]" << endl; + std::cout << "[recompute_bis1]\n"; x = lu.solve(b); - cout << "Residual: " << (A1 * x - b).norm() << endl; -cout << "[recompute_bis1]" << endl; + std::cout << "Residual: " << (A1 * x - b).norm() << "\n"; + std::cout << "[recompute_bis1]\n"; } diff --git a/doc/examples/TutorialLinAlgComputeTwice.cpp b/doc/examples/TutorialLinAlgComputeTwice.cpp index 06ba6461a..a561f086e 100644 --- a/doc/examples/TutorialLinAlgComputeTwice.cpp +++ b/doc/examples/TutorialLinAlgComputeTwice.cpp @@ -1,23 +1,20 @@ #include #include -using namespace std; -using namespace Eigen; - int main() { - Matrix2f A, b; - LLT llt; + Eigen::Matrix2f A, b; + Eigen::LLT llt; A << 2, -1, -1, 3; b << 1, 2, 3, 1; - cout << "Here is the matrix A:\n" << A << endl; - cout << "Here is the right hand side b:\n" << b << endl; - cout << "Computing LLT decomposition..." << endl; + std::cout << "Here is the matrix A:\n" << A << std::endl; + std::cout << "Here is the right hand side b:\n" << b << std::endl; + std::cout << "Computing LLT decomposition..." << std::endl; llt.compute(A); - cout << "The solution is:\n" << llt.solve(b) << endl; + std::cout << "The solution is:\n" << llt.solve(b) << std::endl; A(1,1)++; - cout << "The matrix A is now:\n" << A << endl; - cout << "Computing LLT decomposition..." << endl; + std::cout << "The matrix A is now:\n" << A << std::endl; + std::cout << "Computing LLT decomposition..." << std::endl; llt.compute(A); - cout << "The solution is now:\n" << llt.solve(b) << endl; + std::cout << "The solution is now:\n" << llt.solve(b) << std::endl; } diff --git a/doc/examples/TutorialLinAlgExComputeSolveError.cpp b/doc/examples/TutorialLinAlgExComputeSolveError.cpp index f362fb71a..199f3f589 100644 --- a/doc/examples/TutorialLinAlgExComputeSolveError.cpp +++ b/doc/examples/TutorialLinAlgExComputeSolveError.cpp @@ -1,8 +1,7 @@ #include #include -using namespace std; -using namespace Eigen; +using Eigen::MatrixXd; int main() { @@ -10,5 +9,5 @@ int main() MatrixXd b = MatrixXd::Random(100,50); MatrixXd x = A.fullPivLu().solve(b); double relative_error = (A*x - b).norm() / b.norm(); // norm() is L2 norm - cout << "The relative error is:\n" << relative_error << endl; + std::cout << "The relative error is:\n" << relative_error << std::endl; } diff --git a/doc/examples/TutorialLinAlgExSolveColPivHouseholderQR.cpp b/doc/examples/TutorialLinAlgExSolveColPivHouseholderQR.cpp index 3a99a94d7..5ee6b6acc 100644 --- a/doc/examples/TutorialLinAlgExSolveColPivHouseholderQR.cpp +++ b/doc/examples/TutorialLinAlgExSolveColPivHouseholderQR.cpp @@ -1,17 +1,14 @@ #include #include -using namespace std; -using namespace Eigen; - int main() { - Matrix3f A; - Vector3f b; + Eigen::Matrix3f A; + Eigen::Vector3f b; A << 1,2,3, 4,5,6, 7,8,10; b << 3, 3, 4; - cout << "Here is the matrix A:\n" << A << endl; - cout << "Here is the vector b:\n" << b << endl; - Vector3f x = A.colPivHouseholderQr().solve(b); - cout << "The solution is:\n" << x << endl; + std::cout << "Here is the matrix A:\n" << A << std::endl; + std::cout << "Here is the vector b:\n" << b << std::endl; + Eigen::Vector3f x = A.colPivHouseholderQr().solve(b); + std::cout << "The solution is:\n" << x << std::endl; } diff --git a/doc/examples/TutorialLinAlgExSolveLDLT.cpp b/doc/examples/TutorialLinAlgExSolveLDLT.cpp index f8beacd27..82186d4f6 100644 --- a/doc/examples/TutorialLinAlgExSolveLDLT.cpp +++ b/doc/examples/TutorialLinAlgExSolveLDLT.cpp @@ -1,16 +1,13 @@ #include #include -using namespace std; -using namespace Eigen; - int main() { - Matrix2f A, b; + Eigen::Matrix2f A, b; A << 2, -1, -1, 3; b << 1, 2, 3, 1; - cout << "Here is the matrix A:\n" << A << endl; - cout << "Here is the right hand side b:\n" << b << endl; - Matrix2f x = A.ldlt().solve(b); - cout << "The solution is:\n" << x << endl; + std::cout << "Here is the matrix A:\n" << A << std::endl; + std::cout << "Here is the right hand side b:\n" << b << std::endl; + Eigen::Matrix2f x = A.ldlt().solve(b); + std::cout << "The solution is:\n" << x << std::endl; } diff --git a/doc/examples/TutorialLinAlgInverseDeterminant.cpp b/doc/examples/TutorialLinAlgInverseDeterminant.cpp index 14dde5b35..b31a92ac9 100644 --- a/doc/examples/TutorialLinAlgInverseDeterminant.cpp +++ b/doc/examples/TutorialLinAlgInverseDeterminant.cpp @@ -1,16 +1,13 @@ #include #include -using namespace std; -using namespace Eigen; - int main() { - Matrix3f A; + Eigen::Matrix3f A; A << 1, 2, 1, 2, 1, 0, -1, 1, 2; - cout << "Here is the matrix A:\n" << A << endl; - cout << "The determinant of A is " << A.determinant() << endl; - cout << "The inverse of A is:\n" << A.inverse() << endl; + std::cout << "Here is the matrix A:\n" << A << std::endl; + std::cout << "The determinant of A is " << A.determinant() << std::endl; + std::cout << "The inverse of A is:\n" << A.inverse() << std::endl; } diff --git a/doc/examples/TutorialLinAlgRankRevealing.cpp b/doc/examples/TutorialLinAlgRankRevealing.cpp index c5165077f..fea52ab63 100644 --- a/doc/examples/TutorialLinAlgRankRevealing.cpp +++ b/doc/examples/TutorialLinAlgRankRevealing.cpp @@ -1,20 +1,17 @@ #include #include -using namespace std; -using namespace Eigen; - int main() { - Matrix3f A; + Eigen::Matrix3f A; A << 1, 2, 5, 2, 1, 4, 3, 0, 3; - cout << "Here is the matrix A:\n" << A << endl; - FullPivLU lu_decomp(A); - cout << "The rank of A is " << lu_decomp.rank() << endl; - cout << "Here is a matrix whose columns form a basis of the null-space of A:\n" - << lu_decomp.kernel() << endl; - cout << "Here is a matrix whose columns form a basis of the column-space of A:\n" - << lu_decomp.image(A) << endl; // yes, have to pass the original A + std::cout << "Here is the matrix A:\n" << A << std::endl; + Eigen::FullPivLU lu_decomp(A); + std::cout << "The rank of A is " << lu_decomp.rank() << std::endl; + std::cout << "Here is a matrix whose columns form a basis of the null-space of A:\n" + << lu_decomp.kernel() << std::endl; + std::cout << "Here is a matrix whose columns form a basis of the column-space of A:\n" + << lu_decomp.image(A) << std::endl; // yes, have to pass the original A } diff --git a/doc/examples/TutorialLinAlgSVDSolve.cpp b/doc/examples/TutorialLinAlgSVDSolve.cpp index f109f04e5..23ad42295 100644 --- a/doc/examples/TutorialLinAlgSVDSolve.cpp +++ b/doc/examples/TutorialLinAlgSVDSolve.cpp @@ -1,15 +1,12 @@ #include #include -using namespace std; -using namespace Eigen; - int main() { - MatrixXf A = MatrixXf::Random(3, 2); - cout << "Here is the matrix A:\n" << A << endl; - VectorXf b = VectorXf::Random(3); - cout << "Here is the right hand side b:\n" << b << endl; - cout << "The least-squares solution is:\n" - << A.bdcSvd(ComputeThinU | ComputeThinV).solve(b) << endl; + Eigen::MatrixXf A = Eigen::MatrixXf::Random(3, 2); + std::cout << "Here is the matrix A:\n" << A << std::endl; + Eigen::VectorXf b = Eigen::VectorXf::Random(3); + std::cout << "Here is the right hand side b:\n" << b << std::endl; + std::cout << "The least-squares solution is:\n" + << A.bdcSvd(Eigen::ComputeThinU | Eigen::ComputeThinV).solve(b) << std::endl; } diff --git a/doc/examples/TutorialLinAlgSelfAdjointEigenSolver.cpp b/doc/examples/TutorialLinAlgSelfAdjointEigenSolver.cpp index 8d1d1ed65..fcf2f33a9 100644 --- a/doc/examples/TutorialLinAlgSelfAdjointEigenSolver.cpp +++ b/doc/examples/TutorialLinAlgSelfAdjointEigenSolver.cpp @@ -1,18 +1,15 @@ #include #include -using namespace std; -using namespace Eigen; - int main() { - Matrix2f A; + Eigen::Matrix2f A; A << 1, 2, 2, 3; - cout << "Here is the matrix A:\n" << A << endl; - SelfAdjointEigenSolver eigensolver(A); - if (eigensolver.info() != Success) abort(); - cout << "The eigenvalues of A are:\n" << eigensolver.eigenvalues() << endl; - cout << "Here's a matrix whose columns are eigenvectors of A \n" + std::cout << "Here is the matrix A:\n" << A << std::endl; + Eigen::SelfAdjointEigenSolver eigensolver(A); + if (eigensolver.info() != Eigen::Success) abort(); + std::cout << "The eigenvalues of A are:\n" << eigensolver.eigenvalues() << std::endl; + std::cout << "Here's a matrix whose columns are eigenvectors of A \n" << "corresponding to these eigenvalues:\n" - << eigensolver.eigenvectors() << endl; + << eigensolver.eigenvectors() << std::endl; } diff --git a/doc/examples/TutorialLinAlgSetThreshold.cpp b/doc/examples/TutorialLinAlgSetThreshold.cpp index 3956b13a3..e1335e722 100644 --- a/doc/examples/TutorialLinAlgSetThreshold.cpp +++ b/doc/examples/TutorialLinAlgSetThreshold.cpp @@ -1,16 +1,13 @@ #include #include -using namespace std; -using namespace Eigen; - int main() { - Matrix2d A; + Eigen::Matrix2d A; A << 2, 1, 2, 0.9999999999; - FullPivLU lu(A); - cout << "By default, the rank of A is found to be " << lu.rank() << endl; + Eigen::FullPivLU lu(A); + std::cout << "By default, the rank of A is found to be " << lu.rank() << std::endl; lu.setThreshold(1e-5); - cout << "With threshold 1e-5, the rank of A is found to be " << lu.rank() << endl; + std::cout << "With threshold 1e-5, the rank of A is found to be " << lu.rank() << std::endl; } diff --git a/doc/examples/Tutorial_ArrayClass_accessors.cpp b/doc/examples/Tutorial_ArrayClass_accessors.cpp index dc720ff58..0db52a385 100644 --- a/doc/examples/Tutorial_ArrayClass_accessors.cpp +++ b/doc/examples/Tutorial_ArrayClass_accessors.cpp @@ -1,24 +1,21 @@ #include #include -using namespace Eigen; -using namespace std; - int main() { - ArrayXXf m(2,2); + Eigen::ArrayXXf m(2,2); // assign some values coefficient by coefficient m(0,0) = 1.0; m(0,1) = 2.0; m(1,0) = 3.0; m(1,1) = m(0,1) + m(1,0); // print values to standard output - cout << m << endl << endl; + std::cout << m << std::endl << std::endl; // using the comma-initializer is also allowed m << 1.0,2.0, 3.0,4.0; // print values to standard output - cout << m << endl; + std::cout << m << std::endl; } diff --git a/doc/examples/Tutorial_ArrayClass_addition.cpp b/doc/examples/Tutorial_ArrayClass_addition.cpp index 480ffb00f..4a407a77b 100644 --- a/doc/examples/Tutorial_ArrayClass_addition.cpp +++ b/doc/examples/Tutorial_ArrayClass_addition.cpp @@ -1,13 +1,10 @@ #include #include -using namespace Eigen; -using namespace std; - int main() { - ArrayXXf a(3,3); - ArrayXXf b(3,3); + Eigen::ArrayXXf a(3,3); + Eigen::ArrayXXf b(3,3); a << 1,2,3, 4,5,6, 7,8,9; @@ -16,8 +13,8 @@ int main() 1,2,3; // Adding two arrays - cout << "a + b = " << endl << a + b << endl << endl; + std::cout << "a + b = " << std::endl << a + b << std::endl << std::endl; // Subtracting a scalar from an array - cout << "a - 2 = " << endl << a - 2 << endl; + std::cout << "a - 2 = " << std::endl << a - 2 << std::endl; } diff --git a/doc/examples/Tutorial_ArrayClass_cwise_other.cpp b/doc/examples/Tutorial_ArrayClass_cwise_other.cpp index d9046c63d..12483f363 100644 --- a/doc/examples/Tutorial_ArrayClass_cwise_other.cpp +++ b/doc/examples/Tutorial_ArrayClass_cwise_other.cpp @@ -1,19 +1,16 @@ #include #include -using namespace Eigen; -using namespace std; - int main() { - ArrayXf a = ArrayXf::Random(5); + Eigen::ArrayXf a = Eigen::ArrayXf::Random(5); a *= 2; - cout << "a =" << endl - << a << endl; - cout << "a.abs() =" << endl - << a.abs() << endl; - cout << "a.abs().sqrt() =" << endl - << a.abs().sqrt() << endl; - cout << "a.min(a.abs().sqrt()) =" << endl - << a.min(a.abs().sqrt()) << endl; + std::cout << "a =" << std::endl + << a << std::endl; + std::cout << "a.abs() =" << std::endl + << a.abs() << std::endl; + std::cout << "a.abs().sqrt() =" << std::endl + << a.abs().sqrt() << std::endl; + std::cout << "a.min(a.abs().sqrt()) =" << std::endl + << a.min(a.abs().sqrt()) << std::endl; } diff --git a/doc/examples/Tutorial_ArrayClass_interop.cpp b/doc/examples/Tutorial_ArrayClass_interop.cpp index 371f07068..c9a8352a1 100644 --- a/doc/examples/Tutorial_ArrayClass_interop.cpp +++ b/doc/examples/Tutorial_ArrayClass_interop.cpp @@ -1,8 +1,7 @@ #include #include -using namespace Eigen; -using namespace std; +using Eigen::MatrixXf; int main() { @@ -16,7 +15,7 @@ int main() 7,8; result = (m.array() + 4).matrix() * m; - cout << "-- Combination 1: --" << endl << result << endl << endl; + std::cout << "-- Combination 1: --\n" << result << "\n\n"; result = (m.array() * n.array()).matrix() * m; - cout << "-- Combination 2: --" << endl << result << endl << endl; + std::cout << "-- Combination 2: --\n" << result << "\n\n"; } diff --git a/doc/examples/Tutorial_ArrayClass_interop_matrix.cpp b/doc/examples/Tutorial_ArrayClass_interop_matrix.cpp index 101427511..07ec9b09c 100644 --- a/doc/examples/Tutorial_ArrayClass_interop_matrix.cpp +++ b/doc/examples/Tutorial_ArrayClass_interop_matrix.cpp @@ -1,8 +1,7 @@ #include #include -using namespace Eigen; -using namespace std; +using Eigen::MatrixXf; int main() { @@ -16,11 +15,11 @@ int main() 7,8; result = m * n; - cout << "-- Matrix m*n: --" << endl << result << endl << endl; + std::cout << "-- Matrix m*n: --\n" << result << "\n\n"; result = m.array() * n.array(); - cout << "-- Array m*n: --" << endl << result << endl << endl; + std::cout << "-- Array m*n: --\n" << result << "\n\n"; result = m.cwiseProduct(n); - cout << "-- With cwiseProduct: --" << endl << result << endl << endl; + std::cout << "-- With cwiseProduct: --\n" << result << "\n\n"; result = m.array() + 4; - cout << "-- Array m + 4: --" << endl << result << endl << endl; + std::cout << "-- Array m + 4: --\n" << result << "\n\n"; } diff --git a/doc/examples/Tutorial_ArrayClass_mult.cpp b/doc/examples/Tutorial_ArrayClass_mult.cpp index 6cb439ff7..bada36c8f 100644 --- a/doc/examples/Tutorial_ArrayClass_mult.cpp +++ b/doc/examples/Tutorial_ArrayClass_mult.cpp @@ -1,16 +1,13 @@ #include #include -using namespace Eigen; -using namespace std; - int main() { - ArrayXXf a(2,2); - ArrayXXf b(2,2); + Eigen::ArrayXXf a(2,2); + Eigen::ArrayXXf b(2,2); a << 1,2, 3,4; b << 5,6, 7,8; - cout << "a * b = " << endl << a * b << endl; + std::cout << "a * b = " << std::endl << a * b << std::endl; } diff --git a/doc/examples/Tutorial_BlockOperations_block_assignment.cpp b/doc/examples/Tutorial_BlockOperations_block_assignment.cpp index 0b87313a1..26ad47805 100644 --- a/doc/examples/Tutorial_BlockOperations_block_assignment.cpp +++ b/doc/examples/Tutorial_BlockOperations_block_assignment.cpp @@ -1,18 +1,15 @@ #include #include -using namespace std; -using namespace Eigen; - int main() { - Array22f m; + Eigen::Array22f m; m << 1,2, 3,4; - Array44f a = Array44f::Constant(0.6); - cout << "Here is the array a:" << endl << a << endl << endl; + Eigen::Array44f a = Eigen::Array44f::Constant(0.6); + std::cout << "Here is the array a:\n" << a << "\n\n"; a.block<2,2>(1,1) = m; - cout << "Here is now a with m copied into its central 2x2 block:" << endl << a << endl << endl; + std::cout << "Here is now a with m copied into its central 2x2 block:\n" << a << "\n\n"; a.block(0,0,2,3) = a.block(2,1,2,3); - cout << "Here is now a with bottom-right 2x3 block copied into top-left 2x3 block:" << endl << a << endl << endl; + std::cout << "Here is now a with bottom-right 2x3 block copied into top-left 2x3 block:\n" << a << "\n\n"; } diff --git a/doc/examples/Tutorial_PartialLU_solve.cpp b/doc/examples/Tutorial_PartialLU_solve.cpp index a5608792f..ca72c9965 100644 --- a/doc/examples/Tutorial_PartialLU_solve.cpp +++ b/doc/examples/Tutorial_PartialLU_solve.cpp @@ -2,17 +2,14 @@ #include #include -using namespace std; -using namespace Eigen; - int main() { - Matrix3f A; - Vector3f b; + Eigen::Matrix3f A; + Eigen::Vector3f b; A << 1,2,3, 4,5,6, 7,8,10; b << 3, 3, 4; - cout << "Here is the matrix A:" << endl << A << endl; - cout << "Here is the vector b:" << endl << b << endl; - Vector3f x = A.lu().solve(b); - cout << "The solution is:" << endl << x << endl; + std::cout << "Here is the matrix A:" << std::endl << A << std::endl; + std::cout << "Here is the vector b:" << std::endl << b << std::endl; + Eigen::Vector3f x = A.lu().solve(b); + std::cout << "The solution is:" << std::endl << x << std::endl; } diff --git a/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_broadcast_1nn.cpp b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_broadcast_1nn.cpp index 334b4d852..8ef06be5e 100644 --- a/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_broadcast_1nn.cpp +++ b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_broadcast_1nn.cpp @@ -1,9 +1,6 @@ #include #include -using namespace std; -using namespace Eigen; - int main() { Eigen::MatrixXf m(2,4); @@ -15,10 +12,10 @@ int main() v << 2, 3; - MatrixXf::Index index; + Eigen::Index index; // find nearest neighbour (m.colwise() - v).colwise().squaredNorm().minCoeff(&index); - cout << "Nearest neighbour is column " << index << ":" << endl; - cout << m.col(index) << endl; + std::cout << "Nearest neighbour is column " << index << ":" << std::endl; + std::cout << m.col(index) << std::endl; } diff --git a/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_maxnorm.cpp b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_maxnorm.cpp index 049c747b0..b5d88c3d2 100644 --- a/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_maxnorm.cpp +++ b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_maxnorm.cpp @@ -1,15 +1,13 @@ #include #include -using namespace std; -using namespace Eigen; int main() { - MatrixXf mat(2,4); + Eigen::MatrixXf mat(2,4); mat << 1, 2, 6, 9, 3, 1, 7, 2; - MatrixXf::Index maxIndex; + Eigen::Index maxIndex; float maxNorm = mat.colwise().sum().maxCoeff(&maxIndex); std::cout << "Maximum sum at position " << maxIndex << std::endl; diff --git a/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_bool.cpp b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_bool.cpp index 0cca37f36..7b89bcf37 100644 --- a/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_bool.cpp +++ b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_bool.cpp @@ -1,21 +1,18 @@ #include #include -using namespace std; -using namespace Eigen; - int main() { - ArrayXXf a(2,2); + Eigen::ArrayXXf a(2,2); a << 1,2, 3,4; - cout << "(a > 0).all() = " << (a > 0).all() << endl; - cout << "(a > 0).any() = " << (a > 0).any() << endl; - cout << "(a > 0).count() = " << (a > 0).count() << endl; - cout << endl; - cout << "(a > 2).all() = " << (a > 2).all() << endl; - cout << "(a > 2).any() = " << (a > 2).any() << endl; - cout << "(a > 2).count() = " << (a > 2).count() << endl; + std::cout << "(a > 0).all() = " << (a > 0).all() << std::endl; + std::cout << "(a > 0).any() = " << (a > 0).any() << std::endl; + std::cout << "(a > 0).count() = " << (a > 0).count() << std::endl; + std::cout << std::endl; + std::cout << "(a > 2).all() = " << (a > 2).all() << std::endl; + std::cout << "(a > 2).any() = " << (a > 2).any() << std::endl; + std::cout << "(a > 2).count() = " << (a > 2).count() << std::endl; } diff --git a/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_norm.cpp b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_norm.cpp index 740439fb3..751913700 100644 --- a/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_norm.cpp +++ b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_norm.cpp @@ -1,13 +1,10 @@ #include #include -using namespace std; -using namespace Eigen; - int main() { - VectorXf v(2); - MatrixXf m(2,2), n(2,2); + Eigen::VectorXf v(2); + Eigen::MatrixXf m(2,2), n(2,2); v << -1, 2; @@ -15,14 +12,14 @@ int main() m << 1,-2, -3,4; - cout << "v.squaredNorm() = " << v.squaredNorm() << endl; - cout << "v.norm() = " << v.norm() << endl; - cout << "v.lpNorm<1>() = " << v.lpNorm<1>() << endl; - cout << "v.lpNorm() = " << v.lpNorm() << endl; + std::cout << "v.squaredNorm() = " << v.squaredNorm() << std::endl; + std::cout << "v.norm() = " << v.norm() << std::endl; + std::cout << "v.lpNorm<1>() = " << v.lpNorm<1>() << std::endl; + std::cout << "v.lpNorm() = " << v.lpNorm() << std::endl; - cout << endl; - cout << "m.squaredNorm() = " << m.squaredNorm() << endl; - cout << "m.norm() = " << m.norm() << endl; - cout << "m.lpNorm<1>() = " << m.lpNorm<1>() << endl; - cout << "m.lpNorm() = " << m.lpNorm() << endl; + std::cout << std::endl; + std::cout << "m.squaredNorm() = " << m.squaredNorm() << std::endl; + std::cout << "m.norm() = " << m.norm() << std::endl; + std::cout << "m.lpNorm<1>() = " << m.lpNorm<1>() << std::endl; + std::cout << "m.lpNorm() = " << m.lpNorm() << std::endl; } diff --git a/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_operatornorm.cpp b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_operatornorm.cpp index 62e28fc31..8faa5a189 100644 --- a/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_operatornorm.cpp +++ b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_operatornorm.cpp @@ -1,18 +1,15 @@ #include #include -using namespace Eigen; -using namespace std; - int main() { - MatrixXf m(2,2); + Eigen::MatrixXf m(2,2); m << 1,-2, -3,4; - cout << "1-norm(m) = " << m.cwiseAbs().colwise().sum().maxCoeff() - << " == " << m.colwise().lpNorm<1>().maxCoeff() << endl; + std::cout << "1-norm(m) = " << m.cwiseAbs().colwise().sum().maxCoeff() + << " == " << m.colwise().lpNorm<1>().maxCoeff() << std::endl; - cout << "infty-norm(m) = " << m.cwiseAbs().rowwise().sum().maxCoeff() - << " == " << m.rowwise().lpNorm<1>().maxCoeff() << endl; + std::cout << "infty-norm(m) = " << m.cwiseAbs().rowwise().sum().maxCoeff() + << " == " << m.rowwise().lpNorm<1>().maxCoeff() << std::endl; } diff --git a/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_visitors.cpp b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_visitors.cpp index b54e9aa31..bd294bdf7 100644 --- a/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_visitors.cpp +++ b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_visitors.cpp @@ -1,9 +1,6 @@ #include #include -using namespace std; -using namespace Eigen; - int main() { Eigen::MatrixXf m(2,2); @@ -12,15 +9,15 @@ int main() 3, 4; //get location of maximum - MatrixXf::Index maxRow, maxCol; + Eigen::Index maxRow, maxCol; float max = m.maxCoeff(&maxRow, &maxCol); //get location of minimum - MatrixXf::Index minRow, minCol; + Eigen::Index minRow, minCol; float min = m.minCoeff(&minRow, &minCol); - cout << "Max: " << max << ", at: " << - maxRow << "," << maxCol << endl; - cout << "Min: " << min << ", at: " << - minRow << "," << minCol << endl; + std::cout << "Max: " << max << ", at: " << + maxRow << "," << maxCol << std::endl; + std:: cout << "Min: " << min << ", at: " << + minRow << "," << minCol << std::endl; } diff --git a/doc/examples/Tutorial_simple_example_dynamic_size.cpp b/doc/examples/Tutorial_simple_example_dynamic_size.cpp index defcb1ee4..796bd8735 100644 --- a/doc/examples/Tutorial_simple_example_dynamic_size.cpp +++ b/doc/examples/Tutorial_simple_example_dynamic_size.cpp @@ -1,13 +1,11 @@ #include #include -using namespace Eigen; - int main() { for (int size=1; size<=4; ++size) { - MatrixXi m(size,size+1); // a (size)x(size+1)-matrix of int's + Eigen::MatrixXi m(size,size+1); // a (size)x(size+1)-matrix of int's for (int j=0; j #include -using namespace Eigen; - int main() { - Matrix3f m3; + Eigen::Matrix3f m3; m3 << 1, 2, 3, 4, 5, 6, 7, 8, 9; - Matrix4f m4 = Matrix4f::Identity(); - Vector4i v4(1, 2, 3, 4); + Eigen::Matrix4f m4 = Eigen::Matrix4f::Identity(); + Eigen::Vector4i v4(1, 2, 3, 4); std::cout << "m3\n" << m3 << "\nm4:\n" << m4 << "\nv4:\n" << v4 << std::endl; diff --git a/doc/examples/class_Block.cpp b/doc/examples/class_Block.cpp index ace719afc..9ace0da4e 100644 --- a/doc/examples/class_Block.cpp +++ b/doc/examples/class_Block.cpp @@ -1,27 +1,25 @@ #include #include -using namespace Eigen; -using namespace std; template Eigen::Block -topLeftCorner(MatrixBase& m, int rows, int cols) +topLeftCorner(Eigen::MatrixBase& m, int rows, int cols) { return Eigen::Block(m.derived(), 0, 0, rows, cols); } template const Eigen::Block -topLeftCorner(const MatrixBase& m, int rows, int cols) +topLeftCorner(const Eigen::MatrixBase& m, int rows, int cols) { return Eigen::Block(m.derived(), 0, 0, rows, cols); } int main(int, char**) { - Matrix4d m = Matrix4d::Identity(); - cout << topLeftCorner(4*m, 2, 3) << endl; // calls the const version + Eigen::Matrix4d m = Eigen::Matrix4d::Identity(); + std::cout << topLeftCorner(4*m, 2, 3) << std::endl; // calls the const version topLeftCorner(m, 2, 3) *= 5; // calls the non-const version - cout << "Now the matrix m is:" << endl << m << endl; + std::cout << "Now the matrix m is:" << std::endl << m << std::endl; return 0; } diff --git a/doc/examples/class_CwiseBinaryOp.cpp b/doc/examples/class_CwiseBinaryOp.cpp index 682af46de..aec926dce 100644 --- a/doc/examples/class_CwiseBinaryOp.cpp +++ b/doc/examples/class_CwiseBinaryOp.cpp @@ -1,18 +1,18 @@ #include #include -using namespace Eigen; -using namespace std; + +using Eigen::Matrix4d; // define a custom template binary functor template struct MakeComplexOp { EIGEN_EMPTY_STRUCT_CTOR(MakeComplexOp) - typedef complex result_type; - complex operator()(const Scalar& a, const Scalar& b) const { return complex(a,b); } + typedef std::complex result_type; + result_type operator()(const Scalar& a, const Scalar& b) const { return result_type(a,b); } }; int main(int, char**) { Matrix4d m1 = Matrix4d::Random(), m2 = Matrix4d::Random(); - cout << m1.binaryExpr(m2, MakeComplexOp()) << endl; + std::cout << m1.binaryExpr(m2, MakeComplexOp()) << std::endl; return 0; } diff --git a/doc/examples/class_CwiseUnaryOp.cpp b/doc/examples/class_CwiseUnaryOp.cpp index a5fcc153d..6c65f2e39 100644 --- a/doc/examples/class_CwiseUnaryOp.cpp +++ b/doc/examples/class_CwiseUnaryOp.cpp @@ -1,7 +1,5 @@ #include #include -using namespace Eigen; -using namespace std; // define a custom template unary functor template @@ -13,7 +11,7 @@ struct CwiseClampOp { int main(int, char**) { - Matrix4d m1 = Matrix4d::Random(); - cout << m1 << endl << "becomes: " << endl << m1.unaryExpr(CwiseClampOp(-0.5,0.5)) << endl; + Eigen::Matrix4d m1 = Eigen::Matrix4d::Random(); + std::cout << m1 << std::endl << "becomes: " << std::endl << m1.unaryExpr(CwiseClampOp(-0.5,0.5)) << std::endl; return 0; } diff --git a/doc/examples/class_CwiseUnaryOp_ptrfun.cpp b/doc/examples/class_CwiseUnaryOp_ptrfun.cpp index 36706d8ed..e97095e79 100644 --- a/doc/examples/class_CwiseUnaryOp_ptrfun.cpp +++ b/doc/examples/class_CwiseUnaryOp_ptrfun.cpp @@ -1,7 +1,5 @@ #include #include -using namespace Eigen; -using namespace std; // define function to be applied coefficient-wise double ramp(double x) @@ -14,7 +12,7 @@ double ramp(double x) int main(int, char**) { - Matrix4d m1 = Matrix4d::Random(); - cout << m1 << endl << "becomes: " << endl << m1.unaryExpr(ptr_fun(ramp)) << endl; + Eigen::Matrix4d m1 = Eigen::Matrix4d::Random(); + std::cout << m1 << std::endl << "becomes: " << std::endl << m1.unaryExpr(std::ptr_fun(ramp)) << std::endl; return 0; } diff --git a/doc/examples/class_FixedBlock.cpp b/doc/examples/class_FixedBlock.cpp index 9978b32e8..4bb2d4419 100644 --- a/doc/examples/class_FixedBlock.cpp +++ b/doc/examples/class_FixedBlock.cpp @@ -1,27 +1,25 @@ #include #include -using namespace Eigen; -using namespace std; template Eigen::Block -topLeft2x2Corner(MatrixBase& m) +topLeft2x2Corner(Eigen::MatrixBase& m) { return Eigen::Block(m.derived(), 0, 0); } template const Eigen::Block -topLeft2x2Corner(const MatrixBase& m) +topLeft2x2Corner(const Eigen::MatrixBase& m) { return Eigen::Block(m.derived(), 0, 0); } int main(int, char**) { - Matrix3d m = Matrix3d::Identity(); - cout << topLeft2x2Corner(4*m) << endl; // calls the const version + Eigen::Matrix3d m = Eigen::Matrix3d::Identity(); + std::cout << topLeft2x2Corner(4*m) << std::endl; // calls the const version topLeft2x2Corner(m) *= 2; // calls the non-const version - cout << "Now the matrix m is:" << endl << m << endl; + std::cout << "Now the matrix m is:" << std::endl << m << std::endl; return 0; } diff --git a/doc/examples/class_FixedReshaped.cpp b/doc/examples/class_FixedReshaped.cpp index b6d4085de..be7069d1d 100644 --- a/doc/examples/class_FixedReshaped.cpp +++ b/doc/examples/class_FixedReshaped.cpp @@ -1,22 +1,20 @@ #include #include -using namespace Eigen; -using namespace std; template Eigen::Reshaped -reshape_helper(MatrixBase& m) +reshape_helper(Eigen::MatrixBase& m) { return Eigen::Reshaped(m.derived()); } int main(int, char**) { - MatrixXd m(2, 4); + Eigen::MatrixXd m(2, 4); m << 1, 2, 3, 4, 5, 6, 7, 8; - MatrixXd n = reshape_helper(m); - cout << "matrix m is:" << endl << m << endl; - cout << "matrix n is:" << endl << n << endl; + Eigen::MatrixXd n = reshape_helper(m); + std::cout << "matrix m is:" << std::endl << m << std::endl; + std::cout << "matrix n is:" << std::endl << n << std::endl; return 0; } diff --git a/doc/examples/class_FixedVectorBlock.cpp b/doc/examples/class_FixedVectorBlock.cpp index c88c9fbf1..eed300741 100644 --- a/doc/examples/class_FixedVectorBlock.cpp +++ b/doc/examples/class_FixedVectorBlock.cpp @@ -1,27 +1,25 @@ #include #include -using namespace Eigen; -using namespace std; template Eigen::VectorBlock -firstTwo(MatrixBase& v) +firstTwo(Eigen::MatrixBase& v) { return Eigen::VectorBlock(v.derived(), 0); } template const Eigen::VectorBlock -firstTwo(const MatrixBase& v) +firstTwo(const Eigen::MatrixBase& v) { return Eigen::VectorBlock(v.derived(), 0); } int main(int, char**) { - Matrix v; v << 1,2,3,4,5,6; - cout << firstTwo(4*v) << endl; // calls the const version + Eigen::Matrix v; v << 1,2,3,4,5,6; + std::cout << firstTwo(4*v) << std::endl; // calls the const version firstTwo(v) *= 2; // calls the non-const version - cout << "Now the vector v is:" << endl << v << endl; + std::cout << "Now the vector v is:" << std::endl << v << std::endl; return 0; } diff --git a/doc/examples/class_Reshaped.cpp b/doc/examples/class_Reshaped.cpp index 18fb45454..721985355 100644 --- a/doc/examples/class_Reshaped.cpp +++ b/doc/examples/class_Reshaped.cpp @@ -1,23 +1,21 @@ #include #include -using namespace std; -using namespace Eigen; template -const Reshaped -reshape_helper(const MatrixBase& m, int rows, int cols) +const Eigen::Reshaped +reshape_helper(const Eigen::MatrixBase& m, int rows, int cols) { - return Reshaped(m.derived(), rows, cols); + return Eigen::Reshaped(m.derived(), rows, cols); } int main(int, char**) { - MatrixXd m(3, 4); + Eigen::MatrixXd m(3, 4); m << 1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12; - cout << m << endl; - Ref n = reshape_helper(m, 2, 6); - cout << "Matrix m is:" << endl << m << endl; - cout << "Matrix n is:" << endl << n << endl; + std::cout << m << std::endl; + Eigen::Ref n = reshape_helper(m, 2, 6); + std::cout << "Matrix m is:" << std::endl << m << std::endl; + std::cout << "Matrix n is:" << std::endl << n << std::endl; } diff --git a/doc/examples/class_VectorBlock.cpp b/doc/examples/class_VectorBlock.cpp index dc213df20..5cee147e3 100644 --- a/doc/examples/class_VectorBlock.cpp +++ b/doc/examples/class_VectorBlock.cpp @@ -1,27 +1,25 @@ #include #include -using namespace Eigen; -using namespace std; template Eigen::VectorBlock -segmentFromRange(MatrixBase& v, int start, int end) +segmentFromRange(Eigen::MatrixBase& v, int start, int end) { return Eigen::VectorBlock(v.derived(), start, end-start); } template const Eigen::VectorBlock -segmentFromRange(const MatrixBase& v, int start, int end) +segmentFromRange(const Eigen::MatrixBase& v, int start, int end) { return Eigen::VectorBlock(v.derived(), start, end-start); } int main(int, char**) { - Matrix v; v << 1,2,3,4,5,6; - cout << segmentFromRange(2*v, 2, 4) << endl; // calls the const version + Eigen::Matrix v; v << 1,2,3,4,5,6; + std::cout << segmentFromRange(2*v, 2, 4) << std::endl; // calls the const version segmentFromRange(v, 1, 3) *= 5; // calls the non-const version - cout << "Now the vector v is:" << endl << v << endl; + std::cout << "Now the vector v is:" << std::endl << v << std::endl; return 0; } diff --git a/doc/examples/function_taking_eigenbase.cpp b/doc/examples/function_taking_eigenbase.cpp index 49d94b3d6..4e1e5a94f 100644 --- a/doc/examples/function_taking_eigenbase.cpp +++ b/doc/examples/function_taking_eigenbase.cpp @@ -1,9 +1,8 @@ #include #include -using namespace Eigen; template -void print_size(const EigenBase& b) +void print_size(const Eigen::EigenBase& b) { std::cout << "size (rows, cols): " << b.size() << " (" << b.rows() << ", " << b.cols() << ")" << std::endl; @@ -11,7 +10,7 @@ void print_size(const EigenBase& b) int main() { - Vector3f v; + Eigen::Vector3f v; print_size(v); // v.asDiagonal() returns a 3x3 diagonal matrix pseudo-expression print_size(v.asDiagonal()); diff --git a/doc/examples/function_taking_ref.cpp b/doc/examples/function_taking_ref.cpp index 162a202e4..a837e1915 100644 --- a/doc/examples/function_taking_ref.cpp +++ b/doc/examples/function_taking_ref.cpp @@ -1,19 +1,17 @@ #include #include -using namespace Eigen; -using namespace std; -float inv_cond(const Ref& a) +float inv_cond(const Eigen::Ref& a) { - const VectorXf sing_vals = a.jacobiSvd().singularValues(); + const Eigen::VectorXf sing_vals = a.jacobiSvd().singularValues(); return sing_vals(sing_vals.size()-1) / sing_vals(0); } int main() { - Matrix4f m = Matrix4f::Random(); - cout << "matrix m:" << endl << m << endl << endl; - cout << "inv_cond(m): " << inv_cond(m) << endl; - cout << "inv_cond(m(1:3,1:3)): " << inv_cond(m.topLeftCorner(3,3)) << endl; - cout << "inv_cond(m+I): " << inv_cond(m+Matrix4f::Identity()) << endl; + Eigen::MatrixXf m = Eigen::MatrixXf::Random(4, 4); + std::cout << "matrix m:\n" << m << "\n\n"; + std::cout << "inv_cond(m): " << inv_cond(m) << "\n"; + std::cout << "inv_cond(m(1:3,1:3)): " << inv_cond(m.topLeftCorner(3,3)) << "\n"; + std::cout << "inv_cond(m+I): " << inv_cond(m+Eigen::MatrixXf::Identity(4, 4)) << "\n"; } diff --git a/doc/examples/make_circulant2.cpp b/doc/examples/make_circulant2.cpp index 95d3dd31a..d86a66bcc 100644 --- a/doc/examples/make_circulant2.cpp +++ b/doc/examples/make_circulant2.cpp @@ -1,8 +1,6 @@ #include #include -using namespace Eigen; - // [circulant_func] template class circulant_functor { @@ -10,8 +8,8 @@ class circulant_functor { public: circulant_functor(const ArgType& arg) : m_vec(arg) {} - const typename ArgType::Scalar& operator() (Index row, Index col) const { - Index index = row - col; + const typename ArgType::Scalar& operator() (Eigen::Index row, Eigen::Index col) const { + Eigen::Index index = row - col; if (index < 0) index += m_vec.size(); return m_vec(index); } @@ -21,10 +19,10 @@ public: // [square] template struct circulant_helper { - typedef Matrix MatrixType; }; @@ -32,7 +30,7 @@ struct circulant_helper { // [makeCirculant] template -CwiseNullaryOp, typename circulant_helper::MatrixType> +Eigen::CwiseNullaryOp, typename circulant_helper::MatrixType> makeCirculant(const Eigen::MatrixBase& arg) { typedef typename circulant_helper::MatrixType MatrixType; diff --git a/doc/examples/nullary_indexing.cpp b/doc/examples/nullary_indexing.cpp index f710c84cc..38260afb9 100644 --- a/doc/examples/nullary_indexing.cpp +++ b/doc/examples/nullary_indexing.cpp @@ -1,8 +1,6 @@ #include #include -using namespace Eigen; - // [functor] template class indexing_functor { @@ -10,10 +8,10 @@ class indexing_functor { const RowIndexType &m_rowIndices; const ColIndexType &m_colIndices; public: - typedef Matrix MatrixType; @@ -21,7 +19,7 @@ public: : m_arg(arg), m_rowIndices(row_indices), m_colIndices(col_indices) {} - const typename ArgType::Scalar& operator() (Index row, Index col) const { + const typename ArgType::Scalar& operator() (Eigen::Index row, Eigen::Index col) const { return m_arg(m_rowIndices[row], m_colIndices[col]); } }; @@ -29,7 +27,7 @@ public: // [function] template -CwiseNullaryOp, typename indexing_functor::MatrixType> +Eigen::CwiseNullaryOp, typename indexing_functor::MatrixType> mat_indexing(const Eigen::MatrixBase& arg, const RowIndexType& row_indices, const ColIndexType& col_indices) { typedef indexing_functor Func; @@ -43,8 +41,8 @@ int main() { std::cout << "[main1]\n"; Eigen::MatrixXi A = Eigen::MatrixXi::Random(4,4); - Array3i ri(1,2,1); - ArrayXi ci(6); ci << 3,2,1,0,0,2; + Eigen::Array3i ri(1,2,1); + Eigen::ArrayXi ci(6); ci << 3,2,1,0,0,2; Eigen::MatrixXi B = mat_indexing(A, ri, ci); std::cout << "A =" << std::endl; std::cout << A << std::endl << std::endl; @@ -56,7 +54,7 @@ int main() B = mat_indexing(A, ri+1, ci); std::cout << "A(ri+1,ci) =" << std::endl; std::cout << B << std::endl << std::endl; - B = mat_indexing(A, ArrayXi::LinSpaced(13,0,12).unaryExpr([](int x){return x%4;}), ArrayXi::LinSpaced(4,0,3)); + B = mat_indexing(A, Eigen::ArrayXi::LinSpaced(13,0,12).unaryExpr([](int x){return x%4;}), Eigen::ArrayXi::LinSpaced(4,0,3)); std::cout << "A(ArrayXi::LinSpaced(13,0,12).unaryExpr([](int x){return x%4;}), ArrayXi::LinSpaced(4,0,3)) =" << std::endl; std::cout << B << std::endl << std::endl; std::cout << "[main2]\n"; diff --git a/doc/examples/tut_arithmetic_add_sub.cpp b/doc/examples/tut_arithmetic_add_sub.cpp index e97477b6e..95162c0a1 100644 --- a/doc/examples/tut_arithmetic_add_sub.cpp +++ b/doc/examples/tut_arithmetic_add_sub.cpp @@ -1,14 +1,12 @@ #include #include -using namespace Eigen; - int main() { - Matrix2d a; + Eigen::Matrix2d a; a << 1, 2, 3, 4; - MatrixXd b(2,2); + Eigen::MatrixXd b(2,2); b << 2, 3, 1, 4; std::cout << "a + b =\n" << a + b << std::endl; @@ -16,7 +14,7 @@ int main() std::cout << "Doing a += b;" << std::endl; a += b; std::cout << "Now a =\n" << a << std::endl; - Vector3d v(1,2,3); - Vector3d w(1,0,0); + Eigen::Vector3d v(1,2,3); + Eigen::Vector3d w(1,0,0); std::cout << "-v + w - v =\n" << -v + w - v << std::endl; } diff --git a/doc/examples/tut_arithmetic_dot_cross.cpp b/doc/examples/tut_arithmetic_dot_cross.cpp index 631c9a5e0..5b0fd1eb2 100644 --- a/doc/examples/tut_arithmetic_dot_cross.cpp +++ b/doc/examples/tut_arithmetic_dot_cross.cpp @@ -1,15 +1,13 @@ #include #include -using namespace Eigen; -using namespace std; int main() { - Vector3d v(1,2,3); - Vector3d w(0,1,2); + Eigen::Vector3d v(1,2,3); + Eigen::Vector3d w(0,1,2); - cout << "Dot product: " << v.dot(w) << endl; + std::cout << "Dot product: " << v.dot(w) << std::endl; double dp = v.adjoint()*w; // automatic conversion of the inner product to a scalar - cout << "Dot product via a matrix product: " << dp << endl; - cout << "Cross product:\n" << v.cross(w) << endl; + std::cout << "Dot product via a matrix product: " << dp << std::endl; + std::cout << "Cross product:\n" << v.cross(w) << std::endl; } diff --git a/doc/examples/tut_arithmetic_matrix_mul.cpp b/doc/examples/tut_arithmetic_matrix_mul.cpp index f21390241..c2d5e2d18 100644 --- a/doc/examples/tut_arithmetic_matrix_mul.cpp +++ b/doc/examples/tut_arithmetic_matrix_mul.cpp @@ -1,13 +1,12 @@ #include #include -using namespace Eigen; int main() { - Matrix2d mat; + Eigen::Matrix2d mat; mat << 1, 2, 3, 4; - Vector2d u(-1,1), v(2,0); + Eigen::Vector2d u(-1,1), v(2,0); std::cout << "Here is mat*mat:\n" << mat*mat << std::endl; std::cout << "Here is mat*u:\n" << mat*u << std::endl; std::cout << "Here is u^T*mat:\n" << u.transpose()*mat << std::endl; diff --git a/doc/examples/tut_arithmetic_scalar_mul_div.cpp b/doc/examples/tut_arithmetic_scalar_mul_div.cpp index d5f65b53e..0ba8d6b08 100644 --- a/doc/examples/tut_arithmetic_scalar_mul_div.cpp +++ b/doc/examples/tut_arithmetic_scalar_mul_div.cpp @@ -1,14 +1,12 @@ #include #include -using namespace Eigen; - int main() { - Matrix2d a; + Eigen::Matrix2d a; a << 1, 2, 3, 4; - Vector3d v(1,2,3); + Eigen::Vector3d v(1,2,3); std::cout << "a * 2.5 =\n" << a * 2.5 << std::endl; std::cout << "0.1 * v =\n" << 0.1 * v << std::endl; std::cout << "Doing v *= 2;" << std::endl; diff --git a/doc/examples/tut_matrix_coefficient_accessors.cpp b/doc/examples/tut_matrix_coefficient_accessors.cpp index c2da17158..040087cdd 100644 --- a/doc/examples/tut_matrix_coefficient_accessors.cpp +++ b/doc/examples/tut_matrix_coefficient_accessors.cpp @@ -1,17 +1,15 @@ #include #include -using namespace Eigen; - int main() { - MatrixXd m(2,2); + Eigen::MatrixXd m(2,2); m(0,0) = 3; m(1,0) = 2.5; m(0,1) = -1; m(1,1) = m(1,0) + m(0,1); std::cout << "Here is the matrix m:\n" << m << std::endl; - VectorXd v(2); + Eigen::VectorXd v(2); v(0) = 4; v(1) = v(0) - 1; std::cout << "Here is the vector v:\n" << v << std::endl; diff --git a/doc/examples/tut_matrix_resize.cpp b/doc/examples/tut_matrix_resize.cpp index 0392c3aa5..aa80cf5ee 100644 --- a/doc/examples/tut_matrix_resize.cpp +++ b/doc/examples/tut_matrix_resize.cpp @@ -1,16 +1,14 @@ #include #include -using namespace Eigen; - int main() { - MatrixXd m(2,5); + Eigen::MatrixXd m(2,5); m.resize(4,3); std::cout << "The matrix m is of size " << m.rows() << "x" << m.cols() << std::endl; std::cout << "It has " << m.size() << " coefficients" << std::endl; - VectorXd v(2); + Eigen::VectorXd v(2); v.resize(5); std::cout << "The vector v is of size " << v.size() << std::endl; std::cout << "As a matrix, v is of size " diff --git a/doc/examples/tut_matrix_resize_fixed_size.cpp b/doc/examples/tut_matrix_resize_fixed_size.cpp index dcbdfa783..3df87d2b0 100644 --- a/doc/examples/tut_matrix_resize_fixed_size.cpp +++ b/doc/examples/tut_matrix_resize_fixed_size.cpp @@ -1,11 +1,9 @@ #include #include -using namespace Eigen; - int main() { - Matrix4d m; + Eigen::Matrix4d m; m.resize(4,4); // no operation std::cout << "The matrix m is of size " << m.rows() << "x" << m.cols() << std::endl; diff --git a/doc/special_examples/random_cpp11.cpp b/doc/special_examples/random_cpp11.cpp index 33744c051..bd73800a0 100644 --- a/doc/special_examples/random_cpp11.cpp +++ b/doc/special_examples/random_cpp11.cpp @@ -2,13 +2,11 @@ #include #include -using namespace Eigen; - int main() { std::default_random_engine generator; std::poisson_distribution distribution(4.1); auto poisson = [&] () {return distribution(generator);}; - RowVectorXi v = RowVectorXi::NullaryExpr(10, poisson ); + Eigen::RowVectorXi v = Eigen::RowVectorXi::NullaryExpr(10, poisson ); std::cout << v << "\n"; }