Linear Alegebra in C++

R

RS

Hi all,

I am looking for a fast, efficient (tuned for speed, not size) and
mature C++ code to do some numerical work with. I have looked at the
Template Numerical Toolkit, which the oonumerics.org web page claims is
a successor to lapack++. But on the surface it doesn't seem to have all
the functionalities of lapack++, let alone being its successor. On the
other hand, it may be faster. I haven't checked that yet. Lapack++ is
supposed to be a wrapper for ublas. TNT doesn't seem to have anything to
do with ublas. It hasn't been updated that often. There is also a
cpplapack that is being developed independently of lapack++.

My question is how fast is TNT. Is it faster than the other packages? If
you were to chose one package, which one would you chose?

Thanks,
RS
 
M

mlimber

RS said:
I am looking for a fast, efficient (tuned for speed, not size) and
mature C++ code to do some numerical work with. I have looked at the
Template Numerical Toolkit, which the oonumerics.org web page claims is
a successor to lapack++. But on the surface it doesn't seem to have all
the functionalities of lapack++, let alone being its successor. On the
other hand, it may be faster. I haven't checked that yet. Lapack++ is
supposed to be a wrapper for ublas. TNT doesn't seem to have anything to
do with ublas. It hasn't been updated that often. There is also a
cpplapack that is being developed independently of lapack++.

My question is how fast is TNT. Is it faster than the other packages? If
you were to chose one package, which one would you chose?

I'm no help here, and you'll likely get better answers elsewhere. This
group focuses on the C++ language proper, not third-party libraries
(see http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9).
Sorry.

Cheers! --M
 
M

matthewlimber

Do you know how to write the quadratic equation in C++?

Yes. One way would be:

float qe( const float a, const float b, const float c )
{
const float discriminant = b*b - 4.0*a*c;
if( discriminant < 0 )
{
cout << "Roots are imaginary." << endl;
}
else
{
const float denom = 2*a;
cout << "Roots are: " << (-b+discriminant) / denom
<< ", " << (-b-discriminant) / denom
<< endl;
}
}

Cheers! --M
 
G

Gert Van den Eynde

RS said:
Hi all,

I am looking for a fast, efficient (tuned for speed, not size) and
mature C++ code to do some numerical work with. I have looked at the
Template Numerical Toolkit, which the oonumerics.org web page claims is
a successor to lapack++. But on the surface it doesn't seem to have all
the functionalities of lapack++, let alone being its successor. On the
other hand, it may be faster. I haven't checked that yet. Lapack++ is
supposed to be a wrapper for ublas. TNT doesn't seem to have anything to
do with ublas. It hasn't been updated that often. There is also a
cpplapack that is being developed independently of lapack++.

My question is how fast is TNT. Is it faster than the other packages? If
you were to chose one package, which one would you chose?

Thanks,
RS

I'm using the gmm++ library that is part of GetFem++
http://www-gmm.insa-toulouse.fr/getfem/ It can interface a fortran
Blas/Lapack library like ATLAS and LAPACK. Quite happy with it.

bye,
gert
 
M

mlimber

cout << "Roots are: " << (-b+discriminant) / denom
<< ", " << (-b-discriminant) / denom
<< endl;

Oops. Make that sqrt(discriminant) on both lines.

Cheers! --M
 
P

Philip Potter

Yes. One way would be:

float qe( const float a, const float b, const float c )
{
const float discriminant = b*b - 4.0*a*c;
if( discriminant < 0 )
{
cout << "Roots are imaginary." << endl;
}
else
{
const float denom = 2*a;
cout << "Roots are: " << (-b+discriminant) / denom
<< ", " << (-b-discriminant) / denom
<< endl;
}
}

This method is unnecessarily unstable. If either (-b+sqrt(discriminant)) or
(-b-sqrt(discriminant)) are close to 0 [if b is large compared to a*c], you
will lose a number of significant bits. Consult your favourite numerical
textbook for a better solution, or detect for yourself whether you will lose
significance and calculate the root another way in that case.

Philip
 
V

Victor Bazarov

Philip said:
Do you know how to write the quadratic equation in C++?

Yes. One way would be:

float qe( const float a, const float b, const float c )
{
[..]
}

