LWG 1439
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@119703 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
2f6a627394
commit
9650b6cce3
@ -5922,10 +5922,9 @@ public:
|
|||||||
|
|
||||||
class _LIBCPP_VISIBLE param_type
|
class _LIBCPP_VISIBLE param_type
|
||||||
{
|
{
|
||||||
typedef typename common_type<double, result_type>::type __area_type;
|
|
||||||
vector<result_type> __b_;
|
vector<result_type> __b_;
|
||||||
vector<double> __densities_;
|
vector<result_type> __densities_;
|
||||||
vector<__area_type> __areas_;
|
vector<result_type> __areas_;
|
||||||
public:
|
public:
|
||||||
typedef piecewise_constant_distribution distribution_type;
|
typedef piecewise_constant_distribution distribution_type;
|
||||||
|
|
||||||
@ -5943,7 +5942,7 @@ public:
|
|||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
vector<result_type> intervals() const {return __b_;}
|
vector<result_type> intervals() const {return __b_;}
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
vector<double> densities() const {return __densities_;}
|
vector<result_type> densities() const {return __densities_;}
|
||||||
|
|
||||||
friend _LIBCPP_INLINE_VISIBILITY
|
friend _LIBCPP_INLINE_VISIBILITY
|
||||||
bool operator==(const param_type& __x, const param_type& __y)
|
bool operator==(const param_type& __x, const param_type& __y)
|
||||||
@ -6014,7 +6013,7 @@ public:
|
|||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
vector<result_type> intervals() const {return __p_.intervals();}
|
vector<result_type> intervals() const {return __p_.intervals();}
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
vector<double> densities() const {return __p_.densities();}
|
vector<result_type> densities() const {return __p_.densities();}
|
||||||
|
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
param_type param() const {return __p_;}
|
param_type param() const {return __p_;}
|
||||||
@ -6070,13 +6069,13 @@ void
|
|||||||
piecewise_constant_distribution<_RealType>::param_type::__init()
|
piecewise_constant_distribution<_RealType>::param_type::__init()
|
||||||
{
|
{
|
||||||
// __densities_ contains non-normalized areas
|
// __densities_ contains non-normalized areas
|
||||||
__area_type __total_area = _STD::accumulate(__densities_.begin(),
|
result_type __total_area = _STD::accumulate(__densities_.begin(),
|
||||||
__densities_.end(),
|
__densities_.end(),
|
||||||
__area_type());
|
result_type());
|
||||||
for (size_t __i = 0; __i < __densities_.size(); ++__i)
|
for (size_t __i = 0; __i < __densities_.size(); ++__i)
|
||||||
__densities_[__i] /= __total_area;
|
__densities_[__i] /= __total_area;
|
||||||
// __densities_ contains normalized areas
|
// __densities_ contains normalized areas
|
||||||
__areas_.assign(__densities_.size(), __area_type());
|
__areas_.assign(__densities_.size(), result_type());
|
||||||
_STD::partial_sum(__densities_.begin(), __densities_.end() - 1,
|
_STD::partial_sum(__densities_.begin(), __densities_.end() - 1,
|
||||||
__areas_.begin() + 1);
|
__areas_.begin() + 1);
|
||||||
// __areas_ contains partial sums of normalized areas: [0, __densities_ - 1]
|
// __areas_ contains partial sums of normalized areas: [0, __densities_ - 1]
|
||||||
@ -6167,9 +6166,8 @@ piecewise_constant_distribution<_RealType>::operator()(_URNG& __g, const param_t
|
|||||||
typedef uniform_real_distribution<result_type> _Gen;
|
typedef uniform_real_distribution<result_type> _Gen;
|
||||||
result_type __u = _Gen()(__g);
|
result_type __u = _Gen()(__g);
|
||||||
ptrdiff_t __k = _STD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(),
|
ptrdiff_t __k = _STD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(),
|
||||||
static_cast<double>(__u)) - __p.__areas_.begin() - 1;
|
__u) - __p.__areas_.begin() - 1;
|
||||||
return static_cast<result_type>((__u - __p.__areas_[__k]) / __p.__densities_[__k]
|
return (__u - __p.__areas_[__k]) / __p.__densities_[__k] + __p.__b_[__k];
|
||||||
+ __p.__b_[__k]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class _CharT, class _Traits, class _RT>
|
template <class _CharT, class _Traits, class _RT>
|
||||||
@ -6205,7 +6203,6 @@ operator>>(basic_istream<_CharT, _Traits>& __is,
|
|||||||
typedef piecewise_constant_distribution<_RT> _Eng;
|
typedef piecewise_constant_distribution<_RT> _Eng;
|
||||||
typedef typename _Eng::result_type result_type;
|
typedef typename _Eng::result_type result_type;
|
||||||
typedef typename _Eng::param_type param_type;
|
typedef typename _Eng::param_type param_type;
|
||||||
typedef typename param_type::__area_type __area_type;
|
|
||||||
__save_flags<_CharT, _Traits> _(__is);
|
__save_flags<_CharT, _Traits> _(__is);
|
||||||
__is.flags(ios_base::dec | ios_base::skipws);
|
__is.flags(ios_base::dec | ios_base::skipws);
|
||||||
size_t __n;
|
size_t __n;
|
||||||
@ -6214,11 +6211,11 @@ operator>>(basic_istream<_CharT, _Traits>& __is,
|
|||||||
for (size_t __i = 0; __i < __n; ++__i)
|
for (size_t __i = 0; __i < __n; ++__i)
|
||||||
__is >> __b[__i];
|
__is >> __b[__i];
|
||||||
__is >> __n;
|
__is >> __n;
|
||||||
vector<double> __densities(__n);
|
vector<result_type> __densities(__n);
|
||||||
for (size_t __i = 0; __i < __n; ++__i)
|
for (size_t __i = 0; __i < __n; ++__i)
|
||||||
__is >> __densities[__i];
|
__is >> __densities[__i];
|
||||||
__is >> __n;
|
__is >> __n;
|
||||||
vector<__area_type> __areas(__n);
|
vector<result_type> __areas(__n);
|
||||||
for (size_t __i = 0; __i < __n; ++__i)
|
for (size_t __i = 0; __i < __n; ++__i)
|
||||||
__is >> __areas[__i];
|
__is >> __areas[__i];
|
||||||
if (!__is.fail())
|
if (!__is.fail())
|
||||||
@ -6241,10 +6238,9 @@ public:
|
|||||||
|
|
||||||
class _LIBCPP_VISIBLE param_type
|
class _LIBCPP_VISIBLE param_type
|
||||||
{
|
{
|
||||||
typedef typename common_type<double, result_type>::type __area_type;
|
|
||||||
vector<result_type> __b_;
|
vector<result_type> __b_;
|
||||||
vector<double> __densities_;
|
vector<result_type> __densities_;
|
||||||
vector<__area_type> __areas_;
|
vector<result_type> __areas_;
|
||||||
public:
|
public:
|
||||||
typedef piecewise_linear_distribution distribution_type;
|
typedef piecewise_linear_distribution distribution_type;
|
||||||
|
|
||||||
@ -6262,7 +6258,7 @@ public:
|
|||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
vector<result_type> intervals() const {return __b_;}
|
vector<result_type> intervals() const {return __b_;}
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
vector<double> densities() const {return __densities_;}
|
vector<result_type> densities() const {return __densities_;}
|
||||||
|
|
||||||
friend _LIBCPP_INLINE_VISIBILITY
|
friend _LIBCPP_INLINE_VISIBILITY
|
||||||
bool operator==(const param_type& __x, const param_type& __y)
|
bool operator==(const param_type& __x, const param_type& __y)
|
||||||
@ -6333,7 +6329,7 @@ public:
|
|||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
vector<result_type> intervals() const {return __p_.intervals();}
|
vector<result_type> intervals() const {return __p_.intervals();}
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
vector<double> densities() const {return __p_.densities();}
|
vector<result_type> densities() const {return __p_.densities();}
|
||||||
|
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
param_type param() const {return __p_;}
|
param_type param() const {return __p_;}
|
||||||
@ -6389,8 +6385,8 @@ template<class _RealType>
|
|||||||
void
|
void
|
||||||
piecewise_linear_distribution<_RealType>::param_type::__init()
|
piecewise_linear_distribution<_RealType>::param_type::__init()
|
||||||
{
|
{
|
||||||
__areas_.assign(__densities_.size() - 1, __area_type());
|
__areas_.assign(__densities_.size() - 1, result_type());
|
||||||
__area_type _S = 0;
|
result_type _S = 0;
|
||||||
for (size_t __i = 0; __i < __areas_.size(); ++__i)
|
for (size_t __i = 0; __i < __areas_.size(); ++__i)
|
||||||
{
|
{
|
||||||
__areas_[__i] = (__densities_[__i+1] + __densities_[__i]) *
|
__areas_[__i] = (__densities_[__i+1] + __densities_[__i]) *
|
||||||
@ -6491,19 +6487,19 @@ piecewise_linear_distribution<_RealType>::operator()(_URNG& __g, const param_typ
|
|||||||
typedef uniform_real_distribution<result_type> _Gen;
|
typedef uniform_real_distribution<result_type> _Gen;
|
||||||
result_type __u = _Gen()(__g);
|
result_type __u = _Gen()(__g);
|
||||||
ptrdiff_t __k = _STD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(),
|
ptrdiff_t __k = _STD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(),
|
||||||
static_cast<double>(__u)) - __p.__areas_.begin() - 1;
|
__u) - __p.__areas_.begin() - 1;
|
||||||
__u -= __p.__areas_[__k];
|
__u -= __p.__areas_[__k];
|
||||||
const double __dk = __p.__densities_[__k];
|
const result_type __dk = __p.__densities_[__k];
|
||||||
const double __dk1 = __p.__densities_[__k+1];
|
const result_type __dk1 = __p.__densities_[__k+1];
|
||||||
const double __deltad = __dk1 - __dk;
|
const result_type __deltad = __dk1 - __dk;
|
||||||
const result_type __bk = __p.__b_[__k];
|
const result_type __bk = __p.__b_[__k];
|
||||||
if (__deltad == 0)
|
if (__deltad == 0)
|
||||||
return static_cast<result_type>(__u / __dk + __bk);
|
return __u / __dk + __bk;
|
||||||
const result_type __bk1 = __p.__b_[__k+1];
|
const result_type __bk1 = __p.__b_[__k+1];
|
||||||
const result_type __deltab = __bk1 - __bk;
|
const result_type __deltab = __bk1 - __bk;
|
||||||
return static_cast<result_type>((__bk * __dk1 - __bk1 * __dk +
|
return (__bk * __dk1 - __bk1 * __dk +
|
||||||
_STD::sqrt(__deltab * (__deltab * __dk * __dk + 2 * __deltad * __u))) /
|
_STD::sqrt(__deltab * (__deltab * __dk * __dk + 2 * __deltad * __u))) /
|
||||||
__deltad);
|
__deltad;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class _CharT, class _Traits, class _RT>
|
template <class _CharT, class _Traits, class _RT>
|
||||||
@ -6539,7 +6535,6 @@ operator>>(basic_istream<_CharT, _Traits>& __is,
|
|||||||
typedef piecewise_linear_distribution<_RT> _Eng;
|
typedef piecewise_linear_distribution<_RT> _Eng;
|
||||||
typedef typename _Eng::result_type result_type;
|
typedef typename _Eng::result_type result_type;
|
||||||
typedef typename _Eng::param_type param_type;
|
typedef typename _Eng::param_type param_type;
|
||||||
typedef typename param_type::__area_type __area_type;
|
|
||||||
__save_flags<_CharT, _Traits> _(__is);
|
__save_flags<_CharT, _Traits> _(__is);
|
||||||
__is.flags(ios_base::dec | ios_base::skipws);
|
__is.flags(ios_base::dec | ios_base::skipws);
|
||||||
size_t __n;
|
size_t __n;
|
||||||
@ -6548,11 +6543,11 @@ operator>>(basic_istream<_CharT, _Traits>& __is,
|
|||||||
for (size_t __i = 0; __i < __n; ++__i)
|
for (size_t __i = 0; __i < __n; ++__i)
|
||||||
__is >> __b[__i];
|
__is >> __b[__i];
|
||||||
__is >> __n;
|
__is >> __n;
|
||||||
vector<double> __densities(__n);
|
vector<result_type> __densities(__n);
|
||||||
for (size_t __i = 0; __i < __n; ++__i)
|
for (size_t __i = 0; __i < __n; ++__i)
|
||||||
__is >> __densities[__i];
|
__is >> __densities[__i];
|
||||||
__is >> __n;
|
__is >> __n;
|
||||||
vector<__area_type> __areas(__n);
|
vector<result_type> __areas(__n);
|
||||||
for (size_t __i = 0; __i < __n; ++__i)
|
for (size_t __i = 0; __i < __n; ++__i)
|
||||||
__is >> __areas[__i];
|
__is >> __areas[__i];
|
||||||
if (!__is.fail())
|
if (!__is.fail())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user