Skip to content

Commit

Permalink
[libc++] Fix warning C4244 in std/numerics/rand/rand.dist/rand.dist.s…
Browse files Browse the repository at this point in the history
…amp/rand.dist.samp.discrete/eval.pass.cpp

frederick-vs-ja noticed that microsoft/STL#2976 (comment)
while we are working on updating LLVM submodule for MS STL:

    [...]\std\numerics\rand\rand.dist\rand.dist.samp\rand.dist.samp.discrete\eval.pass.cpp(33): error C2220: the following warning is treated as an error
    [...]\std\numerics\rand\rand.dist\rand.dist.samp\rand.dist.samp.discrete\eval.pass.cpp(287): note: see reference to function template instantiation 'void tests<__int64>(void)' being compiled
    [...]\std\numerics\rand\rand.dist\rand.dist.samp\rand.dist.samp.discrete\eval.pass.cpp(33): warning C4244: 'argument': conversion from '__int64' to 'const unsigned int', possible loss of data

Differential Revision: https://reviews.llvm.org/D130963
  • Loading branch information
fsb4000 authored and ldionne committed Aug 3, 2022
1 parent d434e40 commit db0ac30
Showing 1 changed file with 39 additions and 26 deletions.
Expand Up @@ -30,12 +30,13 @@ void tests() {
G g;
D d;
const int N = 100;
std::vector<Frequency> u(d.max()+1);
std::vector<Frequency> u(static_cast<std::size_t>(d.max()+1));
assert(u.max_size() > static_cast<unsigned long long>(d.max()));
for (int i = 0; i < N; ++i)
{
typename D::result_type v = d(g);
assert(d.min() <= v && v <= d.max());
u[v]++;
u[static_cast<std::size_t>(v)]++;
}
std::vector<double> prob = d.probabilities();
for (unsigned i = 0; i < u.size(); ++i)
Expand All @@ -48,12 +49,13 @@ void tests() {
double p0[] = {.3};
D d(p0, p0+1);
const int N = 100;
std::vector<Frequency> u(d.max()+1);
std::vector<Frequency> u(static_cast<std::size_t>(d.max()+1));
assert(u.max_size() > static_cast<unsigned long long>(d.max()));
for (int i = 0; i < N; ++i)
{
typename D::result_type v = d(g);
assert(d.min() <= v && v <= d.max());
u[v]++;
u[static_cast<std::size_t>(v)]++;
}
std::vector<double> prob = d.probabilities();
for (unsigned i = 0; i < u.size(); ++i)
Expand All @@ -66,12 +68,13 @@ void tests() {
double p0[] = {.75, .25};
D d(p0, p0+2);
const int N = 1000000;
std::vector<Frequency> u(d.max()+1);
std::vector<Frequency> u(static_cast<std::size_t>(d.max()+1));
assert(u.max_size() > static_cast<unsigned long long>(d.max()));
for (int i = 0; i < N; ++i)
{
typename D::result_type v = d(g);
assert(d.min() <= v && v <= d.max());
u[v]++;
u[static_cast<std::size_t>(v)]++;
}
std::vector<double> prob = d.probabilities();
for (unsigned i = 0; i < u.size(); ++i)
Expand All @@ -84,12 +87,13 @@ void tests() {
double p0[] = {0, 1};
D d(p0, p0+2);
const int N = 1000000;
std::vector<Frequency> u(d.max()+1);
std::vector<Frequency> u(static_cast<std::size_t>(d.max()+1));
assert(u.max_size() > static_cast<unsigned long long>(d.max()));
for (int i = 0; i < N; ++i)
{
typename D::result_type v = d(g);
assert(d.min() <= v && v <= d.max());
u[v]++;
u[static_cast<std::size_t>(v)]++;
}
std::vector<double> prob = d.probabilities();
assert((double)u[0]/N == prob[0]);
Expand All @@ -102,12 +106,13 @@ void tests() {
double p0[] = {1, 0};
D d(p0, p0+2);
const int N = 1000000;
std::vector<Frequency> u(d.max()+1);
std::vector<Frequency> u(static_cast<std::size_t>(d.max()+1));
assert(u.max_size() > static_cast<unsigned long long>(d.max()));
for (int i = 0; i < N; ++i)
{
typename D::result_type v = d(g);
assert(d.min() <= v && v <= d.max());
u[v]++;
u[static_cast<std::size_t>(v)]++;
}
std::vector<double> prob = d.probabilities();
assert((double)u[0]/N == prob[0]);
Expand All @@ -120,12 +125,13 @@ void tests() {
double p0[] = {.3, .1, .6};
D d(p0, p0+3);
const int N = 10000000;
std::vector<Frequency> u(d.max()+1);
std::vector<Frequency> u(static_cast<std::size_t>(d.max()+1));
assert(u.max_size() > static_cast<unsigned long long>(d.max()));
for (int i = 0; i < N; ++i)
{
typename D::result_type v = d(g);
assert(d.min() <= v && v <= d.max());
u[v]++;
u[static_cast<std::size_t>(v)]++;
}
std::vector<double> prob = d.probabilities();
for (unsigned i = 0; i < u.size(); ++i)
Expand All @@ -138,12 +144,13 @@ void tests() {
double p0[] = {0, 25, 75};
D d(p0, p0+3);
const int N = 1000000;
std::vector<Frequency> u(d.max()+1);
std::vector<Frequency> u(static_cast<std::size_t>(d.max()+1));
assert(u.max_size() > static_cast<unsigned long long>(d.max()));
for (int i = 0; i < N; ++i)
{
typename D::result_type v = d(g);
assert(d.min() <= v && v <= d.max());
u[v]++;
u[static_cast<std::size_t>(v)]++;
}
std::vector<double> prob = d.probabilities();
for (unsigned i = 0; i < u.size(); ++i)
Expand All @@ -159,12 +166,13 @@ void tests() {
double p0[] = {25, 0, 75};
D d(p0, p0+3);
const int N = 1000000;
std::vector<Frequency> u(d.max()+1);
std::vector<Frequency> u(static_cast<std::size_t>(d.max()+1));
assert(u.max_size() > static_cast<unsigned long long>(d.max()));
for (int i = 0; i < N; ++i)
{
typename D::result_type v = d(g);
assert(d.min() <= v && v <= d.max());
u[v]++;
u[static_cast<std::size_t>(v)]++;
}
std::vector<double> prob = d.probabilities();
for (unsigned i = 0; i < u.size(); ++i)
Expand All @@ -180,12 +188,13 @@ void tests() {
double p0[] = {25, 75, 0};
D d(p0, p0+3);
const int N = 1000000;
std::vector<Frequency> u(d.max()+1);
std::vector<Frequency> u(static_cast<std::size_t>(d.max()+1));
assert(u.max_size() > static_cast<unsigned long long>(d.max()));
for (int i = 0; i < N; ++i)
{
typename D::result_type v = d(g);
assert(d.min() <= v && v <= d.max());
u[v]++;
u[static_cast<std::size_t>(v)]++;
}
std::vector<double> prob = d.probabilities();
for (unsigned i = 0; i < u.size(); ++i)
Expand All @@ -201,12 +210,13 @@ void tests() {
double p0[] = {0, 0, 1};
D d(p0, p0+3);
const int N = 100;
std::vector<Frequency> u(d.max()+1);
std::vector<Frequency> u(static_cast<std::size_t>(d.max()+1));
assert(u.max_size() > static_cast<unsigned long long>(d.max()));
for (int i = 0; i < N; ++i)
{
typename D::result_type v = d(g);
assert(d.min() <= v && v <= d.max());
u[v]++;
u[static_cast<std::size_t>(v)]++;
}
std::vector<double> prob = d.probabilities();
for (unsigned i = 0; i < u.size(); ++i)
Expand All @@ -222,12 +232,13 @@ void tests() {
double p0[] = {0, 1, 0};
D d(p0, p0+3);
const int N = 100;
std::vector<Frequency> u(d.max()+1);
std::vector<Frequency> u(static_cast<std::size_t>(d.max()+1));
assert(u.max_size() > static_cast<unsigned long long>(d.max()));
for (int i = 0; i < N; ++i)
{
typename D::result_type v = d(g);
assert(d.min() <= v && v <= d.max());
u[v]++;
u[static_cast<std::size_t>(v)]++;
}
std::vector<double> prob = d.probabilities();
for (unsigned i = 0; i < u.size(); ++i)
Expand All @@ -243,12 +254,13 @@ void tests() {
double p0[] = {1, 0, 0};
D d(p0, p0+3);
const int N = 100;
std::vector<Frequency> u(d.max()+1);
std::vector<Frequency> u(static_cast<std::size_t>(d.max()+1));
assert(u.max_size() > static_cast<unsigned long long>(d.max()));
for (int i = 0; i < N; ++i)
{
typename D::result_type v = d(g);
assert(d.min() <= v && v <= d.max());
u[v]++;
u[static_cast<std::size_t>(v)]++;
}
std::vector<double> prob = d.probabilities();
for (unsigned i = 0; i < u.size(); ++i)
Expand All @@ -264,12 +276,13 @@ void tests() {
double p0[] = {33, 0, 0, 67};
D d(p0, p0+3);
const int N = 1000000;
std::vector<Frequency> u(d.max()+1);
std::vector<Frequency> u(static_cast<std::size_t>(d.max()+1));
assert(u.max_size() > static_cast<unsigned long long>(d.max()));
for (int i = 0; i < N; ++i)
{
typename D::result_type v = d(g);
assert(d.min() <= v && v <= d.max());
u[v]++;
u[static_cast<std::size_t>(v)]++;
}
std::vector<double> prob = d.probabilities();
for (unsigned i = 0; i < u.size(); ++i)
Expand Down

0 comments on commit db0ac30

Please sign in to comment.