Live data from Hacker News

Eigen: A C++ template library for linear algebra

eigen.tuxfamily.org

61–70 of 85 posts

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

#61

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.

If you have Eigen-like code that won't tend to have many cases where you're not having many branch mispredicts or loads the prefetcher can't figure out and you also have enough calculations that you can use the width of the core on a single thread then there really isn't any potential throughput gain with SMT but you still suffer from cache contention from having two threads. It's really not Eigen's fault, it's the nature of SMT that it doesn't help in all cases.

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

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

But they are nx1 matrices in Eigen, you can call the rows() and cols() methods to check that. However, the nice part is that, since Eigen knows the number of columns at compile time, it enables vector methods such as size() in addition, which lets you handle them as true vector.

But tge nice part is that these vectors can still interact well with parts of the code that expect a matrix.

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

#63
post #50

Eigen is really nice for getting code that looks like the underlying math and it also optimizes away unnecessary temporaries by using template expressions. However, when you mess up, you get a screen full of template errors that take some experience to understand and debug. It makes me wish for a language + compiler where linear algebraic objects are first-class values.

> It makes me wish for a language + compiler where linear algebraic objects are first-class values. Like Fortran?

Fortran gives you first class dense ND-array, but doesn't give you the flexibility to make other types of arrays (banded/blocked/etc) feel first class.

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

#64
Is there anything like Eigen for data that's kept on the GPU? I've been looking at porting some performance-critical scientific computing code from Python to C++ and numpy -> Eigen seems like an obvious migration path, but it's harder to figure out what to do with cupy matrix operations.

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

#65
post #64

Is there anything like Eigen for data that's kept on the GPU? I've been looking at porting some performance-critical scientific computing code from Python to C++ and numpy -> Eigen seems like an obvious migration path, but it's harder to figure out what to do with cupy matrix operations.

There is Kompute.

It wraps Vulkan in a very thin layer, mostly to eliminate boilerplate.

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

#67

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…

This is a problem with C++ in general.

In debug mode it has no notion of performance whatsoever.

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

#68
One of the best things about Eigen is that it is the only linear algebra package that I know of that easily supports using the same code for low, high, and arbitrary precision floating point numbers. I had some linear system of equations that I need to solve in grad school where the condition number was small enough that double precision was not sufficient to solve the problem. I was able to very easily use double double, quad double [1], and arbitrary precision floating [2] point number implementations to solve these problems. The matrices I used were not especially large, but I couldn't find any other existing packages that fit this use case.

[1] https://www.davidhbailey.com/dhbsoftware/

[2] http://www.holoborodko.com/pavel/mpfr/

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

#69
post #15

Earlier quoted context omitted.

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

It's not quite out of the box, but pybind11 has really nice support for eigen matrices and vectors and automatically converts them to/from numpy arrays.

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

#70

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?
Post reply on HN