Created
June 29, 2013 19:29
-
-
Save dandrews/5892343 to your computer and use it in GitHub Desktop.
Example call to Boost/MultiArray library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "boost/multi_array.hpp" | |
#include <cassert> | |
#include <iostream> | |
int | |
main () { | |
// Create a 3D array that is 3 x 3 x 3 | |
typedef boost::multi_array<double, 3> array_type; | |
typedef array_type::index index; | |
array_type A(boost::extents[3][3][3]); | |
// Assign values to the elements | |
int values = 0; | |
for(index i = 0; i != 3; ++i) | |
for(index j = 0; j != 3; ++j) | |
for(index k = 0; k != 3; ++k) | |
A[i][j][k] = values++; | |
// Verify values | |
int verify = 0; | |
for(index i = 0; i != 3; ++i) | |
for(index j = 0; j != 3; ++j) | |
for(index k = 0; k != 3; ++k) { | |
assert(A[i][j][k] == verify++); | |
std::cout << A[i][j][k] << std::endl; | |
} | |
A[0][0][0] = 3.14; | |
assert(A[0][0][0] == 3.14); | |
std::cout << A[0][0][0] << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment