From patchwork Mon Jan 15 19:59:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 861064 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-471300-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="vUbHGnFG"; dkim-atps=neutral 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 3zL43j2RvCz9s1h for ; Tue, 16 Jan 2018 07:01:04 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=HJRjy5e0ekDO6WraI8Kf3UEW4KfMhx9vF/ZrtayLmRXt32dZp+bvD ZPg65E4kw1Oi0uAGWgGW+U8v4Fvv5jRKsAcNgBICfIt8aiq6CBr5WbhgCX1TY3xf 16zPEtFXf2QKZS2cPaHPFqMsTLg8GkGDvNYtphp4TTr9O9y2ua+doc= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=e2peoGvPSm8U2wbMw60TY8cTnJk=; b=vUbHGnFGhz8tlS+2dcWO jnOmlBjpciCwapuRORLiXfAGpu+7kJJrw2sdDLCbKs9u0UAevBZP3lG7cOPgNfGo 1bHi4/0+t7fdv+PKli88jvZBLXJ+LgFK4jY2D7Cd+lFVzWMwf1TceTLQ+ghljTOP o51wpRYApGD1mADWJy5kFx4= Received: (qmail 25744 invoked by alias); 15 Jan 2018 20:00:42 -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 25606 invoked by uid 89); 15 Jan 2018 20:00:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=chi X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 15 Jan 2018 20:00:34 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ACFD87F41E; Mon, 15 Jan 2018 20:00:08 +0000 (UTC) Received: from localhost (unknown [10.33.36.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1E02B619B7; Mon, 15 Jan 2018 20:00:06 +0000 (UTC) Date: Mon, 15 Jan 2018 19:59:57 +0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] PR libstdc++/83833 fix chi_squared_distribution::param(const param&) Message-ID: <20180115195956.GA16615@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.9.1 (2017-09-22) The chi_squared_distribution::param(const param&) function should also update the parameters of the gamma_distribution member. PR libstdc++/83833 * include/bits/random.h (chi_squared_distribution::param): Update gamma distribution parameter. * testsuite/26_numerics/random/chi_squared_distribution/83833.cc: New test. Tested powerpc64le-linux, committed to trunk. (I know this is not a regression, but it's a small fix, and I also plan to apply it on the branches). commit 23aebfd022adb918bbe7e1c12efc00020a4299f6 Author: Jonathan Wakely Date: Mon Jan 15 17:16:07 2018 +0000 PR libstdc++/83833 fix chi_squared_distribution::param(const param&) PR libstdc++/83833 * include/bits/random.h (chi_squared_distribution::param): Update gamma distribution parameter. * testsuite/26_numerics/random/chi_squared_distribution/83833.cc: New test. diff --git a/libstdc++-v3/include/bits/random.h b/libstdc++-v3/include/bits/random.h index 655ee1df6d6..f812bbf18b1 100644 --- a/libstdc++-v3/include/bits/random.h +++ b/libstdc++-v3/include/bits/random.h @@ -2643,7 +2643,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ void param(const param_type& __param) - { _M_param = __param; } + { + _M_param = __param; + typedef typename std::gamma_distribution::param_type + param_type; + _M_gd.param(param_type{__param.n() / 2}); + } /** * @brief Returns the greatest lower bound value of the distribution. diff --git a/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/83833.cc b/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/83833.cc new file mode 100644 index 00000000000..01667635b41 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/83833.cc @@ -0,0 +1,39 @@ +// Copyright (C) 2018 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 +// . + +// { dg-do run { target c++11 } } + +#include +#include + +void +test01() +{ + std::default_random_engine r1, r2; + using chi = std::chi_squared_distribution; + chi::param_type p(5); + chi d1(p); + chi d2; + d2.param(p); + VERIFY( d1(r1) == d2(r2) ); // PR libstdc++/83833 +} + +int +main() +{ + test01(); +}