1 /*****************************************************************************
2  *                                                                           *
3  *          UNURAN -- Universal Non-Uniform Random number generator          *
4  *                                                                           *
5  *****************************************************************************
6  *                                                                           *
7  *   FILE: x_gen_struct.h                                                    *
8  *                                                                           *
9  *   PURPOSE:                                                                *
10  *         declares structures for parameter and generator objects.          *
11  *                                                                           *
12  *   USAGE:                                                                  *
13  *         only included in unur_struct.h                                    *
14  *                                                                           *
15  *****************************************************************************
16  *                                                                           *
17  *   Copyright (c) 2000-2006 Wolfgang Hoermann and Josef Leydold             *
18  *   Department of Statistics and Mathematics, WU Wien, Austria              *
19  *                                                                           *
20  *   This program is free software; you can redistribute it and/or modify    *
21  *   it under the terms of the GNU General Public License as published by    *
22  *   the Free Software Foundation; either version 2 of the License, or       *
23  *   (at your option) any later version.                                     *
24  *                                                                           *
25  *   This program is distributed in the hope that it will be useful,         *
26  *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
27  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
28  *   GNU General Public License for more details.                            *
29  *                                                                           *
30  *   You should have received a copy of the GNU General Public License       *
31  *   along with this program; if not, write to the                           *
32  *   Free Software Foundation, Inc.,                                         *
33  *   59 Temple Place, Suite 330, Boston, MA 02111-1307, USA                  *
34  *                                                                           *
35  *****************************************************************************/
36 
37 /*---------------------------------------------------------------------------*/
38 /* types for sampling routines                                               */
39 
40 /* for univariate continuous distribution */
41 typedef double UNUR_SAMPLING_ROUTINE_CONT(struct unur_gen *gen);
42 
43 /* for univariate discrete distribution */
44 typedef int UNUR_SAMPLING_ROUTINE_DISCR(struct unur_gen *gen);
45 
46 /* for multivariate continuous distribution */
47 typedef int UNUR_SAMPLING_ROUTINE_CVEC(struct unur_gen *gen, double *vec);
48 
49 
50 /*---------------------------------------------------------------------------*/
51 /* parameter objects                                                         */
52 
53 struct unur_par {
54   void *datap;                /* pointer to data for method                  */
55   size_t s_datap;             /* size of data structure                      */
56 
57   struct unur_gen* (*init)(struct unur_par *par);
58 
59   unsigned method;            /* indicates method and generator to be used   */
60   unsigned variant;           /* indicates variant of method                 */
61   unsigned set;               /* stores which parameters have been changed   */
62 
63   UNUR_URNG *urng;            /* pointer to uniform random number generator  */
64   UNUR_URNG *urng_aux;        /* pointer to second (auxiliary) uniform RNG   */
65 
66   const struct unur_distr *distr;  /* pointer to distribution object         */
67   int distr_is_privatecopy;   /* whether the distribution object has to be
68 				 copied into the generator object (TRUE) or
69 				 just the pointer to the given (external)
70 				 distribution object (FALSE).
71 
72 				 Notice: The UNU.RAN design assumes that the
73 				 generator object keeps its own private copy.
74 				 However, in some cases it can be useful
75 				 to avoid making this copy, e.g. when only
76 				 a single random variate is required.
77 
78 				 HOWEVER, this must be used with extreme CARE!
79 
80 				 When the distrubtion object is changed or
81 				 freed then the generator object does not work
82 				 any more or (even worse) produces garbage.
83 			      */
84 
85   unsigned debug;             /* debugging flags                             */
86 #ifdef UNUR_COOKIES
87   unsigned cookie;            /* magic cookie                                */
88 #endif
89 };
90 
91 
92 /*---------------------------------------------------------------------------*/
93 /* generator objects                                                         */
94 
95 struct unur_gen {
96   void *datap;                /* pointer to data for method                  */
97 
98   union {
99     UNUR_SAMPLING_ROUTINE_CONT  *cont;
100     UNUR_SAMPLING_ROUTINE_DISCR *discr;
101     UNUR_SAMPLING_ROUTINE_CVEC  *cvec;
102     UNUR_SAMPLING_ROUTINE_CVEC  *matr;
103   } sample;                   /* pointer to sampling routine                 */
104 
105   UNUR_URNG *urng;            /* pointer to uniform random number generator  */
106   UNUR_URNG *urng_aux;        /* pointer to second (auxiliary) uniform RNG   */
107 
108   struct unur_distr *distr;   /* distribution object                         */
109   int distr_is_privatecopy;   /* whether the distribution object was
110 				 copied into the generator object (TRUE) or
111 				 just the pointer to the given (external)
112 				 distribution object (FALSE).
113 
114 				 Notice: The UNU.RAN design assumes that the
115 				 generator object keeps its own private copy.
116 				 However, in some cases it can be useful
117 				 to avoid making this copy, e.g. when only
118 				 a single random variate is required.
119 
120 				 HOWEVER, this must be used with extreme CARE!
121 
122 				 When the distrubtion object is changed or
123 				 freed then the generator object does not work
124 				 any more or (even worse) produces garbage.
125 			      */
126 
127 
128   unsigned method;            /* indicates method and generator to be used   */
129   unsigned variant;           /* indicates variant of method                 */
130   unsigned set;               /* stores which parameters have been changed   */
131   unsigned status;            /* status of generator object                  */
132 
133   char *genid;                /* identifier for generator                    */
134 
135   struct unur_gen *gen_aux;   /* pointer to auxiliary generator object       */
136   struct unur_gen **gen_aux_list; /* list of pointers to auxiliary generator objects */
137   int n_gen_aux_list;         /* length of this list                         */
138 
139   size_t s_datap;             /* size of data structure                      */
140   unsigned debug;             /* debugging flags                             */
141 
142   void (*destroy)(struct unur_gen *gen); /* pointer to destructor            */
143   struct unur_gen* (*clone)(const struct unur_gen *gen ); /* clone generator */
144   int (*reinit)(struct unur_gen *gen); /* pointer to reinit routine          */
145 
146 #ifdef UNUR_ENABLE_INFO
147   struct unur_string *infostr; /* pointer to info string                     */
148   void (*info)(struct unur_gen *gen, int help); /* routine for creating info string */
149 #endif
150 
151 #ifdef UNUR_COOKIES
152   unsigned cookie;            /* magic cookie                                */
153 #endif
154 };
155 
156 /*---------------------------------------------------------------------------*/
157