From: Paolo Carlini <paolo.carlini@oracle.com>
To: Ed Smith-Rowland <3dw4rd@verizon.net>,
Andreas Schwab <schwab@suse.de>,
Ulrich Drepper <drepper@gmail.com>
Cc: gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] libstdc++: add uniform on sphere distribution
Date: Wed, 16 Jul 2014 15:03:00 -0000 [thread overview]
Message-ID: <53C693DC.70600@oracle.com> (raw)
In-Reply-To: <53C65C72.2010400@verizon.net>
[-- Attachment #1: Type: text/plain, Size: 254 bytes --]
Hi,
On 07/16/2014 01:05 PM, Ed Smith-Rowland wrote:
> One thing we all forgot: the operator== is also non-trivial because it
> needs to compare _M_n.
Right. And reset too. I'm going to test and apply the below.
Thanks,
Paolo.
///////////////////////
[-- Attachment #2: CL --]
[-- Type: text/plain, Size: 474 bytes --]
2014-07-16 Paolo Carlini <paolo.carlini@oracle.com>
* include/ext/random: Minor formatting and cosmetic tweaks.
(uniform_on_sphere_distribution<>::operator==
(const uniform_on_sphere_distribution&,
const uniform_on_sphere_distribution&)): Compare the _M_nds.
(uniform_on_sphere_distribution<>::reset): Reset _M_nd.
(operator!=(const uniform_on_sphere_distribution&,
const uniform_on_sphere_distribution&)): Adjust.
* include/ext/random.tcc: Minor cosmetc tweaks.
[-- Attachment #3: patchlet --]
[-- Type: text/plain, Size: 4548 bytes --]
Index: include/ext/random
===================================================================
--- include/ext/random (revision 212581)
+++ include/ext/random (working copy)
@@ -598,7 +598,7 @@
inline bool
operator!=(const __gnu_cxx::beta_distribution<_RealType>& __d1,
const __gnu_cxx::beta_distribution<_RealType>& __d2)
- { return !(__d1 == __d2); }
+ { return !(__d1 == __d2); }
/**
@@ -2575,7 +2575,7 @@
inline bool
operator!=(const __gnu_cxx::triangular_distribution<_RealType>& __d1,
const __gnu_cxx::triangular_distribution<_RealType>& __d2)
- { return !(__d1 == __d2); }
+ { return !(__d1 == __d2); }
/**
@@ -2810,7 +2810,7 @@
inline bool
operator!=(const __gnu_cxx::von_mises_distribution<_RealType>& __d1,
const __gnu_cxx::von_mises_distribution<_RealType>& __d2)
- { return !(__d1 == __d2); }
+ { return !(__d1 == __d2); }
/**
@@ -3328,12 +3328,12 @@
*/
explicit
uniform_on_sphere_distribution()
- : _M_param(), _M_n(_RealType(0), _RealType(1))
+ : _M_param(), _M_nd()
{ }
explicit
uniform_on_sphere_distribution(const param_type& __p)
- : _M_param(__p), _M_n(_RealType(0), _RealType(1))
+ : _M_param(__p), _M_nd()
{ }
/**
@@ -3341,7 +3341,7 @@
*/
void
reset()
- { }
+ { _M_nd.reset(); }
/**
* @brief Returns the parameter set of the distribution.
@@ -3425,14 +3425,15 @@
friend bool
operator==(const uniform_on_sphere_distribution& __d1,
const uniform_on_sphere_distribution& __d2)
- { return true; }
+ { return __d1._M_nd == __d2._M_nd; }
/**
- * @brief Inserts a %uniform_on_sphere_distribution random number distribution
- * @p __x into the output stream @p __os.
+ * @brief Inserts a %uniform_on_sphere_distribution random number
+ * distribution @p __x into the output stream @p __os.
*
* @param __os An output stream.
- * @param __x A %uniform_on_sphere_distribution random number distribution.
+ * @param __x A %uniform_on_sphere_distribution random number
+ * distribution.
*
* @returns The output stream with the state of @p __x inserted or in
* an error state.
@@ -3446,11 +3447,13 @@
__x);
/**
- * @brief Extracts a %uniform_on_sphere_distribution random number distribution
+ * @brief Extracts a %uniform_on_sphere_distribution random number
+ * distribution
* @p __x from the input stream @p __is.
*
* @param __is An input stream.
- * @param __x A %uniform_on_sphere_distribution random number generator engine.
+ * @param __x A %uniform_on_sphere_distribution random number
+ * generator engine.
*
* @returns The input stream with @p __x extracted or in an error state.
*/
@@ -3470,7 +3473,7 @@
const param_type& __p);
param_type _M_param;
- std::normal_distribution<_RealType> _M_n;
+ std::normal_distribution<_RealType> _M_nd;
};
/**
@@ -3482,7 +3485,7 @@
_RealType>& __d1,
const __gnu_cxx::uniform_on_sphere_distribution<_Dimen,
_RealType>& __d2)
- { return false; }
+ { return !(__d1 == __d2); }
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace __gnu_cxx
Index: include/ext/random.tcc
===================================================================
--- include/ext/random.tcc (revision 212581)
+++ include/ext/random.tcc (working copy)
@@ -1551,7 +1551,7 @@
_RealType __sum = _RealType(0);
std::generate(__ret.begin(), __ret.end(),
- [&__urng, &__sum, this](){ _RealType __t = _M_n(__urng);
+ [&__urng, &__sum, this](){ _RealType __t = _M_nd(__urng);
__sum += __t * __t;
return __t; });
auto __norm = std::sqrt(__sum);
@@ -1583,8 +1583,7 @@
const __gnu_cxx::uniform_on_sphere_distribution<_Dimen,
_RealType>& __x)
{
- // The distribution has no state, nothing to save.
- return __os << __x._M_n;
+ return __os << __x._M_nd;
}
template<std::size_t _Dimen, typename _RealType, typename _CharT,
@@ -1594,8 +1593,7 @@
__gnu_cxx::uniform_on_sphere_distribution<_Dimen,
_RealType>& __x)
{
- // The distribution has no state, nothing to restore.
- return __is >> __x._M_n;
+ return __is >> __x._M_nd;
}
_GLIBCXX_END_NAMESPACE_VERSION
next prev parent reply other threads:[~2014-07-16 15:02 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-13 13:55 Ed Smith-Rowland
2014-07-13 14:12 ` Ulrich Drepper
2014-07-13 14:48 ` Ed Smith-Rowland
2014-07-13 15:47 ` Paolo Carlini
2014-07-13 16:04 ` Ulrich Drepper
2014-07-13 16:12 ` Paolo Carlini
2014-07-13 16:18 ` Ulrich Drepper
2014-07-13 16:29 ` Paolo Carlini
2014-07-13 16:45 ` Ulrich Drepper
2014-07-13 16:56 ` Paolo Carlini
2014-07-14 7:58 ` Andreas Schwab
2014-07-14 8:18 ` Paolo Carlini
2014-07-16 11:30 ` Ed Smith-Rowland
2014-07-16 15:03 ` Paolo Carlini [this message]
2014-07-16 17:38 ` Ulrich Drepper
-- strict thread matches above, loose matches on Subject: below --
2014-07-14 10:31 Dominique Dhumieres
2014-07-13 2:01 Ulrich Drepper
2014-07-13 2:06 ` Ulrich Drepper
2014-07-13 9:28 ` Paolo Carlini
2014-07-13 10:04 ` Ulrich Drepper
2014-07-13 10:40 ` Paolo Carlini
2014-07-23 10:05 ` Marc Glisse
2014-07-23 10:44 ` Jonathan Wakely
2014-07-24 22:14 ` Ulrich Drepper
2014-07-24 23:19 ` Jonathan Wakely
2014-08-08 23:24 ` Ulrich Drepper
2014-08-09 7:15 ` Marc Glisse
2014-08-09 11:55 ` Ulrich Drepper
2014-08-09 12:34 ` Marc Glisse
2014-08-09 15:24 ` Ulrich Drepper
2014-08-09 15:33 ` Marc Glisse
2014-08-09 16:55 ` Ed Smith-Rowland
2014-08-09 16:56 ` Ulrich Drepper
2014-08-09 17:40 ` Marc Glisse
2014-08-09 18:00 ` Ulrich Drepper
2014-08-13 7:36 ` Bin.Cheng
2014-08-13 7:43 ` Bin.Cheng
2014-08-13 8:41 ` Paolo Carlini
2014-08-13 11:25 ` Paolo Carlini
2014-08-13 11:32 ` Marc Glisse
2014-08-13 11:40 ` Paolo Carlini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53C693DC.70600@oracle.com \
--to=paolo.carlini@oracle.com \
--cc=3dw4rd@verizon.net \
--cc=drepper@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=schwab@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).