Commit b01630bb by Paolo Carlini Committed by Paolo Carlini

random.tcc (gamma_distribution<>::operator() (_UniformRandomNumberGenerator&,…

random.tcc (gamma_distribution<>::operator() (_UniformRandomNumberGenerator&, const param_type&): Redo, using the Marsaglia/Tsang algorithm.

2009-06-08  Paolo Carlini  <paolo.carlini@oracle.com>

	* include/bits/random.tcc (gamma_distribution<>::operator()
	(_UniformRandomNumberGenerator&, const param_type&): Redo, using
	the Marsaglia/Tsang algorithm.
	(gamma_distribution<>::param_type::_M_initialize): Adjust.
	(operator<<(basic_ostream<>&, gamma_distribution<>),
	operator>>(basic_ostream<>&, gamma_distribution<>): Likewise.

	* include/bits/random.tcc(student_t_distribution<>::_M_gaussian):
	Remove, just use normal_distribution.
	(operator<<(basic_ostream<>&, student_t_distribution<>),
	operator>>(basic_ostream<>&, student_t_distribution<>): Adjust.
	(linear_congruential_engine<>::operator()()): Move inline.
	(lognormal_distribution<>::operator()(_UniformRandomNumberGenerator&,
	const param_type&)): Move inline, just use normal_distribution.
	(operator<<(basic_ostream<>&, lognormal_distribution<>),
	operator>>(basic_ostream<>&, lognormal_distribution<>): Adjust.
	(weibull_distribution<>::operator()(_UniformRandomNumberGenerator&,
	const param_type&)): Move here, out of line.
	(piecewise_constant_distribution<>::param_type::param_type()): Move
	inline.
	* include/bits/random.h: Adjust, minor tweaks.

From-SVN: r148276
parent 06ddd871
2009-06-08 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/random.tcc (gamma_distribution<>::operator()
(_UniformRandomNumberGenerator&, const param_type&): Redo, using
the Marsaglia/Tsang algorithm.
(gamma_distribution<>::param_type::_M_initialize): Adjust.
(operator<<(basic_ostream<>&, gamma_distribution<>),
operator>>(basic_ostream<>&, gamma_distribution<>): Likewise.
* include/bits/random.tcc(student_t_distribution<>::_M_gaussian):
Remove, just use normal_distribution.
(operator<<(basic_ostream<>&, student_t_distribution<>),
operator>>(basic_ostream<>&, student_t_distribution<>): Adjust.
(linear_congruential_engine<>::operator()()): Move inline.
(lognormal_distribution<>::operator()(_UniformRandomNumberGenerator&,
const param_type&)): Move inline, just use normal_distribution.
(operator<<(basic_ostream<>&, lognormal_distribution<>),
operator>>(basic_ostream<>&, lognormal_distribution<>): Adjust.
(weibull_distribution<>::operator()(_UniformRandomNumberGenerator&,
const param_type&)): Move here, out of line.
(piecewise_constant_distribution<>::param_type::param_type()): Move
inline.
* include/bits/random.h: Adjust, minor tweaks.
2009-06-05 Benjamin Kosnik <bkoz@redhat.com> 2009-06-05 Benjamin Kosnik <bkoz@redhat.com>
* testsuite/29_atomics/atomic_address/cons/aggregate.cc: Remove xfail. * testsuite/29_atomics/atomic_address/cons/aggregate.cc: Remove xfail.
......
...@@ -268,7 +268,11 @@ namespace std ...@@ -268,7 +268,11 @@ namespace std
* @brief Gets the next random number in the sequence. * @brief Gets the next random number in the sequence.
*/ */
result_type result_type
operator()(); operator()()
{
_M_x = __detail::__mod<_UIntType, __a, __c, __m>(_M_x);
return _M_x;
}
/** /**
* @brief Compares two linear congruential random number generator * @brief Compares two linear congruential random number generator
...@@ -1588,12 +1592,7 @@ namespace std ...@@ -1588,12 +1592,7 @@ namespace std
template<typename _UniformRandomNumberGenerator> template<typename _UniformRandomNumberGenerator>
result_type result_type
operator()(_UniformRandomNumberGenerator& __urng) operator()(_UniformRandomNumberGenerator& __urng)
{ { return this->operator()(__urng, this->param()); }
typedef typename _UniformRandomNumberGenerator::result_type
_UResult_type;
return _M_call(__urng, this->a(), this->b(),
typename is_integral<_UResult_type>::type());
}
/** /**
* Gets a uniform random number in the range @f$[0, n)@f$. * Gets a uniform random number in the range @f$[0, n)@f$.
...@@ -1765,11 +1764,7 @@ namespace std ...@@ -1765,11 +1764,7 @@ namespace std
template<typename _UniformRandomNumberGenerator> template<typename _UniformRandomNumberGenerator>
result_type result_type
operator()(_UniformRandomNumberGenerator& __urng) operator()(_UniformRandomNumberGenerator& __urng)
{ { return this->operator()(__urng, this->param()); }
__detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
__aurng(__urng);
return (__aurng() * (this->b() - this->a())) + this->a();
}
template<typename _UniformRandomNumberGenerator> template<typename _UniformRandomNumberGenerator>
result_type result_type
...@@ -2014,12 +2009,12 @@ namespace std ...@@ -2014,12 +2009,12 @@ namespace std
explicit explicit
lognormal_distribution(_RealType __m = _RealType(0), lognormal_distribution(_RealType __m = _RealType(0),
_RealType __s = _RealType(1)) _RealType __s = _RealType(1))
: _M_param(__m, __s) : _M_param(__m, __s), _M_nd()
{ } { }
explicit explicit
lognormal_distribution(const param_type& __p) lognormal_distribution(const param_type& __p)
: _M_param(__p) : _M_param(__p), _M_nd()
{ } { }
/** /**
...@@ -2027,7 +2022,7 @@ namespace std ...@@ -2027,7 +2022,7 @@ namespace std
*/ */
void void
reset() reset()
{ } { _M_nd.reset(); }
/** /**
* *
...@@ -2077,10 +2072,13 @@ namespace std ...@@ -2077,10 +2072,13 @@ namespace std
template<typename _UniformRandomNumberGenerator> template<typename _UniformRandomNumberGenerator>
result_type result_type
operator()(_UniformRandomNumberGenerator& __urng, operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __p); const param_type& __p)
{ return std::exp(__p.s() * _M_nd(__urng) + __p.m()); }
private: private:
param_type _M_param; param_type _M_param;
normal_distribution<result_type> _M_nd;
}; };
/** /**
...@@ -2555,12 +2553,12 @@ namespace std ...@@ -2555,12 +2553,12 @@ namespace std
explicit explicit
student_t_distribution(_RealType __n = _RealType(1)) student_t_distribution(_RealType __n = _RealType(1))
: _M_param(__n) : _M_param(__n), _M_nd()
{ } { }
explicit explicit
student_t_distribution(const param_type& __p) student_t_distribution(const param_type& __p)
: _M_param(__p) : _M_param(__p), _M_nd()
{ } { }
/** /**
...@@ -2568,7 +2566,7 @@ namespace std ...@@ -2568,7 +2566,7 @@ namespace std
*/ */
void void
reset() reset()
{ } { _M_nd.reset(); }
/** /**
* *
...@@ -2617,12 +2615,9 @@ namespace std ...@@ -2617,12 +2615,9 @@ namespace std
const param_type& __p); const param_type& __p);
private: private:
template<typename _UniformRandomNumberGenerator>
result_type
_M_gaussian(_UniformRandomNumberGenerator& __urng,
const result_type __sigma);
param_type _M_param; param_type _M_param;
normal_distribution<result_type> _M_nd;
}; };
/** /**
...@@ -2761,14 +2756,7 @@ namespace std ...@@ -2761,14 +2756,7 @@ namespace std
template<typename _UniformRandomNumberGenerator> template<typename _UniformRandomNumberGenerator>
result_type result_type
operator()(_UniformRandomNumberGenerator& __urng) operator()(_UniformRandomNumberGenerator& __urng)
{ { return this->operator()(__urng, this->param()); }
__detail::_Adaptor<_UniformRandomNumberGenerator, double>
__aurng(__urng);
if ((__aurng() - __aurng.min())
< this->p() * (__aurng.max() - __aurng.min()))
return true;
return false;
}
template<typename _UniformRandomNumberGenerator> template<typename _UniformRandomNumberGenerator>
result_type result_type
...@@ -3539,11 +3527,7 @@ namespace std ...@@ -3539,11 +3527,7 @@ namespace std
template<typename _UniformRandomNumberGenerator> template<typename _UniformRandomNumberGenerator>
result_type result_type
operator()(_UniformRandomNumberGenerator& __urng) operator()(_UniformRandomNumberGenerator& __urng)
{ { return this->operator()(__urng, this->param()); }
__detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
__aurng(__urng);
return -std::log(__aurng()) / this->lambda();
}
template<typename _UniformRandomNumberGenerator> template<typename _UniformRandomNumberGenerator>
result_type result_type
...@@ -3633,8 +3617,7 @@ namespace std ...@@ -3633,8 +3617,7 @@ namespace std
_RealType _M_alpha; _RealType _M_alpha;
_RealType _M_beta; _RealType _M_beta;
// Hosts either lambda of GB or d of modified Vaduva's. _RealType _M_malpha, _M_a2;
_RealType _M_l_d;
}; };
public: public:
...@@ -3645,21 +3628,20 @@ namespace std ...@@ -3645,21 +3628,20 @@ namespace std
explicit explicit
gamma_distribution(_RealType __alpha_val = _RealType(1), gamma_distribution(_RealType __alpha_val = _RealType(1),
_RealType __beta_val = _RealType(1)) _RealType __beta_val = _RealType(1))
: _M_param(__alpha_val, __beta_val) : _M_param(__alpha_val, __beta_val), _M_nd()
{ } { }
explicit explicit
gamma_distribution(const param_type& __p) gamma_distribution(const param_type& __p)
: _M_param(__p) : _M_param(__p), _M_nd()
{ } { }
/** /**
* @brief Resets the distribution state. * @brief Resets the distribution state.
*
* Does nothing for the gamma distribution.
*/ */
void void
reset() { } reset()
{ _M_nd.reset(); }
/** /**
* @brief Returns the @f$ \alpha @f$ of the distribution. * @brief Returns the @f$ \alpha @f$ of the distribution.
...@@ -3716,6 +3698,8 @@ namespace std ...@@ -3716,6 +3698,8 @@ namespace std
private: private:
param_type _M_param; param_type _M_param;
normal_distribution<result_type> _M_nd;
}; };
/** /**
...@@ -3854,13 +3838,7 @@ namespace std ...@@ -3854,13 +3838,7 @@ namespace std
template<typename _UniformRandomNumberGenerator> template<typename _UniformRandomNumberGenerator>
result_type result_type
operator()(_UniformRandomNumberGenerator& __urng, operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __p) const param_type& __p);
{
__detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
__aurng(__urng);
return __p.b() * std::pow(-std::log(__aurng()),
result_type(1) / __p.a());
}
private: private:
param_type _M_param; param_type _M_param;
...@@ -4222,7 +4200,9 @@ namespace std ...@@ -4222,7 +4200,9 @@ namespace std
typedef piecewise_constant_distribution<_RealType> distribution_type; typedef piecewise_constant_distribution<_RealType> distribution_type;
friend class piecewise_constant_distribution<_RealType>; friend class piecewise_constant_distribution<_RealType>;
param_type(); param_type()
: _M_int(), _M_den(), _M_cp()
{ _M_initialize(); }
template<typename _InputIteratorB, typename _InputIteratorW> template<typename _InputIteratorB, typename _InputIteratorW>
param_type(_InputIteratorB __bfirst, param_type(_InputIteratorB __bfirst,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment