Live data from Hacker News

Eigen: A C++ template library for linear algebra

eigen.tuxfamily.org

51–60 of 85 posts

Re: Eigen: A C++ template library for linear algebra

#51
Eigen is the standard choice (for good reason!) for many linear algebra projects, especially in robotics, but there is a big downside users should be aware of before they chose it.

Eigen makes extensive use of expression templates in C++ to collapse complex operation sequences into streamlined and minimal calculations. This is generally ok, until you need a debug build. I've regularly seen debug builds of software using Eigen run 1000x to 10000x slower than the release build, which seriously complicates various debugging workflows. It also makes it a nightmare to run your test suite through valgrind, for example.

I've seen several engineers attempt (and fail) to try creating/linking a release build of Eigen with a debug build of the rest of the program to try to regain most of that speed while still allowing a decent amount of debugability, but this is really hard due to all the aggressive inlining and heavy use of templates.

In my experience, I would happily accept a 2x or more slowdown in linear algebra performance in release builds in exchange for significant boost in debug execution speed. If you're starting a greenfield project, you should consider how important decent debug performance is before choosing Eigen by default.

Re: Eigen: A C++ template library for linear algebra

#52
post #20
post #13

A great library, a cornerstone. Many big libraries build on top of it (e.g. OpenCV, PointCloud Library)

Can you elaborate on how OpenCV is built on top of Eigen? From what I can google it seems that OpenCV can interoperate with Eigen but is not build on top of it.

There are functions related to camera calibration and adjustment of images whose internals are built using Eigen Vectors and Matrixes.

Re: Eigen: A C++ template library for linear algebra

#53

Probably won't ever catch Fortran, but using Eigen templates for reductions really opens the door for compile time optimizations; e.g. these are all reductions that do the same thing const float residual = (L.array() * P.array()).colwise().sum().square().mean(); const float residual = L.cwiseProduct(P).array().colwise().sum().array().square().mean(); const float residual = (L.transpose() * P).diagonal().array().squar…

The compile time loop fusion is also particularly nice.

Thanks -- I just learned something new. Since matrices are primitive types in Fortran, I assume these kinds of optimizations are more abundant in Fortran. I wonder if adding matrices / vectors / tensors as primitive types has even been entertained by the various C++ committees.

Re: Eigen: A C++ template library for linear algebra

#54
post #8

Using it for years, and mostly happy with that library. The performance is awesome for very long vectors / large matrices. It’s less than ideal for small things when the size is known at compile-time. If one knows SIMD intrinsics, in some of these cases the Eigen’s implementation can be outperformed by a large factor like 2-4. Also it’s very hard to mess with RAM layout of some things (like sparse matrices), just too…

Can confirm the poor performance on small matrices (less than 20x20). This is a problem particularly for robotics applications when your entities are positions, velocities, etc. https://stackoverflow.com/questions/58071344/is-eigen-slow-a...

Huh, interesting - this is news to me, as I use Eigen all the time/see it used all over for robotics. Is there a good replacement for robotics-specific operations/small matrices generally (I see some people mentioning DirectXMath?)? Or is the tradeoff just between spending the time and effort to write SIMD intrinsics yourself vs. lower performance but greater convenience with Eigen?

One advantage of Eigen's approach that I haven't seen mentioned here is that its templated design makes it easy to substitute custom scalar types for operations, which helps enable straightforward automatic differentiation and other such tools (e.g. I'm currently using Eigen to make a tracing JIT for computations like FK, etc. over scenegraphs).

Re: Eigen: A C++ template library for linear algebra

#55
post #21
post #8

Using it for years, and mostly happy with that library. The performance is awesome for very long vectors / large matrices. It’s less than ideal for small things when the size is known at compile-time. If one knows SIMD intrinsics, in some of these cases the Eigen’s implementation can be outperformed by a large factor like 2-4. Also it’s very hard to mess with RAM layout of some things (like sparse matrices), just too…

It may have improved recently -- I haven't measured -- but serial Eigen seems mostly a little less performant at plateau than optimized BLAS GEMM for reals, and about half as good for complex in results I've seen for v3.3. For multiplication/convolution of sufficiently small dimension matrices on x86 (aarch64 in development) you probably want libxsmm; it can be used header-only -- at least for C -- if that matters. I…

In my case Eigen is handling some 3000x3000 and bigger matrices. For these scenarios, it’s performance is about 98% of BLAS libraries, which is more than enough when combined with the ease and practicality of Eigen. It also handles RAM placement, so it doesn’t get affected by memory fragmentation.

Their current performance page is here [0].

[0]: https://eigen.tuxfamily.org/index.php?title=Performance_moni...

Re: Eigen: A C++ template library for linear algebra

#56

Earlier quoted context omitted.

Can confirm the poor performance on small matrices (less than 20x20). This is a problem particularly for robotics applications when your entities are positions, velocities, etc. https://stackoverflow.com/questions/58071344/is-eigen-slow-a...

Huh, interesting - this is news to me, as I use Eigen all the time/see it used all over for robotics. Is there a good replacement for robotics-specific operations/small matrices generally (I see some people mentioning DirectXMath?)? Or is the tradeoff just between spending the time and effort to write SIMD intrinsics yourself vs. lower performance but greater convenience with Eigen? One advantage of Eigen's approach…

Blaze [0] looks promising. There was a little discussion here [1] about it's comparison and performance, especially for small sizes.

[0] https://bitbucket.org/blaze-lib/blaze/src/master/

[1] https://bitbucket.org/blaze-lib/blaze/issues/266/blaze-vs-ei...

Re: Eigen: A C++ template library for linear algebra

#57

Earlier quoted context omitted.

Huh, interesting - this is news to me, as I use Eigen all the time/see it used all over for robotics. Is there a good replacement for robotics-specific operations/small matrices generally (I see some people mentioning DirectXMath?)? Or is the tradeoff just between spending the time and effort to write SIMD intrinsics yourself vs. lower performance but greater convenience with Eigen? One advantage of Eigen's approach…

Blaze [0] looks promising. There was a little discussion here [1] about it's comparison and performance, especially for small sizes. [0] https://bitbucket.org/blaze-lib/blaze/src/master/ [1] https://bitbucket.org/blaze-lib/blaze/issues/266/blaze-vs-ei...

Thanks, this looks promising indeed! Especially because it similarly supports custom scalar types: https://bitbucket.org/blaze-lib/blaze/wiki/Vector%20and%20Ma...

Re: Eigen: A C++ template library for linear algebra

#59
Not widely publicized, but the benchmarking code is in the source. At one point I was running it on my specific target machines to get performance estimates in support of porting some large-ish CPU stuff from Matlab into C++.

The max performance was in Eigen-calling Intel MKL, but it was a big plus to not need MKL licenses on every development machine.

Re: Eigen: A C++ template library for linear algebra

#60

Earlier quoted context omitted.

Blaze [0] looks promising. There was a little discussion here [1] about it's comparison and performance, especially for small sizes. [0] https://bitbucket.org/blaze-lib/blaze/src/master/ [1] https://bitbucket.org/blaze-lib/blaze/issues/266/blaze-vs-ei...

Thanks, this looks promising indeed! Especially because it similarly supports custom scalar types: https://bitbucket.org/blaze-lib/blaze/wiki/Vector%20and%20Ma...

One small downside of Blaze vs. Eigen for robotics is that Blaze seems to lack the highly convenient geometry types and operations that Eigen ships with. This wouldn't be difficult to build on top of Blaze (and could lead to some interesting performance comparisons), but does present some additional work necessary to use Blaze in many robotics applications.
Post reply on HN