As discussed in http://listengine.tuxfamily.org/lists.tuxfamily.org/eigen/2013/06/msg00002.html
the following does not compile but should...
using namespace Eigen;
// Works as expected
Matrix3d B1 = Matrix3d::Identity() * A1;
Matrix3d C1 = Matrix3d::Identity() + A1;
Matrix3d D1 = Matrix3d::Identity() - A1;
// Does not work but I expect that it should
Matrix3d B2 = Matrix3d::Identity() * A2.asDiagonal();
Matrix3d C2 = Matrix3d::Identity() + A2.asDiagonal();
Matrix3d D2 = Matrix3d::Identity() - A2.asDiagonal();
Apparently, the multiplication works meanwhile.
I think this is critical enough to block 3.3 and should be fixable using ExprEval (bug 99).
Any progress on this? Addition/subtraction is still broken in 3.3.
Regarding this issue, do we want to support "diagmat +/- diagmat" only or more general "diagmat +/- dense" operations?
The former is easy and can be specialized for Dense::Identity() since it is also a diagonal matrix.
Adding/subtracting dense and diagonal matrices would be very inefficient except for some simple assignments like:
(1) res = diagmat + dense;
(2) res -= dense - diagmat;
for which the rewriting rules I've written for mixing sparse and dense would equally apply here, see: https://bitbucket.org/eigen/eigen/commits/c6447b6d24bb
However, it would be too cumbersome to allow for "res = diagmat + dense" but not for "diagmat + dense" within more general expression.
If we want to support "diagmat + dense" within general expressions, the best approach I can think of would be to evaluate it into a temporary with the same strategy as for expression (1) above:
tmp = dense;
It would of course be awesome, if expressions like:
w = (A+s*Matrix::Identity())*v;
would evaluate to something like
w = s*v; w += A*v;
But rewriting expressions like:
w = (s0*A + s1*diag1 + s2*diag2) * v;
to the following can get arbitrarily complicated:
w = (s1*diag1 + s2*diag2) * v; // element-wise, can happen on-the-fly
w += s0*A*v; // GEMV-product
So I guess, for now it should be sufficient to make them compile (and get correct results), if necessary with temporaries.