From patchwork Wed Jul 16 15:01:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 370774 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id BDFF81400FA for ; Thu, 17 Jul 2014 01:02:09 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=lq/6cNghpS+tE/q1w cBAjxEkiCPIkYWun2GplRE9KsExI/NIUk3l8dU2jcRHs7Y8KzQPDYu/GvFamlT1v O+SpDkxRIZ74P7TRmiJ6J3cZLR7YwV7xmqHSBAuA15FAMHQ0XjPo2WHALbnXlugS qEHTG0WwUDuR5KC9pjOB3Yne0A= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=3bDRQ9Nu0EbM0tByYqlSdpn 5Lf4=; b=GoaVTkDz4D7amoBhJ27d3RBzf6FxspKS798vCBo9PNNCPojlgqI2ZdQ FM4J4Le5jS2yysQ1nmWQt9CnDjAFz/pFfYCjXM6LjpNrp7PlIWRM+bGQ+r2EbIaa pK2StG0q4hStIprxfWcIJZXI6H2w27a5Wyf781/oISjA4F8gSeXE= Received: (qmail 22677 invoked by alias); 16 Jul 2014 15:02:01 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 22663 invoked by uid 89); 16 Jul 2014 15:02:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: aserp1040.oracle.com Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Wed, 16 Jul 2014 15:01:57 +0000 Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s6GF1r5L022750 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 16 Jul 2014 15:01:54 GMT Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s6GF1qPx024576 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 16 Jul 2014 15:01:53 GMT Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s6GF1qpl026383; Wed, 16 Jul 2014 15:01:52 GMT Received: from [192.168.1.4] (/79.27.214.118) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 16 Jul 2014 08:01:52 -0700 Message-ID: <53C693DC.70600@oracle.com> Date: Wed, 16 Jul 2014 17:01:48 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: Ed Smith-Rowland <3dw4rd@verizon.net>, Andreas Schwab , Ulrich Drepper CC: gcc-patches Subject: Re: [PATCH] libstdc++: add uniform on sphere distribution References: <53C28FBB.9080708@verizon.net> <53C2A91D.1070808@oracle.com> <53C2AED6.4040402@oracle.com> <53C2B301.2030205@oracle.com> <53C39149.8000001@oracle.com> <53C65C72.2010400@verizon.net> In-Reply-To: <53C65C72.2010400@verizon.net> X-IsSubscribed: yes 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. /////////////////////// 2014-07-16 Paolo Carlini * 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. 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& __x) { - // The distribution has no state, nothing to restore. - return __is >> __x._M_n; + return __is >> __x._M_nd; } _GLIBCXX_END_NAMESPACE_VERSION