Registered Member
|
Original problem comes from calculating distances (not all) of rows of row major matrices. Now I've noticed that the following code is fast:
But if both vectors are row vectors, the same code is slow:
How is this possible? It seems that row-row case is the only slow one, changing at least one vector as column vector makes it fast again. Therefore when I calculate row distances of two row-major matrices I get this bad case. Using Eigen 2.0.12 on 64-bit Linux with GCC. |
Registered Member
|
Seems like you hit a strange performance bug with eigen 2.0.
Can you try with eigen 3 ( the development branch) ? At this stage i'm not sure we'll still fix purely performance issues in 2.0.
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
|
Seems like eigen 3 also has a strange performance bug. The difference isn't actually huge, around 20 %, but it's still there. Here's a simple test set:
I need to check my other code, because my whole program is hugely slower when using Eigen instead of STL. This was just the first problem I could isolate... |
Registered Member
|
Wait, this is not a good benchmark for a few reasons. First you had to worry about the compiler throwing away the computation; the proper approach was to put it in a non-inlinable function. For that we have EIGEN_DONT_INLINE. Second, you are mostly measuring the time taken by random number generation. Third, the time measurement is best done from the program itself, using performance timers. For that we have the bench/BenchTimer.h helper file. Fourth, your number of repetitions was so small, your program was finishing so fast, that lots of other factors could parasite the result, e.g. startup time. So I rewrote the benchmark as follows:
Here are my compilation options and results:
As you can see, I can't reproduce the problem...
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
|
Well I know it wasn't really a good benchmark, but it still gave me clear differences between STL and Eigen.
However, I know found out also that at least part of the problem was in my function declarations. I had a function
and I called it with two MatrixXd::row objects. It seems that because MatrixXd::row actually gives out a Block object, the arguments to the function are implicitly copy constructed from the Blocks. Just switching to using VectorType from your example gave back the performance difference. So now I'm back to debugging other performance issues in my code... P.S. Does Eigen have anything similar to project function of uBlas? It works like this:
|
Registered Member
|
Another question on the same thing. The foo function you defined above can't handle the case
where one argument is a plain VectorXd and the other one is a Block (e.g. MatrixXd::row). Shouldn't there be a common super-class of both that the compiler sets as VectorType in the template? Is this a problem where we should have dynamic binding instead of static given by templates? |
Registered Member
|
Just let it be template in 2 different parameters:
There is. It's called MatrixBase, templated in the actual derived type (so it's a curiously-recursive-template-pattern).
For example, Matrix4f inherits MatrixBase<Matrix4f>, etc. This is static polymorphism: the base class knows at compile time the derived type, since it's passed to it as a template parameter.
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered users: Bing [Bot], Google [Bot], Sogou [Bot]