DGtal 1.3.0
Loading...
Searching...
No Matches
testLabelledMap-benchmark.cpp
Go to the documentation of this file.
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#include <forward_list>
38#include <boost/version.hpp>
39#include <boost/random/mersenne_twister.hpp>
40#include <boost/random/uniform_smallint.hpp>
41#include <boost/random/uniform_01.hpp>
42#include <boost/random/geometric_distribution.hpp>
43#include <boost/random/variate_generator.hpp>
44
45#include "DGtal/base/Common.h"
46#include "DGtal/base/LabelledMap.h"
47
48// Before 1.47, random number generation in boost.
49// Since 1.47, random number generation in boost::random.
50#define BOOST_MAJOR_VERSION (BOOST_VERSION / 100000)
51#define BOOST_MINOR_VERSION (( BOOST_VERSION / 100) % 1000)
52#define BOOST_SUBMINOR_VERSION (BOOST_VERSION % 100)
53
54
55using namespace DGtal;
56using namespace std;
57
58// A comparer en 2D
59// Array[L][X][Y] of value
60// Array[X][Y] of map<L,Value>
61// map< <L,X,Y>, Value>
62// Array[X][Y] of LabelledMap<L>
63// Array[X][Y] of forward_list< pair<L, Value> >
64
72template <typename Value, unsigned int L, unsigned int X, unsigned int Y>
73class ArrayLXY {
74 Value _data[ L ][ X ][ Y ];
75 Value _invalid;
76
77public:
78 inline
79 ArrayLXY( Value invalid )
80 {
81 _invalid = invalid;
82 clear();
83 }
84
85 inline
86 void clear()
87 {
88 for ( unsigned int l = 0; l < L; ++l )
89 for ( unsigned int y = 0; y < Y; ++y )
90 for ( unsigned int x = 0; x < X; ++x )
91 setValue( _invalid, l, x, y );
92 }
93
94 inline
95 const Value & value( unsigned int l, unsigned int x, unsigned int y ) const
96 {
97 return _data[ l ][ x ][ y ];
98 }
99 inline
100 unsigned int erase( unsigned int l, unsigned int x, unsigned int y )
101 {
102 if ( _data[ l ][ x ][ y ] != _invalid )
103 {
104 _data[ l ][ x ][ y ] = _invalid;
105 return 1;
106 }
107 return 0;
108 }
109
110 inline
111 void setValue( const Value & val, unsigned int l, unsigned int x, unsigned int y )
112 {
113 _data[ l ][ x ][ y ] = val;
114 }
115 inline
116 void setValueNoNewLabel( const Value & val, unsigned int l, unsigned int x, unsigned int y )
117 {
118 _data[ l ][ x ][ y ] = val;
119 }
120 inline
121 bool hasLabel( unsigned int l, unsigned int x, unsigned int y ) const
122 {
123 return value( l, x, y ) != _invalid;
124 }
125 inline
126 void getLabels( std::vector<unsigned int> & labels,
127 unsigned int x, unsigned int y ) const
128 {
129 labels.clear();
130 for ( unsigned int l = 0; l < L; ++l )
131 if ( hasLabel( l, x, y ) )
132 labels.push_back( l );
133 }
134 inline
135 unsigned int nbLabels( unsigned int x, unsigned int y ) const
136 {
137 unsigned int nb = 0;
138 for ( unsigned int l = 0; l < L; ++l )
139 if ( hasLabel( l, x, y ) ) ++nb;
140 return nb;
141 }
142 inline
143 void display ( ostream & , unsigned int , unsigned int , unsigned int )
144 {}
145
146 inline
147 unsigned long long area() const
148 {
149 return L * X * Y * sizeof( Value );
150 }
151};
152
160template <typename Value, unsigned int L, unsigned int X, unsigned int Y>
161class ArrayXYOfMap {
162 typedef typename std::map<unsigned int, Value> MyMap;
163 typedef typename MyMap::const_iterator ConstIterator;
164 MyMap _data[ X ][ Y ];
165
166public:
167 inline
168 ArrayXYOfMap()
169 {
170 }
171
172 inline
173 void clear()
174 {
175 for ( unsigned int y = 0; y < Y; ++y )
176 for ( unsigned int x = 0; x < X; ++x )
177 _data[ x ][ y ].clear();
178 }
179
180 inline
181 const Value & value( unsigned int l, unsigned int x, unsigned int y )
182 {
183 return _data[ x ][ y ][ l ];
184 }
185 inline
186 unsigned int erase( unsigned int l, unsigned int x, unsigned int y )
187 {
188 return _data[ x ][ y ].erase( l );
189 }
190
191 inline
192 void setValue( const Value & val, unsigned int l, unsigned int x, unsigned int y )
193 {
194 _data[ x ][ y ][ l ] = val;
195 }
196 inline
197 void setValueNoNewLabel( const Value & val, unsigned int l, unsigned int x, unsigned int y )
198 {
199 _data[ x ][ y ][ l ] = val;
200 }
201 inline
202 bool hasLabel( unsigned int l, unsigned int x, unsigned int y ) const
203 {
204 return _data[ x ][ y ].count( l ) != 0;
205 }
206 inline
207 void getLabels( std::vector<unsigned int> & labels,
208 unsigned int x, unsigned int y ) const
209 {
210 labels.clear();
211 for ( ConstIterator it = _data[ x ][ y ].begin(), it_end = _data[ x ][ y ].end();
212 it != it_end; ++it )
213 labels.push_back( (*it).first );
214 }
215 inline
216 unsigned int nbLabels( unsigned int x, unsigned int y ) const
217 {
218 return (unsigned int)_data[ x ][ y ].size();
219 }
220 inline
221 void display ( ostream & , unsigned int, unsigned int , unsigned int )
222 {}
223
224
225 inline
226 unsigned long long area() const
227 {
228 unsigned long long total = 0;
229 for ( unsigned int y = 0; y < Y; ++y )
230 for ( unsigned int x = 0; x < X; ++x )
231 {
232 unsigned int size = nbLabels( x, y );
233 total += ( size + 1 ) *
234 ( sizeof( Value ) // one value per node
235 + 3 * sizeof( Value* ) // three pointers
236 + 2 //_RbTreeColor { _S_red = false, _S_black = true };
237 + 8 // dynamic allocation );
238 );
239 }
240 return total;
241 }
242};
243
244
255template <typename Value, unsigned int L, unsigned int X, unsigned int Y>
256class ArrayXYOfList {
257 typedef typename std::pair<DGtal::uint16_t, Value> MyPair;
258 typedef typename std::forward_list<MyPair> MyList;
259 typedef typename MyList::iterator Iterator;
260 typedef typename MyList::const_iterator ConstIterator;
261 MyList _data[ X ][ Y ];
262
263public:
264 inline
265 ArrayXYOfList()
266 {
267 }
268
269 inline
270 void clear()
271 {
272 for ( unsigned int y = 0; y < Y; ++y )
273 for ( unsigned int x = 0; x < X; ++x )
274 _data[ x ][ y ].clear();
275 }
276
277 inline
278 const Value & value( unsigned int l, unsigned int x, unsigned int y )
279 {
280 MyList & list = _data[ x ][ y ];
281 Iterator it = list.begin(), it_end = list.end();
282 for ( ; it != it_end; ++it )
283 {
284 if ( it->first == l ) return it->second;
285 }
286 ASSERT ( it == it_end ) ;
287 list.emplace_front( std::make_pair( l, Value() ) );
288 return list.front().second;
289 }
290 inline
291 unsigned int erase( unsigned int l, unsigned int x, unsigned int y )
292 {
293 MyList & list = _data[ x ][ y ];
294 Iterator it_prev = list.before_begin();
295 Iterator it = list.begin(), it_end = list.end();
296 for ( ; it != it_end; ++it )
297 {
298 if ( it->first == l )
299 {
300 list.erase_after( it_prev );
301 return 1;
302 }
303 it_prev = it;
304 }
305 return 0;
306 }
307
308 inline
309 void setValue( const Value & val, unsigned int l, unsigned int x, unsigned int y )
310 {
311 MyList & list = _data[ x ][ y ];
312 Iterator it = list.begin(), it_end = list.end();
313 for ( ; it != it_end; ++it )
314 {
315 if ( it->first == l )
316 {
317 it->second = val;
318 return;
319 }
320 }
321 if ( it == it_end )
322 list.emplace_front( std::make_pair( l, val ) );
323 }
324 inline
325 void setValueNoNewLabel( const Value & val, unsigned int l, unsigned int x, unsigned int y )
326 {
327 MyList & list = _data[ x ][ y ];
328 Iterator it = list.begin(), it_end = list.end();
329 for ( ; it != it_end; ++it )
330 {
331 if ( it->first == l )
332 {
333 it->second = val;
334 return;
335 }
336 }
337 if ( it == it_end )
338 list.emplace_front( std::make_pair( l, val ) );
339 }
340 inline
341 bool hasLabel( unsigned int l, unsigned int x, unsigned int y ) const
342 {
343 const MyList & list = _data[ x ][ y ];
344 ConstIterator it = list.begin(), it_end = list.end();
345 for ( ; it != it_end; ++it )
346 {
347 if ( it->first == l ) return true;
348 }
349 return false;
350 }
351 inline
352 void getLabels( std::vector<unsigned int> & labels,
353 unsigned int x, unsigned int y ) const
354 {
355 labels.clear();
356 const MyList & list = _data[ x ][ y ];
357 ConstIterator it = list.begin(), it_end = list.end();
358 for ( ; it != it_end; ++it )
359 {
360 labels.push_back( (*it).first );
361 }
362 }
363 inline
364 unsigned int nbLabels( unsigned int x, unsigned int y ) const
365 {
366 const MyList & list = _data[ x ][ y ];
367 ConstIterator it = list.begin(), it_end = list.end();
368 unsigned int n = 0;
369 for ( ; it != it_end; ++it )
370 ++n;
371 return n;
372 }
373 inline
374 void display ( ostream & , unsigned int , unsigned int , unsigned int )
375 {}
376
377
378 inline
379 unsigned long long area() const
380 {
381 unsigned long long total = 0;
382 for ( unsigned int y = 0; y < Y; ++y )
383 for ( unsigned int x = 0; x < X; ++x )
384 {
385 unsigned int size = nbLabels( x, y );
386 total += sizeof( Value* )
387 + ( size ) *
388 ( sizeof( Value ) // one value per node
389 + sizeof( Value* ) // one pointers
390 + 2 // uint16_t
391 + 8 // dynamic allocation );
392 );
393 }
394 return total;
395 }
396};
397
398
410template < typename Value, unsigned int L, unsigned int X, unsigned int Y,
411 typename TWord, unsigned int N, unsigned int M >
412class ArrayXYOfLabelledMap {
413 typedef LabelledMap< Value, L, TWord, N, M> MyLabelledMap;
414 MyLabelledMap _data[ X ][ Y ];
415
416public:
417 inline
418 ArrayXYOfLabelledMap() {}
419
420 inline
421 const Value & value( unsigned int l, unsigned int x, unsigned int y ) const
422 {
423 return _data[ x ][ y ].fastAt( l );
424 }
425
426 inline
427 void setValue( const Value & val, unsigned int l, unsigned int x, unsigned int y )
428 {
429 _data[ x ][ y ][ l ] = val;
430 }
431
432 inline
433 unsigned int erase( unsigned int l, unsigned int x, unsigned int y )
434 {
435 return _data[ x ][ y ].erase( l );
436 }
437
438 inline
439 void setValueNoNewLabel( const Value & val, unsigned int l, unsigned int x, unsigned int y )
440 {
441 _data[ x ][ y ].fastAt( l ) = val;
442 }
443
444 inline
445 bool hasLabel( unsigned int l, unsigned int x, unsigned int y ) const
446 {
447 return _data[ x ][ y ].count( l );
448 }
449
450 inline
451 void getLabels( std::vector<unsigned int> & labels,
452 unsigned int x, unsigned int y ) const
453 {
454 _data[ x ][ y ].labels().getLabels( labels );
455 }
456
457 inline
458 unsigned int nbLabels( unsigned int x, unsigned int y ) const
459 {
460 return _data[ x ][ y ].size();
461 }
462 inline void display ( ostream & , unsigned int , unsigned int x, unsigned int y )
463 {
464 std::cerr << _data[ x ][ y ] << endl;
465 }
466
467 inline
468 unsigned long long area() const
469 {
470 unsigned long long total = 0;
471 for ( unsigned int y = 0; y < Y; ++y )
472 for ( unsigned int x = 0; x < X; ++x )
473 {
474 unsigned int size = nbLabels( x, y );
475 total += sizeof( MyLabelledMap );
476 if ( size > (N+1) )
477 total += ( 1 + ( size - N - 1 ) / M ) * ( M * sizeof( Value ) + 8 );
478 }
479 return total;
480 }
481
482};
483
484// boost::random is different since 1.47
485#if (BOOST_MAJOR_VERSION >= 1 ) && (BOOST_MINOR_VERSION >= 47 )
486template <typename MapLXY, unsigned int L, unsigned int X, unsigned int Y>
487unsigned int
488generateData( MapLXY & m, double proba_no_label, double proba_label )
489{
490 boost::random::mt19937 rng; // produces randomness out of thin air
491 rng.seed( 0 );
492 boost::random::uniform_smallint<> diceL(0, L-1);
493 boost::random::uniform_01<> diceDouble;
494 boost::random::geometric_distribution<> diceNbLabels( proba_label ); // Y
495 // E(Y) = (1-p)/p, Var(Y) = (1-p)/p^2
496 std::cerr << "E(Y)=" << ( (1-proba_label)/proba_label )
497 << " Var(Y)=" << ( (1-proba_label)/(proba_label*proba_label) )
498 << std::endl;
499 unsigned int total = 0;
500 for ( unsigned int y = 0; y < Y; ++y )
501 for ( unsigned int x = 0; x < X; ++x )
502 {
503 if ( diceDouble( rng ) >= proba_no_label )
504 {
505 unsigned int nb = diceNbLabels( rng );
506 for ( unsigned int i = 0; i < nb; ++i )
507 {
508 unsigned int l = diceL( rng );
509 double v = diceDouble( rng );
510 m.setValue( v, l, x, y );
511 }
512 total += nb;
513 }
514 }
515 std::cerr << "- " << total << " insertions." << endl;
516 return total;
517}
518#else
519// boost::random is different since 1.47, below <= 1.46
520template <typename MapLXY, unsigned int L, unsigned int X, unsigned int Y>
521unsigned int
522generateData( MapLXY & m, double proba_no_label, double proba_label )
523{
524 boost::mt19937 rng; // produces randomness out of thin air
525 rng.seed( 0 );
526 boost::uniform_smallint<> diceL(0, L-1);
527 boost::uniform_01<> diceDouble;
528 boost::geometric_distribution<> nbLabelsDist( proba_label ); // Y
529 boost::variate_generator
530 <boost::mt19937&,
531 boost::geometric_distribution<> > diceNbLabels( rng, nbLabelsDist);
532 // E(Y) = (1-p)/p, Var(Y) = (1-p)/p^2
533 std::cerr << "E(Y)=" << ( (1-proba_label)/proba_label )
534 << " Var(Y)=" << ( (1-proba_label)/(proba_label*proba_label) )
535 << std::endl;
536 unsigned int total = 0;
537 for ( unsigned int y = 0; y < Y; ++y )
538 for ( unsigned int x = 0; x < X; ++x )
539 {
540 if ( diceDouble( rng ) >= proba_no_label )
541 {
542 unsigned int nb = diceNbLabels();
543 for ( unsigned int i = 0; i < nb; ++i )
544 {
545 unsigned int l = diceL( rng );
546 double v = diceDouble( rng );
547 m.setValue( v, l, x, y );
548 }
549 total += nb;
550 }
551 }
552 std::cerr << "- " << total << " insertions." << endl;
553 return total;
554}
555#endif
556
557template <typename MapLXY, unsigned int L, unsigned int X, unsigned int Y>
558double
559sumAllData( MapLXY & m )
560{
561 double sum = 0.0;
562 std::vector<unsigned int> labels;
563 for ( unsigned int y = 0; y < Y; ++y )
564 for ( unsigned int x = 0; x < X; ++x )
565 {
566 m.getLabels( labels, x, y );
567 for ( unsigned int i = 0; i < labels.size(); ++i )
568 sum += m.value( labels[ i ], x, y );
569 }
570 std::cerr << "- sum = " << sum << "." << endl;
571 return sum;
572}
573
574template <typename MapLXY, unsigned int L, unsigned int X, unsigned int Y>
575double
576sumOneData( MapLXY & m, unsigned int l )
577{
578 double sum = 0.0;
579 for ( unsigned int y = 0; y < Y; ++y )
580 for ( unsigned int x = 0; x < X; ++x )
581 {
582 if ( m.hasLabel( l, x, y ) )
583 sum += m.value( l, x, y );
584 }
585 std::cerr << "- sum = " << sum << "." << endl;
586 return sum;
587}
588
589template <typename MapLXY, unsigned int L, unsigned int X, unsigned int Y>
590unsigned int
591locateThreeData( MapLXY & m, unsigned int l1, unsigned int l2, unsigned int l3 )
592{
593 unsigned int loc3 = 0;
594 for ( unsigned int y = 0; y < Y; ++y )
595 for ( unsigned int x = 0; x < X; ++x )
596 {
597 if ( ( m.hasLabel( l1, x, y ) )
598 && ( m.hasLabel( l2, x, y ) )
599 && ( m.hasLabel( l3, x, y ) ) )
600 ++loc3;
601 }
602 std::cerr << "- " << loc3 << " places with " << l1 << ", " << l2 << " ," << l3 << endl;
603 return loc3;
604}
605
606template <typename MapLXY, unsigned int L, unsigned int X, unsigned int Y>
607unsigned int
608eraseOneData( MapLXY & m, unsigned int l )
609{
610 unsigned int nb = 0;
611 for ( unsigned int y = 0; y < Y; ++y )
612 for ( unsigned int x = 0; x < X; ++x )
613 {
614 nb += m.erase( l, x, y );
615 }
616 std::cerr << "- " << nb << " values deleted." << endl;
617 return nb;
618}
619
620int main()
621{
622 typedef double Value;
623 static const unsigned int X = 100;
624 static const unsigned int Y = 100;
625 static const unsigned int L = 16;
626 typedef DGtal::uint8_t Word;
627 static const unsigned int N = 1;
628 static const unsigned int M = 5;
630 static const double PROBA_NO_LABEL = 0.75;
635 static const double PROBA_LABEL = 0.5;
636
637 typedef ArrayLXY<Value, L, X, Y> MyArrayLXY;
638 typedef ArrayXYOfMap<Value, L, X, Y> MyArrayXYOfMap;
639 typedef ArrayXYOfList<Value, L, X, Y> MyArrayXYOfList;
640 typedef ArrayXYOfLabelledMap<Value, L, X, Y, Word, N, M > MyArrayXYOfLabelledMap;
641
642 //----------------------------------------------------------------------
643 trace.beginBlock ( "---------- ArrayLXY ---------------" );
644 trace.beginBlock ( "Generating ArrayLXY" );
645 MyArrayLXY* arrayLXY = new MyArrayLXY( -1.0 );
646 generateData< MyArrayLXY, L, X, Y> ( *arrayLXY, PROBA_NO_LABEL, PROBA_LABEL );
647 trace.endBlock();
648
649 trace.beginBlock ( "Memory usage in ArrayLXY" );
650 std::cerr << arrayLXY->area() << " bytes." << std::endl;
651 trace.endBlock();
652
653 trace.beginBlock ( "Sum all values ArrayLXY" );
654 sumAllData< MyArrayLXY, L, X, Y> ( *arrayLXY );
655 trace.endBlock();
656
657 trace.beginBlock ( "Sum label 0 values ArrayLXY" );
658 sumOneData< MyArrayLXY, L, X, Y> ( *arrayLXY, 0 );
659 trace.endBlock();
660
661 trace.beginBlock ( "Sum label 15 values ArrayLXY" );
662 sumOneData< MyArrayLXY, L, X, Y> ( *arrayLXY, 15 );
663 trace.endBlock();
664
665 trace.beginBlock ( "Locate places (3, 7, 8) in ArrayLXY" );
666 locateThreeData< MyArrayLXY, L, X, Y> ( *arrayLXY, 3, 7, 8 );
667 trace.endBlock();
668
669 trace.beginBlock ( "Erase label 9 in ArrayLXY" );
670 eraseOneData< MyArrayLXY, L, X, Y> ( *arrayLXY, 9 );
671 trace.endBlock();
672
673 trace.beginBlock ( "Delete ArrayLXY" );
674 delete arrayLXY;
675 trace.endBlock();
676 trace.endBlock();
677
678 //----------------------------------------------------------------------
679 trace.beginBlock ( "---------- ArrayXYOfMap ---------------" );
680 trace.beginBlock ( "Generating ArrayXYOfMap" );
681 MyArrayXYOfMap* arrayXYOfMap = new MyArrayXYOfMap();
682 generateData< MyArrayXYOfMap, L, X, Y> ( *arrayXYOfMap, PROBA_NO_LABEL, PROBA_LABEL );
683 trace.endBlock();
684
685 trace.beginBlock ( "Memory usage in ArrayXYOfMap" );
686 std::cerr << arrayXYOfMap->area() << " bytes." << std::endl;
687 trace.endBlock();
688
689 trace.beginBlock ( "Sum all values ArrayXYOfMap" );
690 sumAllData< MyArrayXYOfMap, L, X, Y> ( *arrayXYOfMap );
691 trace.endBlock();
692
693 trace.beginBlock ( "Sum label 0 values ArrayXYOfMap" );
694 sumOneData< MyArrayXYOfMap, L, X, Y> ( *arrayXYOfMap, 0 );
695 trace.endBlock();
696
697 trace.beginBlock ( "Sum label 15 values ArrayXYOfMap" );
698 sumOneData< MyArrayXYOfMap, L, X, Y> ( *arrayXYOfMap, 15 );
699 trace.endBlock();
700
701 trace.beginBlock ( "Locate places (3, 7, 8) in ArrayXYOfMap" );
702 locateThreeData< MyArrayXYOfMap, L, X, Y> ( *arrayXYOfMap, 3, 7, 8 );
703 trace.endBlock();
704
705 trace.beginBlock ( "Erase label 9 in ArrayXYOfMap" );
706 eraseOneData< MyArrayXYOfMap, L, X, Y> ( *arrayXYOfMap, 9 );
707 trace.endBlock();
708
709 trace.beginBlock ( "Delete ArrayXYOfMap" );
710 delete arrayXYOfMap;
711 trace.endBlock();
712 trace.endBlock();
713
714 //----------------------------------------------------------------------
715 trace.beginBlock ( "---------- ArrayXYOfList ---------------" );
716 trace.beginBlock ( "Generating ArrayXYOfList" );
717 MyArrayXYOfList* arrayXYOfList = new MyArrayXYOfList();
718 generateData< MyArrayXYOfList, L, X, Y> ( *arrayXYOfList, PROBA_NO_LABEL, PROBA_LABEL );
719 trace.endBlock();
720
721 trace.beginBlock ( "Memory usage in ArrayXYOfList" );
722 std::cerr << arrayXYOfList->area() << " bytes." << std::endl;
723 trace.endBlock();
724
725 trace.beginBlock ( "Sum all values ArrayXYOfList" );
726 sumAllData< MyArrayXYOfList, L, X, Y> ( *arrayXYOfList );
727 trace.endBlock();
728
729 trace.beginBlock ( "Sum label 0 values ArrayXYOfList" );
730 sumOneData< MyArrayXYOfList, L, X, Y> ( *arrayXYOfList, 0 );
731 trace.endBlock();
732
733 trace.beginBlock ( "Sum label 15 values ArrayXYOfList" );
734 sumOneData< MyArrayXYOfList, L, X, Y> ( *arrayXYOfList, 15 );
735 trace.endBlock();
736
737 trace.beginBlock ( "Locate places (3, 7, 8) in ArrayXYOfList" );
738 locateThreeData< MyArrayXYOfList, L, X, Y> ( *arrayXYOfList, 3, 7, 8 );
739 trace.endBlock();
740
741 trace.beginBlock ( "Erase label 9 in ArrayXYOfList" );
742 eraseOneData< MyArrayXYOfList, L, X, Y> ( *arrayXYOfList, 9 );
743 trace.endBlock();
744
745 trace.beginBlock ( "Delete ArrayXYOfList" );
746 delete arrayXYOfList;
747 trace.endBlock();
748 trace.endBlock();
749
750 //----------------------------------------------------------------------
751 trace.beginBlock ( "---------- ArrayXYOfLabelledMap ---------------" );
752 trace.beginBlock ( "Generating ArrayXYOfLabelledMap" );
753 MyArrayXYOfLabelledMap* arrayXYOfLabelledMap = new MyArrayXYOfLabelledMap;
754 generateData< MyArrayXYOfLabelledMap, L, X, Y > ( *arrayXYOfLabelledMap, PROBA_NO_LABEL, PROBA_LABEL );
755 trace.endBlock();
756
757 trace.beginBlock ( "Memory usage in ArrayXYOfLabelledMap" );
758 std::cerr << arrayXYOfLabelledMap->area() << " bytes." << std::endl;
759 trace.endBlock();
760
761 trace.beginBlock ( "Sum all values ArrayXYOfLabelledMap" );
762 sumAllData< MyArrayXYOfLabelledMap, L, X, Y> ( *arrayXYOfLabelledMap );
763 trace.endBlock();
764
765 trace.beginBlock ( "Sum label 0 values ArrayXYOfLabelledMap" );
766 sumOneData< MyArrayXYOfLabelledMap, L, X, Y> ( *arrayXYOfLabelledMap, 0 );
767 trace.endBlock();
768
769 trace.beginBlock ( "Sum label 15 values ArrayXYOfLabelledMap" );
770 sumOneData< MyArrayXYOfLabelledMap, L, X, Y> ( *arrayXYOfLabelledMap, 15 );
771 trace.endBlock();
772
773 trace.beginBlock ( "Locate places (3, 7, 8) in ArrayXYOfLabelledMap" );
774 locateThreeData< MyArrayXYOfLabelledMap, L, X, Y> ( *arrayXYOfLabelledMap, 3, 7, 8 );
775 trace.endBlock();
776
777 trace.beginBlock ( "Erase label 9 in ArrayXYOfLabelledMap" );
778 eraseOneData< MyArrayXYOfLabelledMap, L, X, Y> ( *arrayXYOfLabelledMap, 9 );
779 trace.endBlock();
780
781 trace.beginBlock ( "Delete ArrayXYOfLabelledMap" );
782 delete arrayXYOfLabelledMap;
783 trace.endBlock();
784 trace.endBlock();
785
786 return 0;
787}
Aim: Represents a map label -> data, where the label is an integer between 0 and a constant L-1....
Definition: LabelledMap.h:120
Data & fastAt(const Key &key)
void beginBlock(const std::string &keyword="")
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:154
STL namespace.
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)