From abbe260905e96b9323cb5cf4ab9189a3292bf585 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Thu, 22 Apr 2010 18:27:13 -0400 Subject: [PATCH] remove USING_PART_OF_NAMESPACE_EIGEN, leaving it in Eigen2Support. improve porting-Eigen2-to-3 docs --- Eigen/Eigen2Support | 16 ++ Eigen/src/Core/util/Macros.h | 16 -- bench/BenchSparseUtil.h | 2 +- bench/BenchUtil.h | 2 +- bench/bench_sum.cpp | 2 +- bench/benchmark.cpp | 2 +- bench/benchmarkSlice.cpp | 2 +- bench/benchmarkX.cpp | 2 +- bench/benchmarkXcwise.cpp | 2 +- bench/vdw_new.cpp | 2 +- disabled/class_Eval.cpp | 2 +- disabled/ompbenchmark.cpp | 2 +- doc/A05_PortingFrom2To3.dox | 142 ++++++++++-------- doc/example.cpp | 26 ---- .../Tutorial_simple_example_dynamic_size.cpp | 3 +- .../Tutorial_simple_example_fixed_size.cpp | 3 +- doc/examples/class_Block.cpp | 2 +- doc/examples/class_CwiseBinaryOp.cpp | 2 +- doc/examples/class_CwiseUnaryOp.cpp | 2 +- doc/examples/class_FixedBlock.cpp | 2 +- doc/examples/class_FixedVectorBlock.cpp | 2 +- doc/examples/class_VectorBlock.cpp | 2 +- 22 files changed, 114 insertions(+), 124 deletions(-) delete mode 100644 doc/example.cpp diff --git a/Eigen/Eigen2Support b/Eigen/Eigen2Support index 075985af1..b876cc4c3 100644 --- a/Eigen/Eigen2Support +++ b/Eigen/Eigen2Support @@ -58,4 +58,20 @@ namespace Eigen { // Eigen2 used to include iostream #include +#define USING_PART_OF_NAMESPACE_EIGEN \ +EIGEN_USING_MATRIX_TYPEDEFS \ +using Eigen::Matrix; \ +using Eigen::MatrixBase; \ +using Eigen::ei_random; \ +using Eigen::ei_real; \ +using Eigen::ei_imag; \ +using Eigen::ei_conj; \ +using Eigen::ei_abs; \ +using Eigen::ei_abs2; \ +using Eigen::ei_sqrt; \ +using Eigen::ei_exp; \ +using Eigen::ei_log; \ +using Eigen::ei_sin; \ +using Eigen::ei_cos; + #endif // EIGEN2SUPPORT_H diff --git a/Eigen/src/Core/util/Macros.h b/Eigen/src/Core/util/Macros.h index 73e733cb3..787182444 100644 --- a/Eigen/src/Core/util/Macros.h +++ b/Eigen/src/Core/util/Macros.h @@ -105,22 +105,6 @@ #define EIGEN_DEBUG_VAR(x) std::cerr << #x << " = " << x << std::endl; -#define USING_PART_OF_NAMESPACE_EIGEN \ -EIGEN_USING_MATRIX_TYPEDEFS \ -using Eigen::Matrix; \ -using Eigen::MatrixBase; \ -using Eigen::ei_random; \ -using Eigen::ei_real; \ -using Eigen::ei_imag; \ -using Eigen::ei_conj; \ -using Eigen::ei_abs; \ -using Eigen::ei_abs2; \ -using Eigen::ei_sqrt; \ -using Eigen::ei_exp; \ -using Eigen::ei_log; \ -using Eigen::ei_sin; \ -using Eigen::ei_cos; - #ifdef NDEBUG # ifndef EIGEN_NO_DEBUG # define EIGEN_NO_DEBUG diff --git a/bench/BenchSparseUtil.h b/bench/BenchSparseUtil.h index a5ab10711..82c3b8701 100644 --- a/bench/BenchSparseUtil.h +++ b/bench/BenchSparseUtil.h @@ -6,7 +6,7 @@ using namespace std; using namespace Eigen; -USING_PART_OF_NAMESPACE_EIGEN +using namespace Eigen; #ifndef SIZE #define SIZE 1024 diff --git a/bench/BenchUtil.h b/bench/BenchUtil.h index a7535771e..9798fa385 100644 --- a/bench/BenchUtil.h +++ b/bench/BenchUtil.h @@ -6,7 +6,7 @@ #include "BenchTimer.h" using namespace std; -USING_PART_OF_NAMESPACE_EIGEN +using namespace Eigen; #include #include diff --git a/bench/bench_sum.cpp b/bench/bench_sum.cpp index 82bae80c3..0e16a8eea 100644 --- a/bench/bench_sum.cpp +++ b/bench/bench_sum.cpp @@ -1,5 +1,5 @@ #include -USING_PART_OF_NAMESPACE_EIGEN +using namespace Eigen; using namespace std; int main() diff --git a/bench/benchmark.cpp b/bench/benchmark.cpp index 90e04dd3b..971de4961 100644 --- a/bench/benchmark.cpp +++ b/bench/benchmark.cpp @@ -6,7 +6,7 @@ #endif using namespace std; -USING_PART_OF_NAMESPACE_EIGEN +using namespace Eigen; #ifndef REPEAT #define REPEAT 40000000 diff --git a/bench/benchmarkSlice.cpp b/bench/benchmarkSlice.cpp index 5595d0ae6..8c3d4dd10 100644 --- a/bench/benchmarkSlice.cpp +++ b/bench/benchmarkSlice.cpp @@ -3,7 +3,7 @@ #include using namespace std; -USING_PART_OF_NAMESPACE_EIGEN +using namespace Eigen; #ifndef REPEAT #define REPEAT 10000 diff --git a/bench/benchmarkX.cpp b/bench/benchmarkX.cpp index 18152e9e3..89452b435 100644 --- a/bench/benchmarkX.cpp +++ b/bench/benchmarkX.cpp @@ -2,7 +2,7 @@ #include using namespace std; -USING_PART_OF_NAMESPACE_EIGEN +using namespace Eigen; #ifndef MATTYPE #define MATTYPE MatrixXLd diff --git a/bench/benchmarkXcwise.cpp b/bench/benchmarkXcwise.cpp index bc9b8e716..6a487b409 100644 --- a/bench/benchmarkXcwise.cpp +++ b/bench/benchmarkXcwise.cpp @@ -3,7 +3,7 @@ #include using namespace std; -USING_PART_OF_NAMESPACE_EIGEN +using namespace Eigen; #ifndef VECTYPE #define VECTYPE VectorXLd diff --git a/bench/vdw_new.cpp b/bench/vdw_new.cpp index a1bd422ae..b7f74a68f 100644 --- a/bench/vdw_new.cpp +++ b/bench/vdw_new.cpp @@ -1,6 +1,6 @@ #include -USING_PART_OF_NAMESPACE_EIGEN +using namespace Eigen; #ifndef SCALAR #define SCALAR float diff --git a/disabled/class_Eval.cpp b/disabled/class_Eval.cpp index ee6ee89d1..ceb76897c 100644 --- a/disabled/class_Eval.cpp +++ b/disabled/class_Eval.cpp @@ -1,5 +1,5 @@ #include -USING_PART_OF_NAMESPACE_EIGEN +using namespace Eigen; using namespace std; template diff --git a/disabled/ompbenchmark.cpp b/disabled/ompbenchmark.cpp index 704375b0d..2e996f2e3 100644 --- a/disabled/ompbenchmark.cpp +++ b/disabled/ompbenchmark.cpp @@ -9,7 +9,7 @@ // #include "BenchTimer.h" // // using namespace std; -// USING_PART_OF_NAMESPACE_EIGEN +// using namespace Eigen; // // enum {LazyEval, EarlyEval, OmpEval}; // diff --git a/doc/A05_PortingFrom2To3.dox b/doc/A05_PortingFrom2To3.dox index 554ca7f2c..d1acb055f 100644 --- a/doc/A05_PortingFrom2To3.dox +++ b/doc/A05_PortingFrom2To3.dox @@ -7,82 +7,37 @@ and to help porting an application from Eigen2 to Eigen3. \b Table \b of \b contents - \ref CompatibilitySupport - - \ref ChangeList + - \ref VectorBlocks + - \ref TriangularViews + - \ref TriangularSolveInPlace + - \ref Using - \ref CoefficientWiseOperations - \ref Corners - \ref LazyVsNoalias \section CompatibilitySupport Eigen2 compatibility support -In order to ease the switch from Eigen2 to Eigen3, Eigen3 features a compatibility mode which can be enabled by defining the EIGEN2_SUPPORT preprocessor token \b before including any Eigen's header (typically it should be set in your project options). +In order to ease the switch from Eigen2 to Eigen3, Eigen3 features a compatibility mode which can be enabled by defining the EIGEN2_SUPPORT preprocessor token \b before including any Eigen header (typically it should be set in your project options). -\section ChangeList List of changes in the API +\section VectorBlocks Vector blocks - + - - - - - - - - - +vector.head(length) +vector.head() +vector.tail(length) +vector.tail() +\endcode
Eigen 2Eigen 3Comments
Eigen 2Eigen 3
\code -vec.start(length) -vec.start() -vec.end(length) -vec.end() +vector.start(length) +vector.start() +vector.end(length) +vector.end() \endcode\code -vec.head(length) -vec.head() -vec.tail(length) -vec.tail() -\endcodeTrivial "search and replace".
\code mat.cwise().XXX()\endcode\code mat.array().XXX()\endcodeSee \ref CoefficientWiseOperations.
\code c = (a * b).lazy();\endcode\code c.noalias() = a * b;\endcodeSee \ref LazyVsNoalias.
\code A.triangularSolveInPlace(X);\endcode\code A.triangularView().solveInPlace(X);\endcode
\code -UpperTriangular -LowerTriangular -UnitUpperTriangular -UnitLowerTriangular -StrictlyUpperTriangular -StrictlyLowerTriangular -\endcode\code -Upper -Lower -UnitUpper -UnitLower -StrictlyUpper -StrictlyLower -\endcodeTrivial "search and replace".
-\section CoefficientWiseOperations Coefficient wise operations -In Eigen2, coefficient wise operations which have no proper mathematical definition (as a coefficient wise product) -were achieved using the .cwise() prefix, e.g.: -\code a.cwise() * b \endcode -In Eigen3 this .cwise() prefix has been superseded by a new kind of matrix type called -Array for which all operations are performed coefficient wise. You can easily view a matrix as an array and vice versa using -the MatrixBase::array() and ArrayBase::matrix() functions respectively. Here is an example: -\code -Vector4f a, b, c; -c = a.array() * b.array(); -\endcode -Note that the .array() function is not at all a synonym of the deprecated .cwise() prefix. -While the .cwise() prefix changed the behavior of the following operator, the array() function performs -a permanent conversion to the array world. Therefore, for binary operations such as the coefficient wise product, -both sides must be converted to an \em array as in the above example. On the other hand, when you -concatenate multiple coefficient wise operations you only have to do the conversion once, e.g.: -\code -Vector4f a, b, c; -c = a.array().abs().pow(3) * b.array().abs().sin(); -\endcode -With Eigen2 you would have written: -\code -c = (a.cwise().abs().cwise().pow(3)).cwise() * (b.cwise().abs().cwise().sin()); -\endcode - -\section Corners Corners +\section Corners Matrix Corners @@ -110,6 +65,69 @@ matrix.bottomRightCorner() Notice that Eigen3 also provides these new convenience methods: topRows(), bottomRows(), leftCols(), rightCols(). See in class DenseBase. + +\section TriangularViews Triangular views + +TODO: fill this section + +\section TriangularSolveInPlace Triangular in-place solving + +
Eigen 2Eigen 3
+ + + + + +
Eigen 2Eigen 3
\code A.triangularSolveInPlace(X);\endcode\code A.triangularView().solveInPlace(X);\endcode
\code +UpperTriangular +LowerTriangular +UnitUpperTriangular +UnitLowerTriangular +StrictlyUpperTriangular +StrictlyLowerTriangular +\endcode\code +Upper +Lower +UnitUpper +UnitLower +StrictlyUpper +StrictlyLower +\endcode
+ +\section Using The USING_PART_OF_NAMESPACE_EIGEN macro + +The USING_PART_OF_NAMESPACE_EIGEN macro has been removed. In Eigen 3, just do: +\code +using namespace Eigen; +\endcode + + +\section CoefficientWiseOperations Coefficient wise operations + +In Eigen2, coefficient wise operations which have no proper mathematical definition (as a coefficient wise product) +were achieved using the .cwise() prefix, e.g.: +\code a.cwise() * b \endcode +In Eigen3 this .cwise() prefix has been superseded by a new kind of matrix type called +Array for which all operations are performed coefficient wise. You can easily view a matrix as an array and vice versa using +the MatrixBase::array() and ArrayBase::matrix() functions respectively. Here is an example: +\code +Vector4f a, b, c; +c = a.array() * b.array(); +\endcode +Note that the .array() function is not at all a synonym of the deprecated .cwise() prefix. +While the .cwise() prefix changed the behavior of the following operator, the array() function performs +a permanent conversion to the array world. Therefore, for binary operations such as the coefficient wise product, +both sides must be converted to an \em array as in the above example. On the other hand, when you +concatenate multiple coefficient wise operations you only have to do the conversion once, e.g.: +\code +Vector4f a, b, c; +c = a.array().abs().pow(3) * b.array().abs().sin(); +\endcode +With Eigen2 you would have written: +\code +c = (a.cwise().abs().cwise().pow(3)).cwise() * (b.cwise().abs().cwise().sin()); +\endcode + \section LazyVsNoalias Lazy evaluation and noalias In Eigen all operations are performed in a lazy fashion except the matrix products which are always evaluated into a temporary by default. diff --git a/doc/example.cpp b/doc/example.cpp deleted file mode 100644 index 23893488a..000000000 --- a/doc/example.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include - -USING_PART_OF_NAMESPACE_EIGEN - -using namespace std; - -template -void foo(const MatrixBase& m) -{ - cout << "Here's m:" << endl << m << endl; -} - -template -Eigen::ScalarMultiple -twice(const MatrixBase& m) -{ - return 2 * m; -} - -int main(int, char**) -{ - Matrix2d m = Matrix2d::random(); - foo(m); - foo(twice(m)); - return 0; -} diff --git a/doc/examples/Tutorial_simple_example_dynamic_size.cpp b/doc/examples/Tutorial_simple_example_dynamic_size.cpp index 9a0e2c3d8..d780e7326 100644 --- a/doc/examples/Tutorial_simple_example_dynamic_size.cpp +++ b/doc/examples/Tutorial_simple_example_dynamic_size.cpp @@ -1,8 +1,7 @@ #include #include -// import most common Eigen types -USING_PART_OF_NAMESPACE_EIGEN +using namespace Eigen; int main(int, char *[]) { diff --git a/doc/examples/Tutorial_simple_example_fixed_size.cpp b/doc/examples/Tutorial_simple_example_fixed_size.cpp index 586be863d..a5c856732 100644 --- a/doc/examples/Tutorial_simple_example_fixed_size.cpp +++ b/doc/examples/Tutorial_simple_example_fixed_size.cpp @@ -1,8 +1,7 @@ #include #include -// import most common Eigen types -USING_PART_OF_NAMESPACE_EIGEN +using namespace Eigen; int main(int, char *[]) { diff --git a/doc/examples/class_Block.cpp b/doc/examples/class_Block.cpp index a8e0c85a1..c6144cef5 100644 --- a/doc/examples/class_Block.cpp +++ b/doc/examples/class_Block.cpp @@ -1,6 +1,6 @@ #include #include -USING_PART_OF_NAMESPACE_EIGEN +using namespace Eigen; using namespace std; template diff --git a/doc/examples/class_CwiseBinaryOp.cpp b/doc/examples/class_CwiseBinaryOp.cpp index d26e65f23..682af46de 100644 --- a/doc/examples/class_CwiseBinaryOp.cpp +++ b/doc/examples/class_CwiseBinaryOp.cpp @@ -1,6 +1,6 @@ #include #include -USING_PART_OF_NAMESPACE_EIGEN +using namespace Eigen; using namespace std; // define a custom template binary functor diff --git a/doc/examples/class_CwiseUnaryOp.cpp b/doc/examples/class_CwiseUnaryOp.cpp index 9e22bf095..a5fcc153d 100644 --- a/doc/examples/class_CwiseUnaryOp.cpp +++ b/doc/examples/class_CwiseUnaryOp.cpp @@ -1,6 +1,6 @@ #include #include -USING_PART_OF_NAMESPACE_EIGEN +using namespace Eigen; using namespace std; // define a custom template unary functor diff --git a/doc/examples/class_FixedBlock.cpp b/doc/examples/class_FixedBlock.cpp index 3961119e1..5e0e53da3 100644 --- a/doc/examples/class_FixedBlock.cpp +++ b/doc/examples/class_FixedBlock.cpp @@ -1,6 +1,6 @@ #include #include -USING_PART_OF_NAMESPACE_EIGEN +using namespace Eigen; using namespace std; template diff --git a/doc/examples/class_FixedVectorBlock.cpp b/doc/examples/class_FixedVectorBlock.cpp index 917d465ab..9be7d8d71 100644 --- a/doc/examples/class_FixedVectorBlock.cpp +++ b/doc/examples/class_FixedVectorBlock.cpp @@ -1,6 +1,6 @@ #include #include -USING_PART_OF_NAMESPACE_EIGEN +using namespace Eigen; using namespace std; template diff --git a/doc/examples/class_VectorBlock.cpp b/doc/examples/class_VectorBlock.cpp index 2848bc1ea..2f02c8f69 100644 --- a/doc/examples/class_VectorBlock.cpp +++ b/doc/examples/class_VectorBlock.cpp @@ -1,6 +1,6 @@ #include #include -USING_PART_OF_NAMESPACE_EIGEN +using namespace Eigen; using namespace std; template