472,143 Members | 1,793 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,143 software developers and data experts.

Decent C++ library for matrix manipulation and calculating Eigenvalues/vectors

Does anyone know of a decent (free/easy to use) C++ library for
manipulating matrices and caculating eigenvalues, eigenvectors and so
on? I intend to add some Principal Component Analysis functionality to
some software.

Any recommendations appreciated.

Jul 23 '05 #1
13 5694
Havatcha wrote:
Does anyone know of a decent (free/easy to use) C++ library for
manipulating matrices and caculating eigenvalues, eigenvectors and so
on? I intend to add some Principal Component Analysis functionality to
some software.

Any recommendations appreciated.


There's a collection of Fortran libraries for linear algebra called
LAPACK. I'm pretty sure it's free though I can't testify to its ease of
use. At the very least you'll have to get your compiler to link C++
code to Fortran objects.

A google search reveals that there are packages LAPACK++ and CLAPACK
which appear to be C++ and C code.
Jul 23 '05 #2

"Havatcha" <no****@for.me> wrote in message
news:d5**********@nntp0.reith.bbc.co.uk...
Does anyone know of a decent (free/easy to use) C++ library for
manipulating matrices and caculating eigenvalues, eigenvectors and so
on? I intend to add some Principal Component Analysis functionality to
some software.

Any recommendations appreciated.


what platform and compiler are you using?
Jul 23 '05 #3
Havatcha wrote:
Does anyone know of a decent (free/easy to use) C++ library for
manipulating matrices and caculating eigenvalues, eigenvectors and so
on? I intend to add some Principal Component Analysis functionality to
some software.

Any recommendations appreciated.


Take a look at
The C++ Scalar, Vector, Matrix and Tensor class Library

http://www.netwood.net/~edwin/svmtl/

Then take a look at
The Object-Oriented Numerics Page

http://www.oonumerics.org/oon/
Jul 23 '05 #4
Try this:

The Matrix Template Library (MTL)
http://www.osl.iu.edu/research/mtl/

The Matrix Template Library (MTL) is a high-performance generic
component library that provides comprehensive linear algebra
functionality for a wide variety of matrix formats.

As with the Standard Template Library (STL), MTL uses a five-fold
approach, consisting of generic functions, containers, iterators,
adaptors, and function objects, all developed specifically for high
performance numerical linear algebra. Within this framework, MTL
provides generic algorithms corresponding to the mathematical operations
that define linear algebra. Similarly, the containers, adaptors, and
iterators are used to represent and to manipulate concrete linear
algebra objects such as matrices and vectors.

To many scientific computing users, however, the advantages of an
elegant programming interface are secondary to issues of performance.
Generic programming is a powerful tool in this regard as well -
performance tuning can itself be described in a generic fashion. These
performance tuning abstractions are realized in a generic low-level
library - the Basic Linear Algebra Instruction Set (BLAIS). Experimental
results show that MTL with the BLAIS achieves performance that is as
good as, or better than, vendor-tuned libraries. Thus, MTL demonstrates
that the proper abstractions can be used to achieve high levels of
performance, contrary to conventional wisdom. In addition, MTL requires
orders of magnitude fewer lines of code for its implementation, with the
concomitant savings in development and maintenance effort.

Yuriy

Havatcha wrote:
Does anyone know of a decent (free/easy to use) C++ library for
manipulating matrices and caculating eigenvalues, eigenvectors and so
on? I intend to add some Principal Component Analysis functionality to
some software.

Any recommendations appreciated.


Jul 23 '05 #5


Bill Shortall wrote:
"Havatcha" <no****@for.me> wrote in message
news:d5**********@nntp0.reith.bbc.co.uk...
Does anyone know of a decent (free/easy to use) C++ library for
manipulating matrices and caculating eigenvalues, eigenvectors and so
on? I intend to add some Principal Component Analysis functionality to
some software.

Any recommendations appreciated.

what platform and compiler are you using?

Good point, GCC3.3 and Linux.

Looks like there are a few interesting libraries to choose from already
on the thread, thanks everyone for your help.

Jul 23 '05 #6

"Havatcha" <no****@for.me> wrote in message
news:d5**********@nntp0.reith.bbc.co.uk...


