Marshall Clow found some divide-by-zero warnings with UBSan in rand's binomial_distribution test. This eliminates the divide-by-zeros and describes in comments the numerical difficulties the test is having. Each of the problematic tests are exploring edge cases of the distribution.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@177826 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
9976b5511a
commit
ae7bf9daac
@ -177,15 +177,23 @@ int main()
|
|||||||
}
|
}
|
||||||
var /= u.size();
|
var /= u.size();
|
||||||
double dev = std::sqrt(var);
|
double dev = std::sqrt(var);
|
||||||
skew /= u.size() * dev * var;
|
// In this case:
|
||||||
kurtosis /= u.size() * var * var;
|
// skew computes to 0./0. == nan
|
||||||
kurtosis -= 3;
|
// kurtosis computes to 0./0. == nan
|
||||||
|
// x_skew == inf
|
||||||
|
// x_kurtosis == inf
|
||||||
|
// These tests are commented out because UBSan warns about division by 0
|
||||||
|
// skew /= u.size() * dev * var;
|
||||||
|
// kurtosis /= u.size() * var * var;
|
||||||
|
// kurtosis -= 3;
|
||||||
double x_mean = d.t() * d.p();
|
double x_mean = d.t() * d.p();
|
||||||
double x_var = x_mean*(1-d.p());
|
double x_var = x_mean*(1-d.p());
|
||||||
double x_skew = (1-2*d.p()) / std::sqrt(x_var);
|
// double x_skew = (1-2*d.p()) / std::sqrt(x_var);
|
||||||
double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
|
// double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
|
||||||
assert(mean == x_mean);
|
assert(mean == x_mean);
|
||||||
assert(var == x_var);
|
assert(var == x_var);
|
||||||
|
// assert(skew == x_skew);
|
||||||
|
// assert(kurtosis == x_kurtosis);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
typedef std::binomial_distribution<> D;
|
typedef std::binomial_distribution<> D;
|
||||||
@ -215,15 +223,23 @@ int main()
|
|||||||
}
|
}
|
||||||
var /= u.size();
|
var /= u.size();
|
||||||
double dev = std::sqrt(var);
|
double dev = std::sqrt(var);
|
||||||
skew /= u.size() * dev * var;
|
// In this case:
|
||||||
kurtosis /= u.size() * var * var;
|
// skew computes to 0./0. == nan
|
||||||
kurtosis -= 3;
|
// kurtosis computes to 0./0. == nan
|
||||||
|
// x_skew == -inf
|
||||||
|
// x_kurtosis == inf
|
||||||
|
// These tests are commented out because UBSan warns about division by 0
|
||||||
|
// skew /= u.size() * dev * var;
|
||||||
|
// kurtosis /= u.size() * var * var;
|
||||||
|
// kurtosis -= 3;
|
||||||
double x_mean = d.t() * d.p();
|
double x_mean = d.t() * d.p();
|
||||||
double x_var = x_mean*(1-d.p());
|
double x_var = x_mean*(1-d.p());
|
||||||
double x_skew = (1-2*d.p()) / std::sqrt(x_var);
|
// double x_skew = (1-2*d.p()) / std::sqrt(x_var);
|
||||||
double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
|
// double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
|
||||||
assert(mean == x_mean);
|
assert(mean == x_mean);
|
||||||
assert(var == x_var);
|
assert(var == x_var);
|
||||||
|
// assert(skew == x_skew);
|
||||||
|
// assert(kurtosis == x_kurtosis);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
typedef std::binomial_distribution<> D;
|
typedef std::binomial_distribution<> D;
|
||||||
@ -333,15 +349,23 @@ int main()
|
|||||||
}
|
}
|
||||||
var /= u.size();
|
var /= u.size();
|
||||||
double dev = std::sqrt(var);
|
double dev = std::sqrt(var);
|
||||||
skew /= u.size() * dev * var;
|
// In this case:
|
||||||
kurtosis /= u.size() * var * var;
|
// skew computes to 0./0. == nan
|
||||||
kurtosis -= 3;
|
// kurtosis computes to 0./0. == nan
|
||||||
|
// x_skew == inf
|
||||||
|
// x_kurtosis == inf
|
||||||
|
// These tests are commented out because UBSan warns about division by 0
|
||||||
|
// skew /= u.size() * dev * var;
|
||||||
|
// kurtosis /= u.size() * var * var;
|
||||||
|
// kurtosis -= 3;
|
||||||
double x_mean = d.t() * d.p();
|
double x_mean = d.t() * d.p();
|
||||||
double x_var = x_mean*(1-d.p());
|
double x_var = x_mean*(1-d.p());
|
||||||
double x_skew = (1-2*d.p()) / std::sqrt(x_var);
|
// double x_skew = (1-2*d.p()) / std::sqrt(x_var);
|
||||||
double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
|
// double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
|
||||||
assert(mean == x_mean);
|
assert(mean == x_mean);
|
||||||
assert(var == x_var);
|
assert(var == x_var);
|
||||||
|
// assert(skew == x_skew);
|
||||||
|
// assert(kurtosis == x_kurtosis);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
typedef std::binomial_distribution<> D;
|
typedef std::binomial_distribution<> D;
|
||||||
@ -371,15 +395,23 @@ int main()
|
|||||||
}
|
}
|
||||||
var /= u.size();
|
var /= u.size();
|
||||||
double dev = std::sqrt(var);
|
double dev = std::sqrt(var);
|
||||||
skew /= u.size() * dev * var;
|
// In this case:
|
||||||
kurtosis /= u.size() * var * var;
|
// skew computes to 0./0. == nan
|
||||||
kurtosis -= 3;
|
// kurtosis computes to 0./0. == nan
|
||||||
|
// x_skew == inf
|
||||||
|
// x_kurtosis == inf
|
||||||
|
// These tests are commented out because UBSan warns about division by 0
|
||||||
|
// skew /= u.size() * dev * var;
|
||||||
|
// kurtosis /= u.size() * var * var;
|
||||||
|
// kurtosis -= 3;
|
||||||
double x_mean = d.t() * d.p();
|
double x_mean = d.t() * d.p();
|
||||||
double x_var = x_mean*(1-d.p());
|
double x_var = x_mean*(1-d.p());
|
||||||
double x_skew = (1-2*d.p()) / std::sqrt(x_var);
|
// double x_skew = (1-2*d.p()) / std::sqrt(x_var);
|
||||||
double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
|
// double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
|
||||||
assert(mean == x_mean);
|
assert(mean == x_mean);
|
||||||
assert(var == x_var);
|
assert(var == x_var);
|
||||||
|
// assert(skew == x_skew);
|
||||||
|
// assert(kurtosis == x_kurtosis);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
typedef std::binomial_distribution<> D;
|
typedef std::binomial_distribution<> D;
|
||||||
@ -409,14 +441,22 @@ int main()
|
|||||||
}
|
}
|
||||||
var /= u.size();
|
var /= u.size();
|
||||||
double dev = std::sqrt(var);
|
double dev = std::sqrt(var);
|
||||||
skew /= u.size() * dev * var;
|
// In this case:
|
||||||
kurtosis /= u.size() * var * var;
|
// skew computes to 0./0. == nan
|
||||||
kurtosis -= 3;
|
// kurtosis computes to 0./0. == nan
|
||||||
|
// x_skew == -inf
|
||||||
|
// x_kurtosis == inf
|
||||||
|
// These tests are commented out because UBSan warns about division by 0
|
||||||
|
// skew /= u.size() * dev * var;
|
||||||
|
// kurtosis /= u.size() * var * var;
|
||||||
|
// kurtosis -= 3;
|
||||||
double x_mean = d.t() * d.p();
|
double x_mean = d.t() * d.p();
|
||||||
double x_var = x_mean*(1-d.p());
|
double x_var = x_mean*(1-d.p());
|
||||||
double x_skew = (1-2*d.p()) / std::sqrt(x_var);
|
// double x_skew = (1-2*d.p()) / std::sqrt(x_var);
|
||||||
double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
|
// double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
|
||||||
assert(mean == x_mean);
|
assert(mean == x_mean);
|
||||||
assert(var == x_var);
|
assert(var == x_var);
|
||||||
|
// assert(skew == x_skew);
|
||||||
|
// assert(kurtosis == x_kurtosis);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user