views:

513

answers:

4

Which library do you use for N-dimensional arrays?

I use blitz++ at work and I really dislike some aspect of it. Some aspect of it are even dangerous. The need for resizing before using operator=. A(Range::all(), Range::all()) throws for an (0,0) matrix, etc. and the linear algebra operations are to be done via clapack.

I used and loved eigen. I appreciate its "all-in-header" implementations, the C++ syntactic sugar, and the presence of all the linear algebra operations I need (matrix multiplication, system resolution, cholesky...)

What are you using?

+7  A: 

boost::array and also boost::MultiArray. There's also a pretty good linear algebra package in boost called uBLAS

Andreas Brinck
or std::array, if you are using gcc with -std=c++0x
coelhudo
boost multiarrays are sloooow, see http://stackoverflow.com/questions/446866/boostmultiarray-performance-question
Denis
+2  A: 

There is also armadillo which I am using in some projects. From their website:

Armadillo is a C++ linear algebra library (matrix maths) aiming towards a good balance between speed and ease of use. Integer, floating point and complex numbers are supported, as well as a subset of trigonometric and statistics functions. Various matrix decompositions are provided through optional integration with LAPACK and ATLAS libraries.

A delayed evaluation approach is employed (during compile time) to combine several operations into one and reduce (or eliminate) the need for temporaries. This is accomplished through recursive templates and template meta-programming.

This library is useful if C++ has been decided as the language of choice (due to speed and/or integration capabilities), rather than another language like Matlab ® or Octave. It is distributed under a license that is useful in both open-source and commercial contexts.

Armadillo is primarily developed at NICTA (Australia), with contributions from around the world.

Dirk Eddelbuettel
+1 looks nice, "good balance".Has anyone compared its speed to blitz, numpy ...as in www.scipy.org/PerformancePython laplace.py ?
Denis
+1 for the need for empirical comparisons. We need some sort of library for that so that one could start to collect results for different compilers, OSs, ...
Dirk Eddelbuettel
A: 

Does anyone know of a C++ lib that provides the sort of extended linear algebra functionality of APL?

Jeff Dege
+1  A: 

We've used TNT successfully for a number of years. There are sufficient issues, however, that we're moving toward an internally developed solution instead. The two biggest sticking points for us are that

  • The arrays are not thread safe, even for read access, because they use a non-thread safe reference count.
  • The arrays cause all sorts of problems when you write const-correct code.

If those aren't a problem then they're fairly convenient for a lot of common array tasks.

Adam Bowen