tags:

views:

1944

answers:

8

I would need some basic vector mathematics constructs in an application. Dot product, cross product. Finding the intersection of lines, that kind of stuff.

I can do this by myself (in fact, have already) but isn't there a "standard" to use so bugs and possible optimizations would not be on me?

Boost does not have it. Their mathematics part is about statistical functions, as far as I was able to see.

Addendum:

Boost 1.37 indeed seems to have this. They also gracefully introduce a number of other solutions at the field, and why they still went and did their own. I like that.

+2  A: 

Re-check that ol'good friend of C++ programmers called Boost. It has a linear algebra package that may well suits your needs.

PW
Seems that part is only in the new 1.37 branch, but I will have a look. Thanks!!
akauppi
I'm pretty sure boost::numeric::ublas has been around since 1.29 or earlier. His link is just for 1.37.
tgamblin
indeed, first release is in 1.29, as written by tgamblin: see at the bottom of that page: http://www.boost.org/doc/libs/1_37_0
PW
It is beneficial to compare Boost's UBLAS performance with eigen and others:http://eigen.tuxfamily.org/index.php?title=Benchmark
Comptrol
+1  A: 

Check www.netlib.org, which is maintained by Oak Ridge National Lab and the University of Tennessee. You can search for numerical packages there. There's also Numerical Recipes in C++, which has code that goes with it, but the C++ version of the book is somewhat expensive and I've heard the code described as "terrible." The C and FORTRAN versions are free, and the associated code is quite good.

Scottie T
Besides being generally weak, the code in Numerical Recipes also has an odd license attached to its use.
David Nehme
When using code from Numerical Recipes in C beware of 'exit' statements in the code.It took me some time to figure out why my application sometimes "crashed" because of this.
mxp
About the book itself I'd say it is well written and explains just as much about a problem as necessary. Concerning the provided code, I agree with David.
mxp
boost::numeric::ublas uses ublas, which is maintained by netlib.
tgamblin
+1  A: 

I would stay away from using NRC code for anything other than learning the concepts.

I think what you are looking for is Blitz++

Scott
clearly Blitz++ underperforms with respect to other ones:http://eigen.tuxfamily.org/index.php?title=Benchmark
Comptrol
It depends on the size and kind of the vector. For small vectors whose length is known at compile time, Blitz++ can generate unrolled code for dot products etc., which can't be beat. Large vectors, where tiling and cacheing is of the highest importance, is a different matter.
Seth Johnson
A: 

There is a nice Vector library for 3d graphics in the prophecy SDK:

Check out http://www.twilight3d.com/downloads.html

Laserallan
A: 

For linear algebra: try JAMA/TNT . That would cover dot products. (+matrix factoring and other stuff) As far as vector cross products (really valid only for 3D, otherwise I think you get into tensors), I'm not sure.

Jason S
+3  A: 

I've not tested it, but the C++ eigen library is becoming increasingly more popular these days. According to them, they are on par with the fastest libraries around there and their API looks quite neat to me.

Johannes Schaub - litb
Take a look at some benchmarks at http://eigen.tuxfamily.org/index.php?title=Benchmark
gnud
A: 

For an extremely lightweight (single .h file) library, check out CImg. It's geared towards image processing, but has no problem handling vectors.

eglaser
+1  A: 

Armadillo

Armadillo employs a delayed evaluation approach to combine several operations into one and reduce (or eliminate) the need for temporaries. Where applicable, the order of operations is optimised. Delayed evaluation and optimisation are achieved through recursive templates and template meta-programming.

While chained operations such as addition, subtraction and multiplication (matrix and element-wise) are the primary targets for speed-up opportunities, other operations, such as manipulation of submatrices, can also be optimised. Care was taken to maintain efficiency for both "small" and "big" matrices.

Comptrol