distribution 修正

This commit is contained in:
bolero-MURAKAMI 2011-10-17 13:44:19 +09:00
parent 9255ad6808
commit 6e6c515704
7 changed files with 73 additions and 47 deletions

View file

@ -32,22 +32,26 @@ namespace sprout {
class param_type {
public:
typedef bernoulli_distribution distribution_type;
private:
static SPROUT_CONSTEXPR bool arg_check_nothrow(RealType p_arg) {
return distribution_type::arg_check_nothrow(p_arg);
}
private:
RealType p_;
public:
SPROUT_CONSTEXPR param_type()
: p_(RealType(0.5))
{}
SPROUT_CONSTEXPR explicit param_type(RealType p_arg = RealType(0.5))
SPROUT_CONSTEXPR explicit param_type(RealType p_arg)
: p_(arg_check(p_arg))
{}
SPROUT_CONSTEXPR RealType p() const {
return p_;
}
template<typename Elem, typename Traits>
friend std::basic_ostream<Elem, Traits>& operator>>(
friend std::basic_istream<Elem, Traits>& operator>>(
std::basic_istream<Elem, Traits>& lhs,
param_type const& rhs
param_type& rhs
)
{
RealType p;
@ -93,7 +97,7 @@ namespace sprout {
SPROUT_CONSTEXPR bernoulli_distribution()
: p_(RealType(0.5))
{}
SPROUT_CONSTEXPR explicit bernoulli_distribution(RealType p_arg = RealType(0.5))
SPROUT_CONSTEXPR explicit bernoulli_distribution(RealType p_arg)
: p_(arg_check(p_arg))
{}
SPROUT_CONSTEXPR explicit bernoulli_distribution(param_type const& parm)
@ -122,14 +126,14 @@ namespace sprout {
;
}
template<typename Elem, typename Traits>
friend std::basic_ostream<Elem, Traits>& operator>>(
friend std::basic_istream<Elem, Traits>& operator>>(
std::basic_istream<Elem, Traits>& lhs,
bernoulli_distribution const& rhs
bernoulli_distribution& rhs
)
{
param_type parm;
return lhs >> parm;
param(parm);
rhs.param(parm);
return lhs;
}
template<typename Elem, typename Traits>
@ -138,7 +142,7 @@ namespace sprout {
bernoulli_distribution const& rhs
)
{
return lhs << param();
return lhs << rhs.param();
}
SPROUT_CONSTEXPR friend bool operator==(bernoulli_distribution const& lhs, bernoulli_distribution const& rhs) {
return lhs.param() == rhs.param();

View file

@ -69,6 +69,10 @@ namespace sprout {
class param_type {
public:
typedef binomial_distribution distribution_type;
private:
static SPROUT_CONSTEXPR bool arg_check_nothrow(IntType t_arg, RealType p_arg) {
return distribution_type::arg_check_nothrow(t_arg, p_arg);
}
private:
IntType t_;
RealType p_;
@ -88,9 +92,9 @@ namespace sprout {
return p_;
}
template<typename Elem, typename Traits>
friend std::basic_ostream<Elem, Traits>& operator>>(
friend std::basic_istream<Elem, Traits>& operator>>(
std::basic_istream<Elem, Traits>& lhs,
param_type const& rhs
param_type& rhs
)
{
IntType t;
@ -391,8 +395,8 @@ namespace sprout {
return param_type(t_, p_);
}
void param(param_type const& parm) {
t_ = parm.a();
p_ = parm.b();
t_ = parm.t();
p_ = parm.p();
init();
}
template<typename Engine>
@ -405,14 +409,14 @@ namespace sprout {
;
}
template<typename Elem, typename Traits>
friend std::basic_ostream<Elem, Traits>& operator>>(
friend std::basic_istream<Elem, Traits>& operator>>(
std::basic_istream<Elem, Traits>& lhs,
binomial_distribution const& rhs
binomial_distribution& rhs
)
{
param_type parm;
lhs >> parm;
param(parm);
rhs.param(parm);
return lhs;
}
template<typename Elem, typename Traits>
@ -421,7 +425,7 @@ namespace sprout {
binomial_distribution const& rhs
)
{
return lhs << param();
return lhs << rhs.param();
}
SPROUT_CONSTEXPR friend bool operator==(binomial_distribution const& lhs, binomial_distribution const& rhs) {
return lhs.param() == rhs.param();

View file

@ -45,6 +45,10 @@ namespace sprout {
class param_type {
public:
typedef geometric_distribution distribution_type;
private:
static SPROUT_CONSTEXPR bool arg_check_nothrow(RealType p_arg) {
return distribution_type::arg_check_nothrow(p_arg);
}
private:
RealType p_;
public:
@ -58,9 +62,9 @@ namespace sprout {
return p_;
}
template<typename Elem, typename Traits>
friend std::basic_ostream<Elem, Traits>& operator>>(
friend std::basic_istream<Elem, Traits>& operator>>(
std::basic_istream<Elem, Traits>& lhs,
param_type const& rhs
param_type& rhs
)
{
RealType p;
@ -147,14 +151,14 @@ namespace sprout {
return generate(eng);
}
template<typename Elem, typename Traits>
friend std::basic_ostream<Elem, Traits>& operator>>(
friend std::basic_istream<Elem, Traits>& operator>>(
std::basic_istream<Elem, Traits>& lhs,
geometric_distribution const& rhs
geometric_distribution& rhs
)
{
param_type parm;
lhs >> parm;
param(parm);
rhs.param(parm);
return lhs;
}
template<typename Elem, typename Traits>
@ -163,7 +167,7 @@ namespace sprout {
geometric_distribution const& rhs
)
{
return lhs << param();
return lhs << rhs.param();
}
SPROUT_CONSTEXPR friend bool operator==(geometric_distribution const& lhs, geometric_distribution const& rhs) {
return lhs.param() == rhs.param();

View file

@ -26,9 +26,9 @@ namespace sprout {
typedef uniform_01 distribution_type;
public:
template<typename Elem, typename Traits>
friend std::basic_ostream<Elem, Traits>& operator>>(
friend std::basic_istream<Elem, Traits>& operator>>(
std::basic_istream<Elem, Traits>& lhs,
param_type const& rhs
param_type& rhs
)
{
return lhs;
@ -81,6 +81,8 @@ namespace sprout {
);
}
public:
SPROUT_CONSTEXPR explicit uniform_01()
{}
SPROUT_CONSTEXPR explicit uniform_01(param_type const& parm)
{}
SPROUT_CONSTEXPR result_type min() const {
@ -99,9 +101,9 @@ namespace sprout {
return generate(eng, eng());
}
template<typename Elem, typename Traits>
friend std::basic_ostream<Elem, Traits>& operator>>(
friend std::basic_istream<Elem, Traits>& operator>>(
std::basic_istream<Elem, Traits>& lhs,
uniform_01 const& rhs
uniform_01& rhs
)
{
return lhs;

View file

@ -406,6 +406,10 @@ namespace sprout {
class param_type {
public:
typedef uniform_int_distribution distribution_type;
private:
static SPROUT_CONSTEXPR bool arg_check_nothrow(IntType min_arg, IntType max_arg) {
return distribution_type::arg_check_nothrow(min_arg, max_arg);
}
private:
IntType min_;
IntType max_;
@ -425,9 +429,9 @@ namespace sprout {
return max_;
}
template<typename Elem, typename Traits>
friend std::basic_ostream<Elem, Traits>& operator>>(
friend std::basic_istream<Elem, Traits>& operator>>(
std::basic_istream<Elem, Traits>& lhs,
param_type const& rhs
param_type& rhs
)
{
IntType min;
@ -478,7 +482,7 @@ namespace sprout {
: min_(arg_check(min_arg, max_arg))
, max_(max_arg)
{}
explicit uniform_int_distribution(param_type const& parm)
SPROUT_CONSTEXPR explicit uniform_int_distribution(param_type const& parm)
: min_(parm.a())
, max_(parm.b())
{}
@ -506,14 +510,14 @@ namespace sprout {
return generate<Engine>(sprout::random::detail::generate_uniform_int(eng, min_, max_));
}
template<typename Elem, typename Traits>
friend std::basic_ostream<Elem, Traits>& operator>>(
friend std::basic_istream<Elem, Traits>& operator>>(
std::basic_istream<Elem, Traits>& lhs,
uniform_int_distribution const& rhs
uniform_int_distribution& rhs
)
{
param_type parm;
lhs >> parm;
param(parm);
rhs.param(parm);
return lhs;
}
template<typename Elem, typename Traits>
@ -522,7 +526,7 @@ namespace sprout {
uniform_int_distribution const& rhs
)
{
return lhs << param();
return lhs << rhs.param();
}
SPROUT_CONSTEXPR friend bool operator==(uniform_int_distribution const& lhs, uniform_int_distribution const& rhs) {
return lhs.param() == rhs.param();

View file

@ -198,6 +198,10 @@ namespace sprout {
class param_type {
public:
typedef uniform_real_distribution distribution_type;
private:
static SPROUT_CONSTEXPR bool arg_check_nothrow(RealType min_arg, RealType max_arg) {
return distribution_type::arg_check_nothrow(min_arg, max_arg);
}
private:
RealType min_;
RealType max_;
@ -217,9 +221,9 @@ namespace sprout {
return max_;
}
template<typename Elem, typename Traits>
friend std::basic_ostream<Elem, Traits>& operator>>(
friend std::basic_istream<Elem, Traits>& operator>>(
std::basic_istream<Elem, Traits>& lhs,
param_type const& rhs
param_type& rhs
)
{
RealType min;
@ -270,7 +274,7 @@ namespace sprout {
: min_(arg_check(min_arg, max_arg))
, max_(max_arg)
{}
explicit uniform_real_distribution(param_type const& parm)
SPROUT_CONSTEXPR explicit uniform_real_distribution(param_type const& parm)
: min_(parm.a())
, max_(parm.b())
{}
@ -298,14 +302,14 @@ namespace sprout {
return generate<Engine>(sprout::random::detail::generate_uniform_real(eng, min_, max_));
}
template<typename Elem, typename Traits>
friend std::basic_ostream<Elem, Traits>& operator>>(
friend std::basic_istream<Elem, Traits>& operator>>(
std::basic_istream<Elem, Traits>& lhs,
uniform_real_distribution const& rhs
uniform_real_distribution& rhs
)
{
param_type parm;
lhs >> parm;
param(parm);
rhs.param(parm);
return lhs;
}
template<typename Elem, typename Traits>
@ -314,7 +318,7 @@ namespace sprout {
uniform_real_distribution const& rhs
)
{
return lhs << param();
return lhs << rhs.param();
}
SPROUT_CONSTEXPR friend bool operator==(uniform_real_distribution const& lhs, uniform_real_distribution const& rhs) {
return lhs.param() == rhs.param();

View file

@ -36,6 +36,10 @@ namespace sprout {
class param_type {
public:
typedef uniform_smallint distribution_type;
private:
static SPROUT_CONSTEXPR bool arg_check_nothrow(IntType min_arg, IntType max_arg) {
return distribution_type::arg_check_nothrow(min_arg, max_arg);
}
private:
IntType min_;
IntType max_;
@ -55,9 +59,9 @@ namespace sprout {
return max_;
}
template<typename Elem, typename Traits>
friend std::basic_ostream<Elem, Traits>& operator>>(
friend std::basic_istream<Elem, Traits>& operator>>(
std::basic_istream<Elem, Traits>& lhs,
param_type const& rhs
param_type& rhs
)
{
IntType min;
@ -205,7 +209,7 @@ namespace sprout {
: min_(arg_check(min_arg, max_arg))
, max_(max_arg)
{}
explicit uniform_smallint(param_type const& parm)
SPROUT_CONSTEXPR explicit uniform_smallint(param_type const& parm)
: min_(parm.a())
, max_(parm.b())
{}
@ -234,14 +238,14 @@ namespace sprout {
return generate(eng, typename std::is_integral<base_result>::type());
}
template<typename Elem, typename Traits>
friend std::basic_ostream<Elem, Traits>& operator>>(
friend std::basic_istream<Elem, Traits>& operator>>(
std::basic_istream<Elem, Traits>& lhs,
uniform_smallint const& rhs
uniform_smallint& rhs
)
{
param_type parm;
lhs >> parm;
param(parm);
rhs.param(parm);
return lhs;
}
template<typename Elem, typename Traits>
@ -250,7 +254,7 @@ namespace sprout {
uniform_smallint const& rhs
)
{
return lhs << param();
return lhs << rhs.param();
}
SPROUT_CONSTEXPR friend bool operator==(uniform_smallint const& lhs, uniform_smallint const& rhs) {
return lhs.param() == rhs.param();