Registered Member
|
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. |
Moderator
|
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. |
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]