Live data from Hacker News

Eigen: A C++ template library for linear algebra

eigen.tuxfamily.org

71–80 of 85 posts

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

#71
post #23
post #17

Earlier quoted context omitted.

Eigen has one of if not the best linear algebra APIs I've ever seen. In particular, vectors are column vectors by default and you never need to touch row vectors (if I can editorialize, row vectors shouldn't exist at all), and vectors are not simply "n-by-1" matrices -- they're true vectors.

Could you elaborate a bit more about the difference between Nx1 matrices and "true vectors"?

If you want a great video on the topic, see https://youtu.be/C2RO34b_oPM

Or equivalently https://jiahao.github.io/talk/2017-06-juliacon/

There are basically two self-consistent choices for the design of linear algebra libraries.

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

#72
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…

Any idea about perf diff between this and GLM? In Computer graphics my use case is with fixed 4x4 matrices and vec4s. Thanks!

Last time I tried Eigen, it sucked for 4x4 matrices.

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

#73

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 us…

You can create custom build configurations to set the optimizations and add debug info. Or just add instrumentation code (print debugging) which is more useful for debugging heavy numerical stuff most of the time anyway.

Running anything through valgrind or cachegrind will have several orders of magnitude slowdown - that's inherent to how the tools work.

To your last point, just add -g to your compile flags and see how far you get.

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

#74
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…

Could this be fixed with some template specialisation?

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

#75
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…

Could this be fixed with some template specialisation?

Eigen makes use of these already

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

#76
post #52
post #20

Earlier quoted context omitted.

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.

Are you referring to eigen, the C++ library or eigen vectors/values, the mathematical construct?

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

#77

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 us…

I appreciate being made aware of this downside! Why does this happen with C++ debugging?

In general, in template heavy libraries, what kills performance in debug builds is lack of inlining with optimizations turned off. And templates traditionally need to be inlinable by having their full definition in a header, so one can't even say build with optimizations on with debug info in isolation, because it has to be done where the templates are used, not in the library where they're defined (because there is no separately built library for the template). In other words, it's a real pain to get just the templates optimized while the rest of your code is not optimized for easier debugging.

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

#78

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…

glm is also good for 3d math. It mimics the API of OpenGL shaders, so it's a good option if you already know how to write shaders (or are interested in learning).

https://github.com/g-truc/glm

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

#79
post #23

Earlier quoted context omitted.

Could you elaborate a bit more about the difference between Nx1 matrices and "true vectors"?

One has shape (N, 1) and one has shape (N). Always having a trailing 1 is a pain in many settings. Matlab has that “trailing 1” all the time and it’s a PITA.

Why do you say it's a pain? After working with numpy for the last two years, that's the part I miss most about matlab.

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

#80
post #21

Earlier quoted context omitted.

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...

[0] still looks bad for complex (CGEMM, I assume). It doesn't have comparisons there, but Eigen's claim to be faster than any free BLAS is surely wrong. (I wouldn't doubt its similar if it has the right loop structure and prefetching, and a few percent is within the normal variance of HPC runs anyway, so not worth worry about.) Unfortunately it isn't convenient for me, not being clever enough for C++, but I've nothing against any good free linear algebra implementation for a platform I'm using.

What's "RAM placement" in this context?

Post reply on HN