473,385 Members | 1,373 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 5823
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Sam | last post by:
Hello, in my coding work I'm going to using a lot of matix manipulation, just basic matrix addition, multiplication, Gaussian method solving for roots, least square... But I don't know if there's...
7
by: Erik Borgstr?m | last post by:
Hi, I simply want to use simple matrices of ints or doubles in C++ and I want all the good: 1) be able to use double-index, e.g. m 2) not have to use pointers at all 3) do it fast I know...
13
by: Charulatha Kalluri | last post by:
Hi, I'm implementing a Matrix class, as part of a project. This is the interface I've designed: class Matrix( )
3
by: rickz | last post by:
Hi, Does anybody know where I can find the matrix computation components in .NET framework? Do I need to use a third-party one or there's one that comes with the framework libraries? ...
2
by: Emacs Row | last post by:
Hello NG, I'm using Numerical Recipes in C++. Now I'm looking for a routine to calculate the eigenvalues of a matrix with *complex* valued entries. The matrix type is Mat_IO_CPLX_DP. So...
6
by: lancered | last post by:
Hi dear all, I am using Python2.4.2+NumPy1.0.1 to deal with a parameter estimation problem with the least square methods. During the calculations, I use NumPy package to deal with matrix...
14
by: James Stroud | last post by:
Hello All, I'm using numpy to calculate determinants of matrices that look like this (13x13):
4
by: krishnai888 | last post by:
I had already asked this question long back but no one has replied to me..I hope someone replies to me because its very important for me as I am doing my internship. I am currently writing a code...
9
by: curiously enough | last post by:
I need a practical method to find the eigenvalues of a matrix in C++ because the one I know(the only one I know) is to subtract the elements of the diagonal by the eigenvalue and then find the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.