1
$\begingroup$

I usually work with Python, but my basic knowledge of c++ allows me to switch when I need to increase the speed of my code.

Currently, I have a python script that (among other things) computes the mean and standard deviation of all principal minors (of a specified order) of a square matrix. Minors are determinants of submatrices (see Wikipedia for definition). Even a matrix with 30x30 entries has more than a billion different submatrices and thus more than a billion different minors. So even tiny time differences in the computation of minors matter a lot to me.

Python/NumPy uses LAPACK routines for creating submatrices and computing determinants. So I assumed that it would be best to use the same routines in c++. However, it seems that more experienced programmers tend to dissuade beginners from using the LAPACK library in c++ (see other question on stackexchange) and instead point to other packages, such as Armadillo or Eigen.

As far as I understand, Armadillo and Eigen are libraries that again rely on LAPACK, but I don't know if these libraries generate some kind of overhead that might slow things down.

So my question is: Should I expect that I pay for Armadillo's or Eigen's "beginner friendliness" with an increase in computation time (if compared to LAPACK)? If so, how much?

$\endgroup$
  • $\begingroup$ Eigen is well designed and will pose no overhead when calling LAPACK. Most of the time it will have its own implementation and be superior/faster than LAPACK if you use compiler optimization flags. $\endgroup$ – rfabbri Mar 13 at 6:39
1
$\begingroup$

The answer to your question is benchmarking. Both Armadillo and Eigen provide some benchmarks in their documentation. The only problem is that they don't compare to the same libraries, but you can still get an idea. Maybe there are more comprehensive benchmarks elsewhere...

In any case, the overhead of wrapping LAPACK in a C++ library will be much smaller compared to Python/Numpy.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.