Bill Shortall wrote:
"Havatcha" <no****@for.me> wrote in message
news:d5**********@nntp0.reith.bbc.co.uk...
Does anyone know of a decent (free/easy to use) C++ library for
manipulating matrices and caculating eigenvalues, eigenvectors and so
on? I intend to add some Principal Component Analysis functionality to
some software.

Any recommendations appreciated.
what platform and compiler are you using?

Good point, GCC3.3 and Linux.

Looks like there are a few interesting libraries to choose from already
on the thread, thanks everyone for your help.


Linear algebra libs and eigenvectors rank close to root canal work
in the

heirarcy of assignments C++ programmers avoid. There isn't even the most

remote possibility you will find a library that is

1 written entirely in C++
2 fully featured i.e. has equation solving, decompositions like the
SVD and QR , and eigenvalues symmetric & non symmetric
3 includes the source code
4 free.

There is however the very good probability that you will spend a LOT of

time messing arround with the libs out there and get nothing for your
efforts.

Many of the libs write the kernel in C or C++ and then try to link it to
the old

LAPACK libs written in fortran. Unfortunately they don't include the final
linklib

file so you have to get yourself a fortran compiler, C++ compiler, and

compatable linker for the two .. not easy. LAPACK has many many thousands
of lines

All of the free libs out there have some sort of problem. My advise:

1. buy MATLAB and the toolbox you need for your problem.

2. try the Gnu Scientific Library ( GSL) it's written in C not C++
and it won't compile on windows; but it has the symmetric eigenvalues
and SVD you need for your SCA. It even has a big thick manual in print.

3. Look at Quantlib. It's in C++, free ,very well written, and does have
the
SVD ( not eigens) but its not exactly a Linear Algebra Package .
You will have to pick those parts out. You might get it running in two
weeks.
www.quantlib.org

4. talk to the people who have writen C++ LAPACK combinations and see if
they
will do the fortran compilations and linking for you
5. Do not let the thought of writing it yourself reside in your memory for
more than a nanosecond.

Good luck,.... Bill

Jul 23 '05 #7
On Tue, 10 May 2005 16:47:22 +0100, Havatcha wrote:
Does anyone know of a decent (free/easy to use) C++ library for
manipulating matrices and caculating eigenvalues, eigenvectors and so
on? I intend to add some Principal Component Analysis functionality to
some software.

Any recommendations appreciated.


You may find some useful resources at http://www.oonumerics.org/

--
Greg Schmidt gr***@trawna.com
Trawna Publications http://trawna.com/
Jul 23 '05 #8
Havatcha <no****@for.me> wrote:
Does anyone know of a decent (free/easy to use) C++ library for
manipulating matrices and calculating eigenvalues, eigenvectors and so
on? I intend to add some Principal Component Analysis functionality to
some software.

Any recommendations appreciated.


I think newmat11 is good for this kind of thing, but since I wrote it
this is not an unbiased opinion.

See http://www.robertnz.com

Robert

Jul 23 '05 #9
Robert Davies wrote:
Havatcha wrote:
Does anyone know of a decent (free/easy to use) C++ library for
manipulating matrices and calculating eigenvalues, eigenvectors and so
on? I intend to add some Principal Component Analysis functionality to
some software.

Any recommendations appreciated.
I think newmat11 is good for this kind of thing,


I think so too.
but, since I wrote it, this is not an unbiased opinion.
Your bias is shared by lots of people.
See http://www.robertnz.com

Jul 23 '05 #10
"Bill Shortall" <pe***@cminet.net> wrote in message news:d5********@enews1.newsguy.com...

"Havatcha" <no****@for.me> wrote in message
news:d5**********@nntp0.reith.bbc.co.uk...

Bill Shortall wrote:
"Havatcha" <no****@for.me> wrote in message
news:d5**********@nntp0.reith.bbc.co.uk...

>Does anyone know of a decent (free/easy to use) C++ library for
>manipulating matrices and caculating eigenvalues, eigenvectors and so
>on? I intend to add some Principal Component Analysis functionality to
>some software.
>
>Any recommendations appreciated.

what platform and compiler are you using?
Good point, GCC3.3 and Linux.

Looks like there are a few interesting libraries to choose from already
on the thread, thanks everyone for your help.


