Boost::uBLAS vs Eigen
Asked Answered
N

3

24

I am used to Eigen for almost all my mathematical linear algebra work. Recently, I have discovered that Boost also provides a C++ template class library that provides Basic Linear Algebra Library (Boost::uBLAS). This got me wondering if I can get all my work based only on boost as it is already a major library for my code.

A closer look at both didn't really got me a clearer distinction between them:

  • Boost::uBLAS :

uBLAS provides templated C++ classes for dense, unit and sparse vectors, dense, identity, triangular, banded, symmetric, hermitian and sparse matrices. Views into vectors and matrices can be constructed via ranges, slices, adaptor classes and indirect arrays. The library covers the usual basic linear algebra operations on vectors and matrices: reductions like different norms, addition and subtraction of vectors and matrices and multiplication with a scalar, inner and outer products of vectors, matrix vector and matrix matrix products and triangular solver.

...

  • Eigen :

It supports all matrix sizes, from small fixed-size matrices to arbitrarily large dense matrices, and even sparse matrices.

It supports all standard numeric types, including std::complex, integers, and is easily extensible to custom numeric types.

It supports various matrix decompositions and geometry features.

Its ecosystem of unsupported modules provides many specialized features such as non-linear optimization, matrix functions, a polynomial solver, FFT, and much more.

...

Does anyone have a better idea about their key differences and on which basis can we choose between them?

Nicker answered 14/5, 2016 at 0:7 Comment(0)
A
16

I'm rewriting a substantial project from boost::uBLAS to Eigen. This is production code in a commercial environment. I was the one who chose uBLAS back in 2006 and now recommended the change to Eigen.

uBLAS results in very little actual vectorization performed by the compiler. I can look at the assembly output of big source files, compiled to amd64 architecture, with SSE, using the float type, and not find a single ***ps instruction (addps, mulps, subps, 4 way packed single-precision floating point instructions) and only ***ss instructions (addss, ..., scalar single-precision).

With Eigen, the library is written to make sure that vector instructions result.

Eigen is very feature complete. Has lots of matrix factorizations and solvers. In boost::uBLAS the LU factorization is an undocumented add-on, a piece of contributed code. Eigen has additions for 3D geometry, such as rotations and quaternions, not uBLAS.

uBLAS is slightly more complete on the most basic operations. Eigen lacks some things, such as projection (indexing a matrix using another matrix), while uBLAS has it. For features that both have, Eigen is more terse, resulting in expressions that are easier to read.

Then, uBLAS is completely stale. I can't understand how anyone considers it in 2016/2017. Read the FAQ:

Q: Should I use uBLAS for new projects? A: At the time of writing (09/2012) there are a lot of good matrix libraries available, e.g., MTL4, armadillo, eigen. uBLAS offers a stable, well tested set of vector and matrix classes, the typical operations for linear algebra and solvers for triangular systems of equations. uBLAS offers dense, structured and sparse matrices - all using similar interfaces. And finally uBLAS offers good (but not outstanding) performance. On the other side, the last major improvement of uBLAS was in 2008 and no significant change was committed since 2009. So one should ask himself some questions to aid the decision: Availability? uBLAS is part of boost and thus available in many environments. Easy to use? uBLAS is easy to use for simple things, but needs decent C++ knowledge when you leave the path. Performance? There are faster alternatives. Cutting edge? uBLAS is more than 10 years old and missed all new stuff from C++11.

Aciculate answered 10/10, 2018 at 11:3 Comment(0)
R
6

I just did a time complexity comparison between boost and eigen for fairly trivial matrix computations. These results, limited as they are, seem to denote that boost is a much better alternative. I had an FEM code which does the pre-processing parts (setting up the element matrices and stitching them together). So naturally, this would involve a lot of memory allocations.

enter image description here

I wrote identical pieces of codes with Boost and Eigen on C++ (gcc 5.4.0, ubuntu 16.04, Intel i3 Quad Core, 2.40GHz, RAM : 4Gb) and ran them separately for varying node sizes (N) and calculated time using the linux cl-utility. As far as I'm concerned, I have decided to proceed with my code in Boost.

Rilda answered 2/2, 2017 at 16:45 Comment(4)
Does the memory allocations affect the result?Horsewhip
What operation is the one you are performing here?Hedgehop
You should definitely show the source for this benchmark !Glynis
Unfortunately the source is a fairly large project (set of files) so i don't expect anyone to go through them. But the operations conducted were: (1) Constructing large matrices of size NxN using 8x8 submatrices. (2) Removing specific rows and columns from the "stitched" NxN matrixRilda
C
1

Choose Eigen if you care the performance and performance gain introduced by expression templates, and choose uBlas if you only want to learn expression templates.

http://eigen.tuxfamily.org/index.php?title=Benchmark

Clypeus answered 14/5, 2016 at 1:57 Comment(2)
Eigen also uses expression templates.Cadaverine
Note that these benchmarks are pretty old (from 2011) and not independent.Cadaverine

© 2022 - 2024 — McMap. All rights reserved.