This method is unnecessarily unstable. If either
(-b+sqrt(discriminant)) or (-b-sqrt(discriminant)) are close to 0 [if
b is large compared to a*c], you will lose a number of significant
bits. Consult your favourite numerical textbook for a better
solution, or detect for yourself whether you will lose significance
and calculate the root another way in that case.

Not to mention that if 'a' is 0, it's not quadratic any more...

V
 
D

Dave Steffen

RS said:
Hi all,

I am looking for a fast, efficient (tuned for speed, not size) and
mature C++ code to do some numerical work with. I have looked at the
Template Numerical Toolkit, which the oonumerics.org web page claims
is a successor to lapack++. But on the surface it doesn't seem to have
all the functionalities of lapack++, let alone being its successor. On
the other hand, it may be faster. I haven't checked that yet. Lapack++
is supposed to be a wrapper for ublas. TNT doesn't seem to have
anything to do with ublas. It hasn't been updated that often. There is
also a cpplapack that is being developed independently of lapack++.

My question is how fast is TNT. Is it faster than the other packages?
If you were to chose one package, which one would you chose?

I've done a bit of research in this area recently. The first thing
I'd tell you to do is look around a lot more. There are a load of
linear algebra libraries out there; or rather there are a few _good_
and _complete_ ones, and a load of others. Linear Algebra is one of
those areas that looks stright-forward enough for everyone and their
grandmother to start developing one, but is actually hard enough that
few get anywhere.

I've used TNT in the past, and have to say it's an easy library to
understand, and to hack if you need to. I don't know how fast it is,
but I wouldn't guess it's one of the fastest. (I could be wrong,
though. See below.)

If your problems have compile-time sizes (e.g. you know the vector and
matrix dimensions at compile time), run (don't walk) to 'tvmet'. It's
not a large library, but it's complete, and it's _extremely fast_.

Other libs you might look at are IT++, Boost:uBlas, Blitz++, and
GNUSSL. Although GNUSSL is stricly C, not C++, it's just about the
only such library out there that's thread safe, and its performance
isn't half bad last I looked.

** All that having been said, there's no substitute for profiling.
For example, a library that uses BLAS and LAPACK for the heavy lifting
will be far superior for large matrices, since that's what LAPACK was
really built for. For small matrices, BLAS and LAPACK are typically
slower, sometimes _much_ slower, than other solutions. All of these
libraries make trade-offs, and which one is fastest really depends
rather heavily on your application.
 
B

Bill Shortall

RS said:
Hi all,

I am looking for a fast, efficient (tuned for speed, not size) and
mature C++ code to do some numerical work with. I have looked at the
Template Numerical Toolkit, which the oonumerics.org web page claims is
a successor to lapack++. But on the surface it doesn't seem to have all
the functionalities of lapack++, let alone being its successor. On the
other hand, it may be faster. I haven't checked that yet. Lapack++ is
supposed to be a wrapper for ublas. TNT doesn't seem to have anything to
do with ublas. It hasn't been updated that often. There is also a
cpplapack that is being developed independently of lapack++.

My question is how fast is TNT. Is it faster than the other packages? If
you were to chose one package, which one would you chose?

Thanks,
RS

Try ppLinear
www.pecos-place.com

This is a C++ class library for linear algebra somewhat similiar to the TNT
but
making extensive use of the STL for code compaction. The library ( now in
beta) is fairly complete
i.e. it has the "meat and potatoes " functions of linear algebra - equation
solving, decompositions like SVD, QR, and LU also eigenvectors both
symmetric and non.
The library is designed for electrical engineering problems so the
functions all work for complex variables.
The library is distributed as header files and a static library. There
are versions for Microsoft VC6 and GNU GCC. Souce code is private. Update
coming in a few weeks.
It's very easy to use and quite fast. a 500*500 single precision multiply
takes 125 milliseconds (equates to 2 Gigaflops) timing results are on my
website.
The source code is only 6000 lines of C++ quite a bit smaller than
LAPACK's 100,000 lines. This makes it easy to work with. The algorithms used
are designed for the smaller problems i.e. matrices less than 5000 by 5000
eigenvectors less than 1000.

Bill Shortall
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top