[rand.dist.pois.weibull]
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@103891 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
154
include/random
154
include/random
@@ -842,7 +842,63 @@ public:
|
||||
};
|
||||
|
||||
template<class RealType = double>
|
||||
class weibull_distribution;
|
||||
class weibull_distribution
|
||||
{
|
||||
public:
|
||||
// types
|
||||
typedef RealType result_type;
|
||||
|
||||
class param_type
|
||||
{
|
||||
public:
|
||||
typedef weibull_distribution distribution_type;
|
||||
|
||||
explicit param_type(result_type alpha = 1, result_type beta = 1);
|
||||
|
||||
result_type a() const;
|
||||
result_type b() const;
|
||||
|
||||
friend bool operator==(const param_type& x, const param_type& y);
|
||||
friend bool operator!=(const param_type& x, const param_type& y);
|
||||
};
|
||||
|
||||
// constructor and reset functions
|
||||
explicit weibull_distribution(result_type a = 1, result_type b = 1);
|
||||
explicit weibull_distribution(const param_type& parm);
|
||||
void reset();
|
||||
|
||||
// generating functions
|
||||
template<class URNG> result_type operator()(URNG& g);
|
||||
template<class URNG> result_type operator()(URNG& g, const param_type& parm);
|
||||
|
||||
// property functions
|
||||
result_type a() const;
|
||||
result_type b() const;
|
||||
|
||||
param_type param() const;
|
||||
void param(const param_type& parm);
|
||||
|
||||
result_type min() const;
|
||||
result_type max() const;
|
||||
|
||||
|
||||
friend bool operator==(const weibull_distribution& x,
|
||||
const weibull_distribution& y);
|
||||
friend bool operator!=(const weibull_distribution& x,
|
||||
const weibull_distribution& y);
|
||||
|
||||
template <class charT, class traits>
|
||||
friend
|
||||
basic_ostream<charT, traits>&
|
||||
operator<<(basic_ostream<charT, traits>& os,
|
||||
const weibull_distribution& x);
|
||||
|
||||
template <class charT, class traits>
|
||||
friend
|
||||
basic_istream<charT, traits>&
|
||||
operator>>(basic_istream<charT, traits>& is,
|
||||
weibull_distribution& x);
|
||||
};
|
||||
|
||||
template<class RealType = double>
|
||||
class extreme_value_distribution;
|
||||
@@ -3795,6 +3851,102 @@ operator>>(basic_istream<_CharT, _Traits>& __is,
|
||||
return __is;
|
||||
}
|
||||
|
||||
// weibull_distribution
|
||||
|
||||
template<class _RealType = double>
|
||||
class weibull_distribution
|
||||
{
|
||||
public:
|
||||
// types
|
||||
typedef _RealType result_type;
|
||||
|
||||
class param_type
|
||||
{
|
||||
result_type __a_;
|
||||
result_type __b_;
|
||||
public:
|
||||
typedef weibull_distribution distribution_type;
|
||||
|
||||
explicit param_type(result_type __a = 1, result_type __b = 1)
|
||||
: __a_(__a), __b_(__b) {}
|
||||
|
||||
result_type a() const {return __a_;}
|
||||
result_type b() const {return __b_;}
|
||||
|
||||
friend bool operator==(const param_type& __x, const param_type& __y)
|
||||
{return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;}
|
||||
friend bool operator!=(const param_type& __x, const param_type& __y)
|
||||
{return !(__x == __y);}
|
||||
};
|
||||
|
||||
private:
|
||||
param_type __p_;
|
||||
|
||||
public:
|
||||
// constructor and reset functions
|
||||
explicit weibull_distribution(result_type __a = 1, result_type __b = 1)
|
||||
: __p_(param_type(__a, __b)) {}
|
||||
explicit weibull_distribution(const param_type& __p)
|
||||
: __p_(__p) {}
|
||||
void reset() {}
|
||||
|
||||
// generating functions
|
||||
template<class _URNG> result_type operator()(_URNG& __g)
|
||||
{return (*this)(__g, __p_);}
|
||||
template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p)
|
||||
{return __p.b() *
|
||||
_STD::pow(exponential_distribution<result_type>()(__g), 1/__p.a());}
|
||||
|
||||
// property functions
|
||||
result_type a() const {return __p_.a();}
|
||||
result_type b() const {return __p_.b();}
|
||||
|
||||
param_type param() const {return __p_;}
|
||||
void param(const param_type& __p) {__p_ = __p;}
|
||||
|
||||
result_type min() const {return 0;}
|
||||
result_type max() const {return numeric_limits<result_type>::infinity();}
|
||||
|
||||
|
||||
friend bool operator==(const weibull_distribution& __x,
|
||||
const weibull_distribution& __y)
|
||||
{return __x.__p_ == __y.__p_;}
|
||||
friend bool operator!=(const weibull_distribution& __x,
|
||||
const weibull_distribution& __y)
|
||||
{return !(__x == __y);}
|
||||
};
|
||||
|
||||
template <class _CharT, class _Traits, class _RT>
|
||||
basic_ostream<_CharT, _Traits>&
|
||||
operator<<(basic_ostream<_CharT, _Traits>& __os,
|
||||
const weibull_distribution<_RT>& __x)
|
||||
{
|
||||
__save_flags<_CharT, _Traits> _(__os);
|
||||
__os.flags(ios_base::dec | ios_base::left);
|
||||
_CharT __sp = __os.widen(' ');
|
||||
__os.fill(__sp);
|
||||
__os << __x.a() << __sp << __x.b();
|
||||
return __os;
|
||||
}
|
||||
|
||||
template <class _CharT, class _Traits, class _RT>
|
||||
basic_istream<_CharT, _Traits>&
|
||||
operator>>(basic_istream<_CharT, _Traits>& __is,
|
||||
weibull_distribution<_RT>& __x)
|
||||
{
|
||||
typedef weibull_distribution<_RT> _Eng;
|
||||
typedef typename _Eng::result_type result_type;
|
||||
typedef typename _Eng::param_type param_type;
|
||||
__save_flags<_CharT, _Traits> _(__is);
|
||||
__is.flags(ios_base::dec | ios_base::skipws);
|
||||
result_type __a;
|
||||
result_type __b;
|
||||
__is >> __a >> __b;
|
||||
if (!__is.fail())
|
||||
__x.param(param_type(__a, __b));
|
||||
return __is;
|
||||
}
|
||||
|
||||
// gamma_distribution
|
||||
|
||||
template<class _RealType = double>
|
||||
|
Reference in New Issue
Block a user