Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/llvm/llvm-project.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHoward Hinnant <hhinnant@apple.com>2010-05-16 03:36:00 +0400
committerHoward Hinnant <hhinnant@apple.com>2010-05-16 03:36:00 +0400
commite3900731f690692f3572812106c7fbaeee07639d (patch)
tree44caba5316773abd2968b89d6e8c392711b9fdd1 /libcxx/include/random
parente1b45a5e6b6f646f2a046e2c1686b005bd841cb5 (diff)
[rand.dist.norm.chisq]
llvm-svn: 103888
Diffstat (limited to 'libcxx/include/random')
-rw-r--r--libcxx/include/random144
1 files changed, 143 insertions, 1 deletions
diff --git a/libcxx/include/random b/libcxx/include/random
index 63a44aae443b..07c78d37388b 100644
--- a/libcxx/include/random
+++ b/libcxx/include/random
@@ -909,7 +909,61 @@ template<class RealType = double>
class lognormal_distribution;
template<class RealType = double>
- class chi_squared_distribution;
+class chi_squared_distribution
+{
+public:
+ // types
+ typedef RealType result_type;
+
+ class param_type
+ {
+ public:
+ typedef chi_squared_distribution distribution_type;
+
+ explicit param_type(result_type n = 1);
+
+ result_type n() 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 chi_squared_distribution(result_type n = 1);
+ explicit chi_squared_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 n() const;
+
+ param_type param() const;
+ void param(const param_type& parm);
+
+ result_type min() const;
+ result_type max() const;
+
+
+ friend bool operator==(const chi_squared_distribution& x,
+ const chi_squared_distribution& y);
+ friend bool operator!=(const chi_squared_distribution& x,
+ const chi_squared_distribution& y);
+
+ template <class charT, class traits>
+ friend
+ basic_ostream<charT, traits>&
+ operator<<(basic_ostream<charT, traits>& os,
+ const chi_squared_distribution& x);
+
+ template <class charT, class traits>
+ friend
+ basic_istream<charT, traits>&
+ operator>>(basic_istream<charT, traits>& is,
+ chi_squared_distribution& x);
+};
template<class RealType = double>
class cauchy_distribution;
@@ -3894,6 +3948,94 @@ operator>>(basic_istream<_CharT, _Traits>& __is,
return __is;
}
+// chi_squared_distribution
+
+template<class _RealType = double>
+class chi_squared_distribution
+{
+public:
+ // types
+ typedef _RealType result_type;
+
+ class param_type
+ {
+ result_type __n_;
+ public:
+ typedef chi_squared_distribution distribution_type;
+
+ explicit param_type(result_type __n = 1) : __n_(__n) {}
+
+ result_type n() const {return __n_;}
+
+ friend bool operator==(const param_type& __x, const param_type& __y)
+ {return __x.__n_ == __y.__n_;}
+ friend bool operator!=(const param_type& __x, const param_type& __y)
+ {return !(__x == __y);}
+ };
+
+private:
+ param_type __p_;
+
+public:
+ // constructor and reset functions
+ explicit chi_squared_distribution(result_type __n = 1)
+ : __p_(param_type(__n)) {}
+ explicit chi_squared_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 gamma_distribution<result_type>(__p.n() / 2, 2)(__g);}
+
+ // property functions
+ result_type n() const {return __p_.n();}
+
+ 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 chi_squared_distribution& __x,
+ const chi_squared_distribution& __y)
+ {return __x.__p_ == __y.__p_;}
+ friend bool operator!=(const chi_squared_distribution& __x,
+ const chi_squared_distribution& __y)
+ {return !(__x == __y);}
+};
+
+template <class _CharT, class _Traits, class _RT>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+ const chi_squared_distribution<_RT>& __x)
+{
+ __save_flags<_CharT, _Traits> _(__os);
+ __os.flags(ios_base::dec | ios_base::left);
+ __os << __x.n();
+ return __os;
+}
+
+template <class _CharT, class _Traits, class _RT>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+ chi_squared_distribution<_RT>& __x)
+{
+ typedef chi_squared_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 __n;
+ __is >> __n;
+ if (!__is.fail())
+ __x.param(param_type(__n));
+ return __is;
+}
+
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_RANDOM