gk_macros.h
Go to the documentation of this file.
1 
10 #ifndef _GK_MACROS_H_
11 #define _GK_MACROS_H_
12 
13 /*-------------------------------------------------------------
14  * Usefull commands
15  *-------------------------------------------------------------*/
16 #define gk_max(a, b) ((a) >= (b) ? (a) : (b))
17 #define gk_min(a, b) ((a) >= (b) ? (b) : (a))
18 #define gk_max3(a, b, c) ((a) >= (b) && (a) >= (c) ? (a) : ((b) >= (a) && (b) >= (c) ? (b) : (c)))
19 #define gk_SWAP(a, b, tmp) do {(tmp) = (a); (a) = (b); (b) = (tmp);} while(0)
20 #define INC_DEC(a, b, val) do {(a) += (val); (b) -= (val);} while(0)
21 #define sign(a, b) ((a >= 0 ? b : -b))
22 
23 #define ONEOVERRANDMAX (1.0/(RAND_MAX+1.0))
24 #define RandomInRange(u) ((int) (ONEOVERRANDMAX*(u)*rand()))
25 
26 #define gk_abs(x) ((x) >= 0 ? (x) : -(x))
27 
28 
29 /*-------------------------------------------------------------
30  * Timing macros
31  *-------------------------------------------------------------*/
32 #define gk_clearcputimer(tmr) (tmr = 0.0)
33 #define gk_startcputimer(tmr) (tmr -= gk_CPUSeconds())
34 #define gk_stopcputimer(tmr) (tmr += gk_CPUSeconds())
35 #define gk_getcputimer(tmr) (tmr)
36 
37 #define gk_clearwctimer(tmr) (tmr = 0.0)
38 #define gk_startwctimer(tmr) (tmr -= gk_WClockSeconds())
39 #define gk_stopwctimer(tmr) (tmr += gk_WClockSeconds())
40 #define gk_getwctimer(tmr) (tmr)
41 
42 /*-------------------------------------------------------------
43  * dbglvl handling macros
44  *-------------------------------------------------------------*/
45 #define IFSET(a, flag, cmd) if ((a)&(flag)) (cmd);
46 
47 
48 /*-------------------------------------------------------------
49  * gracefull library exit macro
50  *-------------------------------------------------------------*/
51 #define GKSETJMP() (setjmp(gk_return_to_entry))
52 #define gk_sigcatch() (setjmp(gk_jbufs[gk_cur_jbufs]))
53 
54 
55 /*-------------------------------------------------------------
56  * Debuging memory leaks
57  *-------------------------------------------------------------*/
58 #ifdef DMALLOC
59 # define MALLOC_CHECK(ptr) \
60  if (malloc_verify((ptr)) == DMALLOC_VERIFY_ERROR) { \
61  printf("***MALLOC_CHECK failed on line %d of file %s: " #ptr "\n", \
62  __LINE__, __FILE__); \
63  abort(); \
64  }
65 #else
66 # define MALLOC_CHECK(ptr) ;
67 #endif
68 
69 
70 /*-------------------------------------------------------------
71  * CSR conversion macros
72  *-------------------------------------------------------------*/
73 #define MAKECSR(i, n, a) \
74  do { \
75  for (i=1; i<n; i++) a[i] += a[i-1]; \
76  for (i=n; i>0; i--) a[i] = a[i-1]; \
77  a[0] = 0; \
78  } while(0)
79 
80 #define SHIFTCSR(i, n, a) \
81  do { \
82  for (i=n; i>0; i--) a[i] = a[i-1]; \
83  a[0] = 0; \
84  } while(0)
85 
86 
87 /*-------------------------------------------------------------
88  * ASSERTS that cannot be turned off!
89  *-------------------------------------------------------------*/
90 #define GKASSERT(expr) \
91  if (!(expr)) { \
92  printf("***ASSERTION failed on line %d of file %s: " #expr "\n", \
93  __LINE__, __FILE__); \
94  abort(); \
95  }
96 
97 #define GKASSERTP(expr,msg) \
98  if (!(expr)) { \
99  printf("***ASSERTION failed on line %d of file %s: " #expr "\n", \
100  __LINE__, __FILE__); \
101  printf msg ; \
102  printf("\n"); \
103  abort(); \
104  }
105 
106 #define GKCUASSERT(expr) \
107  if (!(expr)) { \
108  printf("***ASSERTION failed on line %d of file %s: " #expr "\n", \
109  __LINE__, __FILE__); \
110  }
111 
112 #define GKCUASSERTP(expr,msg) \
113  if (!(expr)) { \
114  printf("***ASSERTION failed on line %d of file %s: " #expr "\n", \
115  __LINE__, __FILE__); \
116  printf msg ; \
117  printf("\n"); \
118  }
119 
120 /*-------------------------------------------------------------
121  * Program Assertions
122  *-------------------------------------------------------------*/
123 #ifndef NDEBUG
124 # define ASSERT(expr) \
125  if (!(expr)) { \
126  printf("***ASSERTION failed on line %d of file %s: " #expr "\n", \
127  __LINE__, __FILE__); \
128  assert(expr); \
129  }
130 
131 # define ASSERTP(expr,msg) \
132  if (!(expr)) { \
133  printf("***ASSERTION failed on line %d of file %s: " #expr "\n", \
134  __LINE__, __FILE__); \
135  printf msg ; \
136  printf("\n"); \
137  assert(expr); \
138  }
139 #else
140 # define ASSERT(expr) ;
141 # define ASSERTP(expr,msg) ;
142 #endif
143 
144 #ifndef NDEBUG2
145 # define ASSERT2 ASSERT
146 # define ASSERTP2 ASSERTP
147 #else
148 # define ASSERT2(expr) ;
149 # define ASSERTP2(expr,msg) ;
150 #endif
151 
152 
153 #endif


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:22