Thursday, February 14, 2013

A nice linear algebra library for C++

Normally when coding in C++ you will use the interface of LAPACK or the boost library uBlas. However these are not really nice to use. I found an alternative and after spending an afternoon with it I must say I am impressed. The library is called Armadillo. The nice things are the initialization methods provided, the element access as well as the general operators. For example if I was to create
a 2 x 2 matrix with some values I can simply do this:

matrix << 1 << 2 << endr
           << 0 << 1 << endr;

Accessing an element is simply:

matrix(i, j)

And operations can be performed as:

X =  A * B
X = A + B

The functionality seems to include everything I needed so far:

det(X)
inv(X)

In the end there is a speed comparison in which armadillo is always the fastest.

2 comments:

  1. Nice! Have you tried OpenCV's matrix implementation?

    ReplyDelete
  2. Yes I have, it is a great matrix library, too that I currently use. I use armadillo when I don't want the computer vision overhead.

    ReplyDelete

Note: Only a member of this blog may post a comment.