This forum has been archived. All content is frozen. Please use KDE Discuss instead.

asDiagonal potential issues

Tags: None
(comma "," separated)
Brett
Registered Member
Posts
4
Karma
0

asDiagonal potential issues

Thu Nov 08, 2012 10:33 am
Is it correct that asDiagonal will not properly fill a matrix during comma initialization and cannot be output?
VectorXd(m) v = VectorXd::Ones(m);
MatrixXd J(2*m,m);
//j << MatrixXd::Ones(m,m), v.asDiagonal(); // fails
//j << v.asDiagonal(), v.asDiagonal(); // doesn't compile
j << MatrixXd::Ones(m,m), MatrixXd(v.asDiagonal()); //works
//cout << v.asDiagonal() << endl; //Doesn't compile

I think it would be much better if the above behavior didn't occur.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: asDiagonal potential issues

Thu Nov 08, 2012 6:43 pm
Indeed, by construction it is forbidden to perform random accesses to a diagonal matrix, and so it is not fully compatible with dense matrices. Now I admit that it would be convenient that:

j << MatrixXd::Ones(m,m), v.asDiagonal();

would work, but the second should be compiled as:

j.block(m,0,m,m).setZero();
j.block(m,0,m,m).diagonal() = v;

and not the simple:

j.block(m,0,m,m) = v.asDiagonal();

So that's a bit more complicated to implement, and so it's not supported yet. If someone want to look at this, the best is to implement the comma initializer for general EigenBase object, and call:

general_expression.evalTo( dest.block(i,j, general_expression.rows(), general_expression.cols()) );

This way, band and sparse matrices will be supported too.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]