Skip to content

"best" c++ matrix library?

4 messages · Ott Toomet, Vehbi Sinan Tunalioglu, Rafael Laboissiere +1 more

#
Hi folks,

I am planning to write some more time-consuming matrix manipulations
in c++.  What is the experience with the existing c++ matrix
libraries?  Do you have some recommendations?  Are some libraries more
compatible with R than the others?

All suggestions welcome!

Best,
Ott
#
Hi,

I used Meschach: http://www.math.uiowa.edu/~dstewart/meschach/
However, it is written in C. The API is strong. I used the same API and
trimmed down the functionality, as well. Both worked for me.

IBM Developworks has an article on the subject "Matrix libraries for C
and C++":
http://www-128.ibm.com/developerworks/linux/library/l-matrix.html

It has also a comparison for some libraries.

I wonder if there is another library...

--vst
Ott Toomet wrote:
#
* Ott Toomet <otoomet at ut.ee> [2005-08-31 19:53]:
Liboctave is a quite powerful C++ matrix library.  It is part of Octave
(www.octave.org), but you can write standalone applications with it.
Since liboctave links against standard Fortran and C libraries (lapack,
odepack, minpack, quadpack, slatec, fftw, etc), you have access to all
matrix algorithms of Octave.

Attached below is an example, showing eigenvalue computation (via the
lapack routine).  Also attached is the compilation command and the output
of the program (in my Debian sarge box).

I do not know how liboctave compares with the other libraries as regards
speed.  As far as I know, there is no efforts for gluing liboctave into
R.
#
Ott Toomet <otoomet <at> ut.ee> writes:
A loooong time ago, I used to use the newmat C++ library by Robert Davies -- 
see http://www.robertnz.net/nm_intro.htm which states 
    "This C++ library is intended for scientists and engineers who need to
     manipulate a variety of types of matrices using standard matrix operations.
     Emphasis is on the kind of operations needed in statistical calculations
     such as least squares, linear equation solve and eigenvalues."

In fact, my use even lead to a short review about newmat and g++ for the Journal 
of Applied Econometrics (http://dirk.eddelbuettel.com/papers/gccnewmat.ps.gz).

Robert has continued to maintain, support and extend newmat. I would probably 
start there if I needed a C++ Matrix library as newmat is (in no order of 
preference)
-- fairly small (unlike Boost)
-- as I recall, doesn't depend on anything else
-- well documented 
-- well tested
-- pretty "clean" conceptually

Moreover, Robert really is a statistician so there may be interest on his side
in tieing newmat to R if were to provide some prototypes. 

But this really is a question of programming style and preferences, and mine
certainly changed in the meantime so take this with the usual spoon of salt.

Hope this helps,  Dirk