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:> 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 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
* Ott Toomet <otoomet at ut.ee> [2005-08-31 19:53]:> 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?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. -- Rafael Laboissiere -------------- next part -------------- $ g++ -I/usr/include/octave eig.cc -o eig -L/usr/lib/octave-2.1.69/ -loctave $ LD_LIBRARY_PATH=/usr/lib/octave-2.1.69/ ./eig Original Matrix 3 2 2 0 Eigen Vectors (0.447214,0) (-0.894427,0) (-0.894427,0) (-0.447214,0) Eigen Values (-1,0) (4,0) Recomposed Matrix (3,0) (2,0) (2,0) (-9.92587e-17,0)
Ott Toomet <otoomet <at> ut.ee> writes:> 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?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
Thanks for everyone who replied to my question. I tried newmat myself, seems to be working well. What I am interested in is something like * Fast element-wise operations. You know, it may be slow in R. * (Some) control over memory allocation. I would like to specify when the matrix should not be copied. * Compatibility with R. At least the way how the matrix data is represented in memory should be the same as R has. Otherwise, the data interchange may become slow and memory-consuming. * And, of course, the basic matrix operations like multiplication, inverting, eigenvalues etc.... I am using linux/gcc if that matters. Best, Ott | From: "Tuszynski, Jaroslaw W." <JAROSLAW.W.TUSZYNSKI at saic.com> | Date: Wed, 31 Aug 2005 12:59:04 -0400 | | What kind of matrix operations do you need? | | Jarek | | -----Original Message----- | From: r-help-bounces at stat.math.ethz.ch | [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Ott Toomet | Sent: Wednesday, August 31, 2005 12:54 PM | To: r-help at stat.math.ethz.ch | Subject: [R] "best" c++ matrix library? | | 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
Le 01.09.2005 10:32, Ott Toomet a ??crit :>Thanks for everyone who replied to my question. > >I tried newmat myself, seems to be working well. What I am interested in >is something like > >* Fast element-wise operations. You know, it may be slow in R. > >* (Some) control over memory allocation. I would like to specify when > the matrix should not be copied. > >* Compatibility with R. At least the way how the matrix data is > represented in memory should be the same as R has. Otherwise, the > data interchange may become slow and memory-consuming. > >* And, of course, the basic matrix operations like multiplication, > inverting, eigenvalues etc.... > >I am using linux/gcc if that matters. > >Best, >Ott > | From: "Tuszynski, Jaroslaw W." <JAROSLAW.W.TUSZYNSKI at saic.com> > | Date: Wed, 31 Aug 2005 12:59:04 -0400 > | > | What kind of matrix operations do you need? > | > | Jarek > | > | -----Original Message----- > | From: r-help-bounces at stat.math.ethz.ch > | [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Ott Toomet > | Sent: Wednesday, August 31, 2005 12:54 PM > | To: r-help at stat.math.ethz.ch > | Subject: [R] "best" c++ matrix library? > | > | 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 > >Hello, CPPLAPACK : <http://cpplapack.sourceforge.net/> is a c++ wrapper for lapack routines. It is not so complicated to use once you have blas and lapack installed. I think it is much faster than newmat. Romain -- visit the R Graph Gallery : http://addictedtor.free.fr/graphiques ~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~ ~~~~~~ Romain FRANCOIS - http://addictedtor.free.fr ~~~~~~ ~~~~ Etudiant ISUP - CS3 - Industrie et Services ~~~~ ~~ http://www.isup.cicrp.jussieu.fr/ ~~ ~~~~ Stagiaire INRIA Futurs - Equipe SELECT ~~~~ ~~~~~~ http://www.inria.fr/recherche/equipes/select.fr.html ~~~~~~ ~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~