2#define BOOST_TEST_DYN_LINK
3#include <boost/test/unit_test.hpp>
5#include "multi_array_ref_openfpm.hpp"
6#include <boost/mpl/vector.hpp>
9BOOST_AUTO_TEST_SUITE( multi_array_ref_openfpm_suite )
11BOOST_AUTO_TEST_CASE( multi_array_ref_openfpm_use )
13 std::cout <<
"Test multi array start" <<
"\n";
17 float test_mem[10][3];
18 float * p_test = &test_mem[0][0];
20 for (
size_t i = 0 ; i < 10 ; i++)
22 for (
size_t j = 0 ; j < 3 ; j++)
24 p_test[j*10+i] = i*10 + j;
31 BOOST_REQUIRE_EQUAL(ar[0][0],0);
32 BOOST_REQUIRE_EQUAL(ar[0][1],1);
33 BOOST_REQUIRE_EQUAL(ar[1][0],10);
34 BOOST_REQUIRE_EQUAL(ar[2][2],22);
35 BOOST_REQUIRE_EQUAL(ar[1][2],12);
36 BOOST_REQUIRE_EQUAL(ar[9][2],92);
42 float test_mem[10][3][7];
43 float * p_test = &test_mem[0][0][0];
45 for (
size_t i = 0 ; i < 10 ; i++)
47 for (
size_t j = 0 ; j < 3 ; j++)
49 for (
size_t k = 0 ; k < 7 ; k++)
51 p_test[(j*7+k)*10+i] = i*100 + j*10 + k;
59 BOOST_REQUIRE_EQUAL(ar2[0][0][0],0);
60 BOOST_REQUIRE_EQUAL(ar2[0][0][1],1);
61 BOOST_REQUIRE_EQUAL(ar2[0][0][2],2);
62 BOOST_REQUIRE_EQUAL(ar2[0][0][3],3);
63 BOOST_REQUIRE_EQUAL(ar2[0][0][4],4);
64 BOOST_REQUIRE_EQUAL(ar2[0][0][6],6);
65 BOOST_REQUIRE_EQUAL(ar2[0][1][0],10);
66 BOOST_REQUIRE_EQUAL(ar2[1][0][4],104);
67 BOOST_REQUIRE_EQUAL(ar2[2][2][6],226);
68 BOOST_REQUIRE_EQUAL(ar2[1][2][6],126);
69 BOOST_REQUIRE_EQUAL(ar2[9][2][3],923);
75 float test_mem[10][3][7][2];
76 float * p_test = &test_mem[0][0][0][0];
78 for (
size_t i = 0 ; i < 10 ; i++)
80 for (
size_t j = 0 ; j < 3 ; j++)
82 for (
size_t k = 0 ; k < 7 ; k++)
84 for (
size_t s = 0 ; s < 2 ; s++)
86 p_test[(j*7*2+k*2+s)*10+i] = i*1000 + j*100 + k*10 + s;
93 openfpm::multi_array_ref_openfpm<float,4,boost::mpl::vector<boost::mpl::int_<-1>,boost::mpl::int_<3>,boost::mpl::int_<7>,boost::mpl::int_<2>>> ar2((
float *)test_mem,10,go);
95 BOOST_REQUIRE_EQUAL(ar2[0][0][0][0],0);
96 BOOST_REQUIRE_EQUAL(ar2[0][0][0][1],1);
97 BOOST_REQUIRE_EQUAL(ar2[0][0][2][0],20);
98 BOOST_REQUIRE_EQUAL(ar2[0][0][2][1],21);
99 BOOST_REQUIRE_EQUAL(ar2[0][0][3][0],30);
100 BOOST_REQUIRE_EQUAL(ar2[0][0][4][0],40);
101 BOOST_REQUIRE_EQUAL(ar2[0][2][0][1],201);
102 BOOST_REQUIRE_EQUAL(ar2[0][1][0][0],100);
103 BOOST_REQUIRE_EQUAL(ar2[0][1][6][1],161);
104 BOOST_REQUIRE_EQUAL(ar2[2][2][6][1],2261);
105 BOOST_REQUIRE_EQUAL(ar2[1][1][5][1],1151);
106 BOOST_REQUIRE_EQUAL(ar2[9][2][4][1],9241);
110 ar2[1][1][5][1] = 1111;
111 BOOST_REQUIRE_EQUAL(ar2[1][1][5][1],1111);
115 std::cout <<
"End multi array stop" <<
"\n";
118BOOST_AUTO_TEST_CASE( multi_array_ref_openfpm_copy )
120 std::cout <<
"Test multi array copy start" <<
"\n";
124 float test_mem[10][3][7][2];
125 float * p_test = &test_mem[0][0][0][0];
127 for (
size_t i = 0 ; i < 10 ; i++)
129 for (
size_t j = 0 ; j < 3 ; j++)
131 for (
size_t k = 0 ; k < 7 ; k++)
133 for (
size_t s = 0 ; s < 2 ; s++)
135 p_test[(j*7*2+k*2+s)*10+i] = i*1000 + j*100 + k*10 + s;
142 openfpm::multi_array_ref_openfpm<float,4,boost::mpl::vector<boost::mpl::int_<-1>,boost::mpl::int_<3>,boost::mpl::int_<7>,boost::mpl::int_<2>>> ar2((
float *)test_mem,10,go);
144 float test_mem2[10][3][7][2];
145 openfpm::multi_array_ref_openfpm<float,4,boost::mpl::vector<boost::mpl::int_<-1>,boost::mpl::int_<3>,boost::mpl::int_<7>,boost::mpl::int_<2>>> ar3((
float *)test_mem2,10,go);
152 for (
size_t i = 0 ; i < 10 ; i++)
154 for (
size_t j = 0 ; j < 3 ; j++)
156 for (
size_t k = 0 ; k < 7 ; k++)
158 for (
size_t s = 0 ; s < 2 ; s++)
160 check &= ar3[i][j][k][s] == ar2[i][j][k][s];
166 BOOST_REQUIRE_EQUAL(check,
true);
170 std::cout <<
"End multi array copy stop" <<
"\n";
173BOOST_AUTO_TEST_CASE( multi_array_ref_openfpm_bind_ref )
175 std::cout <<
"Test multi array bind_ref start" <<
"\n";
179 float test_mem[10][3][7][2];
180 float * p_test = &test_mem[0][0][0][0];
182 for (
size_t i = 0 ; i < 10 ; i++)
184 for (
size_t j = 0 ; j < 3 ; j++)
186 for (
size_t k = 0 ; k < 7 ; k++)
188 for (
size_t s = 0 ; s < 2 ; s++)
190 p_test[(j*7*2+k*2+s)*10+i] = i*1000 + j*100 + k*10 + s;
197 openfpm::multi_array_ref_openfpm<float,4,boost::mpl::vector<boost::mpl::int_<-1>,boost::mpl::int_<3>,boost::mpl::int_<7>,boost::mpl::int_<2>>> ar2((
float *)test_mem,10,go);
199 openfpm::multi_array_ref_openfpm<float,4,boost::mpl::vector<boost::mpl::int_<-1>,boost::mpl::int_<3>,boost::mpl::int_<7>,boost::mpl::int_<2>>> ar3((
float *)NULL,10,go);
205 for (
size_t i = 0 ; i < 10 ; i++)
207 for (
size_t j = 0 ; j < 3 ; j++)
209 for (
size_t k = 0 ; k < 7 ; k++)
211 for (
size_t s = 0 ; s < 2 ; s++)
213 check &= ar3[i][j][k][s] == ar2[i][j][k][s];
219 BOOST_REQUIRE_EQUAL(check,
true);
223 std::cout <<
"End multi array copy bind_ref" <<
"\n";
226BOOST_AUTO_TEST_CASE( multi_array_ref_openfpm_swap )
228 std::cout <<
"Test multi array swap start" <<
"\n";
232 float test_mem[10][3][7][2];
233 float * p_test = &test_mem[0][0][0][0];
235 for (
size_t i = 0 ; i < 10 ; i++)
237 for (
size_t j = 0 ; j < 3 ; j++)
239 for (
size_t k = 0 ; k < 7 ; k++)
241 for (
size_t s = 0 ; s < 2 ; s++)
243 p_test[(j*7*2+k*2+s)*10+i] = i*1000 + j*100 + k*10 + s;
250 openfpm::multi_array_ref_openfpm<float,4,boost::mpl::vector<boost::mpl::int_<-1>,boost::mpl::int_<3>,boost::mpl::int_<7>,boost::mpl::int_<2>>> ar2((
float *)test_mem,10,go);
252 float test_mem2[10][3][7][2];
253 float * p_test2 = &test_mem2[0][0][0][0];
255 for (
size_t i = 0 ; i < 10 ; i++)
257 for (
size_t j = 0 ; j < 3 ; j++)
259 for (
size_t k = 0 ; k < 7 ; k++)
261 for (
size_t s = 0 ; s < 2 ; s++)
263 p_test2[(j*7*2+k*2+s)*10+i] = i*1000 + j*100 + k*10 + s + 100000;
269 openfpm::multi_array_ref_openfpm<float,4,boost::mpl::vector<boost::mpl::int_<-1>,boost::mpl::int_<3>,boost::mpl::int_<7>,boost::mpl::int_<2>>> ar3((
float *)test_mem2,10,go);
275 for (
size_t i = 0 ; i < 10 ; i++)
277 for (
size_t j = 0 ; j < 3 ; j++)
279 for (
size_t k = 0 ; k < 7 ; k++)
281 for (
size_t s = 0 ; s < 2 ; s++)
283 check &= ar3[i][j][k][s] == i*1000 + j*100 + k*10 + s;
284 check &= ar2[i][j][k][s] == i*1000 + j*100 + k*10 + s + 100000;
290 BOOST_REQUIRE_EQUAL(check,
true);
294 std::cout <<
"End multi array swap stop" <<
"\n";
297BOOST_AUTO_TEST_CASE( test_is_multi_array )
301 BOOST_REQUIRE_EQUAL(test,
false);
305 BOOST_REQUIRE_EQUAL(test,
true);
308BOOST_AUTO_TEST_SUITE_END()