OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
vector_unit_tests.hpp
1 #ifndef VECTOR_UNIT_TESTS_HPP
2 #define VECTOR_UNIT_TESTS_HPP
3 
4 #include "map_vector.hpp"
5 #include "Point_test.hpp"
6 #include "memory/ExtPreAlloc.hpp"
7 #include "memory/PtrMemory.hpp"
8 #include <cstring>
9 #include "Space/Shape/Point.hpp"
10 #include "util/object_util.hpp"
11 #include "vector_test_util.hpp"
12 
13 BOOST_AUTO_TEST_SUITE( vector_test )
14 
15 #define V_REM_PUSH 1024ul
16 
17 template <typename vector> void test_iterator()
18 {
20 
21  vector v_ofp_test = allocate_openfpm<vector>(FIRST_PUSH);
22 
23  size_t count = 0;
24 
25  auto it = v_ofp_test.getIterator();
26 
27  while (it.isNext())
28  {
29  count++;
30 
31  ++it;
32  }
33 
34  BOOST_REQUIRE_EQUAL(count,v_ofp_test.size());
35 
36  count = 0;
37  auto it_f = v_ofp_test.getIteratorFrom( FIRST_PUSH / 2 );
38 
39  while (it_f.isNext())
40  {
41  count++;
42 
43  ++it_f;
44  }
45 
46  BOOST_REQUIRE_EQUAL(count, v_ofp_test.size() / 2 );
47 }
48 
49 template <typename vector> void test_vector_use()
50 {
51  std::vector<Point_orig<float>> v_stl_test = allocate_stl();
52  vector v_ofp_test = allocate_openfpm<vector>(FIRST_PUSH);
53 
54  // try to duplicate the vector
55  vector dv_ofp_test = v_ofp_test.duplicate();
56 
57  // Check if the STL and openfpm match
58 
59  for (size_t i = 0; i < FIRST_PUSH; i++)
60  {
61  BOOST_REQUIRE_EQUAL(v_stl_test[i].v[0],v_ofp_test.template get<P::v>(i)[0]);
62  BOOST_REQUIRE_EQUAL(v_stl_test[i].v[1],v_ofp_test.template get<P::v>(i)[1]);
63  BOOST_REQUIRE_EQUAL(v_stl_test[i].v[2],v_ofp_test.template get<P::v>(i)[2]);
64 
65  BOOST_REQUIRE_EQUAL(v_stl_test[i].t[0][0],v_ofp_test.template get<P::t>(i)[0][0]);
66  BOOST_REQUIRE_EQUAL(v_stl_test[i].t[0][1],v_ofp_test.template get<P::t>(i)[0][1]);
67  BOOST_REQUIRE_EQUAL(v_stl_test[i].t[0][2],v_ofp_test.template get<P::t>(i)[0][2]);
68  BOOST_REQUIRE_EQUAL(v_stl_test[i].t[1][0],v_ofp_test.template get<P::t>(i)[1][0]);
69  BOOST_REQUIRE_EQUAL(v_stl_test[i].t[1][1],v_ofp_test.template get<P::t>(i)[1][1]);
70  BOOST_REQUIRE_EQUAL(v_stl_test[i].t[1][2],v_ofp_test.template get<P::t>(i)[1][2]);
71  BOOST_REQUIRE_EQUAL(v_stl_test[i].t[2][0],v_ofp_test.template get<P::t>(i)[2][0]);
72  BOOST_REQUIRE_EQUAL(v_stl_test[i].t[2][1],v_ofp_test.template get<P::t>(i)[2][1]);
73  BOOST_REQUIRE_EQUAL(v_stl_test[i].t[2][2],v_ofp_test.template get<P::t>(i)[2][2]);
74  }
75 
76  // Check if the duplicated vector match
77 
78  for (size_t i = 0 ; i < FIRST_PUSH ; i++)
79  {
80  BOOST_REQUIRE_EQUAL(dv_ofp_test.template get<P::v>(i)[0],v_ofp_test.template get<P::v>(i)[0]);
81  BOOST_REQUIRE_EQUAL(dv_ofp_test.template get<P::v>(i)[1],v_ofp_test.template get<P::v>(i)[1]);
82  BOOST_REQUIRE_EQUAL(dv_ofp_test.template get<P::v>(i)[2],v_ofp_test.template get<P::v>(i)[2]);
83 
84  BOOST_REQUIRE_EQUAL(dv_ofp_test.template get<P::t>(i)[0][0],v_ofp_test.template get<P::t>(i)[0][0]);
85  BOOST_REQUIRE_EQUAL(dv_ofp_test.template get<P::t>(i)[0][1],v_ofp_test.template get<P::t>(i)[0][1]);
86  BOOST_REQUIRE_EQUAL(dv_ofp_test.template get<P::t>(i)[0][2],v_ofp_test.template get<P::t>(i)[0][2]);
87  BOOST_REQUIRE_EQUAL(dv_ofp_test.template get<P::t>(i)[1][0],v_ofp_test.template get<P::t>(i)[1][0]);
88  BOOST_REQUIRE_EQUAL(dv_ofp_test.template get<P::t>(i)[1][1],v_ofp_test.template get<P::t>(i)[1][1]);
89  BOOST_REQUIRE_EQUAL(dv_ofp_test.template get<P::t>(i)[1][2],v_ofp_test.template get<P::t>(i)[1][2]);
90  BOOST_REQUIRE_EQUAL(dv_ofp_test.template get<P::t>(i)[2][0],v_ofp_test.template get<P::t>(i)[2][0]);
91  BOOST_REQUIRE_EQUAL(dv_ofp_test.template get<P::t>(i)[2][1],v_ofp_test.template get<P::t>(i)[2][1]);
92  BOOST_REQUIRE_EQUAL(dv_ofp_test.template get<P::t>(i)[2][2],v_ofp_test.template get<P::t>(i)[2][2]);
93  }
94 }
95 
96 template <typename vector> void test_vector_remove()
97 {
98  typedef Point_test<float> p;
99 
101 
102  vector v1;
103 
104  for (size_t i = 0 ; i < V_REM_PUSH ; i++)
105  {
106  // Point
108  p.setx(i);
109 
110  v1.add(p);
111  }
112 
113  {
115  rem.add(0);
116  rem.add(1);
117  rem.add(2);
118  rem.add(3);
119 
120  v1.remove(rem);
121  }
122 
124 
125  BOOST_REQUIRE_EQUAL(v1.size(),1020ul);
126  BOOST_REQUIRE_EQUAL(v1.template get<p::x>(0),4);
127 
128  {
130  rem.add(v1.size()-3);
131  rem.add(v1.size()-2);
132  rem.add(v1.size()-1);
133  rem.add(v1.size());
134 
135  v1.remove(rem);
136  }
137 
138  BOOST_REQUIRE_EQUAL(v1.size(),1016ul);
139  BOOST_REQUIRE_EQUAL(v1.template get<p::x>(v1.size()-1),1019);
140 
141  {
143  for (size_t i = 0 ; i < (V_REM_PUSH - 8) / 2 ; i++)
144  rem.add(i * 2);
145 
146  // remove all the even number
147  v1.remove(rem);
148  }
149 
150  BOOST_REQUIRE_EQUAL(v1.size(),508ul);
151 
152  // Check only odd
153  for (size_t i = 0 ; i < v1.size() ; i++)
154  {
155  BOOST_REQUIRE_EQUAL((size_t)v1.template get<p::x>(v1.size()-1) % 2, 1ul);
156  }
157 }
158 
159 template <typename vector> void test_vector_insert()
160 {
161  typedef Point_test<float> p;
162 
163  vector v1;
164 
165  for (size_t i = 0 ; i < V_REM_PUSH ; i++)
166  {
167  // Point
169  p.setx(i);
170 
171  v1.add(p);
172  }
173 
174  BOOST_REQUIRE_EQUAL(v1.size(),V_REM_PUSH);
175 
176  // Add one at the first element
177 
178  v1.insert(0);
179  v1.template get<p::x>(0) = -9999.0;
180 
181  // Add one in the middle
182 
183  v1.insert(V_REM_PUSH / 2);
184  v1.template get<p::x>(V_REM_PUSH / 2) = -9999.0;
185 
186  // Add one at the end
187 
188  v1.insert(v1.size()-1);
189  v1.template get<p::x>(v1.size()-1) = -9999.0;
190 
191  BOOST_REQUIRE_EQUAL(v1.size(),V_REM_PUSH + 3);
192 
193  BOOST_REQUIRE_EQUAL(v1.template get<p::x>(0), -9999.0);
194  BOOST_REQUIRE_EQUAL(v1.template get<p::x>(V_REM_PUSH / 2), -9999.0);
195  BOOST_REQUIRE_EQUAL(v1.template get<p::x>(v1.size()-1), -9999.0);
196 
197  size_t c = 0;
198 
199  // Check only odd
200  for (size_t i = 0 ; i < v1.size() ; i++)
201  {
202  if (i == 0 || i == V_REM_PUSH / 2 || i == v1.size()-1)
203  continue;
204 
205  BOOST_REQUIRE_EQUAL((size_t)v1.template get<p::x>(i), c);
206 
207  c++;
208  }
209 }
210 
211 template <typename vector> void test_vector_clear()
212 {
213  vector v1;
214 
215  for (size_t i = 0 ; i < V_REM_PUSH ; i++)
216  {
217  // Point
219  p.setx(i);
220 
221  v1.add(p);
222  }
223 
224  v1.clear();
225 
226  BOOST_REQUIRE_EQUAL(v1.size(),0ul);
227 
228  for (size_t i = 0 ; i < V_REM_PUSH ; i++)
229  {
230  // Point
232  p.setx(i);
233 
234  v1.add(p);
235  }
236 
237  BOOST_REQUIRE_EQUAL(v1.size(),V_REM_PUSH);
238 }
239 
240 template <typename vector, template <typename> class layout_base> void test_vector_add_test_case()
241 {
242  // create two vector
243  vector v1;
244 
245  // Point
247  p.setx(1.0);
248  p.sety(2.0);
249  p.setz(3.0);
250  p.sets(4.0);
251 
252  // push objects
253 
254  for (size_t i = 0 ; i < FIRST_PUSH ; i++)
255  {
256  // Modify p
257 
258  p.get<P::v>()[0] = 1.0 + i;
259  p.get<P::v>()[1] = 2.0 + i;
260  p.get<P::v>()[2] = 7.0 + i;
261 
262  p.get<P::t>()[0][0] = 10.0 + i;
263  p.get<P::t>()[0][1] = 13.0 + i;
264  p.get<P::t>()[0][2] = 8.0 + i;
265  p.get<P::t>()[1][0] = 19.0 + i;
266  p.get<P::t>()[1][1] = 23.0 + i;
267  p.get<P::t>()[1][2] = 5.0 + i;
268  p.get<P::t>()[2][0] = 4.0 + i;
269  p.get<P::t>()[2][1] = 3.0 + i;
270  p.get<P::t>()[2][2] = 11.0 + i;
271 
272  // add p
273 
274  v1.add(p);
275  }
276 
277  // Duplicate the vector
278  vector v2 = v1.duplicate();
279 
280  v1.template add_prp<Point_test<float>,HeapMemory,typename openfpm::grow_policy_double,OPENFPM_NATIVE,layout_base,P::x,P::y,P::z,P::s,P::v,P::t>(v2);
281 
282  for (size_t i = 0 ; i < FIRST_PUSH ; i++)
283  {
284  BOOST_REQUIRE_EQUAL(v1.template get<P::v>(i)[0], v1.template get<P::v>(i+v2.size())[0]);
285  BOOST_REQUIRE_EQUAL(v1.template get<P::v>(i)[1], v1.template get<P::v>(i+v2.size())[1]);
286  BOOST_REQUIRE_EQUAL(v1.template get<P::v>(i)[2], v1.template get<P::v>(i+v2.size())[2]);
287 
288  BOOST_REQUIRE_EQUAL(v1.template get<P::t>(i)[0][0], v1.template get<P::t>(i+v2.size())[0][0]);
289  BOOST_REQUIRE_EQUAL(v1.template get<P::t>(i)[0][1], v1.template get<P::t>(i+v2.size())[0][1]);
290  BOOST_REQUIRE_EQUAL(v1.template get<P::t>(i)[0][2], v1.template get<P::t>(i+v2.size())[0][2]);
291  BOOST_REQUIRE_EQUAL(v1.template get<P::t>(i)[1][0], v1.template get<P::t>(i+v2.size())[1][0]);
292  BOOST_REQUIRE_EQUAL(v1.template get<P::t>(i)[1][1], v1.template get<P::t>(i+v2.size())[1][1]);
293  BOOST_REQUIRE_EQUAL(v1.template get<P::t>(i)[1][2], v1.template get<P::t>(i+v2.size())[1][2]);
294  BOOST_REQUIRE_EQUAL(v1.template get<P::t>(i)[2][0], v1.template get<P::t>(i+v2.size())[2][0]);
295  BOOST_REQUIRE_EQUAL(v1.template get<P::t>(i)[2][1], v1.template get<P::t>(i+v2.size())[2][1]);
296  BOOST_REQUIRE_EQUAL(v1.template get<P::t>(i)[2][2], v1.template get<P::t>(i+v2.size())[2][2]);
297  }
298 
299  // add homogeneous
300 
301  v1.template add(v2);
302 
303  for (size_t i = 0 ; i < FIRST_PUSH ; i++)
304  {
305  BOOST_REQUIRE_EQUAL(v1.template get<P::v>(i)[0], v1.template get<P::v>(i+2*v2.size())[0]);
306  BOOST_REQUIRE_EQUAL(v1.template get<P::v>(i)[1], v1.template get<P::v>(i+2*v2.size())[1]);
307  BOOST_REQUIRE_EQUAL(v1.template get<P::v>(i)[2], v1.template get<P::v>(i+2*v2.size())[2]);
308 
309  BOOST_REQUIRE_EQUAL(v1.template get<P::t>(i)[0][0], v1.template get<P::t>(i+2*v2.size())[0][0]);
310  BOOST_REQUIRE_EQUAL(v1.template get<P::t>(i)[0][1], v1.template get<P::t>(i+2*v2.size())[0][1]);
311  BOOST_REQUIRE_EQUAL(v1.template get<P::t>(i)[0][2], v1.template get<P::t>(i+2*v2.size())[0][2]);
312  BOOST_REQUIRE_EQUAL(v1.template get<P::t>(i)[1][0], v1.template get<P::t>(i+2*v2.size())[1][0]);
313  BOOST_REQUIRE_EQUAL(v1.template get<P::t>(i)[1][1], v1.template get<P::t>(i+2*v2.size())[1][1]);
314  BOOST_REQUIRE_EQUAL(v1.template get<P::t>(i)[1][2], v1.template get<P::t>(i+2*v2.size())[1][2]);
315  BOOST_REQUIRE_EQUAL(v1.template get<P::t>(i)[2][0], v1.template get<P::t>(i+2*v2.size())[2][0]);
316  BOOST_REQUIRE_EQUAL(v1.template get<P::t>(i)[2][1], v1.template get<P::t>(i+2*v2.size())[2][1]);
317  BOOST_REQUIRE_EQUAL(v1.template get<P::t>(i)[2][2], v1.template get<P::t>(i+2*v2.size())[2][2]);
318  }
319 }
320 
321 template <typename vector> void test_vector_copy_and_compare()
322 {
323  {
325 
326  v1.add();
327  v1.last().add(1.0);
328  v1.last().add(10.0);
329  v1.last().add(11.0);
330  v1.last().add(21.0);
331  v1.last().add(13.0);
332  v1.add();
333  v1.last().add(11.0);
334  v1.last().add(41.0);
335  v1.last().add(61.0);
336  v1.last().add(91.0);
337  v1.add();
338  v1.last().add(133.0);
339  v1.last().add(221.0);
340 
342 
343  v2 = v1;
344 
345  bool ret = (v2 == v1);
346  BOOST_REQUIRE_EQUAL(ret,true);
347 
348  v1.get(2).get(1) = 222.0;
349 
350  ret = (v2 == v1);
351  BOOST_REQUIRE_EQUAL(ret,false);
352  }
353 
354  {
355  Box<3,float> bt({1.2,1.3,1.5},{6.0,7.0,8.0});
356 
358 
359  v1.add();
360  v1.last().add(bt);
361  v1.last().add(bt);
362  v1.last().add(bt);
363  v1.last().add(bt);
364  v1.last().add(bt);
365  v1.add();
366  v1.last().add(bt);
367  v1.last().add(bt);
368  v1.last().add(bt);
369  v1.last().add(bt);
370  v1.add();
371  v1.last().add(bt);
372  v1.last().add(bt);
373 
375 
376  v2 = v1;
377 
378  bool ret = (v2 == v1);
379  BOOST_REQUIRE_EQUAL(ret,true);
380 
381  v1.get(2).get(1).template get<Box<3,float>::p1>()[0] = 222.0;
382 
383  ret = (v2 == v1);
384  BOOST_REQUIRE_EQUAL(ret,false);
385  }
386 }
387 
388 template <typename vector> void test_vector_load_and_save_check()
389 {
391 
392  for (size_t i = 0; i < 5; i++)
393  {
394  v1.add();
395  for (size_t j = 0; j < 6; j++)
396  {
397  v1.get(i).add(j);
398  }
399  }
400 
401  v1.save("test_save");
403  v2.load("test_save");
404 
405  // check the v1 and v2 match
406 
407  BOOST_REQUIRE_EQUAL(v1.size(),v2.size());
408  for (size_t i = 0; i < v1.size(); i++)
409  {
410  BOOST_REQUIRE_EQUAL(v1.get(i).size(),v2.get(i).size());
411  for (size_t j = 0; j < 6; j++)
412  {
413  BOOST_REQUIRE_EQUAL(v1.get(i).get(j),v2.get(i).get(j));
414  }
415  }
416 }
417 
418 // Test vector iterator
419 
420 BOOST_AUTO_TEST_CASE (vector_iterator_test)
421 {
422  test_iterator< openfpm::vector<Point_test<float>> >();
423  test_iterator< openfpm::vector<Point_test<float>,HeapMemory,memory_traits_inte<Point_test<float>>::type,memory_traits_inte> >();
424 }
425 
426 // Test the openfpm vector
427 
428 BOOST_AUTO_TEST_CASE( vector_use)
429 {
430  std::cout << "Vector unit test start" << "\n";
431 
432  test_vector_use<openfpm::vector<Point_test<float>>>();
433  test_vector_use< openfpm::vector<Point_test<float>,HeapMemory,memory_traits_inte<Point_test<float>>::type,memory_traits_inte> >();
434 
435  std::cout << "Vector unit test end" << "\n";
436 }
437 
438 
439 size_t alloc[] = {235,345,0,520};
440 size_t n_alloc = sizeof(alloc)/sizeof(size_t);
441 
442 
443 BOOST_AUTO_TEST_CASE(vector_remove )
444 {
445  test_vector_remove<openfpm::vector<Point_test<float>>>();
446  test_vector_remove< openfpm::vector<Point_test<float>,HeapMemory,memory_traits_inte<Point_test<float>>::type, memory_traits_inte> >();
447 }
448 
449 BOOST_AUTO_TEST_CASE(vector_insert )
450 {
451  test_vector_insert<openfpm::vector<Point_test<float>>>();
452  test_vector_insert< openfpm::vector<Point_test<float>,HeapMemory,memory_traits_inte<Point_test<float>>::type, memory_traits_inte > >();
453 }
454 
455 BOOST_AUTO_TEST_CASE(vector_clear )
456 {
457  test_vector_clear< openfpm::vector<Point_test<float>> >();
458  test_vector_clear< openfpm::vector<Point_test<float>,HeapMemory,memory_traits_inte<Point_test<float>>::type, memory_traits_inte> >();
459 }
460 
461 BOOST_AUTO_TEST_CASE( vector_add_test_case )
462 {
463  test_vector_add_test_case<openfpm::vector<Point_test<float>>,memory_traits_lin>();
464  test_vector_add_test_case<openfpm::vector<Point_test<float>,HeapMemory,memory_traits_inte<Point_test<float>>::type,memory_traits_inte>, memory_traits_inte >();
465 }
466 
467 BOOST_AUTO_TEST_CASE( vector_copy_and_compare )
468 {
469  test_vector_copy_and_compare< openfpm::vector<Point_test<float>> >();
470  test_vector_copy_and_compare< openfpm::vector<Point_test<float>,HeapMemory,memory_traits_inte<Point_test<float>>::type, memory_traits_inte> >();
471 }
472 
473 BOOST_AUTO_TEST_CASE( vector_load_and_save_check )
474 {
475  test_vector_load_and_save_check< openfpm::vector<Point_test<float>> >();
476  test_vector_load_and_save_check< openfpm::vector<Point_test<float>,HeapMemory,memory_traits_inte<Point_test<float>>::type, memory_traits_inte> >();
477 }
478 
481 
482 #ifdef SE_CLASS2
483 
484 openfpm::vector<aggregate<float>> & test_error_v()
485 {
487 
488  return v;
489 }
490 
491 #endif
492 
493 BOOST_AUTO_TEST_CASE( vector_safety_check )
494 {
495 #if defined(SE_CLASS1) && defined (THROW_ON_ERROR)
496 
497  bool error = false;
498 
499  typedef Point_test<float> p;
500 
501  // Create a vector
502 
505 
506  error = false;
507  try
508  {v.template get<p::x>(23);}
509  catch (std::exception & e)
510  {
511  error = true;
512  BOOST_REQUIRE_EQUAL(e.what(),"Runtime vector error");
513  }
514  BOOST_REQUIRE_EQUAL(error,true);
515 
516  error = false;
518  try
519  {v.set(23,t);}
520  catch (std::exception & e)
521  {
522  error = true;
523  BOOST_REQUIRE_EQUAL(e.what(),"Runtime vector error");
524  }
525  BOOST_REQUIRE_EQUAL(error,true);
526 
527  error = false;
528  try
529  {v.set(6,v2,23);}
530  catch (std::exception & e)
531  {
532  error = true;
533  BOOST_REQUIRE_EQUAL(e.what(),"Runtime grid error");
534  }
535  BOOST_REQUIRE_EQUAL(error,true);
536 
538 
539  error = false;
540  try
541  {v.template get<p::x>(-1);}
542  catch (std::exception & e)
543  {
544  error = true;
545  BOOST_REQUIRE_EQUAL(e.what(),"Runtime vector error");
546  }
547  BOOST_REQUIRE_EQUAL(error,true);
548 
549  error = false;
551  try
552  {v.set(-1,t2);}
553  catch (std::exception & e)
554  {
555  error = true;
556  BOOST_REQUIRE_EQUAL(e.what(),"Runtime vector error");
557  }
558  BOOST_REQUIRE_EQUAL(error,true);
559 
560  error = false;
561  try
562  {v.set(12,v2,-1);}
563  catch (std::exception & e)
564  {
565  error = true;
566  BOOST_REQUIRE_EQUAL(e.what(),"Runtime grid error");
567  }
568  BOOST_REQUIRE_EQUAL(error,true);
569 
570  #if defined(SE_CLASS2) && defined (THROW_ON_ERROR)
571 
572  error = false;
573 
574  // Create a vector
575 
577  delete v3;
578 
579  // Try to access the class
580 
581  try
582  {v3->size();}
583  catch (std::exception & e)
584  {
585  error = true;
586  BOOST_REQUIRE_EQUAL(e.what(),"Runtime memory error");
587  }
588  BOOST_REQUIRE_EQUAL(error,true);
589 
590  try
591  {
592  openfpm::vector<aggregate<float>> vr = test_error_v();
593  }
594  catch (std::exception & e)
595  {
596  error = true;
597  BOOST_REQUIRE_EQUAL(e.what(),"Runtime memory error");
598  }
599  BOOST_REQUIRE_EQUAL(error,true);
600 
601  #endif
602 
603 #endif
604 }
605 
606 BOOST_AUTO_TEST_CASE( object_test_creator )
607 {
608  bool tst = std::is_same< typename object_creator<Point_test<float>::type,0,1,5>::type, typename boost::fusion::vector3<float,float,float[3][3]> >::value;
609 
610  BOOST_REQUIRE_EQUAL(tst , true);
611 }
612 
613 BOOST_AUTO_TEST_CASE( vector_memory_repr )
614 {
615  // create a vector
617 
618  // Point
620  p.setx(1.0);
621  p.sety(2.0);
622  p.setz(3.0);
623  p.sets(4.0);
624 
625  // push objects
626 
627  for (size_t i = 0 ; i < FIRST_PUSH ; i++)
628  {
629  // Modify p
630 
631  p.get<P::v>()[0] = 1.0 + i;
632  p.get<P::v>()[1] = 2.0 + i;
633  p.get<P::v>()[2] = 7.0 + i;
634 
635  p.get<P::t>()[0][0] = 10.0 + i;
636  p.get<P::t>()[0][1] = 13.0 + i;
637  p.get<P::t>()[0][2] = 8.0 + i;
638  p.get<P::t>()[1][0] = 19.0 + i;
639  p.get<P::t>()[1][1] = 23.0 + i;
640  p.get<P::t>()[1][2] = 5.0 + i;
641  p.get<P::t>()[2][0] = 4.0 + i;
642  p.get<P::t>()[2][1] = 3.0 + i;
643  p.get<P::t>()[2][2] = 11.0 + i;
644 
645  // add p
646 
647  v1.add(p);
648  }
649 
650  PtrMemory * ptr1 = new PtrMemory(v1.getPointer(),sizeof(Point_test<float>)*FIRST_PUSH);
651 
652  // create vector representation to a piece of memory already allocated
653 
655 
656  v2.setMemory(*ptr1);
657 
658  v2.resize(FIRST_PUSH);
659 
660  // check
661 
662  // Check if the duplicated vector match
663 
664  for (size_t i = 0 ; i < FIRST_PUSH ; i++)
665  {
666  BOOST_REQUIRE_EQUAL(v1.template get<P::v>(i)[0],v2.template get<P::v>(i)[0]);
667  BOOST_REQUIRE_EQUAL(v1.template get<P::v>(i)[1],v2.template get<P::v>(i)[1]);
668  BOOST_REQUIRE_EQUAL(v1.template get<P::v>(i)[2],v2.template get<P::v>(i)[2]);
669 
670  BOOST_REQUIRE_EQUAL(v1.template get<P::t>(i)[0][0],v2.template get<P::t>(i)[0][0]);
671  BOOST_REQUIRE_EQUAL(v1.template get<P::t>(i)[0][1],v2.template get<P::t>(i)[0][1]);
672  BOOST_REQUIRE_EQUAL(v1.template get<P::t>(i)[0][2],v2.template get<P::t>(i)[0][2]);
673  BOOST_REQUIRE_EQUAL(v1.template get<P::t>(i)[1][0],v2.template get<P::t>(i)[1][0]);
674  BOOST_REQUIRE_EQUAL(v1.template get<P::t>(i)[1][1],v2.template get<P::t>(i)[1][1]);
675  BOOST_REQUIRE_EQUAL(v1.template get<P::t>(i)[1][2],v2.template get<P::t>(i)[1][2]);
676  BOOST_REQUIRE_EQUAL(v1.template get<P::t>(i)[2][0],v2.template get<P::t>(i)[2][0]);
677  BOOST_REQUIRE_EQUAL(v1.template get<P::t>(i)[2][1],v2.template get<P::t>(i)[2][1]);
678  BOOST_REQUIRE_EQUAL(v1.template get<P::t>(i)[2][2],v2.template get<P::t>(i)[2][2]);
679  }
680 }
681 
682 BOOST_AUTO_TEST_CASE( vector_std_utility )
683 {
685 
686  // Create a vector with 13 element
688 
689  // add at the end some othe element
690  pb.add(0);
691  pb.add(1);
692  pb.add(2);
693 
694  // access the vector
695  for (size_t i = 0 ; i < 16 ; i++)
696  {
697  pb.get(i) = i+1;
698  }
699 
701 
702  pb.fill(0);
703 
704  // Check is zero
705  for (size_t i = 0 ; i < 16 ; i++)
706  {
707  BOOST_REQUIRE_EQUAL(pb.get(i),0ul);
708  }
709 
710 }
711 
712 BOOST_AUTO_TEST_CASE ( vector_prealloc_ext )
713 {
714  // Memory for the ghost sending buffer
715  HeapMemory mem;
716 
717  // sequence of pre-allocation pattern
718  std::vector<size_t> pap;
719 
720  size_t total = 0;
721 
723 
724  // Calculate the total size required for the sending buffer
725  for (size_t i = 0 ; i < n_alloc ; i++)
726  {
727  size_t alloc_ele = vect.calculateMem(alloc[i],0);
728  pap.push_back(alloc_ele);
729  total += alloc_ele;
730  }
731 
732  // Create an object of preallocated memory
733  ExtPreAlloc<HeapMemory> * prAlloc = new ExtPreAlloc<HeapMemory>(total,mem);
734 
736 
737  // create a vector of send_vector (ExtPreAlloc warrant that all the created vector are contiguous)
739 
740  // resize
741  g_send.resize(n_alloc);
742 
743  // Number of allocation
744  for (size_t i = 0 ; i < n_alloc ; i++)
745  {
746  // set the preallocated memory to ensure contiguity
747  g_send.get(i).setMemory(*prAlloc);
748 
749  // resize the sending vector (No allocation is produced)
750  g_send.get(i).resize(alloc[i]);
751  }
752 
753  // Fill the send buffer with one
754  for (size_t i = 0 ; i < n_alloc ; i++)
755  {
756  auto it = g_send.get(i).getIterator();
757  auto & v = g_send.get(i);
758 
759  while(it.isNext())
760  {
761  auto kk = it.get();
762 
763  v.template get<P::x>(kk) = 1.0f;
764  v.template get<P::y>(kk) = 1.0f;
765  v.template get<P::z>(kk) = 1.0f;
766  v.template get<P::s>(kk) = 1.0f;
767 
768  v.template get<P::v>(kk)[0] = 1.0f;
769  v.template get<P::v>(kk)[1] = 1.0f;
770  v.template get<P::v>(kk)[2] = 1.0f;
771 
772  v.template get<P::t>(kk)[0][0] = 1.0f;
773  v.template get<P::t>(kk)[0][1] = 1.0f;
774  v.template get<P::t>(kk)[0][2] = 1.0f;
775  v.template get<P::t>(kk)[1][0] = 1.0f;
776  v.template get<P::t>(kk)[1][1] = 1.0f;
777  v.template get<P::t>(kk)[1][2] = 1.0f;
778  v.template get<P::t>(kk)[2][0] = 1.0f;
779  v.template get<P::t>(kk)[2][1] = 1.0f;
780  v.template get<P::t>(kk)[2][2] = 1.0f;
781 
782  ++it;
783  }
784  }
785 
786  // In SE_CLASS3 the memory layout is different disable this check
787 
788 #ifndef SE_CLASS3
789 
790  // check that HeapMemory contain ones in the right position
791  float * ptr = (float *) mem.getPointer();
792  size_t offset = 0;
793 
794  for (size_t i = 0 ; i < n_alloc ; i++)
795  {
796  for (size_t j = 0 ; j < alloc[i] ; j++)
797  BOOST_REQUIRE_EQUAL(ptr[j + offset/sizeof(float)],1.0f);
798 
799  offset += pap[i];
800  }
801 
802 #endif
803 
804  /* coverity[leaked_storage] */
805 }
806 
807 
808 BOOST_AUTO_TEST_SUITE_END()
809 
810 #endif
Transform the boost::fusion::vector into memory specification (memory_traits)
Definition: memory_conf.hpp:93
Grow policy define how the vector should grow every time we exceed the size.
void setz(T z_)
set the z property
Definition: Point_test.hpp:190
static const unsigned int s
s property is at position 3 in the boost::fusion::vector
Definition: Point_test.hpp:143
size_t size()
Stub size.
Definition: map_vector.hpp:70
This class allocate, and destroy CPU memory.
Definition: HeapMemory.hpp:39
Transform the boost::fusion::vector into memory specification (memory_traits)
Definition: memory_conf.hpp:52
virtual void * getPointer()
get a readable pointer with the data
Definition: HeapMemory.cpp:237
Grow policy define how the vector should grow every time we exceed the size.
It model an expression expr1 * expr2.
Definition: mul.hpp:119
void setx(T x_)
set the x property
Definition: Point_test.hpp:176
static const unsigned int y
y property is at position 1 in the boost::fusion::vector
Definition: Point_test.hpp:137
static const unsigned int x
x property is at position 0 in the boost::fusion::vector
Definition: Point_test.hpp:134
boost::fusion::result_of::at< type, boost::mpl::int_< i > >::type get()
getter method for a general property i
Definition: Point_test.hpp:218
static const unsigned int z
z property is at position 2 in the boost::fusion::vector
Definition: Point_test.hpp:140
void sets(T s_)
set the s property
Definition: Point_test.hpp:197
void sety(T y_)
set the y property
Definition: Point_test.hpp:183
static const unsigned int t
t property is at position 5 in the boost::fusion::vector
Definition: Point_test.hpp:149
Test structure used for several test.
Definition: Point_test.hpp:105
static const unsigned int v
v property is at position 4 in the boost::fusion::vector
Definition: Point_test.hpp:146
This class give memory from a preallocated memory, memory destruction is not performed.
Definition: PtrMemory.hpp:42