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>
9 BOOST_AUTO_TEST_SUITE( multi_array_ref_openfpm_suite )
11 BOOST_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;
30 BOOST_REQUIRE_EQUAL(ar[0][0],0);
31 BOOST_REQUIRE_EQUAL(ar[0][1],1);
32 BOOST_REQUIRE_EQUAL(ar[1][0],10);
33 BOOST_REQUIRE_EQUAL(ar[2][2],22);
34 BOOST_REQUIRE_EQUAL(ar[1][2],12);
35 BOOST_REQUIRE_EQUAL(ar[9][2],92);
41 float test_mem[10][3][7];
42 float * p_test = &test_mem[0][0][0];
44 for (
size_t i = 0 ; i < 10 ; i++)
46 for (
size_t j = 0 ; j < 3 ; j++)
48 for (
size_t k = 0 ; k < 7 ; k++)
50 p_test[(j*7+k)*10+i] = i*100 + j*10 + k;
57 BOOST_REQUIRE_EQUAL(ar2[0][0][0],0);
58 BOOST_REQUIRE_EQUAL(ar2[0][0][1],1);
59 BOOST_REQUIRE_EQUAL(ar2[0][0][2],2);
60 BOOST_REQUIRE_EQUAL(ar2[0][0][3],3);
61 BOOST_REQUIRE_EQUAL(ar2[0][0][4],4);
62 BOOST_REQUIRE_EQUAL(ar2[0][0][6],6);
63 BOOST_REQUIRE_EQUAL(ar2[0][1][0],10);
64 BOOST_REQUIRE_EQUAL(ar2[1][0][4],104);
65 BOOST_REQUIRE_EQUAL(ar2[2][2][6],226);
66 BOOST_REQUIRE_EQUAL(ar2[1][2][6],126);
67 BOOST_REQUIRE_EQUAL(ar2[9][2][3],923);
73 float test_mem[10][3][7][2];
74 float * p_test = &test_mem[0][0][0][0];
76 for (
size_t i = 0 ; i < 10 ; i++)
78 for (
size_t j = 0 ; j < 3 ; j++)
80 for (
size_t k = 0 ; k < 7 ; k++)
82 for (
size_t s = 0 ; s < 2 ; s++)
84 p_test[(j*7*2+k*2+s)*10+i] = i*1000 + j*100 + k*10 + s;
90 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);
92 BOOST_REQUIRE_EQUAL(ar2[0][0][0][0],0);
93 BOOST_REQUIRE_EQUAL(ar2[0][0][0][1],1);
94 BOOST_REQUIRE_EQUAL(ar2[0][0][2][0],20);
95 BOOST_REQUIRE_EQUAL(ar2[0][0][2][1],21);
96 BOOST_REQUIRE_EQUAL(ar2[0][0][3][0],30);
97 BOOST_REQUIRE_EQUAL(ar2[0][0][4][0],40);
98 BOOST_REQUIRE_EQUAL(ar2[0][2][0][1],201);
99 BOOST_REQUIRE_EQUAL(ar2[0][1][0][0],100);
100 BOOST_REQUIRE_EQUAL(ar2[0][1][6][1],161);
101 BOOST_REQUIRE_EQUAL(ar2[2][2][6][1],2261);
102 BOOST_REQUIRE_EQUAL(ar2[1][1][5][1],1151);
103 BOOST_REQUIRE_EQUAL(ar2[9][2][4][1],9241);
107 ar2[1][1][5][1] = 1111;
108 BOOST_REQUIRE_EQUAL(ar2[1][1][5][1],1111);
112 std::cout <<
"End multi array stop" <<
"\n";
115 BOOST_AUTO_TEST_CASE( multi_array_ref_openfpm_copy )
117 std::cout <<
"Test multi array copy start" <<
"\n";
121 float test_mem[10][3][7][2];
122 float * p_test = &test_mem[0][0][0][0];
124 for (
size_t i = 0 ; i < 10 ; i++)
126 for (
size_t j = 0 ; j < 3 ; j++)
128 for (
size_t k = 0 ; k < 7 ; k++)
130 for (
size_t s = 0 ; s < 2 ; s++)
132 p_test[(j*7*2+k*2+s)*10+i] = i*1000 + j*100 + k*10 + s;
138 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);
140 float test_mem2[10][3][7][2];
141 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);
148 for (
size_t i = 0 ; i < 10 ; i++)
150 for (
size_t j = 0 ; j < 3 ; j++)
152 for (
size_t k = 0 ; k < 7 ; k++)
154 for (
size_t s = 0 ; s < 2 ; s++)
156 check &= ar3[i][j][k][s] == ar2[i][j][k][s];
162 BOOST_REQUIRE_EQUAL(check,
true);
166 std::cout <<
"End multi array copy stop" <<
"\n";
169 BOOST_AUTO_TEST_CASE( multi_array_ref_openfpm_bind_ref )
171 std::cout <<
"Test multi array bind_ref start" <<
"\n";
175 float test_mem[10][3][7][2];
176 float * p_test = &test_mem[0][0][0][0];
178 for (
size_t i = 0 ; i < 10 ; i++)
180 for (
size_t j = 0 ; j < 3 ; j++)
182 for (
size_t k = 0 ; k < 7 ; k++)
184 for (
size_t s = 0 ; s < 2 ; s++)
186 p_test[(j*7*2+k*2+s)*10+i] = i*1000 + j*100 + k*10 + s;
192 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);
194 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);
200 for (
size_t i = 0 ; i < 10 ; i++)
202 for (
size_t j = 0 ; j < 3 ; j++)
204 for (
size_t k = 0 ; k < 7 ; k++)
206 for (
size_t s = 0 ; s < 2 ; s++)
208 check &= ar3[i][j][k][s] == ar2[i][j][k][s];
214 BOOST_REQUIRE_EQUAL(check,
true);
218 std::cout <<
"End multi array copy bind_ref" <<
"\n";
221 BOOST_AUTO_TEST_CASE( multi_array_ref_openfpm_swap )
223 std::cout <<
"Test multi array swap start" <<
"\n";
227 float test_mem[10][3][7][2];
228 float * p_test = &test_mem[0][0][0][0];
230 for (
size_t i = 0 ; i < 10 ; i++)
232 for (
size_t j = 0 ; j < 3 ; j++)
234 for (
size_t k = 0 ; k < 7 ; k++)
236 for (
size_t s = 0 ; s < 2 ; s++)
238 p_test[(j*7*2+k*2+s)*10+i] = i*1000 + j*100 + k*10 + s;
244 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);
246 float test_mem2[10][3][7][2];
247 float * p_test2 = &test_mem2[0][0][0][0];
249 for (
size_t i = 0 ; i < 10 ; i++)
251 for (
size_t j = 0 ; j < 3 ; j++)
253 for (
size_t k = 0 ; k < 7 ; k++)
255 for (
size_t s = 0 ; s < 2 ; s++)
257 p_test2[(j*7*2+k*2+s)*10+i] = i*1000 + j*100 + k*10 + s + 100000;
263 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);
269 for (
size_t i = 0 ; i < 10 ; i++)
271 for (
size_t j = 0 ; j < 3 ; j++)
273 for (
size_t k = 0 ; k < 7 ; k++)
275 for (
size_t s = 0 ; s < 2 ; s++)
277 check &= ar3[i][j][k][s] == i*1000 + j*100 + k*10 + s;
278 check &= ar2[i][j][k][s] == i*1000 + j*100 + k*10 + s + 100000;
284 BOOST_REQUIRE_EQUAL(check,
true);
288 std::cout <<
"End multi array swap stop" <<
"\n";
291 BOOST_AUTO_TEST_CASE( test_is_multi_array )
295 BOOST_REQUIRE_EQUAL(test,
false);
299 BOOST_REQUIRE_EQUAL(test,
true);
302 BOOST_AUTO_TEST_SUITE_END()