1 /*****************************************************************************
2  *                                                                           *
3  *          UNURAN -- Universal Non-Uniform Random number generator          *
4  *                                                                           *
5  *****************************************************************************
6  *                                                                           *
7  *   FILE: x_gen_source.h                                                    *
8  *                                                                           *
9  *   PURPOSE:                                                                *
10  *         defines macros and function prototypes for handling               *
11  *         generator objects.                                                *
12  *                                                                           *
13  *   USAGE:                                                                  *
14  *         only included in source_unuran.h                                  *
15  *                                                                           *
16  *****************************************************************************
17  *                                                                           *
18  *   Copyright (c) 2000-2006 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 /* Invoke generators (macros to avoid function calls)                        */
40 
41 #define _unur_init(par)               (par)->init(par)
42 
43 #define _unur_sample_discr(gen)       (gen)->sample.discr(gen)
44 #define _unur_sample_cont(gen)        (gen)->sample.cont(gen)
45 #define _unur_sample_vec(gen,vector)  (gen)->sample.cvec(gen,vector)
46 
47 #define _unur_free(gen)               do {if(gen) (gen)->destroy(gen);} while(0)
48 
49 /*---------------------------------------------------------------------------*/
50 /* get type of transformation method                                         */
51 
52 #define _unur_gen_is_discr(gen) ( ((gen)->distr->type == UNUR_DISTR_DISCR) ? 1 : 0 )
53 #define _unur_gen_is_cont(gen)  ( ((gen)->distr->type == UNUR_DISTR_CONT)  ? 1 : 0 )
54 #define _unur_gen_is_vec(gen)   ( ((gen)->distr->type == UNUR_DISTR_CVEC)  ? 1 : 0 )
55 
56 /*---------------------------------------------------------------------------*/
57 /* aux routine when no sampling routine is available                         */
58 
59 int _unur_sample_discr_error( struct unur_gen *gen );
60 double _unur_sample_cont_error( struct unur_gen *gen );
61 int _unur_sample_cvec_error( struct unur_gen *gen, double *vec );
62 int _unur_sample_matr_error( struct unur_gen *gen, double *mat );
63 
64 /*---------------------------------------------------------------------------*/
65 /* create, copy and free parameter object                                    */
66 
67 /* create an empty parameter object with data structure of size 's'          */
68 struct unur_par *_unur_par_new( size_t s );
69 
70 struct unur_par *_unur_par_clone( const struct unur_par *par );
71 
72 /* free memory allocated by parameter obejct                                 */
73 #define _unur_par_free(par)  do {free((par)->datap); free(par);} while(0)
74 
75 /*---------------------------------------------------------------------------*/
76 /* create (new) generic generator object                                     */
77 
78 struct unur_gen *_unur_generic_create( struct unur_par *par, size_t s );
79 
80 /*---------------------------------------------------------------------------*/
81 /* copy (clone) generator objects                                            */
82 
83 struct unur_gen *_unur_generic_clone( const struct unur_gen *gen, const char *type );
84 
85 #define _unur_gen_clone(gen)    ((gen)->clone(gen))
86 
87 /*---------------------------------------------------------------------------*/
88 /* free generic generator object                                             */
89 
90 void _unur_generic_free( struct unur_gen *gen );
91 
92 /*---------------------------------------------------------------------------*/
93 /* check for type of generator object                                        */
94 
95 int _unur_gen_is_inversion ( struct unur_gen *gen );
96 
97 /*---------------------------------------------------------------------------*/
98 /* set and clone arrays of generator objects                                 */
99 
100 struct unur_gen **_unur_gen_list_set( struct unur_gen *gen, int n_gen_list );
101 /* set all entries in list to same generator object                          */
102 /* IMPORTANT: Be careful when using this call. When the resulting array      */
103 /*   is stored in some multivariate generator object then 'gen' _must not_   */
104 /*   be used any more after this call!                                       */
105 
106 struct unur_gen **_unur_gen_list_clone( struct unur_gen **gen_list, int n_gen_list );
107 /* clone list of generator objects                                           */
108 
109 void _unur_gen_list_free( struct unur_gen **gen_list, int n_gen_list );
110 /* free list of generator objects                                            */
111 
112 /*---------------------------------------------------------------------------*/
113