Changeset 2804


Ignore:
Timestamp:
Jul 31, 2012, 12:06:52 PM (10 years ago)
Author:
Peter
Message:

RNG::set_state: prefer throw on error.

Location:
trunk/yat/random
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/random/random.cc

    r2802 r2804  
    127127    if (rng_.get()==NULL)
    128128      rng_alloc();
    129     return gsl_rng_memcpy(rng_.get(), state.rng());
     129    if (gsl_rng_memcpy(rng_.get(), state.rng()))
     130      throw utility::GSL_error("yat::random::RNG::set_state failed");
     131    return 0;
    130132  }
    131133
     
    160162    assert(rng_!=&rng);
    161163    if (!(rng_ = gsl_rng_clone(&rng)))
    162       throw utility::GSL_error("RNG_state::RNG_state failed to allocate memory");
     164      throw utility::GSL_error("RNG_state::clone failed to allocate memory");
    163165  }
    164166
     
    179181  }
    180182
    181  
     183
    182184  Discrete::~Discrete(void)
    183185  {
     
    191193
    192194
    193   unsigned long Discrete::seed_from_devurandom(void) 
    194   { 
    195     return rng_->seed_from_devurandom(); 
     195  unsigned long Discrete::seed_from_devurandom(void)
     196  {
     197    return rng_->seed_from_devurandom();
    196198  }
    197199
     
    201203  {
    202204    p_.reserve(hist.nof_bins());
    203     for (size_t i=0; i<hist.nof_bins(); i++) 
     205    for (size_t i=0; i<hist.nof_bins(); i++)
    204206      p_.push_back(hist[i]);
    205207    preproc();
     
    267269  {
    268270    return (range_ ?
    269             gsl_rng_uniform_int(rng_->rng(), range_) : gsl_rng_get(rng_->rng()));
     271            gsl_rng_uniform_int(rng_->rng(),range_) : gsl_rng_get(rng_->rng()));
    270272  }
    271273
  • trunk/yat/random/random.h

    r2802 r2804  
    156156       \brief Set the state to \a state.
    157157
    158        \return 0 on success, non-zero otherwise.
     158       \return 0 always.
    159159
    160160       \note this function only effects the RNG in current thread
     161
     162       \throw utility::GSL_error on error
    161163
    162164       \see gsl_rng_memcpy
    163165    */
     166    // return int for backward compatibility with yat 0.8
    164167    int set_state(const RNG_state&);
    165168
Note: See TracChangeset for help on using the changeset viewer.