Live data from Hacker News

Eigen: A C++ template library for linear algebra

eigen.tuxfamily.org

21–30 of 85 posts

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

#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 might guess Eigen does relatively better on L1 and L2 than BLAS libraries.

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

#23
post #17
post #12

God bless Eigen, I am using it to implement the state matrices of a Kalman Filter and it's a joy to use its APIs.

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"?

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

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

Thank you for this. I wrote a small linear algebra library using intrinsics in C#, and my code was beating Eigen at the n<50 level, but I figured it was just some error of mine, so I never had the balls to make the claim publicly.

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

#25
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"?

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.

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

#28

BLAS vs Eigen Go

I believe (haven't looked at benchmarks lately) Eigen has trouble beating a good BLAS implementation like MKL or BLIS at doing BLAS stuff, but it is more expressive and has the ability to do lazy evaluation/fuse operations. Anyway since you can get it to call your favorite BLAS/LAPACK library, these are really complementary projects.

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

#29

My only complaint is that using OpenMP Eigen can be slower with SMT than without SMT. They even suggest telling to use half as many threads as you have "cores" when "cores" means twice as many due to SMT. Otherwise, we've seen a 8-10x performance increase in SolveSpace (CAD) in some situations after switching from home-grown matrix operations to Eigen.

This has been true for years, Intel CPU's can't efficiently perform math operations when hyperthreading is involved. Generally there is only a single shared FPU/AVX/SSE unit doing the math over two hyperthreads. Since the Eigen implementation often can keep that unit 100% busy, it makes no sense to try and run two threads at full tilt through the units.

I tested all this very heavily before Eigen had AVX-512 support. In that environment there might be some differences and I would suggest you benchmark both configurations.

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

#30
post #15

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 wonder how Eigen compares to xtensor, which was inspired by Numpy and has support for views, slicing, and broadcasting? https://github.com/xtensor-stack/xtensor

Eigen is similar to xtensor, but with 1) Eigen being significantly more mature, and used in production in simulation/research environments and 2) Eigen having not just basic operations on arrays, but also a full suite of linear algebra operations comparable to a full BLAS library, including a full test suite. xtensor wins on having better integration with Python and other languages out of the box. There's also some performance limitations due to being inspired by numpy, particularly with respect to memory management.
Post reply on HN