* von Mises distribution improvement
@ 2013-03-04 4:56 Ulrich Drepper
2013-03-04 9:46 ` Paolo Carlini
0 siblings, 1 reply; 2+ messages in thread
From: Ulrich Drepper @ 2013-03-04 4:56 UTC (permalink / raw)
To: GCC Patches, libstdc++
I'd like to check in this patch which would improve the performance of
the distribution quite a bit by pulling constant computations into the
constructor. This patch will change the memory layout which can be
done easily only now. It also fixes one small bug in operator== and
in a comment.
OK?
Index: libstdc++-v3/include/ext/random
===================================================================
--- libstdc++-v3/include/ext/random (revision 196416)
+++ libstdc++-v3/include/ext/random (working copy)
@@ -2621,6 +2621,12 @@
const _RealType __pi = __gnu_cxx::__math_constants<_RealType>::__pi;
_GLIBCXX_DEBUG_ASSERT(_M_mu >= -__pi && _M_mu <= __pi);
_GLIBCXX_DEBUG_ASSERT(_M_kappa >= _RealType(0));
+
+ auto __tau = std::sqrt(_RealType(4) * _M_kappa * _M_kappa
+ + _RealType(1)) + _RealType(1);
+ auto __rho = ((__tau - std::sqrt(_RealType(2) * __tau))
+ / (_RealType(2) * _M_kappa));
+ _M_r = (_RealType(1) + __rho * __rho) / (_RealType(2) * __rho);
}
_RealType
@@ -2633,16 +2639,17 @@
friend bool
operator==(const param_type& __p1, const param_type& __p2)
- { return __p1._M_kappa == __p2._M_kappa; }
+ { return (__p1._M_mu == __p2._M_mu
+ && __p1._M_kappa == __p2._M_kappa); }
private:
-
_RealType _M_mu;
_RealType _M_kappa;
+ _RealType _M_r;
};
/**
- * @brief Constructs a beta distribution with parameters
+ * @brief Constructs a von Mises distribution with parameters
* @f$\mu@f$ and @f$\kappa@f$.
*/
explicit
@@ -2727,20 +2734,13 @@
= __gnu_cxx::__math_constants<result_type>::__pi;
std::__detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
__aurng(__urng);
- result_type __tau = (std::sqrt(result_type(4) * this->kappa()
- * this->kappa() + result_type(1))
- + result_type(1));
- result_type __rho = ((__tau - std::sqrt(result_type(2) * __tau))
- / (result_type(2) * this->kappa()));
- result_type __r = ((result_type(1) + __rho * __rho)
- / (result_type(2) * __rho));
result_type __f;
while (1)
{
result_type __rnd = std::cos(__pi * __aurng());
- __f = (result_type(1) + __r * __rnd) / (__r + __rnd);
- result_type __c = this->kappa() * (__r - __f);
+ __f = (result_type(1) + __p._M_r * __rnd) / (__p._M_r + __rnd);
+ result_type __c = __p._M_kappa * (__p._M_r - __f);
result_type __rnd2 = __aurng();
if (__c * (result_type(2) - __c) > __rnd2)
@@ -2756,7 +2756,7 @@
if (__aurng() < result_type(0.5))
__res = -__res;
#endif
- __res += this->mu();
+ __res += __p._M_mu;
if (__res > __pi)
__res -= result_type(2) * __pi;
else if (__res < -__pi)
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: von Mises distribution improvement
2013-03-04 4:56 von Mises distribution improvement Ulrich Drepper
@ 2013-03-04 9:46 ` Paolo Carlini
0 siblings, 0 replies; 2+ messages in thread
From: Paolo Carlini @ 2013-03-04 9:46 UTC (permalink / raw)
To: Ulrich Drepper; +Cc: GCC Patches, libstdc++
On 03/04/2013 05:56 AM, Ulrich Drepper wrote:
> I'd like to check in this patch which would improve the performance of
> the distribution quite a bit by pulling constant computations into the
> constructor. This patch will change the memory layout which can be
> done easily only now. It also fixes one small bug in operator== and
> in a comment.
>
> OK?
Sure.
Paolo.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-03-04 9:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-04 4:56 von Mises distribution improvement Ulrich Drepper
2013-03-04 9:46 ` Paolo Carlini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).