Linear algebra libs and eigenvectors rank close to root canal work
in the heirarcy of assignments C++ programmers avoid. There isn't
even the most remote possibility you will find a library that is

1 written entirely in C++
2 fully featured i.e. has equation solving, decompositions like the
SVD and QR , and eigenvalues symmetric & non symmetric
3 includes the source code
4 free.

There is however the very good probability that you will spend a LOT of
time messing arround with the libs out there


I'm with you so far...
and get nothing for your efforts.
Why? The learning curve may be steep but it's not rocket science...
Many of the libs write the kernel in C or C++ and then try to link it to
the old LAPACK libs written in fortran.
.... actually, LAPACK is probably very widely used in rocket science ;-)

Anyhow, old it may be, but LAPACK (with the BLAS linear algebra kernel) is *very* efficient, exceedingly well debugged,
stable and probably among the most "tried and tested" software in existence. LAPACK still represents the state of the
art in efficient linear algebra manipulation. It is not pretty, nor is the programming interface particularly friendly
(that may be an understatement), but if you are serious about linear numerics it may well be worth getting to grips
with. You will certainly end up learning (possibly more than you wanted to know) about linear algebra computing.
Unfortunately they don't include the final linklib file so you have to get
yourself a fortran compiler, C++ compiler, and compatable linker for the
two .. not easy.


Seeing as the OP has GCC he/she already has a fortran compiler (g77), C compiler (gcc), C++ compiler (g++), compatible
linker (ld) and will indeed be able to build and link with fortran LAPACK.

Many processor/compiler vendors provide highly optimised BLAS and/or LAPACK implementations. There is also the open
source ATLAS project (http://math-atlas.sourceforge.net/) which can build BLAS + (a subset of) LAPACK libraries -
automatically tuned for your platform - and includes a C (although not C++) interface. It is simple to build with GCC (I
have done so under Linux and also under Cygwin on Win32).

Regards,

--
Lionel B

Jul 23 '05 #11

Linear algebra libs and eigenvectors rank close to root canal work
in the

heirarcy of assignments C++ programmers avoid. There isn't even the most

remote possibility you will find a library that is

1 written entirely in C++
2 fully featured i.e. has equation solving, decompositions like the
SVD and QR , and eigenvalues symmetric & non symmetric
3 includes the source code
4 free.


I had started to come to that conclusion, and since time is pressing, I
will be using Octave (www.octave.org) instead for the calculations with
a few system() calls and string parsing. Clunky, but less of a headache.

Jul 23 '05 #12

"Lionel B" <me@privacy.net> wrote in message
news:42***********************@news.sunsite.dk...
"Bill Shortall" <pe***@cminet.net> wrote in message news:d5********@enews1.newsguy.com...

"Havatcha" <no****@for.me> wrote in message
news:d5**********@nntp0.reith.bbc.co.uk...

Bill Shortall wrote:

> "Havatcha" <no****@for.me> wrote in message
> news:d5**********@nntp0.reith.bbc.co.uk...
>
>>Does anyone know of a decent (free/easy to use) C++ library for
>>manipulating matrices and caculating eigenvalues, eigenvectors and so >>on? I intend to add some Principal Component Analysis functionality to >>some software.
>>
>>Any recommendations appreciated.
>
> what platform and compiler are you using?

Good point, GCC3.3 and Linux.

Looks like there are a few interesting libraries to choose from already on the thread, thanks everyone for your help.


Linear algebra libs and eigenvectors rank close to root canal work
in the heirarcy of assignments C++ programmers avoid. There isn't
even the most remote possibility you will find a library that is

1 written entirely in C++
2 fully featured i.e. has equation solving, decompositions like the
SVD and QR , and eigenvalues symmetric & non symmetric
3 includes the source code
4 free.

There is however the very good probability that you will spend a LOT of
time messing arround with the libs out there


I'm with you so far...
and get nothing for your efforts.


Why? The learning curve may be steep but it's not rocket science...
Many of the libs write the kernel in C or C++ and then try to link it to
the old LAPACK libs written in fortran.


... actually, LAPACK is probably very widely used in rocket science ;-)

Anyhow, old it may be, but LAPACK (with the BLAS linear algebra kernel) is

