random.h (discrete_distribution<>::param_type:: param_type()): Default construct the vectors.
2010-10-13 Paolo Carlini <paolo.carlini@oracle.com> * include/bits/random.h (discrete_distribution<>::param_type:: param_type()): Default construct the vectors. (discrete_distribution<>::param_type::probabilities): Adjust. (discrete_distribution<>::probabilities): Likewise. (discrete_distribution<>::max): Likewise. (piecewise_constant_distribution<>::param_type:: param_type()): Default construct the vectors. (piecewise_constant_distribution<>::param_type::intervals): Adjust. (piecewise_constant_distribution<>::param_type::densities): Likewise. (piecewise_constant_distribution<>::intervals): Likewise. (piecewise_constant_distribution<>::densities): Likewise. (piecewise_constant_distribution<>::min): Likewise. (piecewise_constant_distribution<>::max): Likewise. (piecewise_linear_distribution<>::param_type:: param_type()): Default construct the vectors. (piecewise_linear_distribution<>::param_type::intervals): Adjust. (piecewise_linear_distribution<>::param_type::densities): Likewise. (piecewise_linear_distribution<>::intervals): Likewise. (piecewise_linear_distribution<>::densities): Likewise. (piecewise_linear_distribution<>::min): Likewise. (piecewise_linear_distribution<>::max): Likewise. * include/bits/random.tcc (discrete_distribution<>::param_type:: _M_initialize): Deal quickly with raw _M_prob equivalent to a default constructed param_type, just clear the vector. (discrete_distribution<>::operator()): Early return 0 for a default constructed distribution. (piecewise_constant_distribution<>::param_type::_M_initialize): Likewise for _M_int and _M_den. (piecewise_constant_distribution<>::operator()): Early return for a default constructed distribution. (piecewise_linear_distribution<>::param_type::_M_initialize): Likewise. (piecewise_linear_distribution<>::operator()): Early return for a default constructed distribution. * testsuite/26_numerics/random/discrete_distribution/operators/ call-default.cc: New. * testsuite/26_numerics/random/piecewise_constant_distribution/ operators/call-default.cc: Likewise. From-SVN: r165427
This commit is contained in:
parent
18aebb0e6f
commit
879b9073c8
5 changed files with 219 additions and 38 deletions
|
@ -1,3 +1,44 @@
|
|||
2010-10-13 Paolo Carlini <paolo.carlini@oracle.com>
|
||||
|
||||
* include/bits/random.h (discrete_distribution<>::param_type::
|
||||
param_type()): Default construct the vectors.
|
||||
(discrete_distribution<>::param_type::probabilities): Adjust.
|
||||
(discrete_distribution<>::probabilities): Likewise.
|
||||
(discrete_distribution<>::max): Likewise.
|
||||
(piecewise_constant_distribution<>::param_type::
|
||||
param_type()): Default construct the vectors.
|
||||
(piecewise_constant_distribution<>::param_type::intervals): Adjust.
|
||||
(piecewise_constant_distribution<>::param_type::densities): Likewise.
|
||||
(piecewise_constant_distribution<>::intervals): Likewise.
|
||||
(piecewise_constant_distribution<>::densities): Likewise.
|
||||
(piecewise_constant_distribution<>::min): Likewise.
|
||||
(piecewise_constant_distribution<>::max): Likewise.
|
||||
(piecewise_linear_distribution<>::param_type::
|
||||
param_type()): Default construct the vectors.
|
||||
(piecewise_linear_distribution<>::param_type::intervals): Adjust.
|
||||
(piecewise_linear_distribution<>::param_type::densities): Likewise.
|
||||
(piecewise_linear_distribution<>::intervals): Likewise.
|
||||
(piecewise_linear_distribution<>::densities): Likewise.
|
||||
(piecewise_linear_distribution<>::min): Likewise.
|
||||
(piecewise_linear_distribution<>::max): Likewise.
|
||||
* include/bits/random.tcc (discrete_distribution<>::param_type::
|
||||
_M_initialize): Deal quickly with raw _M_prob equivalent to
|
||||
a default constructed param_type, just clear the vector.
|
||||
(discrete_distribution<>::operator()): Early return 0 for a
|
||||
default constructed distribution.
|
||||
(piecewise_constant_distribution<>::param_type::_M_initialize):
|
||||
Likewise for _M_int and _M_den.
|
||||
(piecewise_constant_distribution<>::operator()): Early return
|
||||
for a default constructed distribution.
|
||||
(piecewise_linear_distribution<>::param_type::_M_initialize):
|
||||
Likewise.
|
||||
(piecewise_linear_distribution<>::operator()): Early return
|
||||
for a default constructed distribution.
|
||||
* testsuite/26_numerics/random/discrete_distribution/operators/
|
||||
call-default.cc: New.
|
||||
* testsuite/26_numerics/random/piecewise_constant_distribution/
|
||||
operators/call-default.cc: Likewise.
|
||||
|
||||
2010-10-12 Paolo Carlini <paolo.carlini@oracle.com>
|
||||
|
||||
* include/bits/random.h (discrete_distribution<>::param_type):
|
||||
|
|
|
@ -4697,7 +4697,7 @@ namespace std
|
|||
friend class discrete_distribution<_IntType>;
|
||||
|
||||
param_type()
|
||||
: _M_prob(1, 1.0), _M_cp()
|
||||
: _M_prob(), _M_cp()
|
||||
{ }
|
||||
|
||||
template<typename _InputIterator>
|
||||
|
@ -4720,7 +4720,7 @@ namespace std
|
|||
|
||||
std::vector<double>
|
||||
probabilities() const
|
||||
{ return _M_prob; }
|
||||
{ return _M_prob.empty() ? std::vector<double>(1, 1.0) : _M_prob; }
|
||||
|
||||
friend bool
|
||||
operator==(const param_type& __p1, const param_type& __p2)
|
||||
|
@ -4771,7 +4771,10 @@ namespace std
|
|||
*/
|
||||
std::vector<double>
|
||||
probabilities() const
|
||||
{ return _M_param.probabilities(); }
|
||||
{
|
||||
return _M_param._M_prob.empty()
|
||||
? std::vector<double>(1, 1.0) : _M_param._M_prob;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the parameter set of the distribution.
|
||||
|
@ -4800,7 +4803,10 @@ namespace std
|
|||
*/
|
||||
result_type
|
||||
max() const
|
||||
{ return this->_M_param._M_prob.size() - 1; }
|
||||
{
|
||||
return _M_param._M_prob.empty()
|
||||
? result_type(0) : result_type(_M_param._M_prob.size() - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Generating functions.
|
||||
|
@ -4893,8 +4899,8 @@ namespace std
|
|||
friend class piecewise_constant_distribution<_RealType>;
|
||||
|
||||
param_type()
|
||||
: _M_int(2), _M_den(1, 1.0), _M_cp()
|
||||
{ _M_int[1] = _RealType(1); }
|
||||
: _M_int(), _M_den(), _M_cp()
|
||||
{ }
|
||||
|
||||
template<typename _InputIteratorB, typename _InputIteratorW>
|
||||
param_type(_InputIteratorB __bfirst,
|
||||
|
@ -4914,11 +4920,20 @@ namespace std
|
|||
|
||||
std::vector<_RealType>
|
||||
intervals() const
|
||||
{ return _M_int; }
|
||||
{
|
||||
if (_M_int.empty())
|
||||
{
|
||||
std::vector<_RealType> __tmp(2);
|
||||
__tmp[1] = _RealType(1);
|
||||
return __tmp;
|
||||
}
|
||||
else
|
||||
return _M_int;
|
||||
}
|
||||
|
||||
std::vector<double>
|
||||
densities() const
|
||||
{ return _M_den; }
|
||||
{ return _M_den.empty() ? std::vector<double>(1, 1.0) : _M_den; }
|
||||
|
||||
friend bool
|
||||
operator==(const param_type& __p1, const param_type& __p2)
|
||||
|
@ -4975,14 +4990,26 @@ namespace std
|
|||
*/
|
||||
std::vector<_RealType>
|
||||
intervals() const
|
||||
{ return _M_param.intervals(); }
|
||||
{
|
||||
if (_M_param._M_int.empty())
|
||||
{
|
||||
std::vector<_RealType> __tmp(2);
|
||||
__tmp[1] = _RealType(1);
|
||||
return __tmp;
|
||||
}
|
||||
else
|
||||
return _M_param._M_int;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns a vector of the probability densities.
|
||||
*/
|
||||
std::vector<double>
|
||||
densities() const
|
||||
{ return _M_param.densities(); }
|
||||
{
|
||||
return _M_param._M_den.empty()
|
||||
? std::vector<double>(1, 1.0) : _M_param._M_den;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the parameter set of the distribution.
|
||||
|
@ -5004,14 +5031,20 @@ namespace std
|
|||
*/
|
||||
result_type
|
||||
min() const
|
||||
{ return this->_M_param._M_int.front(); }
|
||||
{
|
||||
return _M_param._M_int.empty()
|
||||
? result_type(0) : _M_param._M_int.front();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the least upper bound value of the distribution.
|
||||
*/
|
||||
result_type
|
||||
max() const
|
||||
{ return this->_M_param._M_int.back(); }
|
||||
{
|
||||
return _M_param._M_int.empty()
|
||||
? result_type(1) : _M_param._M_int.back();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Generating functions.
|
||||
|
@ -5105,8 +5138,8 @@ namespace std
|
|||
friend class piecewise_linear_distribution<_RealType>;
|
||||
|
||||
param_type()
|
||||
: _M_int(2), _M_den(2, 1.0), _M_cp(), _M_m()
|
||||
{ _M_int[1] = _RealType(1); }
|
||||
: _M_int(), _M_den(), _M_cp(), _M_m()
|
||||
{ }
|
||||
|
||||
template<typename _InputIteratorB, typename _InputIteratorW>
|
||||
param_type(_InputIteratorB __bfirst,
|
||||
|
@ -5126,11 +5159,20 @@ namespace std
|
|||
|
||||
std::vector<_RealType>
|
||||
intervals() const
|
||||
{ return _M_int; }
|
||||
{
|
||||
if (_M_int.empty())
|
||||
{
|
||||
std::vector<_RealType> __tmp(2);
|
||||
__tmp[1] = _RealType(1);
|
||||
return __tmp;
|
||||
}
|
||||
else
|
||||
return _M_int;
|
||||
}
|
||||
|
||||
std::vector<double>
|
||||
densities() const
|
||||
{ return _M_den; }
|
||||
{ return _M_den.empty() ? std::vector<double>(2, 1.0) : _M_den; }
|
||||
|
||||
friend bool
|
||||
operator==(const param_type& __p1, const param_type& __p2)
|
||||
|
@ -5189,7 +5231,16 @@ namespace std
|
|||
*/
|
||||
std::vector<_RealType>
|
||||
intervals() const
|
||||
{ return _M_param.intervals(); }
|
||||
{
|
||||
if (_M_param._M_int.empty())
|
||||
{
|
||||
std::vector<_RealType> __tmp(2);
|
||||
__tmp[1] = _RealType(1);
|
||||
return __tmp;
|
||||
}
|
||||
else
|
||||
return _M_param._M_int;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return a vector of the probability densities of the
|
||||
|
@ -5197,7 +5248,10 @@ namespace std
|
|||
*/
|
||||
std::vector<double>
|
||||
densities() const
|
||||
{ return _M_param.densities(); }
|
||||
{
|
||||
return _M_param._M_den.empty()
|
||||
? std::vector<double>(2, 1.0) : _M_param._M_den;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the parameter set of the distribution.
|
||||
|
@ -5219,14 +5273,20 @@ namespace std
|
|||
*/
|
||||
result_type
|
||||
min() const
|
||||
{ return this->_M_param._M_int.front(); }
|
||||
{
|
||||
return _M_param._M_int.empty()
|
||||
? result_type(0) : _M_param._M_int.front();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the least upper bound value of the distribution.
|
||||
*/
|
||||
result_type
|
||||
max() const
|
||||
{ return this->_M_param._M_int.back(); }
|
||||
{
|
||||
return _M_param._M_int.empty()
|
||||
? result_type(1) : _M_param._M_int.back();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Generating functions.
|
||||
|
|
|
@ -2217,7 +2217,6 @@ namespace std
|
|||
if (_M_prob.size() < 2)
|
||||
{
|
||||
_M_prob.clear();
|
||||
_M_prob.push_back(1.0);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2257,6 +2256,9 @@ namespace std
|
|||
operator()(_UniformRandomNumberGenerator& __urng,
|
||||
const param_type& __param)
|
||||
{
|
||||
if (__param._M_cp.empty())
|
||||
return result_type(0);
|
||||
|
||||
__detail::_Adaptor<_UniformRandomNumberGenerator, double>
|
||||
__aurng(__urng);
|
||||
|
||||
|
@ -2330,16 +2332,13 @@ namespace std
|
|||
piecewise_constant_distribution<_RealType>::param_type::
|
||||
_M_initialize()
|
||||
{
|
||||
if (_M_int.size() < 2)
|
||||
if (_M_int.size() < 2
|
||||
|| (_M_int.size() == 2
|
||||
&& _M_int[0] == _RealType(0)
|
||||
&& _M_int[1] == _RealType(1)))
|
||||
{
|
||||
_M_int.clear();
|
||||
_M_int.reserve(2);
|
||||
_M_int.push_back(_RealType(0));
|
||||
_M_int.push_back(_RealType(1));
|
||||
|
||||
_M_den.clear();
|
||||
_M_den.push_back(1.0);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2433,6 +2432,9 @@ namespace std
|
|||
__aurng(__urng);
|
||||
|
||||
const double __p = __aurng();
|
||||
if (__param._M_cp.empty())
|
||||
return __p;
|
||||
|
||||
auto __pos = std::lower_bound(__param._M_cp.begin(),
|
||||
__param._M_cp.end(), __p);
|
||||
const size_t __i = __pos - __param._M_cp.begin();
|
||||
|
@ -2519,18 +2521,14 @@ namespace std
|
|||
piecewise_linear_distribution<_RealType>::param_type::
|
||||
_M_initialize()
|
||||
{
|
||||
if (_M_int.size() < 2)
|
||||
if (_M_int.size() < 2
|
||||
|| (_M_int.size() == 2
|
||||
&& _M_int[0] == _RealType(0)
|
||||
&& _M_int[1] == _RealType(1)
|
||||
&& _M_den[0] == _M_den[1]))
|
||||
{
|
||||
_M_int.clear();
|
||||
_M_int.reserve(2);
|
||||
_M_int.push_back(_RealType(0));
|
||||
_M_int.push_back(_RealType(1));
|
||||
|
||||
_M_den.clear();
|
||||
_M_den.reserve(2);
|
||||
_M_den.push_back(1.0);
|
||||
_M_den.push_back(1.0);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2623,7 +2621,7 @@ namespace std
|
|||
__aurng(__urng);
|
||||
|
||||
const double __p = __aurng();
|
||||
if (__param._M_m.empty())
|
||||
if (__param._M_cp.empty())
|
||||
return __p;
|
||||
|
||||
auto __pos = std::lower_bound(__param._M_cp.begin(),
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
// { dg-options "-std=c++0x" }
|
||||
// { dg-require-cstdint "" }
|
||||
//
|
||||
// 2010-10-13 Paolo Carlini <paolo.carlini@oracle.com>
|
||||
//
|
||||
// Copyright (C) 2010 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 3, or (at your option)
|
||||
// any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING3. If not see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// 26.5.8.5.1 Class template discrete_distribution
|
||||
// [rand.dist.samp.discrete]
|
||||
|
||||
#include <random>
|
||||
|
||||
void
|
||||
test01()
|
||||
{
|
||||
std::discrete_distribution<> u;
|
||||
std::minstd_rand0 rng;
|
||||
|
||||
u(rng);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
// { dg-options "-std=c++0x" }
|
||||
// { dg-require-cstdint "" }
|
||||
//
|
||||
// 2010-10-13 Paolo Carlini <paolo.carlini@oracle.com>
|
||||
//
|
||||
// Copyright (C) 2010 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 3, or (at your option)
|
||||
// any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING3. If not see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// 26.5.8.5.2 Class template piecewise_constant_distribution
|
||||
// [rand.dist.samp.pconst]
|
||||
|
||||
#include <random>
|
||||
|
||||
void
|
||||
test01()
|
||||
{
|
||||
std::piecewise_constant_distribution<> u;
|
||||
std::minstd_rand0 rng;
|
||||
|
||||
u(rng);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Reference in a new issue