diff options
author | Gael Guennebaud <g.gael@free.fr> | 2009-08-16 11:01:32 +0200 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2009-08-16 11:01:32 +0200 |
commit | 5274c5c3262cea98d5b78962af5680e4ae6050c0 (patch) | |
tree | 283ba715e42751a1804f84994bb9e89440c287ae | |
parent | fc9480cbb38db2c7585e3ac5d14719237a85d2d7 (diff) |
quick update of TopicLazyEvaluation
-rw-r--r-- | doc/I01_TopicLazyEvaluation.dox | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/doc/I01_TopicLazyEvaluation.dox b/doc/I01_TopicLazyEvaluation.dox index 3e2b9db5f..f40afa06d 100644 --- a/doc/I01_TopicLazyEvaluation.dox +++ b/doc/I01_TopicLazyEvaluation.dox @@ -42,11 +42,11 @@ Eigen chooses lazy evaluation at every stage in that example, which is clearly t Eigen first evaluates <tt>matrix * matrix</tt> into a temporary matrix, and then copies it into the original \c matrix. This guarantees a correct result as we saw above that lazy evaluation gives wrong results with matrix products. It also doesn't cost much, as the cost of the matrix product itself is much higher. -What if you know what you are doing and want to force lazy evaluation? Then use \link MatrixBase::lazy() .lazy()\endlink instead. Here is an example: +What if you know that the result does no alias the operand of the product and want to force lazy evaluation? Then use \link MatrixBase::noalias() .noalias()\endlink instead. Here is an example: -\code matrix1 = (matrix2 * matrix2).lazy(); \endcode +\code matrix1.noalias() = matrix2 * matrix2; \endcode -Here, since we know that matrix2 is not the same matrix as matrix1, we know that lazy evaluation is not dangerous, so we may force lazy evaluation. Concretely, the effect of lazy() here is to remove the evaluate-before-assigning \link flags flag\endlink and also the evaluate-before-nesting \link flags flag\endlink which we now discuss. +Here, since we know that matrix2 is not the same matrix as matrix1, we know that lazy evaluation is not dangerous, so we may force lazy evaluation. Concretely, the effect of noalias() here is to bypass the evaluate-before-assigning \link flags flag\endlink. <b>The second circumstance</b> in which Eigen chooses immediate evaluation, is when it sees a nested expression such as <tt>a + b</tt> where \c b is already an expression having the evaluate-before-nesting \link flags flag\endlink. Again, the most important example of such an expression is the \link Product matrix product expression\endlink. For example, when you do @@ -54,8 +54,6 @@ Here, since we know that matrix2 is not the same matrix as matrix1, we know that the product <tt>matrix3 * matrix4</tt> gets evaluated immediately into a temporary matrix. Indeed, experiments showed that it is often beneficial for performance to evaluate immediately matrix products when they are nested into bigger expressions. -Again, \link MatrixBase::lazy() .lazy()\endlink can be used to force lazy evaluation here. - <b>The third circumstance</b> in which Eigen chooses immediate evaluation, is when its cost model shows that the total cost of an operation is reduced if a sub-expression gets evaluated into a temporary. Indeed, in certain cases, an intermediate result is sufficiently costly to compute and is reused sufficiently many times, that is worth "caching". Here is an example: \code matrix1 = matrix2 * (matrix3 + matrix4); \endcode |