Changeset 3898


Ignore:
Timestamp:
Mar 31, 2020, 4:02:42 AM (2 months ago)
Author:
Peter
Message:

closes #858 and #869

Location:
trunk
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/Makefile.am

    r3894 r3898  
    4949  test/bam_pair_iterator.test \
    5050  test/bam_pair_iterator2.test \
     51  test/random_distribution.test \
    5152  test/chi2.test \
    5253  test/cigar.test \
  • trunk/test/negative_binomial_distribution.cc

    r3897 r3898  
    2828#include "Suite.h"
    2929
    30 #include "yat/random/Distribution.h"
     30#include "yat/random/DiscreteDistribution.h"
     31#include "yat/random/ContinuousDistribution.h"
    3132
    3233#include <boost/random/negative_binomial_distribution.hpp>
  • trunk/yat/random/Distribution.h

    r3894 r3898  
    2525#include "random.h"
    2626
    27 #include <yat/utility/yat_assert.h>
    28 
    2927namespace theplu {
    3028namespace yat {
     
    3230
    3331  /**
    34      Proxy class between RNG and <a href=\"https://www.boost.org/doc/libs/1_72_0/doc/html/boost_random/reference.html#boost_random.reference.distributions">Boost Distributions</a>
     32     Proxy class between RNG and <a
     33     href="https://www.boost.org/doc/libs/1_72_0/doc/html/boost_random/reference.html#boost_random.reference.distributions">Boost
     34     Distributions</a>, which makes it convenient to the boost
     35     distribution classses with random numbers from RNG.
    3536
    36      \c T is expected to return type that is convertibale to \c unsigned
    37      \c long \c int
     37     Please see files DiscreteDistribution.h and
     38     ContinuousDistribution for typedefs provided for convenience.
     39
     40     Type Requirement
     41     - \c RND is <a
     42       href="https://www.boost.org/doc/libs/1_72_0/doc/html/boost_random/reference.html#boost_random.reference.concepts.random_distribution">Boost
     43       Random Distribution</a>
     44       \c RND::result_type has to be convertible to \c resType
    3845
    3946     \since New in yat 0.18
    4047   */
    41   template<class T>
    42   class DiscreteDistribution : public Discrete
     48  template<class RND, typename resType = typename RND::result_type>
     49  class Distribution
    4350  {
    4451  public:
     52    /// Underlying distribution
     53    typedef RND distribution_type;
     54
    4555    /// param type, see boost documentation
    46     typedef typename T::param_type param_type;
     56    typedef typename RND::param_type param_type;
    4757
    48     DiscreteDistribution(void)
    49       : urng_(0)
    50     {
    51     }
     58    /// param type, see boost documentation
     59    typedef resType result_type;
    5260
    5361    /**
     
    6876
    6977    /**
     78       \return a random number from distribution with parameters \a p.
     79     */
     80    resType operator()(const param_type& p) const
     81    {
     82      // see comment in operator()(1)
     83      return const_cast<RND&>(distribution_)(urng_, p);
     84    }
     85
     86
     87    /**
    7088       \return a random number from distribution with parameters as in
    7189       param().
    7290     */
    73     unsigned long int operator()(void) const
     91    resType operator()(void) const
    7492    {
    75       return distribution_(urng_);
     93      // In Discrete and Continuous operator() is const so we want to
     94      // be const here. In the boost concept constness is
     95      // undocumented, so we cast to allow regardless of
     96      // implementation.
     97      return const_cast<RND&>(this->distribution_)(this->urng_);
    7698    }
    7799
    78     /**
    79        \return a random number from distribution with parameters \a p.
    80      */
    81     unsigned long int operator()(const param_type& p) const
    82     {
    83       return distribution_(urng_, p);
    84     }
    85 
    86   private:
    87     T distribution_;
     100  protected:
     101    /// Underlying class defining the distribution
     102    RND distribution_;
     103    /// access to random numbers from RNG singleton
    88104    DiscreteUniform urng_;
    89105  };
    90 
    91106
    92107}}} // of namespace random, yat, and theplu
  • trunk/yat/random/Makefile.am

    r3894 r3898  
    2222yat_libyat_la_SOURCES += yat/random/random.cc
    2323
     24nobase_include_HEADERS += $(srcdir)/yat/random/ContinuousDistribution.h
    2425nobase_include_HEADERS += $(srcdir)/yat/random/copy_k_of_n.h
     26nobase_include_HEADERS += $(srcdir)/yat/random/DiscreteDistribution.h
    2527nobase_include_HEADERS += $(srcdir)/yat/random/Distribution.h
    2628nobase_include_HEADERS += $(srcdir)/yat/random/random.h
  • trunk/yat/utility/config_public.h.in

    r3883 r3898  
    2828///
    2929
     30
     31/* Define if deprecated boost headers should be allowed */
     32#undef YAT_BOOST_ALLOW_DEPRECATED_HEADERS
     33
     34// If not defined and YAT_BOOST_ALLOW_DEPRECATED_HEADERS (see above)
     35// is defined, define it to same as YAT_BOOST_ALLOW_DEPRECATED_HEADERS
     36#ifndef BOOST_ALLOW_DEPRECATED_HEADERS
     37#ifdef YAT_BOOST_ALLOW_DEPRECATED_HEADERS
     38#define BOOST_ALLOW_DEPRECATED_HEADERS YAT_BOOST_ALLOW_DEPRECATED_HEADERS
     39#endif
     40#endif
    3041
    3142/// Define to 1 if htslib is available
Note: See TracChangeset for help on using the changeset viewer.