DGtal 1.4.0
Loading...
Searching...
No Matches
testMultiMap-benchmark.cpp
1
29//#define TRACE_BITS
30
31#include <cstdio>
32#include <cmath>
33#include <iostream>
34#include <algorithm>
35#include <vector>
36#include <map>
37#if __GXX_EXPERIMENTAL_CXX0X__ && ( __GNUC__ >= 4 ) && ( __GNUC_MINOR__ >= 6 )
38#include <forward_list>
39#endif
40#include <boost/version.hpp>
41#include <boost/random/mersenne_twister.hpp>
42#include <boost/random/uniform_smallint.hpp>
43#include <boost/random/uniform_01.hpp>
44#include <boost/random/geometric_distribution.hpp>
45#include <boost/random/variate_generator.hpp>
46
47
48#include "DGtal/base/Common.h"
49#include "DGtal/base/LabelledMap.h"
50
51// Before 1.47, random number generation in boost.
52// Since 1.47, random number generation in boost::random.
53#define BOOST_MAJOR_VERSION (BOOST_VERSION / 100000)
54#define BOOST_MINOR_VERSION (( BOOST_VERSION / 100) % 1000)
55#define BOOST_SUBMINOR_VERSION (BOOST_VERSION % 100)
56
57
58using namespace DGtal;
59using namespace std;
60
61// A comparer en 2D
62// Array[L][X][Y] of value
63// Array[X][Y] of map<L,Value>
64// map< <L,X,Y>, Value>
65// Array[X][Y] of LabelledMap<L>
66// Array[X][Y] of forward_list< pair<L, Value> >
67
75template <typename Value>
76class DynArrayLXY {
77public:
78 typedef Value ValueType;
79 const unsigned int L;
80 const unsigned int X;
81 const unsigned int Y;
82
83private:
84 Value* _data;
85 Value _invalid;
86
87public:
88 inline
89 DynArrayLXY( unsigned int _L, unsigned int _X, unsigned int _Y, Value invalid )
90 : L( _L ), X( _X ), Y( _Y )
91 {
92 _invalid = invalid;
93 _data = new Value[ L * X * Y ];
94 clear();
95 }
96 inline
97 ~DynArrayLXY()
98 {
99 delete[] _data;
100 }
101 inline
102 void clear()
103 {
104 for ( unsigned int l = 0; l < L; ++l )
105 for ( unsigned int x = 0; x < X; ++x )
106 for ( unsigned int y = 0; y < Y; ++y )
107 setValue( _invalid, l, x, y );
108 }
109
110 inline
111 size_t offset( unsigned int l, unsigned int x, unsigned int y ) const
112 {
113 return ( ( l * X ) + x ) * Y + y;
114 }
115 inline
116 const Value & value( unsigned int l, unsigned int x, unsigned int y ) const
117 {
118 return _data[ offset( l, x, y ) ];
119 }
120 inline
121 unsigned int erase( unsigned int l, unsigned int x, unsigned int y )
122 {
123 size_t offs = offset( l, x, y );
124 if ( _data[ offs ] != _invalid )
125 {
126 _data[ offs ] = _invalid;
127 return 1;
128 }
129 return 0;
130 }
131
132 inline
133 void setValue( const Value & val, unsigned int l, unsigned int x, unsigned int y )
134 {
135 _data[ offset( l, x, y ) ] = val;
136 }
137 inline
138 void setValueNoNewLabel( const Value & val, unsigned int l, unsigned int x, unsigned int y )
139 {
140 _data[ offset( l, x, y ) ] = val;
141 }
142 inline
143 bool hasLabel( unsigned int l, unsigned int x, unsigned int y ) const
144 {
145 return value( l, x, y ) != _invalid;
146 }
147 inline
148 void getLabels( std::vector<unsigned int> & labels,
149 unsigned int x, unsigned int y ) const
150 {
151 labels.clear();
152 for ( unsigned int l = 0; l < L; ++l )
153 if ( hasLabel( l, x, y ) )
154 labels.push_back( l );
155 }
156 inline
157 unsigned int nbLabels( unsigned int x, unsigned int y ) const
158 {
159 unsigned int nb = 0;
160 for ( unsigned int l = 0; l < L; ++l )
161 if ( hasLabel( l, x, y ) ) ++nb;
162 return nb;
163 }
164 inline
165 void display ( ostream & , unsigned int , unsigned int , unsigned int )
166 {}
167
168 inline
169 unsigned long long area() const
170 {
171 return L * X * Y * sizeof( Value );
172 }
173};
174
182template <typename Value>
183class DynArrayXYOfMap {
184 typedef typename std::map<unsigned int, Value> MyMap;
185 typedef typename MyMap::const_iterator ConstIterator;
186
187public:
188 typedef Value ValueType;
189 const unsigned int L;
190 const unsigned int X;
191 const unsigned int Y;
192
193private:
194 MyMap* _data;
195
196public:
197 inline
198 DynArrayXYOfMap( unsigned int _L, unsigned int _X, unsigned int _Y )
199 : L( _L ), X( _X ), Y( _Y )
200 {
201 _data = new MyMap[ X * Y ];
202 }
203 inline
204 ~DynArrayXYOfMap()
205 {
206 delete[] _data;
207 }
208 inline
209 size_t offset( unsigned int x, unsigned int y ) const
210 {
211 return x * Y + y;
212 }
213
214 inline
215 void clear()
216 {
217 for ( unsigned int x = 0; x < X; ++x )
218 for ( unsigned int y = 0; y < Y; ++y )
219 _data[ offset( x, y ) ].clear();
220 }
221
222 inline
223 const Value & value( unsigned int l, unsigned int x, unsigned int y )
224 {
225 return _data[ offset( x, y ) ][ l ];
226 }
227 inline
228 unsigned int erase( unsigned int l, unsigned int x, unsigned int y )
229 {
230 return static_cast<unsigned int>(_data[ offset( x, y ) ].erase( l ));
231 }
232
233 inline
234 void setValue( const Value & val, unsigned int l, unsigned int x, unsigned int y )
235 {
236 _data[ offset( x, y ) ][ l ] = val;
237 }
238 inline
239 void setValueNoNewLabel( const Value & val, unsigned int l, unsigned int x, unsigned int y )
240 {
241 _data[ offset( x, y ) ][ l ] = val;
242 }
243 inline
244 bool hasLabel( unsigned int l, unsigned int x, unsigned int y ) const
245 {
246 return _data[ offset( x, y ) ].count( l ) != 0;
247 }
248 inline
249 void getLabels( std::vector<unsigned int> & labels,
250 unsigned int x, unsigned int y ) const
251 {
252 labels.clear();
253 for ( ConstIterator it = _data[ offset( x, y ) ].begin(),
254 it_end = _data[ offset( x, y ) ].end();
255 it != it_end; ++it )
256 labels.push_back( (*it).first );
257 }
258 inline
259 unsigned int nbLabels( unsigned int x, unsigned int y ) const
260 {
261 return static_cast<unsigned int>(_data[ offset( x, y ) ].size());
262 }
263 inline
264 void display ( ostream & , unsigned int , unsigned int , unsigned int )
265 {}
266
267
268 inline
269 unsigned long long area() const
270 {
271 unsigned long long total = 0;
272 for ( unsigned int y = 0; y < Y; ++y )
273 for ( unsigned int x = 0; x < X; ++x )
274 {
275 unsigned int size = nbLabels( x, y );
276 total += ( size + 1 ) *
277 ( sizeof( Value ) // one value per node
278 + 3 * sizeof( Value* ) // three pointers
279 + 2 //_RbTreeColor { _S_red = false, _S_black = true };
280 + 8 // dynamic allocation );
281 );
282 }
283 return total;
284 }
285};
286
287
288#if __GXX_EXPERIMENTAL_CXX0X__ && ( __GNUC__ >= 4 ) && ( __GNUC_MINOR__ >= 6 )
289
300template <typename Value>
301class DynArrayXYOfList {
302 typedef typename std::pair<uint16_t, Value> MyPair;
303 typedef typename std::forward_list<MyPair> MyList;
304 typedef typename MyList::iterator Iterator;
305 typedef typename MyList::const_iterator ConstIterator;
306public:
307 typedef Value ValueType;
308 const unsigned int L;
309 const unsigned int X;
310 const unsigned int Y;
311
312private:
313 MyList* _data;
314
315
316public:
317 inline
318 DynArrayXYOfList( unsigned int _L, unsigned int _X, unsigned int _Y )
319 : L( _L ), X( _X ), Y( _Y )
320 {
321 _data = new MyList[ X * Y ];
322 }
323 inline
324 ~DynArrayXYOfList()
325 {
326 delete[] _data;
327 }
328 inline
329 size_t offset( unsigned int x, unsigned int y ) const
330 {
331 return x * Y + y;
332 }
333
334 inline
335 void clear()
336 {
337 for ( unsigned int y = 0; y < Y; ++y )
338 for ( unsigned int x = 0; x < X; ++x )
339 _data[ offset( x, y ) ].clear();
340 }
341
342 inline
343 const Value & value( unsigned int l, unsigned int x, unsigned int y )
344 {
345 MyList & list = _data[ offset( x, y ) ];
346 Iterator it = list.begin(), it_end = list.end();
347 for ( ; it != it_end; ++it )
348 {
349 if ( it->first == l ) return it->second;
350 }
351 ASSERT(it == it_end);
352 list.emplace_front( std::make_pair( l, Value() ) );
353 return list.front().second;
354 }
355 inline
356 unsigned int erase( unsigned int l, unsigned int x, unsigned int y )
357 {
358 MyList & list = _data[ offset( x, y ) ];
359 Iterator it_prev = list.before_begin();
360 Iterator it = list.begin(), it_end = list.end();
361 for ( ; it != it_end; ++it )
362 {
363 if ( it->first == l )
364 {
365 list.erase_after( it_prev );
366 return 1;
367 }
368 it_prev = it;
369 }
370 return 0;
371 }
372
373 inline
374 void setValue( const Value & val, unsigned int l, unsigned int x, unsigned int y )
375 {
376 MyList & list = _data[ offset( x, y ) ];
377 Iterator it = list.begin(), it_end = list.end();
378 for ( ; it != it_end; ++it )
379 {
380 if ( it->first == l )
381 {
382 it->second = val;
383 return;
384 }
385 }
386 if ( it == it_end )
387 list.emplace_front( std::make_pair( l, val ) );
388 }
389 inline
390 void setValueNoNewLabel( const Value & val, unsigned int l, unsigned int x, unsigned int y )
391 {
392 MyList & list = _data[ offset( x, y ) ];
393 Iterator it = list.begin(), it_end = list.end();
394 for ( ; it != it_end; ++it )
395 {
396 if ( it->first == l )
397 {
398 it->second = val;
399 return;
400 }
401 }
402 if ( it == it_end )
403 list.emplace_front( std::make_pair( l, val ) );
404 }
405 inline
406 bool hasLabel( unsigned int l, unsigned int x, unsigned int y ) const
407 {
408 const MyList & list = _data[ offset( x, y ) ];
409 ConstIterator it = list.begin(), it_end = list.end();
410 for ( ; it != it_end; ++it )
411 {
412 if ( it->first == l ) return true;
413 }
414 return false;
415 }
416 inline
417 void getLabels( std::vector<unsigned int> & labels,
418 unsigned int x, unsigned int y ) const
419 {
420 labels.clear();
421 const MyList & list = _data[ offset( x, y ) ];
422 ConstIterator it = list.begin(), it_end = list.end();
423 for ( ; it != it_end; ++it )
424 {
425 labels.push_back( (*it).first );
426 }
427 }
428 inline
429 unsigned int nbLabels( unsigned int x, unsigned int y ) const
430 {
431 const MyList & list = _data[ offset( x, y ) ];
432 ConstIterator it = list.begin(), it_end = list.end();
433 unsigned int n = 0;
434 for ( ; it != it_end; ++it )
435 ++n;
436 return n;
437 }
438 inline
439 void display ( ostream & , unsigned int , unsigned int , unsigned int )
440 {}
441
442
443 inline
444 unsigned long long area() const
445 {
446 unsigned long long total = 0;
447 for ( unsigned int y = 0; y < Y; ++y )
448 for ( unsigned int x = 0; x < X; ++x )
449 {
450 unsigned int size = nbLabels( x, y );
451 total += sizeof( Value* )
452 + ( size ) *
453 ( sizeof( Value ) // one value per node
454 + sizeof( Value* ) // one pointers
455 + 2 // uint16_t
456 + 8 // dynamic allocation );
457 );
458 }
459 return total;
460 }
461};
462
463#endif
464
476template < typename Value, unsigned int L,
477 typename TWord, unsigned int N, unsigned int M >
478class DynArrayXYOfLabelledMap {
479 typedef LabelledMap< Value, L, TWord, N, M> MyLabelledMap;
480public:
481 typedef Value ValueType;
482 const unsigned int X;
483 const unsigned int Y;
484
485private:
486 MyLabelledMap* _data;
487
488public:
489 inline
490 DynArrayXYOfLabelledMap( unsigned int _X, unsigned int _Y )
491 : X( _X ), Y( _Y )
492 {
493 _data = new MyLabelledMap[ X * Y ];
494 }
495 inline
496 ~DynArrayXYOfLabelledMap()
497 {
498 delete[] _data;
499 }
500 inline
501 size_t offset( unsigned int x, unsigned int y ) const
502 {
503 return x * Y + y;
504 }
505
506 inline
507 void clear()
508 {
509 for ( unsigned int y = 0; y < Y; ++y )
510 for ( unsigned int x = 0; x < X; ++x )
511 _data[ offset( x, y ) ].clear();
512 }
513
514 inline
515 const Value & value( unsigned int l, unsigned int x, unsigned int y ) const
516 {
517 return _data[ offset( x, y ) ].fastAt( l );
518 }
519
520 inline
521 void setValue( const Value & val, unsigned int l, unsigned int x, unsigned int y )
522 {
523 _data[ offset( x, y ) ][ l ] = val;
524 }
525
526 inline
527 unsigned int erase( unsigned int l, unsigned int x, unsigned int y )
528 {
529 return _data[ offset( x, y ) ].erase( l );
530 }
531
532 inline
533 void setValueNoNewLabel( const Value & val, unsigned int l, unsigned int x, unsigned int y )
534 {
535 _data[ offset( x, y ) ].fastAt( l ) = val;
536 }
537
538 inline
539 bool hasLabel( unsigned int l, unsigned int x, unsigned int y ) const
540 {
541 return _data[ offset( x, y ) ].count( l );
542 }
543
544 inline
545 void getLabels( std::vector<unsigned int> & labels,
546 unsigned int x, unsigned int y ) const
547 {
548 _data[ offset( x, y ) ].labels().getLabels( labels );
549 }
550
551 inline
552 unsigned int nbLabels( unsigned int x, unsigned int y ) const
553 {
554 return static_cast<unsigned int>(_data[ offset( x, y ) ].size());
555 }
556 inline void display ( ostream & , unsigned int , unsigned int x, unsigned int y )
557 {
558 std::cerr << _data[ offset( x, y ) ] << endl;
559 }
560
561 inline
562 unsigned long long area() const
563 {
564 unsigned long long total = 0;
565 for ( unsigned int y = 0; y < Y; ++y )
566 for ( unsigned int x = 0; x < X; ++x )
567 {
568 unsigned int size = nbLabels( x, y );
569 total += sizeof( MyLabelledMap );
570 if ( size > (N+1) )
571 total += ( 1 + ( size - N - 1 ) / M ) * ( M * sizeof( Value ) + 8 );
572 }
573 return total;
574 }
575
576};
577
578
579// template <typename MapLXY>
580// unsigned int
581// generateData( MapLXY & m, unsigned int L, double proba_no_label, double proba_label )
582// {
583// BOOST_RANDOM_NAMESPACE::mt19937 rng; // produces randomness out of thin air
584// rng.seed( 0 );
585// BOOST_RANDOM_NAMESPACE::uniform_smallint<> diceL(0, L-1);
586// BOOST_RANDOM_NAMESPACE::uniform_01<> diceDouble;
587// BOOST_RANDOM_NAMESPACE::geometric_distribution<> diceNbLabels( proba_label ); // Y
588// // E(Y) = (1-p)/p, Var(Y) = (1-p)/p^2
589// std::cerr << "E(Y)=" << ( (1-proba_label)/proba_label )
590// << " Var(Y)=" << ( (1-proba_label)/(proba_label*proba_label) )
591// << std::endl;
592// unsigned int X = m.X;
593// unsigned int Y = m.Y;
594// unsigned int total = 0;
595// for ( unsigned int y = 0; y < Y; ++y )
596// for ( unsigned int x = 0; x < X; ++x )
597// {
598// if ( diceDouble( rng ) >= proba_no_label )
599// {
600// unsigned int nb = diceNbLabels( rng );
601// for ( unsigned int i = 0; i < nb; ++i )
602// {
603// unsigned int l = diceL( rng );
604// double v = diceDouble( rng );
605// // if ( ( x == 408 ) && ( y == 171 ) )
606// // {
607// // std::cerr << "+ Insert( " << l << ", " << v << " ) l=";
608// // m.display ( std::cerr, l, x, y );
609// // }
610// m.setValue( v, l, x, y );
611// }
612// total += nb;
613// }
614// }
615// std::cerr << "- " << total << " insertions." << endl;
616// return total;
617// }
618
619// boost::random is different since 1.47
620#if (BOOST_MAJOR_VERSION >= 1 ) && (BOOST_MINOR_VERSION >= 47 )
621template <typename MapLXY>
622unsigned int
623generateData( MapLXY & m, unsigned int L, double proba_no_label, double proba_label )
624{
625 boost::random::mt19937 rng; // produces randomness out of thin air
626 rng.seed( 0 );
627 boost::random::uniform_smallint<> diceL(0, L-1);
628 boost::random::uniform_01<> diceDouble;
629 boost::random::geometric_distribution<> diceNbLabels( proba_label ); // Y
630 // E(Y) = (1-p)/p, Var(Y) = (1-p)/p^2
631 std::cerr << "E(Y)=" << ( (1-proba_label)/proba_label )
632 << " Var(Y)=" << ( (1-proba_label)/(proba_label*proba_label) )
633 << std::endl;
634 unsigned int X = m.X;
635 unsigned int Y = m.Y;
636 unsigned int total = 0;
637 for ( unsigned int y = 0; y < Y; ++y )
638 for ( unsigned int x = 0; x < X; ++x )
639 {
640 if ( diceDouble( rng ) >= proba_no_label )
641 {
642 unsigned int nb = diceNbLabels( rng );
643 for ( unsigned int i = 0; i < nb; ++i )
644 {
645 unsigned int l = diceL( rng );
646 double v = diceDouble( rng );
647 m.setValue( v, l, x, y );
648 }
649 total += nb;
650 }
651 }
652 std::cerr << "- " << total << " insertions." << endl;
653 return total;
654}
655#else
656// boost::random is different since 1.47, below <= 1.46
657template <typename MapLXY>
658unsigned int
659generateData( MapLXY & m, unsigned int L, double proba_no_label, double proba_label )
660{
661 boost::mt19937 rng; // produces randomness out of thin air
662 rng.seed( 0 );
663 boost::uniform_smallint<> diceL(0, L-1);
664 boost::uniform_01<> diceDouble;
665 boost::geometric_distribution<> nbLabelsDist( proba_label ); // Y
666 boost::variate_generator
667 <boost::mt19937&,
668 boost::geometric_distribution<> > diceNbLabels( rng, nbLabelsDist);
669 // E(Y) = (1-p)/p, Var(Y) = (1-p)/p^2
670 std::cerr << "E(Y)=" << ( (1-proba_label)/proba_label )
671 << " Var(Y)=" << ( (1-proba_label)/(proba_label*proba_label) )
672 << std::endl;
673 unsigned int X = m.X;
674 unsigned int Y = m.Y;
675 unsigned int total = 0;
676 for ( unsigned int y = 0; y < Y; ++y )
677 for ( unsigned int x = 0; x < X; ++x )
678 {
679 if ( diceDouble( rng ) >= proba_no_label )
680 {
681 unsigned int nb = diceNbLabels();
682 for ( unsigned int i = 0; i < nb; ++i )
683 {
684 unsigned int l = diceL( rng );
685 double v = diceDouble( rng );
686 m.setValue( v, l, x, y );
687 }
688 total += nb;
689 }
690 }
691 std::cerr << "- " << total << " insertions." << endl;
692 return total;
693}
694#endif
695
696template <typename MapLXY>
697double
698sumAllData( MapLXY & m )
699{
700 unsigned int X = m.X;
701 unsigned int Y = m.Y;
702 double sum = 0.0;
703 std::vector<unsigned int> labels;
704 for ( unsigned int y = 0; y < Y; ++y )
705 for ( unsigned int x = 0; x < X; ++x )
706 {
707 m.getLabels( labels, x, y );
708 for ( unsigned int i = 0; i < labels.size(); ++i )
709 sum += m.value( labels[ i ], x, y );
710 }
711 std::cerr << "- sum = " << sum << "." << endl;
712 return sum;
713}
714
715template <typename MapLXY>
716double
717sumOneData( MapLXY & m, unsigned int l )
718{
719 unsigned int X = m.X;
720 unsigned int Y = m.Y;
721 double sum = 0.0;
722 for ( unsigned int y = 0; y < Y; ++y )
723 for ( unsigned int x = 0; x < X; ++x )
724 {
725 if ( m.hasLabel( l, x, y ) )
726 sum += m.value( l, x, y );
727 }
728 std::cerr << "- sum = " << sum << "." << endl;
729 return sum;
730}
731
732template <typename MapLXY>
733unsigned int
734locateThreeData( MapLXY & m, unsigned int l1, unsigned int l2, unsigned int l3 )
735{
736 unsigned int X = m.X;
737 unsigned int Y = m.Y;
738 unsigned int loc3 = 0;
739 for ( unsigned int y = 0; y < Y; ++y )
740 for ( unsigned int x = 0; x < X; ++x )
741 {
742 if ( ( m.hasLabel( l1, x, y ) )
743 && ( m.hasLabel( l2, x, y ) )
744 && ( m.hasLabel( l3, x, y ) ) )
745 ++loc3;
746 }
747 std::cerr << "- " << loc3 << " places with " << l1 << ", " << l2 << " ," << l3 << endl;
748 return loc3;
749}
750
751template <typename MapLXY>
752unsigned int
753eraseOneData( MapLXY & m, unsigned int l )
754{
755 unsigned int X = m.X;
756 unsigned int Y = m.Y;
757 unsigned int nb = 0;
758 for ( unsigned int y = 0; y < Y; ++y )
759 for ( unsigned int x = 0; x < X; ++x )
760 {
761 nb += m.erase( l, x, y );
762 }
763 return nb;
764}
765
766template <typename MapLXY>
767void generateStatsMultiMapXY( const string & name,
768 MapLXY & m,
769 const unsigned int L,
770 const unsigned int X,
771 const unsigned int Y,
772 double PROBA_NO_LABEL,
773 double PROBA_LABEL )
774{
775 typedef typename MapLXY::ValueType Value;
776 //----------------------------------------------------------------------
777 string msg = "Generating statistics for " + name;
778 trace.beginBlock ( msg.c_str() );
779 trace.beginBlock ( "Generating data." );
780 generateData< MapLXY > ( m, L, PROBA_NO_LABEL, PROBA_LABEL );
781 long tgen = trace.endBlock();
782
783 trace.beginBlock ( "Memory usage." );
784 unsigned long long mem = m.area();
785 trace.info() << mem << " bytes." << std::endl;
786 long tmem = trace.endBlock();
787
788 trace.beginBlock ( "Sum all values." );
789 double sumAll = sumAllData< MapLXY > ( m );
790 trace.info() << "- sum_all = " << sumAll << "." << endl;
791 long tsumall = trace.endBlock();
792
793 trace.beginBlock ( "Sum label 0 values." );
794 double sum0 = sumOneData< MapLXY > ( m, 0 );
795 trace.info() << "- sum_0 = " << sum0 << "." << endl;
796 long tsum0 = trace.endBlock();
797
798 trace.beginBlock ( "Sum label 15 values." );
799 double sum15 = sumOneData< MapLXY > ( m, 15 );
800 trace.info() << "- sum_15 = " << sum15 << "." << endl;
801 long tsum15 = trace.endBlock();
802
803 trace.beginBlock ( "Locate places (3, 7, 8)." );
804 unsigned int nbThree = locateThreeData< MapLXY > ( m, 3, 7, 8 );
805 trace.info() << "- " << nbThree << " places (3, 7, 8) detected." << endl;
806 long tthree = trace.endBlock();
807
808 trace.beginBlock ( "Erase label 9." );
809 unsigned int nbErased = eraseOneData< MapLXY > ( m, 9 );
810 trace.info() << "- " << nbErased << " values deleted." << endl;
811 long terase9 = trace.endBlock();
812
813 trace.beginBlock ( "Clear data" );
814 m.clear();
815 long tclear = trace.endBlock();
816 trace.endBlock();
817
818 std::cout << name << " " << L << " " << X << " " << Y
819 << " " << PROBA_NO_LABEL << " " << PROBA_LABEL
820 << " " << sizeof(Value) << " " << sizeof(Value*) << " " << mem
821 << " " << tgen << " " << tmem
822 << " " << tsumall << " " << tsum0 << " " << tsum15
823 << " " << tthree << " " << terase9 << " " << tclear
824 << " " << sumAll << " " << sum0 << " " << sum15
825 << " " << nbThree << " " << nbErased
826 << std::endl;
827}
828
829#define GENERATE_STATS_NM( Word, N , M ) \
830 { \
831 typedef DynArrayXYOfLabelledMap<Value,L,Word,N,M> MyArrayXYOfLabelledMap; \
832 MyArrayXYOfLabelledMap* anArrayXYOfLabelledMap = new MyArrayXYOfLabelledMap( X, Y ); \
833 generateStatsMultiMapXY( "DynArrayXYOfLabelledMap<double," #Word "," #N "," #M ">", \
834 *anArrayXYOfLabelledMap, L, X, Y, PROB_NO_DATA, PROB_ONE_DATA ); \
835 delete anArrayXYOfLabelledMap; \
836 }
837
838
840
841
842int main( int /*argc*/, char** /*argv*/ )
843{
844 typedef double Value;
845 static const unsigned int L = 16;
846 trace.info()<< "Test several multi-map structures and compute some statistics." <<std::endl << "With parameter: "<<std::endl
847 << "\t tested image size: 500 500"<<std::endl
848 <<"Probability that there is no data at all at an image position (Bernouilli distribution): 0.5"
849 << "Probability for the geometric distribution of the number of data per image position (E(Y)=(1-p)/p, Var(Y)=(1-p)/p^2 :0.5"<< std::endl;
850
851
852
853 unsigned int X = 100;
854 unsigned int Y = 100;
856 double PROB_NO_DATA = 0.5;
861 double PROB_ONE_DATA = 0.5;
862
863 typedef DynArrayLXY<Value> MyArrayLXY;
864 MyArrayLXY* anArrayLXY = new MyArrayLXY( L, X, Y, -1.0 );
865 generateStatsMultiMapXY( "DynArrayLXY<double>",
866 *anArrayLXY, L, X, Y, PROB_NO_DATA, PROB_ONE_DATA );
867 delete anArrayLXY;
868
869 typedef DynArrayXYOfMap<Value> MyArrayXYOfMap;
870 MyArrayXYOfMap* anArrayXYOfMap = new MyArrayXYOfMap( L, X, Y );
871 generateStatsMultiMapXY( "DynArrayXYOfMap<double>",
872 *anArrayXYOfMap, L, X, Y, PROB_NO_DATA, PROB_ONE_DATA );
873 delete anArrayXYOfMap;
874
875#if __GXX_EXPERIMENTAL_CXX0X__ && ( __GNUC__ >= 4 ) && ( __GNUC_MINOR__ >= 6 )
876 typedef DynArrayXYOfList<Value> MyArrayXYOfList;
877 MyArrayXYOfList* anArrayXYOfList = new MyArrayXYOfList( L, X, Y );
878 generateStatsMultiMapXY( "DynArrayXYOfList<double>",
879 *anArrayXYOfList, L, X, Y, PROB_NO_DATA, PROB_ONE_DATA );
880 delete anArrayXYOfList;
881#endif
882
883 GENERATE_STATS_NM( DGtal::uint8_t, 1, 2 )
884 GENERATE_STATS_NM( DGtal::uint8_t, 1, 3 )
885 GENERATE_STATS_NM( DGtal::uint8_t, 1, 4 )
886 GENERATE_STATS_NM( DGtal::uint8_t, 1, 5 )
887 GENERATE_STATS_NM( DGtal::uint8_t, 1, 6 )
888 GENERATE_STATS_NM( DGtal::uint8_t, 1, 7 )
889 GENERATE_STATS_NM( DGtal::uint8_t, 1, 8 )
890
891 GENERATE_STATS_NM( DGtal::uint8_t, 2, 2 )
892 GENERATE_STATS_NM( DGtal::uint8_t, 2, 3 )
893 GENERATE_STATS_NM( DGtal::uint8_t, 2, 4 )
894 GENERATE_STATS_NM( DGtal::uint8_t, 2, 5 )
895 GENERATE_STATS_NM( DGtal::uint8_t, 2, 6 )
896 GENERATE_STATS_NM( DGtal::uint8_t, 2, 7 )
897 GENERATE_STATS_NM( DGtal::uint8_t, 2, 8 )
898
899 GENERATE_STATS_NM( DGtal::uint8_t, 3, 2 )
900 GENERATE_STATS_NM( DGtal::uint8_t, 3, 3 )
901 GENERATE_STATS_NM( DGtal::uint8_t, 3, 4 )
902 GENERATE_STATS_NM( DGtal::uint8_t, 3, 5 )
903 GENERATE_STATS_NM( DGtal::uint8_t, 3, 6 )
904 GENERATE_STATS_NM( DGtal::uint8_t, 3, 7 )
905 GENERATE_STATS_NM( DGtal::uint8_t, 3, 8 )
906
907 GENERATE_STATS_NM( DGtal::uint8_t, 4, 2 )
908 GENERATE_STATS_NM( DGtal::uint8_t, 4, 3 )
909 GENERATE_STATS_NM( DGtal::uint8_t, 4, 4 )
910 GENERATE_STATS_NM( DGtal::uint8_t, 4, 5 )
911 GENERATE_STATS_NM( DGtal::uint8_t, 4, 6 )
912 GENERATE_STATS_NM( DGtal::uint8_t, 4, 7 )
913 GENERATE_STATS_NM( DGtal::uint8_t, 4, 8 )
914
915 GENERATE_STATS_NM( DGtal::uint8_t, 5, 2 )
916 GENERATE_STATS_NM( DGtal::uint8_t, 5, 3 )
917 GENERATE_STATS_NM( DGtal::uint8_t, 5, 4 )
918 GENERATE_STATS_NM( DGtal::uint8_t, 5, 5 )
919 GENERATE_STATS_NM( DGtal::uint8_t, 5, 6 )
920 GENERATE_STATS_NM( DGtal::uint8_t, 5, 7 )
921 GENERATE_STATS_NM( DGtal::uint8_t, 5, 8 )
922
923
924 return 0;
925}
Aim: Represents a map label -> data, where the label is an integer between 0 and a constant L-1....
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
MyDigitalSurface::ConstIterator ConstIterator
DGtal is the top-level namespace which contains all DGtal functions and types.
boost::uint8_t uint8_t
unsigned 8-bit integer.
Definition BasicTypes.h:59
Trace trace
Definition Common.h:153
STL namespace.
int main()
Definition testBits.cpp:56
void erase(VContainer1 &c1, LContainer2 &c2, unsigned int idx)
unsigned int generateData(MapLXY &m, double proba_no_label, double proba_label)
double sumAllData(MapLXY &m)
unsigned int eraseOneData(MapLXY &m, unsigned int l)
double sumOneData(MapLXY &m, unsigned int l)
unsigned int locateThreeData(MapLXY &m, unsigned int l1, unsigned int l2, unsigned int l3)
void display(ostream &out, const AContainer &C)