[cfe-commits] [libcxx] r103937 - in /libcxx/trunk: include/ test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/
Howard Hinnant
hhinnant at apple.com
Mon May 17 06:44:28 PDT 2010
Author: hhinnant
Date: Mon May 17 08:44:27 2010
New Revision: 103937
URL: http://llvm.org/viewvc/llvm-project?rev=103937&view=rev
Log:
[rand.dist.bern.geo]
Added:
libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/assign.pass.cpp
libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/copy.pass.cpp
libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/ctor_double.pass.cpp
libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/ctor_param.pass.cpp
libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/eq.pass.cpp
libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/eval.pass.cpp
libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/eval_param.pass.cpp
libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/get_param.pass.cpp
libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/io.pass.cpp
libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/max.pass.cpp
libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/min.pass.cpp
libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_assign.pass.cpp
libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_copy.pass.cpp
libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_ctor.pass.cpp
libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_eq.pass.cpp
libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_types.pass.cpp
libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/set_param.pass.cpp
libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/types.pass.cpp
Modified:
libcxx/trunk/include/random
Modified: libcxx/trunk/include/random
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/random?rev=103937&r1=103936&r2=103937&view=diff
==============================================================================
--- libcxx/trunk/include/random (original)
+++ libcxx/trunk/include/random Mon May 17 08:44:27 2010
@@ -666,7 +666,60 @@
};
template<class IntType = int>
- class geometric_distribution;
+class geometric_distribution
+{
+public:
+ // types
+ typedef IntType result_type;
+
+ class param_type
+ {
+ public:
+ typedef geometric_distribution distribution_type;
+
+ explicit param_type(double p = 0.5);
+
+ double p() 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 geometric_distribution(double p = 0.5);
+ explicit geometric_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
+ double p() const;
+
+ param_type param() const;
+ void param(const param_type& parm);
+
+ result_type min() const;
+ result_type max() const;
+
+ friend bool operator==(const geometric_distribution& x,
+ const geometric_distribution& y);
+ friend bool operator!=(const geometric_distribution& x,
+ const geometric_distribution& y);
+
+ template <class charT, class traits>
+ friend
+ basic_ostream<charT, traits>&
+ operator<<(basic_ostream<charT, traits>& os,
+ const geometric_distribution& x);
+
+ template <class charT, class traits>
+ friend
+ basic_istream<charT, traits>&
+ operator>>(basic_istream<charT, traits>& is,
+ geometric_distribution& x);
+};
template<class IntType = int>
class negative_binomial_distribution
@@ -4269,6 +4322,89 @@
return __is;
}
+// geometric_distribution
+
+template<class _IntType = int>
+class geometric_distribution
+{
+public:
+ // types
+ typedef _IntType result_type;
+
+ class param_type
+ {
+ double __p_;
+ public:
+ typedef geometric_distribution distribution_type;
+
+ explicit param_type(double __p = 0.5) : __p_(__p) {}
+
+ double p() const {return __p_;}
+
+ friend bool operator==(const param_type& __x, const param_type& __y)
+ {return __x.__p_ == __y.__p_;}
+ friend bool operator!=(const param_type& __x, const param_type& __y)
+ {return !(__x == __y);}
+ };
+
+private:
+ param_type __p_;
+
+public:
+ // constructors and reset functions
+ explicit geometric_distribution(double __p = 0.5) : __p_(__p) {}
+ explicit geometric_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 negative_binomial_distribution<result_type>(1, __p.p())(__g);}
+
+ // property functions
+ double p() const {return __p_.p();}
+
+ 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>::max();}
+
+ friend bool operator==(const geometric_distribution& __x,
+ const geometric_distribution& __y)
+ {return __x.__p_ == __y.__p_;}
+ friend bool operator!=(const geometric_distribution& __x,
+ const geometric_distribution& __y)
+ {return !(__x == __y);}
+};
+
+template <class _CharT, class _Traits, class _IntType>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+ const geometric_distribution<_IntType>& __x)
+{
+ __save_flags<_CharT, _Traits> _(__os);
+ __os.flags(ios_base::dec | ios_base::left);
+ return __os << __x.p();
+}
+
+template <class _CharT, class _Traits, class _IntType>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+ geometric_distribution<_IntType>& __x)
+{
+ typedef geometric_distribution<_IntType> _Eng;
+ typedef typename _Eng::param_type param_type;
+ __save_flags<_CharT, _Traits> _(__is);
+ __is.flags(ios_base::dec | ios_base::skipws);
+ double __p;
+ __is >> __p;
+ if (!__is.fail())
+ __x.param(param_type(__p));
+ return __is;
+}
+
// chi_squared_distribution
template<class _RealType = double>
Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/assign.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/assign.pass.cpp?rev=103937&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/assign.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/assign.pass.cpp Mon May 17 08:44:27 2010
@@ -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.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class IntType = int>
+// class geometric_distribution
+
+// geometric_distribution& operator=(const geometric_distribution&);
+
+#include <random>
+#include <cassert>
+
+void
+test1()
+{
+ typedef std::geometric_distribution<> D;
+ D d1(0.75);
+ D d2;
+ assert(d1 != d2);
+ d2 = d1;
+ assert(d1 == d2);
+}
+
+int main()
+{
+ test1();
+}
Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/copy.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/copy.pass.cpp?rev=103937&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/copy.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/copy.pass.cpp Mon May 17 08:44:27 2010
@@ -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.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class IntType = int>
+// class geometric_distribution
+
+// geometric_distribution(const geometric_distribution&);
+
+#include <random>
+#include <cassert>
+
+void
+test1()
+{
+ typedef std::geometric_distribution<> D;
+ D d1(0.75);
+ D d2 = d1;
+ assert(d1 == d2);
+}
+
+int main()
+{
+ test1();
+}
Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/ctor_double.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/ctor_double.pass.cpp?rev=103937&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/ctor_double.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/ctor_double.pass.cpp Mon May 17 08:44:27 2010
@@ -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.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class IntType = int>
+// class geometric_distribution
+
+// explicit geometric_distribution(double p = 0.5);
+
+#include <random>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef std::geometric_distribution<> D;
+ D d;
+ assert(d.p() == 0.5);
+ }
+ {
+ typedef std::geometric_distribution<> D;
+ D d(0.75);
+ assert(d.p() == 0.75);
+ }
+}
Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/ctor_param.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/ctor_param.pass.cpp?rev=103937&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/ctor_param.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/ctor_param.pass.cpp Mon May 17 08:44:27 2010
@@ -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.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class IntType = int>
+// class geometric_distribution
+
+// explicit geometric_distribution(const param_type& parm);
+
+#include <random>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef std::geometric_distribution<> D;
+ typedef D::param_type P;
+ P p(0.25);
+ D d(p);
+ assert(d.p() == 0.25);
+ }
+}
Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/eq.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/eq.pass.cpp?rev=103937&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/eq.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/eq.pass.cpp Mon May 17 08:44:27 2010
@@ -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.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class IntType = int>
+// class geometric_distribution
+
+// bool operator=(const geometric_distribution& x,
+// const geometric_distribution& y);
+// bool operator!(const geometric_distribution& x,
+// const geometric_distribution& y);
+
+#include <random>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef std::geometric_distribution<> D;
+ D d1(.25);
+ D d2(.25);
+ assert(d1 == d2);
+ }
+ {
+ typedef std::geometric_distribution<> D;
+ D d1(.28);
+ D d2(.25);
+ assert(d1 != d2);
+ }
+}
Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/eval.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/eval.pass.cpp?rev=103937&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/eval.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/eval.pass.cpp Mon May 17 08:44:27 2010
@@ -0,0 +1,272 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class IntType = int>
+// class geometric_distribution
+
+// template<class _URNG> result_type operator()(_URNG& g);
+
+#include <random>
+#include <numeric>
+#include <vector>
+#include <cassert>
+
+template <class T>
+inline
+T
+sqr(T x)
+{
+ return x * x;
+}
+
+int main()
+{
+ {
+ typedef std::geometric_distribution<> D;
+ typedef std::mt19937 G;
+ G g;
+ D d(.03125);
+ const int N = 1000000;
+ std::vector<D::result_type> u;
+ for (int i = 0; i < N; ++i)
+ {
+ D::result_type v = d(g);
+ assert(d.min() <= v && v <= d.max());
+ u.push_back(v);
+ }
+ double mean = std::accumulate(u.begin(), u.end(),
+ double(0)) / u.size();
+ double var = 0;
+ double skew = 0;
+ double kurtosis = 0;
+ for (int i = 0; i < u.size(); ++i)
+ {
+ double d = (u[i] - mean);
+ double d2 = sqr(d);
+ var += d2;
+ skew += d * d2;
+ kurtosis += d2 * d2;
+ }
+ var /= u.size();
+ double dev = std::sqrt(var);
+ skew /= u.size() * dev * var;
+ kurtosis /= u.size() * var * var;
+ kurtosis -= 3;
+ double x_mean = (1 - d.p()) / d.p();
+ double x_var = x_mean / d.p();
+ double x_skew = (2 - d.p()) / std::sqrt((1 - d.p()));
+ double x_kurtosis = 6 + sqr(d.p()) / (1 - d.p());
+ assert(std::abs(mean - x_mean) / x_mean < 0.01);
+ assert(std::abs(var - x_var) / x_var < 0.01);
+ assert(std::abs(skew - x_skew) / x_skew < 0.01);
+ assert(std::abs(kurtosis - x_kurtosis) / x_kurtosis < 0.01);
+ }
+ {
+ typedef std::geometric_distribution<> D;
+ typedef std::mt19937 G;
+ G g;
+ D d(0.05);
+ const int N = 1000000;
+ std::vector<D::result_type> u;
+ for (int i = 0; i < N; ++i)
+ {
+ D::result_type v = d(g);
+ assert(d.min() <= v && v <= d.max());
+ u.push_back(v);
+ }
+ double mean = std::accumulate(u.begin(), u.end(),
+ double(0)) / u.size();
+ double var = 0;
+ double skew = 0;
+ double kurtosis = 0;
+ for (int i = 0; i < u.size(); ++i)
+ {
+ double d = (u[i] - mean);
+ double d2 = sqr(d);
+ var += d2;
+ skew += d * d2;
+ kurtosis += d2 * d2;
+ }
+ var /= u.size();
+ double dev = std::sqrt(var);
+ skew /= u.size() * dev * var;
+ kurtosis /= u.size() * var * var;
+ kurtosis -= 3;
+ double x_mean = (1 - d.p()) / d.p();
+ double x_var = x_mean / d.p();
+ double x_skew = (2 - d.p()) / std::sqrt((1 - d.p()));
+ double x_kurtosis = 6 + sqr(d.p()) / (1 - d.p());
+ assert(std::abs(mean - x_mean) / x_mean < 0.01);
+ assert(std::abs(var - x_var) / x_var < 0.01);
+ assert(std::abs(skew - x_skew) / x_skew < 0.01);
+ assert(std::abs(kurtosis - x_kurtosis) / x_kurtosis < 0.02);
+ }
+ {
+ typedef std::geometric_distribution<> D;
+ typedef std::minstd_rand G;
+ G g;
+ D d(.25);
+ const int N = 1000000;
+ std::vector<D::result_type> u;
+ for (int i = 0; i < N; ++i)
+ {
+ D::result_type v = d(g);
+ assert(d.min() <= v && v <= d.max());
+ u.push_back(v);
+ }
+ double mean = std::accumulate(u.begin(), u.end(),
+ double(0)) / u.size();
+ double var = 0;
+ double skew = 0;
+ double kurtosis = 0;
+ for (int i = 0; i < u.size(); ++i)
+ {
+ double d = (u[i] - mean);
+ double d2 = sqr(d);
+ var += d2;
+ skew += d * d2;
+ kurtosis += d2 * d2;
+ }
+ var /= u.size();
+ double dev = std::sqrt(var);
+ skew /= u.size() * dev * var;
+ kurtosis /= u.size() * var * var;
+ kurtosis -= 3;
+ double x_mean = (1 - d.p()) / d.p();
+ double x_var = x_mean / d.p();
+ double x_skew = (2 - d.p()) / std::sqrt((1 - d.p()));
+ double x_kurtosis = 6 + sqr(d.p()) / (1 - d.p());
+ assert(std::abs(mean - x_mean) / x_mean < 0.01);
+ assert(std::abs(var - x_var) / x_var < 0.01);
+ assert(std::abs(skew - x_skew) / x_skew < 0.01);
+ assert(std::abs(kurtosis - x_kurtosis) / x_kurtosis < 0.02);
+ }
+ {
+ typedef std::geometric_distribution<> D;
+ typedef std::mt19937 G;
+ G g;
+ D d(0.5);
+ const int N = 1000000;
+ std::vector<D::result_type> u;
+ for (int i = 0; i < N; ++i)
+ {
+ D::result_type v = d(g);
+ assert(d.min() <= v && v <= d.max());
+ u.push_back(v);
+ }
+ double mean = std::accumulate(u.begin(), u.end(),
+ double(0)) / u.size();
+ double var = 0;
+ double skew = 0;
+ double kurtosis = 0;
+ for (int i = 0; i < u.size(); ++i)
+ {
+ double d = (u[i] - mean);
+ double d2 = sqr(d);
+ var += d2;
+ skew += d * d2;
+ kurtosis += d2 * d2;
+ }
+ var /= u.size();
+ double dev = std::sqrt(var);
+ skew /= u.size() * dev * var;
+ kurtosis /= u.size() * var * var;
+ kurtosis -= 3;
+ double x_mean = (1 - d.p()) / d.p();
+ double x_var = x_mean / d.p();
+ double x_skew = (2 - d.p()) / std::sqrt((1 - d.p()));
+ double x_kurtosis = 6 + sqr(d.p()) / (1 - d.p());
+ assert(std::abs(mean - x_mean) / x_mean < 0.01);
+ assert(std::abs(var - x_var) / x_var < 0.01);
+ assert(std::abs(skew - x_skew) / x_skew < 0.01);
+ assert(std::abs(kurtosis - x_kurtosis) / x_kurtosis < 0.01);
+ }
+ {
+ typedef std::geometric_distribution<> D;
+ typedef std::mt19937 G;
+ G g;
+ D d(0.75);
+ const int N = 1000000;
+ std::vector<D::result_type> u;
+ for (int i = 0; i < N; ++i)
+ {
+ D::result_type v = d(g);
+ assert(d.min() <= v && v <= d.max());
+ u.push_back(v);
+ }
+ double mean = std::accumulate(u.begin(), u.end(),
+ double(0)) / u.size();
+ double var = 0;
+ double skew = 0;
+ double kurtosis = 0;
+ for (int i = 0; i < u.size(); ++i)
+ {
+ double d = (u[i] - mean);
+ double d2 = sqr(d);
+ var += d2;
+ skew += d * d2;
+ kurtosis += d2 * d2;
+ }
+ var /= u.size();
+ double dev = std::sqrt(var);
+ skew /= u.size() * dev * var;
+ kurtosis /= u.size() * var * var;
+ kurtosis -= 3;
+ double x_mean = (1 - d.p()) / d.p();
+ double x_var = x_mean / d.p();
+ double x_skew = (2 - d.p()) / std::sqrt((1 - d.p()));
+ double x_kurtosis = 6 + sqr(d.p()) / (1 - d.p());
+ assert(std::abs(mean - x_mean) / x_mean < 0.01);
+ assert(std::abs(var - x_var) / x_var < 0.01);
+ assert(std::abs(skew - x_skew) / x_skew < 0.01);
+ assert(std::abs(kurtosis - x_kurtosis) / x_kurtosis < 0.02);
+ }
+ {
+ typedef std::geometric_distribution<> D;
+ typedef std::mt19937 G;
+ G g;
+ D d(0.96875);
+ const int N = 1000000;
+ std::vector<D::result_type> u;
+ for (int i = 0; i < N; ++i)
+ {
+ D::result_type v = d(g);
+ assert(d.min() <= v && v <= d.max());
+ u.push_back(v);
+ }
+ double mean = std::accumulate(u.begin(), u.end(),
+ double(0)) / u.size();
+ double var = 0;
+ double skew = 0;
+ double kurtosis = 0;
+ for (int i = 0; i < u.size(); ++i)
+ {
+ double d = (u[i] - mean);
+ double d2 = sqr(d);
+ var += d2;
+ skew += d * d2;
+ kurtosis += d2 * d2;
+ }
+ var /= u.size();
+ double dev = std::sqrt(var);
+ skew /= u.size() * dev * var;
+ kurtosis /= u.size() * var * var;
+ kurtosis -= 3;
+ double x_mean = (1 - d.p()) / d.p();
+ double x_var = x_mean / d.p();
+ double x_skew = (2 - d.p()) / std::sqrt((1 - d.p()));
+ double x_kurtosis = 6 + sqr(d.p()) / (1 - d.p());
+ assert(std::abs(mean - x_mean) / x_mean < 0.01);
+ assert(std::abs(var - x_var) / x_var < 0.01);
+ assert(std::abs(skew - x_skew) / x_skew < 0.01);
+ assert(std::abs(kurtosis - x_kurtosis) / x_kurtosis < 0.01);
+ }
+}
Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/eval_param.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/eval_param.pass.cpp?rev=103937&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/eval_param.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/eval_param.pass.cpp Mon May 17 08:44:27 2010
@@ -0,0 +1,158 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class IntType = int>
+// class geometric_distribution
+
+// template<class _URNG> result_type operator()(_URNG& g, const param_type& parm);
+
+#include <random>
+#include <numeric>
+#include <vector>
+#include <cassert>
+
+template <class T>
+inline
+T
+sqr(T x)
+{
+ return x * x;
+}
+
+int main()
+{
+ {
+ typedef std::geometric_distribution<> D;
+ typedef D::param_type P;
+ typedef std::mt19937 G;
+ G g;
+ D d(.75);
+ P p(.03125);
+ const int N = 1000000;
+ std::vector<D::result_type> u;
+ for (int i = 0; i < N; ++i)
+ {
+ D::result_type v = d(g, p);
+ assert(d.min() <= v && v <= d.max());
+ u.push_back(v);
+ }
+ double mean = std::accumulate(u.begin(), u.end(),
+ double(0)) / u.size();
+ double var = 0;
+ double skew = 0;
+ double kurtosis = 0;
+ for (int i = 0; i < u.size(); ++i)
+ {
+ double d = (u[i] - mean);
+ double d2 = sqr(d);
+ var += d2;
+ skew += d * d2;
+ kurtosis += d2 * d2;
+ }
+ var /= u.size();
+ double dev = std::sqrt(var);
+ skew /= u.size() * dev * var;
+ kurtosis /= u.size() * var * var;
+ kurtosis -= 3;
+ double x_mean = (1 - p.p()) / p.p();
+ double x_var = x_mean / p.p();
+ double x_skew = (2 - p.p()) / std::sqrt((1 - p.p()));
+ double x_kurtosis = 6 + sqr(p.p()) / (1 - p.p());
+ assert(std::abs(mean - x_mean) / x_mean < 0.01);
+ assert(std::abs(var - x_var) / x_var < 0.01);
+ assert(std::abs(skew - x_skew) / x_skew < 0.01);
+ assert(std::abs(kurtosis - x_kurtosis) / x_kurtosis < 0.01);
+ }
+ {
+ typedef std::geometric_distribution<> D;
+ typedef D::param_type P;
+ typedef std::mt19937 G;
+ G g;
+ D d(.75);
+ P p(.25);
+ const int N = 1000000;
+ std::vector<D::result_type> u;
+ for (int i = 0; i < N; ++i)
+ {
+ D::result_type v = d(g, p);
+ assert(d.min() <= v && v <= d.max());
+ u.push_back(v);
+ }
+ double mean = std::accumulate(u.begin(), u.end(),
+ double(0)) / u.size();
+ double var = 0;
+ double skew = 0;
+ double kurtosis = 0;
+ for (int i = 0; i < u.size(); ++i)
+ {
+ double d = (u[i] - mean);
+ double d2 = sqr(d);
+ var += d2;
+ skew += d * d2;
+ kurtosis += d2 * d2;
+ }
+ var /= u.size();
+ double dev = std::sqrt(var);
+ skew /= u.size() * dev * var;
+ kurtosis /= u.size() * var * var;
+ kurtosis -= 3;
+ double x_mean = (1 - p.p()) / p.p();
+ double x_var = x_mean / p.p();
+ double x_skew = (2 - p.p()) / std::sqrt((1 - p.p()));
+ double x_kurtosis = 6 + sqr(p.p()) / (1 - p.p());
+ assert(std::abs(mean - x_mean) / x_mean < 0.01);
+ assert(std::abs(var - x_var) / x_var < 0.01);
+ assert(std::abs(skew - x_skew) / x_skew < 0.01);
+ assert(std::abs(kurtosis - x_kurtosis) / x_kurtosis < 0.03);
+ }
+ {
+ typedef std::geometric_distribution<> D;
+ typedef D::param_type P;
+ typedef std::minstd_rand G;
+ G g;
+ D d(.5);
+ P p(.75);
+ const int N = 1000000;
+ std::vector<D::result_type> u;
+ for (int i = 0; i < N; ++i)
+ {
+ D::result_type v = d(g, p);
+ assert(d.min() <= v && v <= d.max());
+ u.push_back(v);
+ }
+ double mean = std::accumulate(u.begin(), u.end(),
+ double(0)) / u.size();
+ double var = 0;
+ double skew = 0;
+ double kurtosis = 0;
+ for (int i = 0; i < u.size(); ++i)
+ {
+ double d = (u[i] - mean);
+ double d2 = sqr(d);
+ var += d2;
+ skew += d * d2;
+ kurtosis += d2 * d2;
+ }
+ var /= u.size();
+ double dev = std::sqrt(var);
+ skew /= u.size() * dev * var;
+ kurtosis /= u.size() * var * var;
+ kurtosis -= 3;
+ double x_mean = (1 - p.p()) / p.p();
+ double x_var = x_mean / p.p();
+ double x_skew = (2 - p.p()) / std::sqrt((1 - p.p()));
+ double x_kurtosis = 6 + sqr(p.p()) / (1 - p.p());
+ assert(std::abs(mean - x_mean) / x_mean < 0.01);
+ assert(std::abs(var - x_var) / x_var < 0.01);
+ assert(std::abs(skew - x_skew) / x_skew < 0.01);
+ assert(std::abs(kurtosis - x_kurtosis) / x_kurtosis < 0.01);
+ }
+}
Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/get_param.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/get_param.pass.cpp?rev=103937&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/get_param.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/get_param.pass.cpp Mon May 17 08:44:27 2010
@@ -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.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class IntType = int>
+// class geometric_distribution
+
+// param_type param() const;
+
+#include <random>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef std::geometric_distribution<> D;
+ typedef D::param_type P;
+ P p(.125);
+ D d(p);
+ assert(d.param() == p);
+ }
+}
Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/io.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/io.pass.cpp?rev=103937&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/io.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/io.pass.cpp Mon May 17 08:44:27 2010
@@ -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.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class IntType = int>
+// class geometric_distribution
+
+// template <class charT, class traits>
+// basic_ostream<charT, traits>&
+// operator<<(basic_ostream<charT, traits>& os,
+// const geometric_distribution& x);
+//
+// template <class charT, class traits>
+// basic_istream<charT, traits>&
+// operator>>(basic_istream<charT, traits>& is,
+// geometric_distribution& x);
+
+#include <random>
+#include <sstream>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef std::geometric_distribution<> D;
+ D d1(.25);
+ std::ostringstream os;
+ os << d1;
+ std::istringstream is(os.str());
+ D d2;
+ is >> d2;
+ assert(d1 == d2);
+ }
+}
Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/max.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/max.pass.cpp?rev=103937&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/max.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/max.pass.cpp Mon May 17 08:44:27 2010
@@ -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.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class IntType = int>
+// class geometric_distribution
+
+// result_type max() const;
+
+#include <random>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef std::geometric_distribution<> D;
+ D d(.25);
+ assert(d.max() == std::numeric_limits<int>::max());
+ }
+}
Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/min.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/min.pass.cpp?rev=103937&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/min.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/min.pass.cpp Mon May 17 08:44:27 2010
@@ -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.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class IntType = int>
+// class geometric_distribution
+
+// result_type min() const;
+
+#include <random>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef std::geometric_distribution<> D;
+ D d(.5);
+ assert(d.min() == 0);
+ }
+}
Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_assign.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_assign.pass.cpp?rev=103937&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_assign.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_assign.pass.cpp Mon May 17 08:44:27 2010
@@ -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.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class IntType = int>
+// class geometric_distribution
+// {
+// class param_type;
+
+#include <random>
+#include <limits>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef std::geometric_distribution<> D;
+ typedef D::param_type param_type;
+ param_type p0(.7);
+ param_type p;
+ p = p0;
+ assert(p.p() == .7);
+ }
+}
Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_copy.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_copy.pass.cpp?rev=103937&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_copy.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_copy.pass.cpp Mon May 17 08:44:27 2010
@@ -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.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class IntType = int>
+// class geometric_distribution
+// {
+// class param_type;
+
+#include <random>
+#include <limits>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef std::geometric_distribution<> D;
+ typedef D::param_type param_type;
+ param_type p0(.125);
+ param_type p = p0;
+ assert(p.p() == .125);
+ }
+}
Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_ctor.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_ctor.pass.cpp?rev=103937&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_ctor.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_ctor.pass.cpp Mon May 17 08:44:27 2010
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class IntType = int>
+// class geometric_distribution
+// {
+// class param_type;
+
+#include <random>
+#include <limits>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef std::geometric_distribution<> D;
+ typedef D::param_type param_type;
+ param_type p;
+ assert(p.p() == 0.5);
+ }
+ {
+ typedef std::geometric_distribution<> D;
+ typedef D::param_type param_type;
+ param_type p(0.25);
+ assert(p.p() == 0.25);
+ }
+}
Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_eq.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_eq.pass.cpp?rev=103937&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_eq.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_eq.pass.cpp Mon May 17 08:44:27 2010
@@ -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.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class IntType = int>
+// class geometric_distribution
+// {
+// class param_type;
+
+#include <random>
+#include <limits>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef std::geometric_distribution<> D;
+ typedef D::param_type param_type;
+ param_type p1(0.75);
+ param_type p2(0.75);
+ assert(p1 == p2);
+ }
+ {
+ typedef std::geometric_distribution<> D;
+ typedef D::param_type param_type;
+ param_type p1(0.75);
+ param_type p2(0.5);
+ assert(p1 != p2);
+ }
+}
Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_types.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_types.pass.cpp?rev=103937&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_types.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/param_types.pass.cpp Mon May 17 08:44:27 2010
@@ -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.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class IntType = int>
+// class geometric_distribution
+// {
+// class param_type;
+
+#include <random>
+#include <type_traits>
+
+int main()
+{
+ {
+ typedef std::geometric_distribution<> D;
+ typedef D::param_type param_type;
+ typedef param_type::distribution_type distribution_type;
+ static_assert((std::is_same<D, distribution_type>::value), "");
+ }
+}
Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/set_param.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/set_param.pass.cpp?rev=103937&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/set_param.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/set_param.pass.cpp Mon May 17 08:44:27 2010
@@ -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.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class IntType = int>
+// class geometric_distribution
+
+// void param(const param_type& parm);
+
+#include <random>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef std::geometric_distribution<> D;
+ typedef D::param_type P;
+ P p(0.25);
+ D d(0.75);
+ d.param(p);
+ assert(d.param() == p);
+ }
+}
Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/types.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/types.pass.cpp?rev=103937&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/types.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.geo/types.pass.cpp Mon May 17 08:44:27 2010
@@ -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.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class IntType = int>
+// class geometric_distribution
+// {
+// typedef bool result_type;
+
+#include <random>
+#include <type_traits>
+
+int main()
+{
+ {
+ typedef std::geometric_distribution<> D;
+ typedef D::result_type result_type;
+ static_assert((std::is_same<result_type, int>::value), "");
+ }
+ {
+ typedef std::geometric_distribution<long> D;
+ typedef D::result_type result_type;
+ static_assert((std::is_same<result_type, long>::value), "");
+ }
+}
More information about the cfe-commits
mailing list