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