From 33788b97dd2cd8662c598e14e1e901a7bd4df93b Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Tue, 18 Jun 2013 00:48:47 +0200 Subject: Fix compilation issue with some compilers (when doing using Base::foo;, foo must be visible in the direct base class) --- Eigen/src/Core/Transpose.h | 1 + 1 file changed, 1 insertion(+) (limited to 'Eigen/src/Core/Transpose.h') diff --git a/Eigen/src/Core/Transpose.h b/Eigen/src/Core/Transpose.h index 2bc828e19..95a7b95e5 100644 --- a/Eigen/src/Core/Transpose.h +++ b/Eigen/src/Core/Transpose.h @@ -104,6 +104,7 @@ template class TransposeImpl typedef typename internal::TransposeImpl_base::type Base; EIGEN_DENSE_PUBLIC_INTERFACE(Transpose) + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(TransposeImpl) inline Index innerStride() const { return derived().nestedExpression().innerStride(); } inline Index outerStride() const { return derived().nestedExpression().outerStride(); } -- cgit v1.2.3 From c21a04bcf978556555f874b780cae14dbdf4827f Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 24 Jun 2013 13:35:13 +0200 Subject: fix compilation of ArrayBase::transposeInPlace --- Eigen/src/Core/Transpose.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Eigen/src/Core/Transpose.h') diff --git a/Eigen/src/Core/Transpose.h b/Eigen/src/Core/Transpose.h index 95a7b95e5..aa197db0b 100644 --- a/Eigen/src/Core/Transpose.h +++ b/Eigen/src/Core/Transpose.h @@ -253,7 +253,7 @@ struct inplace_transpose_selector; template struct inplace_transpose_selector { // square matrix static void run(MatrixType& m) { - m.template triangularView().swap(m.transpose()); + m.matrix().template triangularView().swap(m.matrix().transpose()); } }; @@ -261,7 +261,7 @@ template struct inplace_transpose_selector { // non square matrix static void run(MatrixType& m) { if (m.rows()==m.cols()) - m.template triangularView().swap(m.transpose()); + m.matrix().template triangularView().swap(m.matrix().transpose()); else m = m.transpose().eval(); } -- cgit v1.2.3 From 419b5cff44a6d2cdd3872a809f9dfdfa283f0dc3 Mon Sep 17 00:00:00 2001 From: Jitse Niesen Date: Tue, 2 Jul 2013 13:35:36 +0100 Subject: doc: Mention vec=vec.head(n) in aliasing page. --- Eigen/src/Core/Transpose.h | 2 +- doc/TopicAliasing.dox | 50 ++++++++++++++++++++++++++-------------------- 2 files changed, 29 insertions(+), 23 deletions(-) (limited to 'Eigen/src/Core/Transpose.h') diff --git a/Eigen/src/Core/Transpose.h b/Eigen/src/Core/Transpose.h index aa197db0b..798120bf4 100644 --- a/Eigen/src/Core/Transpose.h +++ b/Eigen/src/Core/Transpose.h @@ -388,7 +388,7 @@ struct checkTransposeAliasing_impl eigen_assert((!check_transpose_aliasing_run_time_selector ::IsTransposed,OtherDerived> ::run(extract_data(dst), other)) - && "aliasing detected during tranposition, use transposeInPlace() " + && "aliasing detected during transposition, use transposeInPlace() " "or evaluate the rhs into a temporary using .eval()"); } diff --git a/doc/TopicAliasing.dox b/doc/TopicAliasing.dox index bd1d329ce..c2654aed2 100644 --- a/doc/TopicAliasing.dox +++ b/doc/TopicAliasing.dox @@ -2,7 +2,7 @@ namespace Eigen { /** \eigenManualPage TopicAliasing Aliasing -In Eigen, aliasing refers to assignment statement in which the same matrix (or array or vector) appears on the +In %Eigen, aliasing refers to assignment statement in which the same matrix (or array or vector) appears on the left and on the right of the assignment operators. Statements like mat = 2 * mat; or mat = mat.transpose(); exhibit aliasing. The aliasing in the first example is harmless, but the aliasing in the second example leads to unexpected results. This page explains what aliasing is, when it is harmful, and what @@ -32,7 +32,7 @@ This assignment exhibits aliasing: the coefficient \c mat(1,1) appears both in t mat.bottomRightCorner(2,2) on the left-hand side of the assignment and the block mat.topLeftCorner(2,2) on the right-hand side. After the assignment, the (2,2) entry in the bottom right corner should have the value of \c mat(1,1) before the assignment, which is 5. However, the output shows -that \c mat(2,2) is actually 1. The problem is that Eigen uses lazy evaluation (see +that \c mat(2,2) is actually 1. The problem is that %Eigen uses lazy evaluation (see \ref TopicEigenExpressionTemplates) for mat.topLeftCorner(2,2). The result is similar to \code mat(1,1) = mat(0,0); @@ -43,10 +43,13 @@ mat(2,2) = mat(1,1); Thus, \c mat(2,2) is assigned the \e new value of \c mat(1,1) instead of the old value. The next section explains how to solve this problem by calling \link DenseBase::eval() eval()\endlink. -Note that if \c mat were a bigger, then the blocks would not overlap, and there would be no aliasing -problem. This means that in general aliasing cannot be detected at compile time. However, Eigen does detect -some instances of aliasing, albeit at run time. The following example exhibiting aliasing was mentioned in -\ref TutorialMatrixArithmetic : +Aliasing occurs more naturally when trying to shrink a matrix. For example, the expressions vec = +vec.head(n) and mat = mat.block(i,j,r,c) exhibit aliasing. + +In general, aliasing cannot be detected at compile time: if \c mat in the first example were a bit bigger, +then the blocks would not overlap, and there would be no aliasing problem. However, %Eigen does detect some +instances of aliasing, albeit at run time. The following example exhibiting aliasing was mentioned in \ref +TutorialMatrixArithmetic : @@ -57,24 +60,24 @@ some instances of aliasing, albeit at run time. The following example exhibitin \verbinclude tut_arithmetic_transpose_aliasing.out
ExampleOutput
-Again, the output shows the aliasing issue. However, by default Eigen uses a run-time assertion to detect this +Again, the output shows the aliasing issue. However, by default %Eigen uses a run-time assertion to detect this and exits with a message like \verbatim void Eigen::DenseBase::checkTransposeAliasing(const OtherDerived&) const [with OtherDerived = Eigen::Transpose >, Derived = Eigen::Matrix]: Assertion `(!internal::check_transpose_aliasing_selector::IsTransposed,OtherDerived>::run(internal::extract_data(derived()), other)) -&& "aliasing detected during tranposition, use transposeInPlace() or evaluate the rhs into a temporary using .eval()"' failed. +&& "aliasing detected during transposition, use transposeInPlace() or evaluate the rhs into a temporary using .eval()"' failed. \endverbatim -The user can turn Eigen's run-time assertions like the one to detect this aliasing problem off by defining the +The user can turn %Eigen's run-time assertions like the one to detect this aliasing problem off by defining the EIGEN_NO_DEBUG macro, and the above program was compiled with this macro turned off in order to illustrate the -aliasing problem. See \ref TopicAssertions for more information about Eigen's run-time assertions. +aliasing problem. See \ref TopicAssertions for more information about %Eigen's run-time assertions. \section TopicAliasingSolution Resolving aliasing issues -If you understand the cause of the aliasing issue, then it is obvious what must happen to solve it: Eigen has +If you understand the cause of the aliasing issue, then it is obvious what must happen to solve it: %Eigen has to evaluate the right-hand side fully into a temporary matrix/array and then assign it to the left-hand side. The function \link DenseBase::eval() eval() \endlink does precisely that. @@ -93,7 +96,7 @@ Now, \c mat(2,2) equals 5 after the assignment, as it should be. The same solution also works for the second example, with the transpose: simply replace the line a = a.transpose(); with a = a.transpose().eval();. However, in this common case there is a -better solution. Eigen provides the special-purpose function +better solution. %Eigen provides the special-purpose function \link DenseBase::transposeInPlace() transposeInPlace() \endlink which replaces a matrix by its transpose. This is shown below: @@ -107,7 +110,7 @@ This is shown below: If an xxxInPlace() function is available, then it is best to use it, because it indicates more clearly what you -are doing. This may also allow Eigen to optimize more aggressively. These are some of the xxxInPlace() +are doing. This may also allow %Eigen to optimize more aggressively. These are some of the xxxInPlace() functions provided: @@ -120,6 +123,9 @@ functions provided:
DenseBase::transpose() DenseBase::transposeInPlace()
+In the special case where a matrix or vector is shrunk using an expression like vec = vec.head(n), +you can use \link PlainObjectBase::conservativeResize() conservativeResize() \endlink. + \section TopicAliasingCwise Aliasing and component-wise operations @@ -128,8 +134,8 @@ right-hand side of an assignment operator, and it is then often necessary to eva explicitly. However, applying component-wise operations (such as matrix addition, scalar multiplication and array multiplication) is safe. -The following example has only component-wise operations. Thus, there is no need for .eval() even though -the same matrix appears on both sides of the assignments. +The following example has only component-wise operations. Thus, there is no need for \link DenseBase::eval() +eval() \endlink even though the same matrix appears on both sides of the assignments. @@ -147,8 +153,8 @@ not necessary to evaluate the right-hand side explicitly. \section TopicAliasingMatrixMult Aliasing and matrix multiplication -Matrix multiplication is the only operation in Eigen that assumes aliasing by default. Thus, if \c matA is a -matrix, then the statement matA = matA * matA; is safe. All other operations in Eigen assume that +Matrix multiplication is the only operation in %Eigen that assumes aliasing by default. Thus, if \c matA is a +matrix, then the statement matA = matA * matA; is safe. All other operations in %Eigen assume that there are no aliasing problems, either because the result is assigned to a different matrix or because it is a component-wise operation. @@ -161,14 +167,14 @@ component-wise operation. \verbinclude TopicAliasing_mult1.out
ExampleOutput
-However, this comes at a price. When executing the expression matA = matA * matA, Eigen evaluates the -product in a temporary matrix which is assigned to \c matA after the computation. This is fine. But Eigen does +However, this comes at a price. When executing the expression matA = matA * matA, %Eigen evaluates the +product in a temporary matrix which is assigned to \c matA after the computation. This is fine. But %Eigen does the same when the product is assigned to a different matrix (e.g., matB = matA * matA). In that case, it is more efficient to evaluate the product directly into \c matB instead of evaluating it first into a temporary matrix and copying that matrix to \c matB. The user can indicate with the \link MatrixBase::noalias() noalias()\endlink function that there is no -aliasing, as follows: matB.noalias() = matA * matA. This allows Eigen to evaluate the matrix product +aliasing, as follows: matB.noalias() = matA * matA. This allows %Eigen to evaluate the matrix product matA * matA directly into \c matB. @@ -199,9 +205,9 @@ Aliasing occurs when the same matrix or array coefficients appear both on the le an assignment operator. - Aliasing is harmless with coefficient-wise computations; this includes scalar multiplication and matrix or array addition. - - When you multiply two matrices, Eigen assumes that aliasing occurs. If you know that there is no aliasing, + - When you multiply two matrices, %Eigen assumes that aliasing occurs. If you know that there is no aliasing, then you can use \link MatrixBase::noalias() noalias()\endlink. - - In all other situations, Eigen assumes that there is no aliasing issue and thus gives the wrong result if + - In all other situations, %Eigen assumes that there is no aliasing issue and thus gives the wrong result if aliasing does in fact occur. To prevent this, you have to use \link DenseBase::eval() eval() \endlink or one of the xxxInPlace() functions. -- cgit v1.2.3 From 84f52ad317f64d01174c622ae596701088237487 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 10 Jul 2013 23:54:53 +0200 Subject: Remove double const qualifier --- Eigen/src/Core/Diagonal.h | 2 +- Eigen/src/Core/MatrixBase.h | 2 +- Eigen/src/Core/Transpose.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'Eigen/src/Core/Transpose.h') diff --git a/Eigen/src/Core/Diagonal.h b/Eigen/src/Core/Diagonal.h index c106f93c4..aab8007b3 100644 --- a/Eigen/src/Core/Diagonal.h +++ b/Eigen/src/Core/Diagonal.h @@ -172,7 +172,7 @@ MatrixBase::diagonal() /** This is the const version of diagonal(). */ template -inline const typename MatrixBase::ConstDiagonalReturnType +inline typename MatrixBase::ConstDiagonalReturnType MatrixBase::diagonal() const { return ConstDiagonalReturnType(derived()); diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 198e51084..373c6821e 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -216,7 +216,7 @@ template class MatrixBase typedef Diagonal DiagonalReturnType; DiagonalReturnType diagonal(); typedef const Diagonal ConstDiagonalReturnType; - const ConstDiagonalReturnType diagonal() const; + ConstDiagonalReturnType diagonal() const; template struct DiagonalIndexReturnType { typedef Diagonal Type; }; template struct ConstDiagonalIndexReturnType { typedef const Diagonal Type; }; diff --git a/Eigen/src/Core/Transpose.h b/Eigen/src/Core/Transpose.h index 798120bf4..f21b3aa65 100644 --- a/Eigen/src/Core/Transpose.h +++ b/Eigen/src/Core/Transpose.h @@ -207,7 +207,7 @@ DenseBase::transpose() * * \sa transposeInPlace(), adjoint() */ template -inline const typename DenseBase::ConstTransposeReturnType +inline typename DenseBase::ConstTransposeReturnType DenseBase::transpose() const { return ConstTransposeReturnType(derived()); -- cgit v1.2.3