*very* efficient, exceedingly well debugged, stable and probably among the most "tried and tested" software in existence. LAPACK still represents the state of the art in efficient linear algebra manipulation. It is not pretty, nor is the programming interface particularly friendly (that may be an understatement), but if you are serious about linear numerics it may well be worth getting to grips with. You will certainly end up learning (possibly more than you wanted to know) about linear algebra computing.
Unfortunately they don't include the final linklib file so you have to get yourself a fortran compiler, C++ compiler, and compatable linker for the two .. not easy.
Seeing as the OP has GCC he/she already has a fortran compiler (g77), C

compiler (gcc), C++ compiler (g++), compatible linker (ld) and will indeed be able to build and link with fortran LAPACK.

Many processor/compiler vendors provide highly optimised BLAS and/or LAPACK implementations. There is also the open source ATLAS project (http://math-atlas.sourceforge.net/) which can build BLAS + (a subset of) LAPACK libraries - automatically tuned for your platform - and includes a C (although not C++) interface. It is simple to build with GCC (I have done so under Linux and also under Cygwin on Win32).

Regards,

--
Lionel B
LAPACK is a great system; but I believe
that getting it up and running is too
much to expect for a C++ programmer especially if his Fortran is rusty,

You didn't say which C++ main library you linked to - MTL, IT++ ?? How
long did it take you to do it? What are the problems.?

Regards...Bill

Jul 23 '05 #13
"Bill Shortall" <pe***@cminet.net> wrote in message news:d5*********@enews4.newsguy.com...

"Lionel B" <me@privacy.net> wrote in message
news:42***********************@news.sunsite.dk...
"Bill Shortall" <pe***@cminet.net> wrote in message news:d5********@enews1.newsguy.com...

[...]
Many processor/compiler vendors provide highly optimised BLAS and/or

LAPACK implementations. There is also the open
source ATLAS project (http://math-atlas.sourceforge.net/) which can build

BLAS + (a subset of) LAPACK libraries -
automatically tuned for your platform - and includes a C (although not

C++) interface. It is simple to build with GCC (I
have done so under Linux and also under Cygwin on Win32).


LAPACK is a great system; but I believe
that getting it up and running is too
much to expect for a C++ programmer especially if his Fortran is rusty,


I found getting ATLAS[*] up and running to be as simple as typing "make" and "make install" and answering a few prompts
(it can be a rather lengthy process - about 6-8 hours on my P4 (!) - as ATLAS tunes itself by running screeds of timing
tests). At the end of the install you're set up with the atlas/blas/lapack libraries and C headers cblas.h and
clapack.h. The function calls in these headers are reasonably documented and correspond exactly to the legacy Fortran
BLAS and LAPACK interface - but you don't need to know any Fortran at all - it's straight C (you'll need to wrap the
headers in extern "C" to use in C++).
You didn't say which C++ main library you linked to - MTL, IT++ ?? How
long did it take you to do it? What are the problems.?


The point to note is that BLAS/LAPACK handle (dense) matrices as simple 1-d arrays (of float, double or complex type);
as long as your C++ matrix library can handle this storage format (row- or column-major is ok), implementing an
interface shouldn't be too problematic. I generally use my own rather basic matrix library, but I have in the past
successfully hacked Blitz++ (http://www.oonumerics.org/blitz/) to interface to a few BLAS/LAPACK routines - that wasn't
too difficult. The trickiest part is probably matching up the strides, transpose states, order, etc. with your library.

Efficiency-wise alone it pays off; I've found straight matrix multiplication via the ATLAS/BLAS gemm() call to be orders
of magnitude faster than I could code it in pure C or C++. Even beats Matlab hands down on my system...
[*] Be aware that ATLAS doesn't implement the full LAPACK (although I believe there's work underway to extend it).
Enough to do eigenvalues, solve equations, invert matrices, etc, though. [There are instructions in the ATLAS docs on
how to set up a full Fortran LAPACK so that it will use the ATLAS BLAS, but that sounded a little hairy... haven't tried
it].

Cheers,

--
Lionel B
Jul 23 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Erik Borgstr?m | last post: by
13 posts views Thread by Charulatha Kalluri | last post: by
3 posts views Thread by rickz | last post: by
2 posts views Thread by Emacs Row | last post: by
6 posts views Thread by lancered | last post: by
14 posts views Thread by James Stroud | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.