From a64111c95ac2e7bc337def0426d512c81307c166 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Wed, 12 May 2010 21:02:31 +0000 Subject: [PATCH] [rand.dist.norm.normal] git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@103646 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/random | 214 +++++++++++++++++- .../rand.dist.norm.normal/assign.pass.cpp | 34 +++ .../rand.dist.norm.normal/copy.pass.cpp | 32 +++ .../ctor_double_double.pass.cpp | 40 ++++ .../rand.dist.norm.normal/ctor_param.pass.cpp | 30 +++ .../rand.dist.norm.normal/eq.pass.cpp | 37 +++ .../rand.dist.norm.normal/eval.pass.cpp | 53 +++++ .../rand.dist.norm.normal/eval_param.pass.cpp | 54 +++++ .../rand.dist.norm.normal/get_param.pass.cpp | 29 +++ .../rand.dist.norm.normal/io.pass.cpp | 41 ++++ .../rand.dist.norm.normal/max.pass.cpp | 28 +++ .../rand.dist.norm.normal/min.pass.cpp | 27 +++ .../param_assign.pass.cpp | 32 +++ .../rand.dist.norm.normal/param_copy.pass.cpp | 31 +++ .../rand.dist.norm.normal/param_ctor.pass.cpp | 44 ++++ .../rand.dist.norm.normal/param_eq.pass.cpp | 37 +++ .../param_types.pass.cpp | 28 +++ .../rand.dist.norm.normal/set_param.pass.cpp | 30 +++ .../rand.dist.norm.normal/types.pass.cpp | 34 +++ 19 files changed, 850 insertions(+), 5 deletions(-) create mode 100644 test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/assign.pass.cpp create mode 100644 test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/copy.pass.cpp create mode 100644 test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/ctor_double_double.pass.cpp create mode 100644 test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/ctor_param.pass.cpp create mode 100644 test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/eq.pass.cpp create mode 100644 test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/eval.pass.cpp create mode 100644 test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/eval_param.pass.cpp create mode 100644 test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/get_param.pass.cpp create mode 100644 test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/io.pass.cpp create mode 100644 test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/max.pass.cpp create mode 100644 test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/min.pass.cpp create mode 100644 test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_assign.pass.cpp create mode 100644 test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_copy.pass.cpp create mode 100644 test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_ctor.pass.cpp create mode 100644 test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_eq.pass.cpp create mode 100644 test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_types.pass.cpp create mode 100644 test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/set_param.pass.cpp create mode 100644 test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/types.pass.cpp diff --git a/include/random b/include/random index 849dce4c1..a94ca2cc2 100644 --- a/include/random +++ b/include/random @@ -686,16 +686,16 @@ public: public: typedef exponential_distribution distribution_type; - explicit param_type(RealType lambda = 1.0); + explicit param_type(result_type lambda = 1.0); - RealType lambda() const; + result_type lambda() const; friend bool operator==(const param_type& x, const param_type& y); friend bool operator!=(const param_type& x, const param_type& y); }; // constructors and reset functions - explicit exponential_distribution(RealType lambda = 1.0); + explicit exponential_distribution(result_type lambda = 1.0); explicit exponential_distribution(const param_type& parm); void reset(); @@ -704,7 +704,7 @@ public: template result_type operator()(URNG& g, const param_type& parm); // property functions - RealType lambda() const; + result_type lambda() const; param_type param() const; void param(const param_type& parm); @@ -740,7 +740,62 @@ template class extreme_value_distribution; template - class normal_distribution; +class normal_distribution +{ +public: + // types + typedef RealType result_type; + + class param_type + { + public: + typedef normal_distribution distribution_type; + + explicit param_type(result_type mean = 0, result_type stddev = 1); + + result_type mean() const; + result_type stddev() const; + + friend bool operator==(const param_type& x, const param_type& y); + friend bool operator!=(const param_type& x, const param_type& y); + }; + + // constructors and reset functions + explicit normal_distribution(result_type mean = 0, result_type stddev = 1); + explicit normal_distribution(const param_type& parm); + void reset(); + + // generating functions + template result_type operator()(URNG& g); + template result_type operator()(URNG& g, const param_type& parm); + + // property functions + result_type mean() const; + result_type stddev() const; + + param_type param() const; + void param(const param_type& parm); + + result_type min() const; + result_type max() const; + + friend bool operator==(const normal_distribution& x, + const normal_distribution& y); + friend bool operator!=(const normal_distribution& x, + const normal_distribution& y); + + template + friend + basic_ostream& + operator<<(basic_ostream& os, + const normal_distribution& x); + + template + friend + basic_istream& + operator>>(basic_istream& is, + normal_distribution& x); +}; template class lognormal_distribution; @@ -3171,6 +3226,155 @@ operator>>(basic_istream<_CharT, _Traits>& __is, return __is; } +// normal_distribution + +template +class normal_distribution +{ +public: + // types + typedef _RealType result_type; + + class param_type + { + result_type __mean_; + result_type __stddev_; + public: + typedef normal_distribution distribution_type; + + explicit param_type(result_type __mean = 0, result_type __stddev = 1) + : __mean_(__mean), __stddev_(__stddev) {} + + result_type mean() const {return __mean_;} + result_type stddev() const {return __stddev_;} + + friend bool operator==(const param_type& __x, const param_type& __y) + {return __x.__mean_ == __y.__mean_ && __x.__stddev_ == __y.__stddev_;} + friend bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + result_type _V_; + bool _V_hot_; + +public: + // constructors and reset functions + explicit normal_distribution(result_type __mean = 0, result_type __stddev = 1) + : __p_(param_type(__mean, __stddev)), _V_hot_(false) {} + explicit normal_distribution(const param_type& __p) + : __p_(__p), _V_hot_(false) {} + void reset() {_V_hot_ = false;} + + // generating functions + template result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + result_type mean() const {return __p_.mean();} + result_type stddev() const {return __p_.stddev();} + + param_type param() const {return __p_;} + void param(const param_type& __p) {__p_ = __p;} + + result_type min() const {return -numeric_limits::infinity();} + result_type max() const {return numeric_limits::infinity();} + + friend bool operator==(const normal_distribution& __x, + const normal_distribution& __y) + {return __x.__p_ == __y.__p_ && __x._V_hot_ == __y._V_hot_ && + (!__x._V_hot_ || __x._V_ == __y._V_);} + friend bool operator!=(const normal_distribution& __x, + const normal_distribution& __y) + {return !(__x == __y);} + + template + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const normal_distribution<_RT>& __x); + + template + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + normal_distribution<_RT>& __x); +}; + +template +template +_RealType +normal_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) +{ + result_type _U; + if (_V_hot_) + { + _V_hot_ = false; + _U = _V_; + } + else + { + uniform_real_distribution _Uni(-1, 1); + result_type __u; + result_type __v; + result_type __s; + do + { + __u = _Uni(__g); + __v = _Uni(__g); + __s = __u * __u + __v * __v; + } while (__s > 1 || __s == 0); + result_type _F = _STD::sqrt(-2 * _STD::log(__s) / __s); + _V_ = __v * _F; + _V_hot_ = true; + _U = __u * _F; + } + return _U * __p.stddev() + __p.mean(); +} + +template +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const normal_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.mean() << __sp << __x.stddev() << __sp << __x._V_hot_; + if (__x._V_hot_) + __os << __sp << __x._V_; + return __os; +} + +template +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + normal_distribution<_RT>& __x) +{ + typedef normal_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 __mean; + result_type __stddev; + result_type _V = 0; + bool _V_hot = false; + __is >> __mean >> __stddev >> _V_hot; + if (_V_hot) + __is >> _V; + if (!__is.fail()) + { + __x.param(param_type(__mean, __stddev)); + __x._V_hot_ = _V_hot; + __x._V_ = _V; + } + return __is; +} + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_RANDOM diff --git a/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/assign.pass.cpp b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/assign.pass.cpp new file mode 100644 index 000000000..c5f1df2be --- /dev/null +++ b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/assign.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// class normal_distribution + +// normal_distribution& operator=(const normal_distribution&); + +#include +#include + +void +test1() +{ + typedef std::normal_distribution<> D; + D d1(20, 0.75); + D d2; + assert(d1 != d2); + d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/copy.pass.cpp b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/copy.pass.cpp new file mode 100644 index 000000000..a3fc95cd2 --- /dev/null +++ b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/copy.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// class normal_distribution + +// normal_distribution(const normal_distribution&); + +#include +#include + +void +test1() +{ + typedef std::normal_distribution<> D; + D d1(20, 1.75); + D d2 = d1; + assert(d1 == d2); +} + +int main() +{ + test1(); +} diff --git a/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/ctor_double_double.pass.cpp b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/ctor_double_double.pass.cpp new file mode 100644 index 000000000..d4694dc71 --- /dev/null +++ b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/ctor_double_double.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// class normal_distribution + +// explicit normal_distribution(result_type mean = 0, result_type stddev = 1); + +#include +#include + +int main() +{ + { + typedef std::normal_distribution<> D; + D d; + assert(d.mean() == 0); + assert(d.stddev() == 1); + } + { + typedef std::normal_distribution<> D; + D d(14.5); + assert(d.mean() == 14.5); + assert(d.stddev() == 1); + } + { + typedef std::normal_distribution<> D; + D d(14.5, 5.25); + assert(d.mean() == 14.5); + assert(d.stddev() == 5.25); + } +} diff --git a/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/ctor_param.pass.cpp b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/ctor_param.pass.cpp new file mode 100644 index 000000000..cf965652e --- /dev/null +++ b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/ctor_param.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// class normal_distribution + +// explicit normal_distribution(const param_type& parm); + +#include +#include + +int main() +{ + { + typedef std::normal_distribution<> D; + typedef D::param_type P; + P p(0.25, 10); + D d(p); + assert(d.mean() == 0.25); + assert(d.stddev() == 10); + } +} diff --git a/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/eq.pass.cpp b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/eq.pass.cpp new file mode 100644 index 000000000..52082b326 --- /dev/null +++ b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// class normal_distribution + +// bool operator=(const normal_distribution& x, +// const normal_distribution& y); +// bool operator!(const normal_distribution& x, +// const normal_distribution& y); + +#include +#include + +int main() +{ + { + typedef std::normal_distribution<> D; + D d1(2.5, 4); + D d2(2.5, 4); + assert(d1 == d2); + } + { + typedef std::normal_distribution<> D; + D d1(2.5, 4); + D d2(2.5, 4.5); + assert(d1 != d2); + } +} diff --git a/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/eval.pass.cpp b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/eval.pass.cpp new file mode 100644 index 000000000..b6d9550a0 --- /dev/null +++ b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/eval.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// class normal_distribution + +// template result_type operator()(_URNG& g); + +#include +#include +#include +#include + +template +inline +T +sqr(T x) +{ + return x * x; +} + +int main() +{ + { + typedef std::normal_distribution<> D; + typedef D::param_type P; + typedef std::minstd_rand G; + G g; + D d(5, 4); + const int N = 1000; + std::vector u; + for (int i = 0; i < N; ++i) + u.push_back(d(g)); + D::result_type mean = std::accumulate(u.begin(), u.end(), + D::result_type(0)) / u.size(); + D::result_type var = 0; + for (int i = 0; i < u.size(); ++i) + var += sqr(u[i] - mean); + var /= u.size(); + D::result_type x_mean = d.mean(); + D::result_type x_var = sqr(d.stddev()); + assert(std::abs(mean - x_mean) / x_mean < 0.01); + assert(std::abs(var - x_var) / x_var < 0.01); + } +} diff --git a/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/eval_param.pass.cpp b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/eval_param.pass.cpp new file mode 100644 index 000000000..652c4c1dc --- /dev/null +++ b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/eval_param.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// class normal_distribution + +// template result_type operator()(_URNG& g, const param_type& parm); + +#include +#include +#include +#include + +template +inline +T +sqr(T x) +{ + return x * x; +} + +int main() +{ + { + typedef std::normal_distribution<> D; + typedef D::param_type P; + typedef std::minstd_rand G; + G g; + D d(5, 4); + P p(50, .5); + const int N = 1000; + std::vector u; + for (int i = 0; i < N; ++i) + u.push_back(d(g, p)); + D::result_type mean = std::accumulate(u.begin(), u.end(), + D::result_type(0)) / u.size(); + D::result_type var = 0; + for (int i = 0; i < u.size(); ++i) + var += sqr(u[i] - mean); + var /= u.size(); + D::result_type x_mean = p.mean(); + D::result_type x_var = sqr(p.stddev()); + assert(std::abs(mean - x_mean) / x_mean < 0.01); + assert(std::abs(var - x_var) / x_var < 0.01); + } +} diff --git a/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/get_param.pass.cpp b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/get_param.pass.cpp new file mode 100644 index 000000000..6a1afd757 --- /dev/null +++ b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/get_param.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// class normal_distribution + +// param_type param() const; + +#include +#include + +int main() +{ + { + typedef std::normal_distribution<> D; + typedef D::param_type P; + P p(.125, .5); + D d(p); + assert(d.param() == p); + } +} diff --git a/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/io.pass.cpp b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/io.pass.cpp new file mode 100644 index 000000000..51a2185e3 --- /dev/null +++ b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/io.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// class normal_distribution + +// template +// basic_ostream& +// operator<<(basic_ostream& os, +// const normal_distribution& x); + +// template +// basic_istream& +// operator>>(basic_istream& is, +// normal_distribution& x); + +#include +#include +#include + +int main() +{ + { + typedef std::normal_distribution<> D; + D d1(7, 5); + std::ostringstream os; + os << d1; + std::istringstream is(os.str()); + D d2; + is >> d2; + assert(d1 == d2); + } +} diff --git a/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/max.pass.cpp b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/max.pass.cpp new file mode 100644 index 000000000..6e91d1605 --- /dev/null +++ b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/max.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// class normal_distribution + +// result_type max() const; + +#include +#include + +int main() +{ + { + typedef std::normal_distribution<> D; + D d(5, .25); + D::result_type m = d.max(); + assert(m == INFINITY); + } +} diff --git a/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/min.pass.cpp b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/min.pass.cpp new file mode 100644 index 000000000..e251e16b5 --- /dev/null +++ b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/min.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// class normal_distribution + +// result_type min() const; + +#include +#include + +int main() +{ + { + typedef std::normal_distribution<> D; + D d(.5, .5); + assert(d.min() == -INFINITY); + } +} diff --git a/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_assign.pass.cpp b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_assign.pass.cpp new file mode 100644 index 000000000..f5cb6ad2c --- /dev/null +++ b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_assign.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// class normal_distribution +// { +// class param_type; + +#include +#include +#include + +int main() +{ + { + typedef std::normal_distribution<> D; + typedef D::param_type param_type; + param_type p0(.75, 6); + param_type p; + p = p0; + assert(p.mean() == .75); + assert(p.stddev() == 6); + } +} diff --git a/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_copy.pass.cpp b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_copy.pass.cpp new file mode 100644 index 000000000..8ddff2fa1 --- /dev/null +++ b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_copy.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// class normal_distribution +// { +// class param_type; + +#include +#include +#include + +int main() +{ + { + typedef std::normal_distribution<> D; + typedef D::param_type param_type; + param_type p0(10, .125); + param_type p = p0; + assert(p.mean() == 10); + assert(p.stddev() == .125); + } +} diff --git a/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_ctor.pass.cpp b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_ctor.pass.cpp new file mode 100644 index 000000000..1f184e911 --- /dev/null +++ b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_ctor.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// class normal_distribution +// { +// class param_type; + +#include +#include +#include + +int main() +{ + { + typedef std::normal_distribution<> D; + typedef D::param_type param_type; + param_type p; + assert(p.mean() == 0); + assert(p.stddev() == 1); + } + { + typedef std::normal_distribution<> D; + typedef D::param_type param_type; + param_type p(10); + assert(p.mean() == 10); + assert(p.stddev() == 1); + } + { + typedef std::normal_distribution<> D; + typedef D::param_type param_type; + param_type p(10, 5); + assert(p.mean() == 10); + assert(p.stddev() == 5); + } +} diff --git a/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_eq.pass.cpp b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_eq.pass.cpp new file mode 100644 index 000000000..c04f8bc08 --- /dev/null +++ b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// class normal_distribution +// { +// class param_type; + +#include +#include +#include + +int main() +{ + { + typedef std::normal_distribution<> D; + typedef D::param_type param_type; + param_type p1(0.75, .5); + param_type p2(0.75, .5); + assert(p1 == p2); + } + { + typedef std::normal_distribution<> D; + typedef D::param_type param_type; + param_type p1(0.75, .5); + param_type p2(0.5, .5); + assert(p1 != p2); + } +} diff --git a/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_types.pass.cpp b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_types.pass.cpp new file mode 100644 index 000000000..edd2b8b05 --- /dev/null +++ b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/param_types.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// class normal_distribution +// { +// class param_type; + +#include +#include + +int main() +{ + { + typedef std::normal_distribution<> D; + typedef D::param_type param_type; + typedef param_type::distribution_type distribution_type; + static_assert((std::is_same::value), ""); + } +} diff --git a/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/set_param.pass.cpp b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/set_param.pass.cpp new file mode 100644 index 000000000..a85dc466a --- /dev/null +++ b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/set_param.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// class normal_distribution; + +// void param(const param_type& parm); + +#include +#include + +int main() +{ + { + typedef std::normal_distribution<> D; + typedef D::param_type P; + P p(0.25, 5.5); + D d(0.75, 4); + d.param(p); + assert(d.param() == p); + } +} diff --git a/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/types.pass.cpp b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/types.pass.cpp new file mode 100644 index 000000000..9fbaed3f8 --- /dev/null +++ b/test/numerics/rand/rand.dis/rand.dist.norm/rand.dist.norm.normal/types.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// class normal_distribution +// { +// public: +// // types +// typedef RealType result_type; + +#include +#include + +int main() +{ + { + typedef std::normal_distribution<> D; + typedef D::result_type result_type; + static_assert((std::is_same::value), ""); + } + { + typedef std::normal_distribution D; + typedef D::result_type result_type; + static_assert((std::is_same::value), ""); + } +}