Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fortran-style multidimensional arrays in C++

Is there a C++ library which provides Fortran-style multidimensional arrays with support for slicing, passing as procedural parameter and decent documentation? I've looked into blitz++ but its dead!

like image 668
fedvasu Avatar asked Mar 13 '12 01:03

fedvasu


People also ask

Which index comes first in a Fortran array?

In Fortran arrays, the most rapidly changing index comes first: (i,j,k). Let's compare C memory ordering and Fortran memory ordering to see if there is a difference in how the data are actually stored in memory or whether the order is the same and it's just the language syntax that is different.

What is a multidimensional array in C programming language?

C programming language allows multidimensional arrays. Here is the general form of a multidimensional array declaration − For example, the following declaration creates a three dimensional integer array − The simplest form of multidimensional array is the two-dimensional array.

How to create a three-dimensional array in C?

Please note, that in C, you need to explicitly define the second, third, fourth and so on dimensions of an array. For example, if you want to create a three-dimensional array: 1 int a[][3][2]; The simplest approach to pass a two-dimensional array to a function is to specify the second dimension of the array, e.g.:

Which two-dimensional array contains three rows and four columns?

A two-dimensional array a, which contains three rows and four columns can be shown as follows − Thus, every element in the array a is identified by an element name of the form a [ i ] [ j ], where 'a' is the name of the array, and 'i' and 'j' are the subscripts that uniquely identify each element in 'a'.


1 Answers

I highly suggest Armadillo:

Armadillo is a C++ linear algebra library (matrix maths) aiming towards a good balance between speed and ease of use

It is a C++ template library:

A delayed evaluation approach is employed (at compile-time) to combine several operations into one and reduce (or eliminate) the need for temporaries; this is automatically accomplished through template meta-programming

A simple example from the web page:

#include <iostream>
#include <armadillo>

int main(int argc, char** argv)
{
    arma::mat A = arma::randu<arma::mat>(4,5);
    arma::mat B = arma::randu<arma::mat>(4,5);

    std::cout << A*B.t() << std::endl;

    return 0;
}
like image 67
big_gie Avatar answered Oct 09 '22 19:10

big_gie