eigen/doc/A05_PortingFrom2To3.dox

103 lines
4.2 KiB
Plaintext

namespace Eigen {
/** \page Eigen2ToEigen3 Porting from Eigen2 to Eigen3
The goals of this page is to enumerate the API changes between Eigen2 and Eigen3,
and to help porting an application from Eigen2 to Eigen3.
\b Table \b of \b contents
- \ref CompatibilitySupport
- \ref ChangeList
- \ref CoefficientWiseOperations
- \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).
\section ChangeList List of changes in the API
<table>
<tr><td>Eigen 2</td><td>Eigen 3</td><td>Comments</td></tr>
<tr><td>\code
vec.start(length)
vec.start<length>()
vec.end(length)
vec.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>
</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 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.
In Eigen2, lazy evaluation could be enforced by tagging a product using the .lazy() function. However, in complex expressions it was not
easy to determine where to put the lazy() function. In Eigen3, the lazy() feature has been superseded by the MatrixBase::noalias() function
which can be used on the left hand side of an assignment when no aliasing can occur. Here is an example:
\code
MatrixXf a, b, c;
...
c.noalias() += 2 * a.transpose() * b;
\endcode
However, the noalias mechanism does not cover all the features of the old .lazy(). Indeed, in some extremely rare cases,
it might be useful to explicit request for a lay product, i.e., for a product which will be evaluated one coefficient at once, on request,
just like any other expressions. To this end you can use the MatrixBase::lazyProduct() function, however we strongly discourage you to
use it unless you are sure of what you are doing, i.e., you have rigourosly measured a speed improvement.
*/
}