From patchwork Wed Nov 2 10:07:50 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 123245 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]) by ozlabs.org (Postfix) with SMTP id 69563B6F85 for ; Wed, 2 Nov 2011 21:08:27 +1100 (EST) Received: (qmail 24601 invoked by alias); 2 Nov 2011 10:08:24 -0000 Received: (qmail 24587 invoked by uid 22791); 2 Nov 2011 10:08:22 -0000 X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from acsinet15.oracle.com (HELO acsinet15.oracle.com) (141.146.126.227) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 02 Nov 2011 10:08:07 +0000 Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by acsinet15.oracle.com (Switch-3.4.4/Switch-3.4.4) with ESMTP id pA2A827J026832 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 2 Nov 2011 10:08:04 GMT Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id pA2A81X4001771 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 2 Nov 2011 10:08:02 GMT Received: from abhmt102.oracle.com (abhmt102.oracle.com [141.146.116.54]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id pA2A7ujS011611; Wed, 2 Nov 2011 05:07:56 -0500 Received: from [192.168.1.4] (/79.51.11.246) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 02 Nov 2011 03:07:56 -0700 Message-ID: <4EB11676.4030007@oracle.com> Date: Wed, 02 Nov 2011 11:07:50 +0100 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: libstdc++ Subject: [v3] PR libstdc++/50951 X-IsSubscribed: yes 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 Hi, just consistently save the whole state and compare the whole state (in operator==). Tested x86_64-linux, committed to mainline. Maybe will go to 4_6-branch too. Thanks, Paolo. /////////////////////// 2011-11-02 Paolo Carlini PR libstdc++/50951 * include/bits/random.tcc (operator<<(basic_ostream<>&, const mersenne_twister_engine<>&): Output _M_p too. (operator<<(basic_ostream<>&, const subtract_with_carry_engine<>&): Likewise. (operator>>(basic_istream<>&, mersenne_twister_engine<>&): Reload it. (operator>>(basic_istream<>&, subtract_with_carry_engine<>&): Likewise. * include/bits/random.h (mersenne_twister_engine<>::operator==): Compare _M_p too. (subtract_with_carry_engine<>::operator==): Compare _M_carry and _M_p too. (shuffle_order_engine<>::operator==): Compare _M_v(s) and _M_y too. * testsuite/26_numerics/random/independent_bits_engine/ operators/serialize.cc: Extend. * testsuite/26_numerics/random/subtract_with_carry_engine/ operators/serialize.cc: Likewise. * testsuite/26_numerics/random/discard_block_engine/ operators/serialize.cc: Likewise. * testsuite/26_numerics/random/mersenne_twister_engine/ operators/serialize.cc: Likewise. * testsuite/26_numerics/random/linear_congruential_engine/ operators/serialize.cc: Likewise. * testsuite/26_numerics/random/shuffle_order_engine/ operators/serialize.cc: Likewise. Index: include/bits/random.tcc =================================================================== --- include/bits/random.tcc (revision 180749) +++ include/bits/random.tcc (working copy) @@ -471,9 +471,9 @@ __os.flags(__ios_base::dec | __ios_base::fixed | __ios_base::left); __os.fill(__space); - for (size_t __i = 0; __i < __n - 1; ++__i) + for (size_t __i = 0; __i < __n; ++__i) __os << __x._M_x[__i] << __space; - __os << __x._M_x[__n - 1]; + __os << __x._M_p; __os.flags(__flags); __os.fill(__fill); @@ -498,6 +498,7 @@ for (size_t __i = 0; __i < __n; ++__i) __is >> __x._M_x[__i]; + __is >> __x._M_p; __is.flags(__flags); return __is; @@ -627,7 +628,7 @@ for (size_t __i = 0; __i < __r; ++__i) __os << __x._M_x[__i] << __space; - __os << __x._M_carry; + __os << __x._M_carry << __space << __x._M_p; __os.flags(__flags); __os.fill(__fill); @@ -649,6 +650,7 @@ for (size_t __i = 0; __i < __r; ++__i) __is >> __x._M_x[__i]; __is >> __x._M_carry; + __is >> __x._M_p; __is.flags(__flags); return __is; Index: include/bits/random.h =================================================================== --- include/bits/random.h (revision 180749) +++ include/bits/random.h (working copy) @@ -491,7 +491,8 @@ friend bool operator==(const mersenne_twister_engine& __lhs, const mersenne_twister_engine& __rhs) - { return std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x); } + { return (std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x) + && __lhs._M_p == __rhs._M_p); } /** * @brief Inserts the current state of a % mersenne_twister_engine @@ -705,7 +706,9 @@ friend bool operator==(const subtract_with_carry_engine& __lhs, const subtract_with_carry_engine& __rhs) - { return std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x); } + { return (std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x) + && __lhs._M_carry == __rhs._M_carry + && __lhs._M_p == __rhs._M_p); } /** * @brief Inserts the current state of a % subtract_with_carry_engine @@ -1370,7 +1373,9 @@ friend bool operator==(const shuffle_order_engine& __lhs, const shuffle_order_engine& __rhs) - { return __lhs._M_b == __rhs._M_b; } + { return (__lhs._M_b == __rhs._M_b + && std::equal(__lhs._M_v, __lhs._M_v + __k, __rhs._M_v) + && __lhs._M_y == __rhs._M_y); } /** * @brief Inserts the current state of a %shuffle_order_engine random Index: testsuite/26_numerics/random/independent_bits_engine/operators/serialize.cc =================================================================== --- testsuite/26_numerics/random/independent_bits_engine/operators/serialize.cc (revision 180749) +++ testsuite/26_numerics/random/independent_bits_engine/operators/serialize.cc (working copy) @@ -3,7 +3,7 @@ // // 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> // -// Copyright (C) 2008, 2009 Free Software Foundation, Inc. +// Copyright (C) 2008, 2009, 2010, 2011 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 @@ -44,6 +44,20 @@ str >> v; VERIFY( u == v ); + for (unsigned i = 0; i < 1000; ++i) + VERIFY( u() == v() ); + + str.clear(); + str << v; + + u(); + u(); + u(); + + str >> u; + VERIFY( u == v ); + for (unsigned i = 0; i < 1000; ++i) + VERIFY( u() == v() ); } int main() Index: testsuite/26_numerics/random/subtract_with_carry_engine/operators/serialize.cc =================================================================== --- testsuite/26_numerics/random/subtract_with_carry_engine/operators/serialize.cc (revision 180749) +++ testsuite/26_numerics/random/subtract_with_carry_engine/operators/serialize.cc (working copy) @@ -3,7 +3,7 @@ // // 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> // -// Copyright (C) 2008, 2009 Free Software Foundation, Inc. +// Copyright (C) 2008, 2009, 2010, 2011 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 @@ -43,6 +43,20 @@ str >> v; VERIFY( u == v ); + for (unsigned i = 0; i < 1000; ++i) + VERIFY( u() == v() ); + + str.clear(); + str << v; + + u(); + u(); + u(); + + str >> u; + VERIFY( u == v ); + for (unsigned i = 0; i < 1000; ++i) + VERIFY( u() == v() ); } int main() Index: testsuite/26_numerics/random/discard_block_engine/operators/serialize.cc =================================================================== --- testsuite/26_numerics/random/discard_block_engine/operators/serialize.cc (revision 180749) +++ testsuite/26_numerics/random/discard_block_engine/operators/serialize.cc (working copy) @@ -3,7 +3,7 @@ // // 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> // -// Copyright (C) 2008, 2009 Free Software Foundation, Inc. +// Copyright (C) 2008, 2009, 2010, 2011 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 @@ -46,6 +46,20 @@ str >> v; VERIFY( u == v ); + for (unsigned i = 0; i < 1000; ++i) + VERIFY( u() == v() ); + + str.clear(); + str << v; + + u(); + u(); + u(); + + str >> u; + VERIFY( u == v ); + for (unsigned i = 0; i < 1000; ++i) + VERIFY( u() == v() ); } int main() Index: testsuite/26_numerics/random/mersenne_twister_engine/operators/serialize.cc =================================================================== --- testsuite/26_numerics/random/mersenne_twister_engine/operators/serialize.cc (revision 180749) +++ testsuite/26_numerics/random/mersenne_twister_engine/operators/serialize.cc (working copy) @@ -3,7 +3,7 @@ // // 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> // -// Copyright (C) 2008, 2009 Free Software Foundation, Inc. +// Copyright (C) 2008, 2009, 2010, 2011 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 @@ -47,6 +47,20 @@ str >> v; VERIFY( u == v ); + for (unsigned i = 0; i < 1000; ++i) + VERIFY( u() == v() ); + + str.clear(); + str << v; + + u(); + u(); + u(); + + str >> u; + VERIFY( u == v ); + for (unsigned i = 0; i < 1000; ++i) + VERIFY( u() == v() ); } int main() Index: testsuite/26_numerics/random/linear_congruential_engine/operators/serialize.cc =================================================================== --- testsuite/26_numerics/random/linear_congruential_engine/operators/serialize.cc (revision 180749) +++ testsuite/26_numerics/random/linear_congruential_engine/operators/serialize.cc (working copy) @@ -3,7 +3,7 @@ // // 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> // -// Copyright (C) 2008, 2009 Free Software Foundation, Inc. +// Copyright (C) 2008, 2009, 2010, 2011 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 @@ -33,15 +33,29 @@ bool test __attribute__((unused)) = true; std::stringstream str; - std::minstd_rand0 a; - std::minstd_rand0 b; + std::minstd_rand0 u; + std::minstd_rand0 v; - a(); // advance - str << a; - VERIFY( !(a == b) ); + u(); // advance + str << u; + VERIFY( !(u == v) ); - str >> b; - VERIFY( a == b ); + str >> v; + VERIFY( u == v ); + for (unsigned i = 0; i < 1000; ++i) + VERIFY( u() == v() ); + + str.clear(); + str << v; + + u(); + u(); + u(); + + str >> u; + VERIFY( u == v ); + for (unsigned i = 0; i < 1000; ++i) + VERIFY( u() == v() ); } int main() Index: testsuite/26_numerics/random/shuffle_order_engine/operators/serialize.cc =================================================================== --- testsuite/26_numerics/random/shuffle_order_engine/operators/serialize.cc (revision 180749) +++ testsuite/26_numerics/random/shuffle_order_engine/operators/serialize.cc (working copy) @@ -3,7 +3,7 @@ // // 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> // -// Copyright (C) 2008, 2009 Free Software Foundation, Inc. +// Copyright (C) 2008, 2009, 2010, 2011 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 @@ -46,6 +46,20 @@ str >> v; VERIFY( u == v ); + for (unsigned i = 0; i < 1000; ++i) + VERIFY( u() == v() ); + + str.clear(); + str << v; + + u(); + u(); + u(); + + str >> u; + VERIFY( u == v ); + for (unsigned i = 0; i < 1000; ++i) + VERIFY( u() == v() ); } int main()