File indexing completed on 2026-05-03 08:13:40
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___CXX03___RANDOM_WEIBULL_DISTRIBUTION_H
0010 #define _LIBCPP___CXX03___RANDOM_WEIBULL_DISTRIBUTION_H
0011
0012 #include <__cxx03/__config>
0013 #include <__cxx03/__random/exponential_distribution.h>
0014 #include <__cxx03/__random/is_valid.h>
0015 #include <__cxx03/cmath>
0016 #include <__cxx03/iosfwd>
0017 #include <__cxx03/limits>
0018
0019 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0020 # pragma GCC system_header
0021 #endif
0022
0023 _LIBCPP_PUSH_MACROS
0024 #include <__cxx03/__undef_macros>
0025
0026 _LIBCPP_BEGIN_NAMESPACE_STD
0027
0028 template <class _RealType = double>
0029 class _LIBCPP_TEMPLATE_VIS weibull_distribution {
0030 static_assert(__libcpp_random_is_valid_realtype<_RealType>::value,
0031 "RealType must be a supported floating-point type");
0032
0033 public:
0034
0035 typedef _RealType result_type;
0036
0037 class _LIBCPP_TEMPLATE_VIS param_type {
0038 result_type __a_;
0039 result_type __b_;
0040
0041 public:
0042 typedef weibull_distribution distribution_type;
0043
0044 _LIBCPP_HIDE_FROM_ABI explicit param_type(result_type __a = 1, result_type __b = 1) : __a_(__a), __b_(__b) {}
0045
0046 _LIBCPP_HIDE_FROM_ABI result_type a() const { return __a_; }
0047 _LIBCPP_HIDE_FROM_ABI result_type b() const { return __b_; }
0048
0049 friend _LIBCPP_HIDE_FROM_ABI bool operator==(const param_type& __x, const param_type& __y) {
0050 return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;
0051 }
0052 friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const param_type& __x, const param_type& __y) { return !(__x == __y); }
0053 };
0054
0055 private:
0056 param_type __p_;
0057
0058 public:
0059
0060 #ifndef _LIBCPP_CXX03_LANG
0061 _LIBCPP_HIDE_FROM_ABI weibull_distribution() : weibull_distribution(1) {}
0062 _LIBCPP_HIDE_FROM_ABI explicit weibull_distribution(result_type __a, result_type __b = 1)
0063 : __p_(param_type(__a, __b)) {}
0064 #else
0065 _LIBCPP_HIDE_FROM_ABI explicit weibull_distribution(result_type __a = 1, result_type __b = 1)
0066 : __p_(param_type(__a, __b)) {}
0067 #endif
0068 _LIBCPP_HIDE_FROM_ABI explicit weibull_distribution(const param_type& __p) : __p_(__p) {}
0069 _LIBCPP_HIDE_FROM_ABI void reset() {}
0070
0071
0072 template <class _URNG>
0073 _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) {
0074 return (*this)(__g, __p_);
0075 }
0076 template <class _URNG>
0077 _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p) {
0078 return __p.b() * std::pow(exponential_distribution<result_type>()(__g), 1 / __p.a());
0079 }
0080
0081
0082 _LIBCPP_HIDE_FROM_ABI result_type a() const { return __p_.a(); }
0083 _LIBCPP_HIDE_FROM_ABI result_type b() const { return __p_.b(); }
0084
0085 _LIBCPP_HIDE_FROM_ABI param_type param() const { return __p_; }
0086 _LIBCPP_HIDE_FROM_ABI void param(const param_type& __p) { __p_ = __p; }
0087
0088 _LIBCPP_HIDE_FROM_ABI result_type min() const { return 0; }
0089 _LIBCPP_HIDE_FROM_ABI result_type max() const { return numeric_limits<result_type>::infinity(); }
0090
0091 friend _LIBCPP_HIDE_FROM_ABI bool operator==(const weibull_distribution& __x, const weibull_distribution& __y) {
0092 return __x.__p_ == __y.__p_;
0093 }
0094 friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const weibull_distribution& __x, const weibull_distribution& __y) {
0095 return !(__x == __y);
0096 }
0097 };
0098
0099 template <class _CharT, class _Traits, class _RT>
0100 _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
0101 operator<<(basic_ostream<_CharT, _Traits>& __os, const weibull_distribution<_RT>& __x) {
0102 __save_flags<_CharT, _Traits> __lx(__os);
0103 typedef basic_ostream<_CharT, _Traits> _OStream;
0104 __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | _OStream::scientific);
0105 _CharT __sp = __os.widen(' ');
0106 __os.fill(__sp);
0107 __os << __x.a() << __sp << __x.b();
0108 return __os;
0109 }
0110
0111 template <class _CharT, class _Traits, class _RT>
0112 _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
0113 operator>>(basic_istream<_CharT, _Traits>& __is, weibull_distribution<_RT>& __x) {
0114 typedef weibull_distribution<_RT> _Eng;
0115 typedef typename _Eng::result_type result_type;
0116 typedef typename _Eng::param_type param_type;
0117 __save_flags<_CharT, _Traits> __lx(__is);
0118 typedef basic_istream<_CharT, _Traits> _Istream;
0119 __is.flags(_Istream::dec | _Istream::skipws);
0120 result_type __a;
0121 result_type __b;
0122 __is >> __a >> __b;
0123 if (!__is.fail())
0124 __x.param(param_type(__a, __b));
0125 return __is;
0126 }
0127
0128 _LIBCPP_END_NAMESPACE_STD
0129
0130 _LIBCPP_POP_MACROS
0131
0132 #endif