Good matrix libraries?

I do math code and need a good matrix library. I could use a two-dimensional array, but a full library of matrices (with multiplication, addition, etc.) would be much more convenient. Obviously, I was already looking for it, but it gave me many options. I was hoping that the opinions of several experienced programmers would help narrow it down.

What are good free matrix / linear algebra libraries for C ++?

+4
source share
4 answers

You can try uBlas

Functionality

uBLAS provides C ++ template classes for dense, unit, and sparse vectors, dense, identical, triangular, striped, symmetric, Hermitian, and sparse matrices. Representations in vectors and matrices can be constructed through ranges, slices, adapter classes, and indirect arrays. The library covers the usual basic operations of linear algebra on vectors and matrices: abbreviations as different norms, addition and subtraction of vectors and matrices, and multiplication by scalar, internal and external products of vectors, matrix vector and matrix matrix products, and triangular solver. The glue between containers, views, and templates with an expression template is mainly STL-compatible iterator interface.

+5
source

Eigen is a very fast matrix manipulation and linear algebra library that uses hardware acceleration when available.

+6
source

There is also IT ++ , which has an easy-to-use syntax similar to Matlab. Armadillo also has very similar syntax, but is known to be significantly faster than IT ++. (Armadillo uses meta-programming of templates, but IT ++ does not). Both Armadillo and IT ++ provide their own decomposition, decomposition of singular values, matrix inversion, etc. In contrast, uBlas uses template metaprogramming for speed, but can invert the matrix, etc.

Speed ​​difference cones in a compromise in terms of different sets of functionality in various fields, for example. IT ++ has many functions for signal processing, and Armadillo almost exclusively focuses on linear algebra.

This causes a related point: the speed of the library is only one of the factors of its overall utility or value. For example, you may have a very fast library, but it takes quite a while to learn its API / syntax, or the syntax is difficult to use. Another problem is the amount of functionality already present in the library - for example. You may need to write your own functions. You may also need to consider whether the purpose of the library is to facilitate the conversion of Matlab code to C ++ or whether you are already familiar with the Matlab syntax.

Given the above points, you can end up spending more time coding and debugging than running your code, which ultimately wins the goal of a fast library. In other words, raw execution speed is just one factor, and you cannot rely on it as a common deciding factor. Development time is also a very important factor (for example, "time for the product"), not only in terms of costs, but also because less time spent on coding frees you from other things.

+5
source

In the past, I used Armadillo . I can’t talk about its speed capabilities - it was recommended to me by a friend, as it demonstrates some similarities with the functions and designations of MATLAB. I did not try anything very intense, but it served my purpose at the time when I used it. I also heard good things about uBlas, also recommended here.

+2
source

All Articles