mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-01-18 14:34:17 +08:00
remove USING_PART_OF_NAMESPACE_EIGEN, leaving it in Eigen2Support.
improve porting-Eigen2-to-3 docs
This commit is contained in:
parent
ef789fe0d2
commit
abbe260905
@ -58,4 +58,20 @@ namespace Eigen {
|
||||
// Eigen2 used to include iostream
|
||||
#include<iostream>
|
||||
|
||||
#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
|
||||
|
@ -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
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
using namespace std;
|
||||
using namespace Eigen;
|
||||
USING_PART_OF_NAMESPACE_EIGEN
|
||||
using namespace Eigen;
|
||||
|
||||
#ifndef SIZE
|
||||
#define SIZE 1024
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include "BenchTimer.h"
|
||||
|
||||
using namespace std;
|
||||
USING_PART_OF_NAMESPACE_EIGEN
|
||||
using namespace Eigen;
|
||||
|
||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
||||
#include <boost/preprocessor/repetition.hpp>
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include <Eigen/Core>
|
||||
USING_PART_OF_NAMESPACE_EIGEN
|
||||
using namespace Eigen;
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
|
@ -6,7 +6,7 @@
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
USING_PART_OF_NAMESPACE_EIGEN
|
||||
using namespace Eigen;
|
||||
|
||||
#ifndef REPEAT
|
||||
#define REPEAT 40000000
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <Eigen/Array>
|
||||
|
||||
using namespace std;
|
||||
USING_PART_OF_NAMESPACE_EIGEN
|
||||
using namespace Eigen;
|
||||
|
||||
#ifndef REPEAT
|
||||
#define REPEAT 10000
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include <Eigen/Core>
|
||||
|
||||
using namespace std;
|
||||
USING_PART_OF_NAMESPACE_EIGEN
|
||||
using namespace Eigen;
|
||||
|
||||
#ifndef MATTYPE
|
||||
#define MATTYPE MatrixXLd
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <Eigen/Core>
|
||||
|
||||
using namespace std;
|
||||
USING_PART_OF_NAMESPACE_EIGEN
|
||||
using namespace Eigen;
|
||||
|
||||
#ifndef VECTYPE
|
||||
#define VECTYPE VectorXLd
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <Eigen/Array>
|
||||
|
||||
USING_PART_OF_NAMESPACE_EIGEN
|
||||
using namespace Eigen;
|
||||
|
||||
#ifndef SCALAR
|
||||
#define SCALAR float
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include <Eigen/Core>
|
||||
USING_PART_OF_NAMESPACE_EIGEN
|
||||
using namespace Eigen;
|
||||
using namespace std;
|
||||
|
||||
template<typename Derived>
|
||||
|
@ -9,7 +9,7 @@
|
||||
// #include "BenchTimer.h"
|
||||
//
|
||||
// using namespace std;
|
||||
// USING_PART_OF_NAMESPACE_EIGEN
|
||||
// using namespace Eigen;
|
||||
//
|
||||
// enum {LazyEval, EarlyEval, OmpEval};
|
||||
//
|
||||
|
@ -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
|
||||
|
||||
<table>
|
||||
<tr><td>Eigen 2</td><td>Eigen 3</td><td>Comments</td></tr>
|
||||
<tr><td>Eigen 2</td><td>Eigen 3</td></tr>
|
||||
<tr><td>\code
|
||||
vec.start(length)
|
||||
vec.start<length>()
|
||||
vec.end(length)
|
||||
vec.end<length>()
|
||||
vector.start(length)
|
||||
vector.start<length>()
|
||||
vector.end(length)
|
||||
vector.end<length>()
|
||||
\endcode</td><td>\code
|
||||
vec.head(length)
|
||||
vec.head<length>()
|
||||
vec.tail(length)
|
||||
vec.tail<length>()
|
||||
\endcode</td><td>Trivial "search and replace".</td></tr>
|
||||
<tr><td colspan="3"></td></tr>
|
||||
<tr><td>\code mat.cwise().XXX()\endcode</td><td>\code mat.array().XXX()\endcode</td><td>See \ref CoefficientWiseOperations. </td></tr>
|
||||
<tr><td colspan="3"></td></tr>
|
||||
<tr><td>\code c = (a * b).lazy();\endcode</td><td>\code c.noalias() = a * b;\endcode</td><td>See \ref LazyVsNoalias. </td></tr>
|
||||
<tr><td colspan="3"></td></tr>
|
||||
<tr><td>\code A.triangularSolveInPlace<XXX>(X);\endcode</td><td>\code A.triangularView<XXX>().solveInPlace(X);\endcode</td><td></td></tr>
|
||||
<tr><td colspan="3"></td></tr>
|
||||
<tr><td>\code
|
||||
UpperTriangular
|
||||
LowerTriangular
|
||||
UnitUpperTriangular
|
||||
UnitLowerTriangular
|
||||
StrictlyUpperTriangular
|
||||
StrictlyLowerTriangular
|
||||
\endcode</td><td>\code
|
||||
Upper
|
||||
Lower
|
||||
UnitUpper
|
||||
UnitLower
|
||||
StrictlyUpper
|
||||
StrictlyLower
|
||||
\endcode</td>
|
||||
<td>Trivial "search and replace".</td></tr>
|
||||
vector.head(length)
|
||||
vector.head<length>()
|
||||
vector.tail(length)
|
||||
vector.tail<length>()
|
||||
\endcode</td></tr>
|
||||
</table>
|
||||
|
||||
\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
|
||||
|
||||
<table>
|
||||
<tr><td>Eigen 2</td><td>Eigen 3</td></tr>
|
||||
@ -110,6 +65,69 @@ matrix.bottomRightCorner<r,c>()
|
||||
|
||||
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
|
||||
|
||||
<table>
|
||||
<tr><td>Eigen 2</td><td>Eigen 3</td></tr>
|
||||
<tr><td>\code A.triangularSolveInPlace<XXX>(X);\endcode</td><td>\code A.triangularView<XXX>().solveInPlace(X);\endcode</td></tr>
|
||||
<tr><td colspan="3"></td></tr>
|
||||
<tr><td>\code
|
||||
UpperTriangular
|
||||
LowerTriangular
|
||||
UnitUpperTriangular
|
||||
UnitLowerTriangular
|
||||
StrictlyUpperTriangular
|
||||
StrictlyLowerTriangular
|
||||
\endcode</td><td>\code
|
||||
Upper
|
||||
Lower
|
||||
UnitUpper
|
||||
UnitLower
|
||||
StrictlyUpper
|
||||
StrictlyLower
|
||||
\endcode</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
\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.
|
||||
|
@ -1,26 +0,0 @@
|
||||
#include <Eigen/Core>
|
||||
|
||||
USING_PART_OF_NAMESPACE_EIGEN
|
||||
|
||||
using namespace std;
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
void foo(const MatrixBase<Scalar, Derived>& m)
|
||||
{
|
||||
cout << "Here's m:" << endl << m << endl;
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
Eigen::ScalarMultiple<Derived>
|
||||
twice(const MatrixBase<Scalar, Derived>& m)
|
||||
{
|
||||
return 2 * m;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
Matrix2d m = Matrix2d::random();
|
||||
foo(m);
|
||||
foo(twice(m));
|
||||
return 0;
|
||||
}
|
@ -1,8 +1,7 @@
|
||||
#include <Eigen/Core>
|
||||
#include <iostream>
|
||||
|
||||
// import most common Eigen types
|
||||
USING_PART_OF_NAMESPACE_EIGEN
|
||||
using namespace Eigen;
|
||||
|
||||
int main(int, char *[])
|
||||
{
|
||||
|
@ -1,8 +1,7 @@
|
||||
#include <Eigen/Core>
|
||||
#include <iostream>
|
||||
|
||||
// import most common Eigen types
|
||||
USING_PART_OF_NAMESPACE_EIGEN
|
||||
using namespace Eigen;
|
||||
|
||||
int main(int, char *[])
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <Eigen/Core>
|
||||
#include <iostream>
|
||||
USING_PART_OF_NAMESPACE_EIGEN
|
||||
using namespace Eigen;
|
||||
using namespace std;
|
||||
|
||||
template<typename Derived>
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <Eigen/Core>
|
||||
#include <iostream>
|
||||
USING_PART_OF_NAMESPACE_EIGEN
|
||||
using namespace Eigen;
|
||||
using namespace std;
|
||||
|
||||
// define a custom template binary functor
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <Eigen/Core>
|
||||
#include <iostream>
|
||||
USING_PART_OF_NAMESPACE_EIGEN
|
||||
using namespace Eigen;
|
||||
using namespace std;
|
||||
|
||||
// define a custom template unary functor
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <Eigen/Core>
|
||||
#include <iostream>
|
||||
USING_PART_OF_NAMESPACE_EIGEN
|
||||
using namespace Eigen;
|
||||
using namespace std;
|
||||
|
||||
template<typename Derived>
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <Eigen/Core>
|
||||
#include <iostream>
|
||||
USING_PART_OF_NAMESPACE_EIGEN
|
||||
using namespace Eigen;
|
||||
using namespace std;
|
||||
|
||||
template<typename Derived>
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <Eigen/Core>
|
||||
#include <iostream>
|
||||
USING_PART_OF_NAMESPACE_EIGEN
|
||||
using namespace Eigen;
|
||||
using namespace std;
|
||||
|
||||
template<typename Derived>
|
||||
|
Loading…
Reference in New Issue
Block a user