1 /*****************************************************************************
2  *                                                                           *
3  *          UNURAN -- Universal Non-Uniform Random number generator          *
4  *                                                                           *
5  *****************************************************************************
6  *                                                                           *
7  *   FILE: source_cookies.h                                                  *
8  *                                                                           *
9  *   PURPOSE:                                                                *
10  *         defines magic cookies.                                            *
11  *                                                                           *
12  *   USAGE:                                                                  *
13  *         internal header file                                              *
14  *          included only in source_unuran.h                                 *
15  *                                                                           *
16  *****************************************************************************
17  *                                                                           *
18  *   Copyright (c) 2000-2010 Wolfgang Hoermann and Josef Leydold             *
19  *   Department of Statistics and Mathematics, WU Wien, Austria              *
20  *                                                                           *
21  *   This program is free software; you can redistribute it and/or modify    *
22  *   it under the terms of the GNU General Public License as published by    *
23  *   the Free Software Foundation; either version 2 of the License, or       *
24  *   (at your option) any later version.                                     *
25  *                                                                           *
26  *   This program is distributed in the hope that it will be useful,         *
27  *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
28  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
29  *   GNU General Public License for more details.                            *
30  *                                                                           *
31  *   You should have received a copy of the GNU General Public License       *
32  *   along with this program; if not, write to the                           *
33  *   Free Software Foundation, Inc.,                                         *
34  *   59 Temple Place, Suite 330, Boston, MA 02111-1307, USA                  *
35  *                                                                           *
36  *****************************************************************************/
37 
38 /*---------------------------------------------------------------------------*/
39 #ifndef SOURCE_COOKIES_H_SEEN
40 #define SOURCE_COOKIES_H_SEEN
41 /*---------------------------------------------------------------------------*/
42 
43 /*---------------------------------------------------------------------------*/
44 #ifdef UNUR_COOKIES    /* use magic cookies                                  */
45 /*---------------------------------------------------------------------------*/
46 /* name of cookies                                                           */
47 
48 /* generators discrete distributions */
49 #define CK_DARI_PAR      0x00000010u
50 #define CK_DARI_GEN      0x00000011u
51 #define CK_DAU_PAR       0x00000020u
52 #define CK_DAU_GEN       0x00000021u
53 #define CK_DGT_PAR       0x00000030u
54 #define CK_DGT_GEN       0x00000031u
55 #define CK_DSROU_PAR     0x00000040u
56 #define CK_DSROU_GEN     0x00000041u
57 #define CK_DSS_PAR       0x00000050u
58 #define CK_DSS_GEN       0x00000051u
59 
60 /* generators continuous distributions */
61 #define CK_AROU_PAR      0x00100010u
62 #define CK_AROU_GEN      0x00100011u
63 #define CK_AROU_SEG      0x00100012u
64 #define CK_ARS_PAR       0x001000d0u
65 #define CK_ARS_GEN       0x001000d1u
66 #define CK_ARS_IV        0x001000d2u
67 #define CK_HINV_PAR      0x00100020u
68 #define CK_HINV_GEN      0x00100021u
69 #define CK_HINV_IV       0x00100022u
70 #define CK_HRB_PAR       0x00100030u
71 #define CK_HRB_GEN       0x00100031u
72 #define CK_HRD_PAR       0x00100040u
73 #define CK_HRD_GEN       0x00100041u
74 #define CK_HRI_PAR       0x00100050u
75 #define CK_HRI_GEN       0x00100051u
76 #define CK_ITDR_PAR      0x00100080u
77 #define CK_ITDR_GEN      0x00100081u
78 #define CK_NINV_PAR      0x00100060u
79 #define CK_NINV_GEN      0x00100061u
80 #define CK_NROU_PAR      0x00100070u
81 #define CK_NROU_GEN      0x00100071u
82 #define CK_PINV_PAR      0x00100130u
83 #define CK_PINV_GEN      0x00100131u
84 #define CK_PINV_IV       0x00100132u
85 #define CK_SROU_PAR      0x00100090u
86 #define CK_SROU_GEN      0x00100091u
87 #define CK_SSR_PAR       0x001000a0u
88 #define CK_SSR_GEN       0x001000a1u
89 #define CK_TABL_PAR      0x001000b0u
90 #define CK_TABL_GEN      0x001000b1u
91 #define CK_TABL_IV       0x001000b2u
92 #define CK_TDR_PAR       0x001000c0u
93 #define CK_TDR_GEN       0x001000c1u
94 #define CK_TDR_IV        0x001000c2u
95 #define CK_UNIF_PAR      0x001000e0u
96 #define CK_UNIF_GEN      0x001000e1u
97 #define CK_UTDR_PAR      0x001000f0u
98 #define CK_UTDR_GEN      0x001000f1u
99 #define CK_EMPK_PAR      0x00100100u
100 #define CK_EMPK_GEN      0x00100101u
101 #define CK_EMPL_PAR      0x00100110u
102 #define CK_EMPL_GEN      0x00100111u
103 #define CK_HIST_PAR      0x00100120u
104 #define CK_HIST_GEN      0x00100121u
105 /* meta generators */
106 #define CK_MIXT_PAR      0x00110130u
107 #define CK_MIXT_GEN      0x00110131u
108 
109 /* generators multivariate continuous distributions */
110 #define CK_MVTDR_PAR     0x00200010u
111 #define CK_MVTDR_GEN     0x00200010u
112 #define CK_VMT_PAR       0x00200020u
113 #define CK_VMT_GEN       0x00200021u
114 #define CK_VEMPK_PAR     0x00200030u
115 #define CK_VEMPK_GEN     0x00200031u
116 #define CK_VNROU_PAR     0x00200040u
117 #define CK_VNROU_GEN     0x00200041u
118 #define CK_VAROU_PAR     0x00200050u
119 #define CK_VAROU_GEN     0x00200051u
120 #define CK_NORTA_PAR     0x00200060u
121 #define CK_NORTA_GEN     0x00200061u
122 /* Markov chain samplers */
123 #define CK_BALL_PAR      0x00201010u
124 #define CK_BALL_GEN      0x00201011u
125 #define CK_GIBBS_PAR     0x00201020u
126 #define CK_GIBBS_GEN     0x00201021u
127 #define CK_HITRO_PAR     0x00201030u
128 #define CK_HITRO_GEN     0x00201031u
129 #define CK_WALK_PAR      0x00201040u
130 #define CK_WALK_GEN      0x00201041u
131 
132 /* generators for random matrices */
133 #define CK_MCORR_PAR     0x00400010u
134 #define CK_MCORR_GEN     0x00400011u
135 
136 /* special generators */
137 #define CK_CSTD_PAR      0x10000010u
138 #define CK_CSTD_GEN      0x10000011u
139 #define CK_DSTD_PAR      0x10000020u
140 #define CK_DSTD_GEN      0x10000021u
141 #define CK_MVSTD_PAR     0x10000040u
142 #define CK_MVSTD_GEN     0x10000041u
143 
144 #define CK_CEXT_PAR      0x10000110u
145 #define CK_CEXT_GEN      0x10000111u
146 #define CK_DEXT_PAR      0x10000120u
147 #define CK_DEXT_GEN      0x10000121u
148 
149 #define CK_MBLOCK        0xf0000001u
150 
151 /* misc methods */
152 #define CK_AUTO_PAR      0xa0000010u
153 
154 /* distribution objects */
155 #define CK_DISTR         0xe0000000u
156 #define CK_DISTR_CONT    0xe0000001u
157 #define CK_DISTR_CEMP    0xe0000002u
158 #define CK_DISTR_MATR    0xe0000003u
159 #define CK_DISTR_CVEC    0xe0000004u
160 #define CK_DISTR_CVEMP   0xe0000005u
161 #define CK_DISTR_DISCR   0xe0000006u
162 
163 #define CK_SPECIALGEN_CONT 0xd00001u
164 
165 /* URNG (uniform random number generator objects) */
166 #define CK_URNG          0xb0000001u
167 
168 /* function parser */
169 #define CK_FSTR_PDATA    0xa0000001u
170 #define CK_FSTR_TNODE    0xa0000002u
171 
172 /* auxiliary tools */
173 #define CK_SLIST         0xa0000004u
174 
175 /*---------------------------------------------------------------------------*/
176 /* macros for dealing with magic cookies                                     */
177 
178 /* set magic cookies */
179 #define COOKIE_SET(ptr,ck)           (ptr)->cookie=(ck)
180 
181 #define COOKIE_SET_ARRAY(ptr,ck,n) { \
182   register int i; \
183   for (i=0;i<(n);i++) \
184     ((ptr)+(i))->cookie=(ck); \
185 }
186 
187 /* check magic cookies */
188 #define COOKIE_CHECK(ptr,ck,rval) \
189   if((ptr)->cookie!=(ck)) { \
190     _unur_error_cookies(__FILE__,__LINE__,(ptr)->cookie, (ck)); \
191     return rval; \
192   }
193 
194 /* clear magic cookies (set to 0u). To be used in connection with free() to  */
195 /* to detect access to freed object.                                         */
196 #define COOKIE_CLEAR(ptr)           (ptr)->cookie=0u
197 
198 /*---------------------------------------------------------------------------*/
199 #else                               /* do not use magic cookies              */
200 /*---------------------------------------------------------------------------*/
201 
202 #define COOKIE_SET(ptr,ck)
203 #define COOKIE_SET_ARRAY(ptr,ck,n)
204 #define COOKIE_CHECK(ptr,ck,rval)
205 #define COOKIE_CLEAR(ptr)
206 
207 /*---------------------------------------------------------------------------*/
208 #endif
209 /*---------------------------------------------------------------------------*/
210 
211 /*---------------------------------------------------------------------------*/
212 #endif  /* SOURCE_COOKIES_H_SEEN */
213 /*---------------------------------------------------------------------------*/
214