Scythe-1.0.3
wrapped_generator.h
Go to the documentation of this file.
00001 /* 
00002  * Scythe Statistical Library
00003  * Copyright (C) 2000-2002 Andrew D. Martin and Kevin M. Quinn;
00004  * 2002-present Andrew D. Martin, Kevin M. Quinn, and Daniel
00005  * Pemstein.  All Rights Reserved.
00006  *
00007  * This program is free software; you can redistribute it and/or modify
00008  * under the terms of the GNU General Public License as published by
00009  * Free Software Foundation; either version 2 of the License, or (at
00010  * your option) any later version.  See the text files COPYING
00011  * and LICENSE, distributed with this source code, for further
00012  * information.
00013  * --------------------------------------------------------------------
00014  * scythestat/rng/wrapped_generator.h
00015  *
00016  * Provides a class definition that allows users to adapt non-Scythe
00017  * pseudo-random number generators to Scythe's rng interface.
00018  * Specifically, wraps any functor that generators uniform variates on
00019  * (0, 1).
00020  *
00021  */
00022 
00032 #ifndef SCYTHE_WRAPPED_GENERATOR_H
00033 #define SCYTHE_WRAPPED_GENERATOR_H
00034 
00035 #ifdef SCYTHE_COMPILE_DIRECT
00036 #include "rng.h"
00037 #else
00038 #include "scythestat/rng.h"
00039 #endif
00040 
00041 namespace scythe {
00042 
00059   template <typename ENGINE>
00060   class wrapped_generator: public rng<wrapped_generator<ENGINE> >
00061   {
00062     public:
00063 
00077       wrapped_generator (ENGINE& e)
00078         : rng<wrapped_generator<ENGINE> > (),
00079           engine (e)
00080       {}
00081 
00094       wrapped_generator(const wrapped_generator& wg)
00095         : rng<wrapped_generator<ENGINE> > (),
00096           engine (wg.engine)
00097       {}
00098 
00109       inline double runif()
00110       {
00111         return engine();
00112       }
00113 
00114       /* We have to override the overloaded forms of runif because
00115        * overloading the no-arg runif() hides the base class
00116        * definition; C++ stops looking once it finds the above.
00117        */
00139       template <matrix_order O, matrix_style S>
00140       inline Matrix<double,O> runif(unsigned int rows,
00141                                     unsigned int cols)
00142       {
00143         return rng<wrapped_generator<ENGINE> >::runif<O, S>(rows, cols);
00144       }
00145 
00167       Matrix<double,Col,Concrete> runif (unsigned int rows,
00168                                          unsigned int cols)
00169       {
00170         return rng<wrapped_generator<ENGINE> >::runif<Col,Concrete>(rows, 
00171             cols);
00172       }
00173 
00174     protected:
00175       ENGINE& engine; // The wrapped runif engine
00176   };
00177 } // end namespace scythe
00178 
00179 #endif /* SCYTHE_WRAPPED_GENERATOR_H */