Registered Member
|
I've found that in one of my programs, the asDiagonal() method is running in quadratic time. Is this likely to be because I am misunderstanding how to use it, or is it still not supported very well?
For example, should this code run in quadratic time? void foo(VectorXf & v, MatrixXf & m) { m = v.asDiagonal(); } I would expect it to run in time linear in the size of v, but I could see how if m is fixed as diagonal or not diagonal at compile time this would not actually happen. Also if there's anything you could point me to that I could read that would help me answer such questions on my own in the future, that would be great. Thanks in advance! |
Registered Member
|
asDiagonal() by itself only constructs an abstract expression: as such, it returns in constant time.
But when you do:
you're asking for the dense (MatrixXf is a dense matrix type) matrix m to be initialized as a diagonal matrix, which requires writing zeros everywhere outside the diagonal. That takes quadratic time. In Eigen 2.0, there's no way around that. In the development branch, you can now use a "diagonal matrix" type that stores only the diagonal. You would do:
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
Is it possible to make a matrix that is agnostic at compile time as to whether it is dense or sparse? I'm writing a class that represents vector-valued functions, and can return the Jacobian at a specific point. Often the Jacobian is a diagonal matrix so there could be considerable savings in both time and memory if the class could return a sparse matrix, but I'd prefer that the client didn't have to worry about which type would be returned.
|
Registered Member
|
No, we don't have such a class.
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
Registered users: Bing [Bot], Google [Bot], Sogou [Bot]