Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

High-performance C++ multi-dimensional arrays

I am looking for advice regarding high performance multi-dimensional array libraries/classes for C++. What I really need is:

  • the ability to dynamically allocate arrays with a size determined at run-time

  • the ability to access and modify single array values (fast)

  • to be able to use simple array arithmetic such as array1 = array2 + 2 * array3

  • a well-maintained library

I have come across various libraries, including:

  • Blitz++, which looks exactly what I need, but which doesn't seem very well maintained (latest stable release was 5 years ago)

  • Boost, which doesn't support array arithmetic, and appears to be a quite slow compared to say Blitz++.

  • Jonn Bowman's array.h which has no documentation.

Does anyone have any other suggestions or comments about the above options?

like image 200
astrofrog Avatar asked Oct 18 '10 13:10

astrofrog


People also ask

Can C language handle multidimensional arrays?

In C programming, you can create an array of arrays. These arrays are known as multidimensional arrays. For example, float x[3][4];

What is multi-dimensional array in C with example?

A multi-dimensional array is an array with more than one level or dimension. For example, a 2D array, or two-dimensional array, is an array of arrays, meaning it is a matrix of rows and columns (think of a table). A 3D array adds another dimension, turning it into an array of arrays of arrays.

Are there 3D arrays in C?

3D Array in CC allows for arrays of two or more dimensions. A two-dimensional (2D) array is an array of arrays. A three-dimensional (3D) array is an array of arrays of arrays. In C programming, an array can have two, three, or even ten or more dimensions.


2 Answers

Eigen is extremely well-maintained (right now, at least, there are new versions coming out every month) and supports the other operations you need.

like image 55
Neil G Avatar answered Oct 17 '22 18:10

Neil G


There is a broad and relatively recent survey, including benchmarks, here.

I believe that you can speed up Boost.UBlas by binding it to underlying numerical libraries like LAPACK or Intel MKL, but have not done that.

fwiw, the implementations that seem to come up most often as candidates are Boost.UBlas and MTL. It's my experience that wide adoption is more likely to foster ongoing support and development.

like image 40
Steve Townsend Avatar answered Oct 17 '22 19:10

Steve Townsend