Live data from Hacker News

Eigen: A C++ template library for linear algebra

eigen.tuxfamily.org

31–40 of 85 posts

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

#31
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!

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

#32
post #4

Eigen is a great library. A similar one to consider that can at times be slightly easier to use coming from a python background is armadillo: http://arma.sourceforge.net/

I really like armadillo's syntax, it feels like your doing R/Matlab.

That's not a positive for everyone, Matlab's API choices are a bit polarizing/confusing for people who don't use it.

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

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

An other answer just debates wether that was a benchmarking issue

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

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

> when your entities are positions, velocities, etc.

For use cases where FP32 precision is enough, I usually use DirectXMath library https://github.com/Microsoft/DirectXMath for that. That thing is cross-platform in practice. Even when building things for ARM Linux, it’s easy to copy-paste required pieces, NEON support is there.

When I need FP64 precision on PCs, I usually proceed without libraries, using AVX intrinsics.

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

#35
post #33

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

An other answer just debates wether that was a benchmarking issue

Multiple other users confirmed the results and that one answer's author never followed up.

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

#36
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!

I never really used GLM, but Eigen was substantially slower than DirectXMath https://github.com/microsoft/DirectXMath for these things. Despite the name, 99% of that library is OS agnostic, only a few small pieces (like perspective projection matrix formula) are specific to Direct3D. When enabled with corresponding macros, inline functions from that library normally compile into pretty efficient manually vectorized SSE, AVX or NEON code.

The only major issue, DirectXMath doesn’t support FP64 precision.

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

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

That's interesting. I'd assume that a template library like Eigen would be most competitive for really small matrices and vectors of a known size -- it should have a fundamental advantage over something like MKL or BLIS, in that it can fully inline and unroll everything if it wants, right?

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

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

That's interesting. I'd assume that a template library like Eigen would be most competitive for really small matrices and vectors of a known size -- it should have a fundamental advantage over something like MKL or BLIS, in that it can fully inline and unroll everything if it wants, right?

My guess it’s their deliberate design decision. It could be that most users of the library don’t care about small things.

About the template stuff, I think their main performance advantage over traditional BLAS is not even SIMD, it’s lazy evaluation. Expressions like x=a*b+c never compute the complete a*b matrix or vector. The a*b expression returns a small placeholder object on the stack, of a scary type with couple lines of template arguments in the type name. This way the complete expression runs without making temporary matrices, instead it streams data from all 3 arguments and only writes to memory once. And if the `x` is of the correct size already, it doesn’t call malloc/free.

Post reply on HN