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!
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.
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.
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.:
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'.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With