[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / numerics / rand / rand.dist / rand.dist.pois / rand.dist.pois.poisson / eval_param.pass.cpp
blob8d60be4e656e4341fbacd58bace45bc650518e10
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // REQUIRES: long_tests
11 // <random>
13 // template<class IntType = int>
14 // class poisson_distribution
16 // template<class _URNG> result_type operator()(_URNG& g, const param_type& parm);
18 #include <random>
19 #include <cassert>
20 #include <vector>
21 #include <numeric>
23 #include "test_macros.h"
25 template <class T>
26 inline
28 sqr(T x)
30 return x * x;
33 int main(int, char**)
36 typedef std::poisson_distribution<> D;
37 typedef D::param_type P;
38 typedef std::minstd_rand G;
39 G g;
40 D d(.75);
41 P p(2);
42 const int N = 100000;
43 std::vector<double> u;
44 for (int i = 0; i < N; ++i)
46 D::result_type v = d(g, p);
47 assert(d.min() <= v && v <= d.max());
48 u.push_back(v);
50 double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size();
51 double var = 0;
52 double skew = 0;
53 double kurtosis = 0;
54 for (unsigned i = 0; i < u.size(); ++i)
56 double dbl = (u[i] - mean);
57 double d2 = sqr(dbl);
58 var += d2;
59 skew += dbl * d2;
60 kurtosis += d2 * d2;
62 var /= u.size();
63 double dev = std::sqrt(var);
64 skew /= u.size() * dev * var;
65 kurtosis /= u.size() * var * var;
66 kurtosis -= 3;
67 double x_mean = p.mean();
68 double x_var = p.mean();
69 double x_skew = 1 / std::sqrt(x_var);
70 double x_kurtosis = 1 / x_var;
71 assert(std::abs((mean - x_mean) / x_mean) < 0.01);
72 assert(std::abs((var - x_var) / x_var) < 0.01);
73 assert(std::abs((skew - x_skew) / x_skew) < 0.01);
74 assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.03);
77 typedef std::poisson_distribution<> D;
78 typedef D::param_type P;
79 typedef std::minstd_rand G;
80 G g;
81 D d(2);
82 P p(.75);
83 const int N = 100000;
84 std::vector<double> u;
85 for (int i = 0; i < N; ++i)
87 D::result_type v = d(g, p);
88 assert(d.min() <= v && v <= d.max());
89 u.push_back(v);
91 double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size();
92 double var = 0;
93 double skew = 0;
94 double kurtosis = 0;
95 for (unsigned i = 0; i < u.size(); ++i)
97 double dbl = (u[i] - mean);
98 double d2 = sqr(dbl);
99 var += d2;
100 skew += dbl * d2;
101 kurtosis += d2 * d2;
103 var /= u.size();
104 double dev = std::sqrt(var);
105 skew /= u.size() * dev * var;
106 kurtosis /= u.size() * var * var;
107 kurtosis -= 3;
108 double x_mean = p.mean();
109 double x_var = p.mean();
110 double x_skew = 1 / std::sqrt(x_var);
111 double x_kurtosis = 1 / x_var;
112 assert(std::abs((mean - x_mean) / x_mean) < 0.01);
113 assert(std::abs((var - x_var) / x_var) < 0.01);
114 assert(std::abs((skew - x_skew) / x_skew) < 0.01);
115 assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.04);
118 typedef std::poisson_distribution<> D;
119 typedef D::param_type P;
120 typedef std::mt19937 G;
121 G g;
122 D d(2);
123 P p(20);
124 const int N = 1000000;
125 std::vector<double> u;
126 for (int i = 0; i < N; ++i)
128 D::result_type v = d(g, p);
129 assert(d.min() <= v && v <= d.max());
130 u.push_back(v);
132 double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size();
133 double var = 0;
134 double skew = 0;
135 double kurtosis = 0;
136 for (unsigned i = 0; i < u.size(); ++i)
138 double dbl = (u[i] - mean);
139 double d2 = sqr(dbl);
140 var += d2;
141 skew += dbl * d2;
142 kurtosis += d2 * d2;
144 var /= u.size();
145 double dev = std::sqrt(var);
146 skew /= u.size() * dev * var;
147 kurtosis /= u.size() * var * var;
148 kurtosis -= 3;
149 double x_mean = p.mean();
150 double x_var = p.mean();
151 double x_skew = 1 / std::sqrt(x_var);
152 double x_kurtosis = 1 / x_var;
153 assert(std::abs((mean - x_mean) / x_mean) < 0.01);
154 assert(std::abs((var - x_var) / x_var) < 0.01);
155 assert(std::abs((skew - x_skew) / x_skew) < 0.01);
156 assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01);
159 return 0;