libstdc++
|
00001 // Random number extensions -*- C++ -*- 00002 00003 // Copyright (C) 2012-2019 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /** @file ext/random.tcc 00026 * This is an internal header file, included by other library headers. 00027 * Do not attempt to use it directly. @headername{ext/random} 00028 */ 00029 00030 #ifndef _EXT_RANDOM_TCC 00031 #define _EXT_RANDOM_TCC 1 00032 00033 #pragma GCC system_header 00034 00035 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) 00036 { 00037 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00038 00039 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 00040 00041 template<typename _UIntType, size_t __m, 00042 size_t __pos1, size_t __sl1, size_t __sl2, 00043 size_t __sr1, size_t __sr2, 00044 uint32_t __msk1, uint32_t __msk2, 00045 uint32_t __msk3, uint32_t __msk4, 00046 uint32_t __parity1, uint32_t __parity2, 00047 uint32_t __parity3, uint32_t __parity4> 00048 void simd_fast_mersenne_twister_engine<_UIntType, __m, 00049 __pos1, __sl1, __sl2, __sr1, __sr2, 00050 __msk1, __msk2, __msk3, __msk4, 00051 __parity1, __parity2, __parity3, 00052 __parity4>:: 00053 seed(_UIntType __seed) 00054 { 00055 _M_state32[0] = static_cast<uint32_t>(__seed); 00056 for (size_t __i = 1; __i < _M_nstate32; ++__i) 00057 _M_state32[__i] = (1812433253UL 00058 * (_M_state32[__i - 1] ^ (_M_state32[__i - 1] >> 30)) 00059 + __i); 00060 _M_pos = state_size; 00061 _M_period_certification(); 00062 } 00063 00064 00065 namespace { 00066 00067 inline uint32_t _Func1(uint32_t __x) 00068 { 00069 return (__x ^ (__x >> 27)) * UINT32_C(1664525); 00070 } 00071 00072 inline uint32_t _Func2(uint32_t __x) 00073 { 00074 return (__x ^ (__x >> 27)) * UINT32_C(1566083941); 00075 } 00076 00077 } 00078 00079 00080 template<typename _UIntType, size_t __m, 00081 size_t __pos1, size_t __sl1, size_t __sl2, 00082 size_t __sr1, size_t __sr2, 00083 uint32_t __msk1, uint32_t __msk2, 00084 uint32_t __msk3, uint32_t __msk4, 00085 uint32_t __parity1, uint32_t __parity2, 00086 uint32_t __parity3, uint32_t __parity4> 00087 template<typename _Sseq> 00088 auto 00089 simd_fast_mersenne_twister_engine<_UIntType, __m, 00090 __pos1, __sl1, __sl2, __sr1, __sr2, 00091 __msk1, __msk2, __msk3, __msk4, 00092 __parity1, __parity2, __parity3, 00093 __parity4>:: 00094 seed(_Sseq& __q) 00095 -> _If_seed_seq<_Sseq> 00096 { 00097 size_t __lag; 00098 00099 if (_M_nstate32 >= 623) 00100 __lag = 11; 00101 else if (_M_nstate32 >= 68) 00102 __lag = 7; 00103 else if (_M_nstate32 >= 39) 00104 __lag = 5; 00105 else 00106 __lag = 3; 00107 const size_t __mid = (_M_nstate32 - __lag) / 2; 00108 00109 std::fill(_M_state32, _M_state32 + _M_nstate32, UINT32_C(0x8b8b8b8b)); 00110 uint32_t __arr[_M_nstate32]; 00111 __q.generate(__arr + 0, __arr + _M_nstate32); 00112 00113 uint32_t __r = _Func1(_M_state32[0] ^ _M_state32[__mid] 00114 ^ _M_state32[_M_nstate32 - 1]); 00115 _M_state32[__mid] += __r; 00116 __r += _M_nstate32; 00117 _M_state32[__mid + __lag] += __r; 00118 _M_state32[0] = __r; 00119 00120 for (size_t __i = 1, __j = 0; __j < _M_nstate32; ++__j) 00121 { 00122 __r = _Func1(_M_state32[__i] 00123 ^ _M_state32[(__i + __mid) % _M_nstate32] 00124 ^ _M_state32[(__i + _M_nstate32 - 1) % _M_nstate32]); 00125 _M_state32[(__i + __mid) % _M_nstate32] += __r; 00126 __r += __arr[__j] + __i; 00127 _M_state32[(__i + __mid + __lag) % _M_nstate32] += __r; 00128 _M_state32[__i] = __r; 00129 __i = (__i + 1) % _M_nstate32; 00130 } 00131 for (size_t __j = 0; __j < _M_nstate32; ++__j) 00132 { 00133 const size_t __i = (__j + 1) % _M_nstate32; 00134 __r = _Func2(_M_state32[__i] 00135 + _M_state32[(__i + __mid) % _M_nstate32] 00136 + _M_state32[(__i + _M_nstate32 - 1) % _M_nstate32]); 00137 _M_state32[(__i + __mid) % _M_nstate32] ^= __r; 00138 __r -= __i; 00139 _M_state32[(__i + __mid + __lag) % _M_nstate32] ^= __r; 00140 _M_state32[__i] = __r; 00141 } 00142 00143 _M_pos = state_size; 00144 _M_period_certification(); 00145 } 00146 00147 00148 template<typename _UIntType, size_t __m, 00149 size_t __pos1, size_t __sl1, size_t __sl2, 00150 size_t __sr1, size_t __sr2, 00151 uint32_t __msk1, uint32_t __msk2, 00152 uint32_t __msk3, uint32_t __msk4, 00153 uint32_t __parity1, uint32_t __parity2, 00154 uint32_t __parity3, uint32_t __parity4> 00155 void simd_fast_mersenne_twister_engine<_UIntType, __m, 00156 __pos1, __sl1, __sl2, __sr1, __sr2, 00157 __msk1, __msk2, __msk3, __msk4, 00158 __parity1, __parity2, __parity3, 00159 __parity4>:: 00160 _M_period_certification(void) 00161 { 00162 static const uint32_t __parity[4] = { __parity1, __parity2, 00163 __parity3, __parity4 }; 00164 uint32_t __inner = 0; 00165 for (size_t __i = 0; __i < 4; ++__i) 00166 if (__parity[__i] != 0) 00167 __inner ^= _M_state32[__i] & __parity[__i]; 00168 00169 if (__builtin_parity(__inner) & 1) 00170 return; 00171 for (size_t __i = 0; __i < 4; ++__i) 00172 if (__parity[__i] != 0) 00173 { 00174 _M_state32[__i] ^= 1 << (__builtin_ffs(__parity[__i]) - 1); 00175 return; 00176 } 00177 __builtin_unreachable(); 00178 } 00179 00180 00181 template<typename _UIntType, size_t __m, 00182 size_t __pos1, size_t __sl1, size_t __sl2, 00183 size_t __sr1, size_t __sr2, 00184 uint32_t __msk1, uint32_t __msk2, 00185 uint32_t __msk3, uint32_t __msk4, 00186 uint32_t __parity1, uint32_t __parity2, 00187 uint32_t __parity3, uint32_t __parity4> 00188 void simd_fast_mersenne_twister_engine<_UIntType, __m, 00189 __pos1, __sl1, __sl2, __sr1, __sr2, 00190 __msk1, __msk2, __msk3, __msk4, 00191 __parity1, __parity2, __parity3, 00192 __parity4>:: 00193 discard(unsigned long long __z) 00194 { 00195 while (__z > state_size - _M_pos) 00196 { 00197 __z -= state_size - _M_pos; 00198 00199 _M_gen_rand(); 00200 } 00201 00202 _M_pos += __z; 00203 } 00204 00205 00206 #ifndef _GLIBCXX_OPT_HAVE_RANDOM_SFMT_GEN_READ 00207 00208 namespace { 00209 00210 template<size_t __shift> 00211 inline void __rshift(uint32_t *__out, const uint32_t *__in) 00212 { 00213 uint64_t __th = ((static_cast<uint64_t>(__in[3]) << 32) 00214 | static_cast<uint64_t>(__in[2])); 00215 uint64_t __tl = ((static_cast<uint64_t>(__in[1]) << 32) 00216 | static_cast<uint64_t>(__in[0])); 00217 00218 uint64_t __oh = __th >> (__shift * 8); 00219 uint64_t __ol = __tl >> (__shift * 8); 00220 __ol |= __th << (64 - __shift * 8); 00221 __out[1] = static_cast<uint32_t>(__ol >> 32); 00222 __out[0] = static_cast<uint32_t>(__ol); 00223 __out[3] = static_cast<uint32_t>(__oh >> 32); 00224 __out[2] = static_cast<uint32_t>(__oh); 00225 } 00226 00227 00228 template<size_t __shift> 00229 inline void __lshift(uint32_t *__out, const uint32_t *__in) 00230 { 00231 uint64_t __th = ((static_cast<uint64_t>(__in[3]) << 32) 00232 | static_cast<uint64_t>(__in[2])); 00233 uint64_t __tl = ((static_cast<uint64_t>(__in[1]) << 32) 00234 | static_cast<uint64_t>(__in[0])); 00235 00236 uint64_t __oh = __th << (__shift * 8); 00237 uint64_t __ol = __tl << (__shift * 8); 00238 __oh |= __tl >> (64 - __shift * 8); 00239 __out[1] = static_cast<uint32_t>(__ol >> 32); 00240 __out[0] = static_cast<uint32_t>(__ol); 00241 __out[3] = static_cast<uint32_t>(__oh >> 32); 00242 __out[2] = static_cast<uint32_t>(__oh); 00243 } 00244 00245 00246 template<size_t __sl1, size_t __sl2, size_t __sr1, size_t __sr2, 00247 uint32_t __msk1, uint32_t __msk2, uint32_t __msk3, uint32_t __msk4> 00248 inline void __recursion(uint32_t *__r, 00249 const uint32_t *__a, const uint32_t *__b, 00250 const uint32_t *__c, const uint32_t *__d) 00251 { 00252 uint32_t __x[4]; 00253 uint32_t __y[4]; 00254 00255 __lshift<__sl2>(__x, __a); 00256 __rshift<__sr2>(__y, __c); 00257 __r[0] = (__a[0] ^ __x[0] ^ ((__b[0] >> __sr1) & __msk1) 00258 ^ __y[0] ^ (__d[0] << __sl1)); 00259 __r[1] = (__a[1] ^ __x[1] ^ ((__b[1] >> __sr1) & __msk2) 00260 ^ __y[1] ^ (__d[1] << __sl1)); 00261 __r[2] = (__a[2] ^ __x[2] ^ ((__b[2] >> __sr1) & __msk3) 00262 ^ __y[2] ^ (__d[2] << __sl1)); 00263 __r[3] = (__a[3] ^ __x[3] ^ ((__b[3] >> __sr1) & __msk4) 00264 ^ __y[3] ^ (__d[3] << __sl1)); 00265 } 00266 00267 } 00268 00269 00270 template<typename _UIntType, size_t __m, 00271 size_t __pos1, size_t __sl1, size_t __sl2, 00272 size_t __sr1, size_t __sr2, 00273 uint32_t __msk1, uint32_t __msk2, 00274 uint32_t __msk3, uint32_t __msk4, 00275 uint32_t __parity1, uint32_t __parity2, 00276 uint32_t __parity3, uint32_t __parity4> 00277 void simd_fast_mersenne_twister_engine<_UIntType, __m, 00278 __pos1, __sl1, __sl2, __sr1, __sr2, 00279 __msk1, __msk2, __msk3, __msk4, 00280 __parity1, __parity2, __parity3, 00281 __parity4>:: 00282 _M_gen_rand(void) 00283 { 00284 const uint32_t *__r1 = &_M_state32[_M_nstate32 - 8]; 00285 const uint32_t *__r2 = &_M_state32[_M_nstate32 - 4]; 00286 static constexpr size_t __pos1_32 = __pos1 * 4; 00287 00288 size_t __i; 00289 for (__i = 0; __i < _M_nstate32 - __pos1_32; __i += 4) 00290 { 00291 __recursion<__sl1, __sl2, __sr1, __sr2, 00292 __msk1, __msk2, __msk3, __msk4> 00293 (&_M_state32[__i], &_M_state32[__i], 00294 &_M_state32[__i + __pos1_32], __r1, __r2); 00295 __r1 = __r2; 00296 __r2 = &_M_state32[__i]; 00297 } 00298 00299 for (; __i < _M_nstate32; __i += 4) 00300 { 00301 __recursion<__sl1, __sl2, __sr1, __sr2, 00302 __msk1, __msk2, __msk3, __msk4> 00303 (&_M_state32[__i], &_M_state32[__i], 00304 &_M_state32[__i + __pos1_32 - _M_nstate32], __r1, __r2); 00305 __r1 = __r2; 00306 __r2 = &_M_state32[__i]; 00307 } 00308 00309 _M_pos = 0; 00310 } 00311 00312 #endif 00313 00314 #ifndef _GLIBCXX_OPT_HAVE_RANDOM_SFMT_OPERATOREQUAL 00315 template<typename _UIntType, size_t __m, 00316 size_t __pos1, size_t __sl1, size_t __sl2, 00317 size_t __sr1, size_t __sr2, 00318 uint32_t __msk1, uint32_t __msk2, 00319 uint32_t __msk3, uint32_t __msk4, 00320 uint32_t __parity1, uint32_t __parity2, 00321 uint32_t __parity3, uint32_t __parity4> 00322 bool 00323 operator==(const __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType, 00324 __m, __pos1, __sl1, __sl2, __sr1, __sr2, 00325 __msk1, __msk2, __msk3, __msk4, 00326 __parity1, __parity2, __parity3, __parity4>& __lhs, 00327 const __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType, 00328 __m, __pos1, __sl1, __sl2, __sr1, __sr2, 00329 __msk1, __msk2, __msk3, __msk4, 00330 __parity1, __parity2, __parity3, __parity4>& __rhs) 00331 { 00332 typedef __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType, 00333 __m, __pos1, __sl1, __sl2, __sr1, __sr2, 00334 __msk1, __msk2, __msk3, __msk4, 00335 __parity1, __parity2, __parity3, __parity4> __engine; 00336 return (std::equal(__lhs._M_stateT, 00337 __lhs._M_stateT + __engine::state_size, 00338 __rhs._M_stateT) 00339 && __lhs._M_pos == __rhs._M_pos); 00340 } 00341 #endif 00342 00343 template<typename _UIntType, size_t __m, 00344 size_t __pos1, size_t __sl1, size_t __sl2, 00345 size_t __sr1, size_t __sr2, 00346 uint32_t __msk1, uint32_t __msk2, 00347 uint32_t __msk3, uint32_t __msk4, 00348 uint32_t __parity1, uint32_t __parity2, 00349 uint32_t __parity3, uint32_t __parity4, 00350 typename _CharT, typename _Traits> 00351 std::basic_ostream<_CharT, _Traits>& 00352 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 00353 const __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType, 00354 __m, __pos1, __sl1, __sl2, __sr1, __sr2, 00355 __msk1, __msk2, __msk3, __msk4, 00356 __parity1, __parity2, __parity3, __parity4>& __x) 00357 { 00358 typedef std::basic_ostream<_CharT, _Traits> __ostream_type; 00359 typedef typename __ostream_type::ios_base __ios_base; 00360 00361 const typename __ios_base::fmtflags __flags = __os.flags(); 00362 const _CharT __fill = __os.fill(); 00363 const _CharT __space = __os.widen(' '); 00364 __os.flags(__ios_base::dec | __ios_base::fixed | __ios_base::left); 00365 __os.fill(__space); 00366 00367 for (size_t __i = 0; __i < __x._M_nstate32; ++__i) 00368 __os << __x._M_state32[__i] << __space; 00369 __os << __x._M_pos; 00370 00371 __os.flags(__flags); 00372 __os.fill(__fill); 00373 return __os; 00374 } 00375 00376 00377 template<typename _UIntType, size_t __m, 00378 size_t __pos1, size_t __sl1, size_t __sl2, 00379 size_t __sr1, size_t __sr2, 00380 uint32_t __msk1, uint32_t __msk2, 00381 uint32_t __msk3, uint32_t __msk4, 00382 uint32_t __parity1, uint32_t __parity2, 00383 uint32_t __parity3, uint32_t __parity4, 00384 typename _CharT, typename _Traits> 00385 std::basic_istream<_CharT, _Traits>& 00386 operator>>(std::basic_istream<_CharT, _Traits>& __is, 00387 __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType, 00388 __m, __pos1, __sl1, __sl2, __sr1, __sr2, 00389 __msk1, __msk2, __msk3, __msk4, 00390 __parity1, __parity2, __parity3, __parity4>& __x) 00391 { 00392 typedef std::basic_istream<_CharT, _Traits> __istream_type; 00393 typedef typename __istream_type::ios_base __ios_base; 00394 00395 const typename __ios_base::fmtflags __flags = __is.flags(); 00396 __is.flags(__ios_base::dec | __ios_base::skipws); 00397 00398 for (size_t __i = 0; __i < __x._M_nstate32; ++__i) 00399 __is >> __x._M_state32[__i]; 00400 __is >> __x._M_pos; 00401 00402 __is.flags(__flags); 00403 return __is; 00404 } 00405 00406 #endif // __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 00407 00408 /** 00409 * Iteration method due to M.D. J<o:>hnk. 00410 * 00411 * M.D. J<o:>hnk, Erzeugung von betaverteilten und gammaverteilten 00412 * Zufallszahlen, Metrika, Volume 8, 1964 00413 */ 00414 template<typename _RealType> 00415 template<typename _UniformRandomNumberGenerator> 00416 typename beta_distribution<_RealType>::result_type 00417 beta_distribution<_RealType>:: 00418 operator()(_UniformRandomNumberGenerator& __urng, 00419 const param_type& __param) 00420 { 00421 std::__detail::_Adaptor<_UniformRandomNumberGenerator, result_type> 00422 __aurng(__urng); 00423 00424 result_type __x, __y; 00425 do 00426 { 00427 __x = std::exp(std::log(__aurng()) / __param.alpha()); 00428 __y = std::exp(std::log(__aurng()) / __param.beta()); 00429 } 00430 while (__x + __y > result_type(1)); 00431 00432 return __x / (__x + __y); 00433 } 00434 00435 template<typename _RealType> 00436 template<typename _OutputIterator, 00437 typename _UniformRandomNumberGenerator> 00438 void 00439 beta_distribution<_RealType>:: 00440 __generate_impl(_OutputIterator __f, _OutputIterator __t, 00441 _UniformRandomNumberGenerator& __urng, 00442 const param_type& __param) 00443 { 00444 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, 00445 result_type>) 00446 00447 std::__detail::_Adaptor<_UniformRandomNumberGenerator, result_type> 00448 __aurng(__urng); 00449 00450 while (__f != __t) 00451 { 00452 result_type __x, __y; 00453 do 00454 { 00455 __x = std::exp(std::log(__aurng()) / __param.alpha()); 00456 __y = std::exp(std::log(__aurng()) / __param.beta()); 00457 } 00458 while (__x + __y > result_type(1)); 00459 00460 *__f++ = __x / (__x + __y); 00461 } 00462 } 00463 00464 template<typename _RealType, typename _CharT, typename _Traits> 00465 std::basic_ostream<_CharT, _Traits>& 00466 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 00467 const __gnu_cxx::beta_distribution<_RealType>& __x) 00468 { 00469 typedef std::basic_ostream<_CharT, _Traits> __ostream_type; 00470 typedef typename __ostream_type::ios_base __ios_base; 00471 00472 const typename __ios_base::fmtflags __flags = __os.flags(); 00473 const _CharT __fill = __os.fill(); 00474 const std::streamsize __precision = __os.precision(); 00475 const _CharT __space = __os.widen(' '); 00476 __os.flags(__ios_base::scientific | __ios_base::left); 00477 __os.fill(__space); 00478 __os.precision(std::numeric_limits<_RealType>::max_digits10); 00479 00480 __os << __x.alpha() << __space << __x.beta(); 00481 00482 __os.flags(__flags); 00483 __os.fill(__fill); 00484 __os.precision(__precision); 00485 return __os; 00486 } 00487 00488 template<typename _RealType, typename _CharT, typename _Traits> 00489 std::basic_istream<_CharT, _Traits>& 00490 operator>>(std::basic_istream<_CharT, _Traits>& __is, 00491 __gnu_cxx::beta_distribution<_RealType>& __x) 00492 { 00493 typedef std::basic_istream<_CharT, _Traits> __istream_type; 00494 typedef typename __istream_type::ios_base __ios_base; 00495 00496 const typename __ios_base::fmtflags __flags = __is.flags(); 00497 __is.flags(__ios_base::dec | __ios_base::skipws); 00498 00499 _RealType __alpha_val, __beta_val; 00500 __is >> __alpha_val >> __beta_val; 00501 __x.param(typename __gnu_cxx::beta_distribution<_RealType>:: 00502 param_type(__alpha_val, __beta_val)); 00503 00504 __is.flags(__flags); 00505 return __is; 00506 } 00507 00508 00509 template<std::size_t _Dimen, typename _RealType> 00510 template<typename _InputIterator1, typename _InputIterator2> 00511 void 00512 normal_mv_distribution<_Dimen, _RealType>::param_type:: 00513 _M_init_full(_InputIterator1 __meanbegin, _InputIterator1 __meanend, 00514 _InputIterator2 __varcovbegin, _InputIterator2 __varcovend) 00515 { 00516 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) 00517 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) 00518 std::fill(std::copy(__meanbegin, __meanend, _M_mean.begin()), 00519 _M_mean.end(), _RealType(0)); 00520 00521 // Perform the Cholesky decomposition 00522 auto __w = _M_t.begin(); 00523 for (size_t __j = 0; __j < _Dimen; ++__j) 00524 { 00525 _RealType __sum = _RealType(0); 00526 00527 auto __slitbegin = __w; 00528 auto __cit = _M_t.begin(); 00529 for (size_t __i = 0; __i < __j; ++__i) 00530 { 00531 auto __slit = __slitbegin; 00532 _RealType __s = *__varcovbegin++; 00533 for (size_t __k = 0; __k < __i; ++__k) 00534 __s -= *__slit++ * *__cit++; 00535 00536 *__w++ = __s /= *__cit++; 00537 __sum += __s * __s; 00538 } 00539 00540 __sum = *__varcovbegin - __sum; 00541 if (__builtin_expect(__sum <= _RealType(0), 0)) 00542 std::__throw_runtime_error(__N("normal_mv_distribution::" 00543 "param_type::_M_init_full")); 00544 *__w++ = std::sqrt(__sum); 00545 00546 std::advance(__varcovbegin, _Dimen - __j); 00547 } 00548 } 00549 00550 template<std::size_t _Dimen, typename _RealType> 00551 template<typename _InputIterator1, typename _InputIterator2> 00552 void 00553 normal_mv_distribution<_Dimen, _RealType>::param_type:: 00554 _M_init_lower(_InputIterator1 __meanbegin, _InputIterator1 __meanend, 00555 _InputIterator2 __varcovbegin, _InputIterator2 __varcovend) 00556 { 00557 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) 00558 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) 00559 std::fill(std::copy(__meanbegin, __meanend, _M_mean.begin()), 00560 _M_mean.end(), _RealType(0)); 00561 00562 // Perform the Cholesky decomposition 00563 auto __w = _M_t.begin(); 00564 for (size_t __j = 0; __j < _Dimen; ++__j) 00565 { 00566 _RealType __sum = _RealType(0); 00567 00568 auto __slitbegin = __w; 00569 auto __cit = _M_t.begin(); 00570 for (size_t __i = 0; __i < __j; ++__i) 00571 { 00572 auto __slit = __slitbegin; 00573 _RealType __s = *__varcovbegin++; 00574 for (size_t __k = 0; __k < __i; ++__k) 00575 __s -= *__slit++ * *__cit++; 00576 00577 *__w++ = __s /= *__cit++; 00578 __sum += __s * __s; 00579 } 00580 00581 __sum = *__varcovbegin++ - __sum; 00582 if (__builtin_expect(__sum <= _RealType(0), 0)) 00583 std::__throw_runtime_error(__N("normal_mv_distribution::" 00584 "param_type::_M_init_full")); 00585 *__w++ = std::sqrt(__sum); 00586 } 00587 } 00588 00589 template<std::size_t _Dimen, typename _RealType> 00590 template<typename _InputIterator1, typename _InputIterator2> 00591 void 00592 normal_mv_distribution<_Dimen, _RealType>::param_type:: 00593 _M_init_diagonal(_InputIterator1 __meanbegin, _InputIterator1 __meanend, 00594 _InputIterator2 __varbegin, _InputIterator2 __varend) 00595 { 00596 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) 00597 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) 00598 std::fill(std::copy(__meanbegin, __meanend, _M_mean.begin()), 00599 _M_mean.end(), _RealType(0)); 00600 00601 auto __w = _M_t.begin(); 00602 size_t __step = 0; 00603 while (__varbegin != __varend) 00604 { 00605 std::fill_n(__w, __step, _RealType(0)); 00606 __w += __step++; 00607 if (__builtin_expect(*__varbegin < _RealType(0), 0)) 00608 std::__throw_runtime_error(__N("normal_mv_distribution::" 00609 "param_type::_M_init_diagonal")); 00610 *__w++ = std::sqrt(*__varbegin++); 00611 } 00612 } 00613 00614 template<std::size_t _Dimen, typename _RealType> 00615 template<typename _UniformRandomNumberGenerator> 00616 typename normal_mv_distribution<_Dimen, _RealType>::result_type 00617 normal_mv_distribution<_Dimen, _RealType>:: 00618 operator()(_UniformRandomNumberGenerator& __urng, 00619 const param_type& __param) 00620 { 00621 result_type __ret; 00622 00623 _M_nd.__generate(__ret.begin(), __ret.end(), __urng); 00624 00625 auto __t_it = __param._M_t.crbegin(); 00626 for (size_t __i = _Dimen; __i > 0; --__i) 00627 { 00628 _RealType __sum = _RealType(0); 00629 for (size_t __j = __i; __j > 0; --__j) 00630 __sum += __ret[__j - 1] * *__t_it++; 00631 __ret[__i - 1] = __sum; 00632 } 00633 00634 return __ret; 00635 } 00636 00637 template<std::size_t _Dimen, typename _RealType> 00638 template<typename _ForwardIterator, typename _UniformRandomNumberGenerator> 00639 void 00640 normal_mv_distribution<_Dimen, _RealType>:: 00641 __generate_impl(_ForwardIterator __f, _ForwardIterator __t, 00642 _UniformRandomNumberGenerator& __urng, 00643 const param_type& __param) 00644 { 00645 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept< 00646 _ForwardIterator>) 00647 while (__f != __t) 00648 *__f++ = this->operator()(__urng, __param); 00649 } 00650 00651 template<size_t _Dimen, typename _RealType> 00652 bool 00653 operator==(const __gnu_cxx::normal_mv_distribution<_Dimen, _RealType>& 00654 __d1, 00655 const __gnu_cxx::normal_mv_distribution<_Dimen, _RealType>& 00656 __d2) 00657 { 00658 return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd; 00659 } 00660 00661 template<size_t _Dimen, typename _RealType, typename _CharT, typename _Traits> 00662 std::basic_ostream<_CharT, _Traits>& 00663 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 00664 const __gnu_cxx::normal_mv_distribution<_Dimen, _RealType>& __x) 00665 { 00666 typedef std::basic_ostream<_CharT, _Traits> __ostream_type; 00667 typedef typename __ostream_type::ios_base __ios_base; 00668 00669 const typename __ios_base::fmtflags __flags = __os.flags(); 00670 const _CharT __fill = __os.fill(); 00671 const std::streamsize __precision = __os.precision(); 00672 const _CharT __space = __os.widen(' '); 00673 __os.flags(__ios_base::scientific | __ios_base::left); 00674 __os.fill(__space); 00675 __os.precision(std::numeric_limits<_RealType>::max_digits10); 00676 00677 auto __mean = __x._M_param.mean(); 00678 for (auto __it : __mean) 00679 __os << __it << __space; 00680 auto __t = __x._M_param.varcov(); 00681 for (auto __it : __t) 00682 __os << __it << __space; 00683 00684 __os << __x._M_nd; 00685 00686 __os.flags(__flags); 00687 __os.fill(__fill); 00688 __os.precision(__precision); 00689 return __os; 00690 } 00691 00692 template<size_t _Dimen, typename _RealType, typename _CharT, typename _Traits> 00693 std::basic_istream<_CharT, _Traits>& 00694 operator>>(std::basic_istream<_CharT, _Traits>& __is, 00695 __gnu_cxx::normal_mv_distribution<_Dimen, _RealType>& __x) 00696 { 00697 typedef std::basic_istream<_CharT, _Traits> __istream_type; 00698 typedef typename __istream_type::ios_base __ios_base; 00699 00700 const typename __ios_base::fmtflags __flags = __is.flags(); 00701 __is.flags(__ios_base::dec | __ios_base::skipws); 00702 00703 std::array<_RealType, _Dimen> __mean; 00704 for (auto& __it : __mean) 00705 __is >> __it; 00706 std::array<_RealType, _Dimen * (_Dimen + 1) / 2> __varcov; 00707 for (auto& __it : __varcov) 00708 __is >> __it; 00709 00710 __is >> __x._M_nd; 00711 00712 __x.param(typename normal_mv_distribution<_Dimen, _RealType>:: 00713 param_type(__mean.begin(), __mean.end(), 00714 __varcov.begin(), __varcov.end())); 00715 00716 __is.flags(__flags); 00717 return __is; 00718 } 00719 00720 00721 template<typename _RealType> 00722 template<typename _OutputIterator, 00723 typename _UniformRandomNumberGenerator> 00724 void 00725 rice_distribution<_RealType>:: 00726 __generate_impl(_OutputIterator __f, _OutputIterator __t, 00727 _UniformRandomNumberGenerator& __urng, 00728 const param_type& __p) 00729 { 00730 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, 00731 result_type>) 00732 00733 while (__f != __t) 00734 { 00735 typename std::normal_distribution<result_type>::param_type 00736 __px(__p.nu(), __p.sigma()), __py(result_type(0), __p.sigma()); 00737 result_type __x = this->_M_ndx(__px, __urng); 00738 result_type __y = this->_M_ndy(__py, __urng); 00739 #if _GLIBCXX_USE_C99_MATH_TR1 00740 *__f++ = std::hypot(__x, __y); 00741 #else 00742 *__f++ = std::sqrt(__x * __x + __y * __y); 00743 #endif 00744 } 00745 } 00746 00747 template<typename _RealType, typename _CharT, typename _Traits> 00748 std::basic_ostream<_CharT, _Traits>& 00749 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 00750 const rice_distribution<_RealType>& __x) 00751 { 00752 typedef std::basic_ostream<_CharT, _Traits> __ostream_type; 00753 typedef typename __ostream_type::ios_base __ios_base; 00754 00755 const typename __ios_base::fmtflags __flags = __os.flags(); 00756 const _CharT __fill = __os.fill(); 00757 const std::streamsize __precision = __os.precision(); 00758 const _CharT __space = __os.widen(' '); 00759 __os.flags(__ios_base::scientific | __ios_base::left); 00760 __os.fill(__space); 00761 __os.precision(std::numeric_limits<_RealType>::max_digits10); 00762 00763 __os << __x.nu() << __space << __x.sigma(); 00764 __os << __space << __x._M_ndx; 00765 __os << __space << __x._M_ndy; 00766 00767 __os.flags(__flags); 00768 __os.fill(__fill); 00769 __os.precision(__precision); 00770 return __os; 00771 } 00772 00773 template<typename _RealType, typename _CharT, typename _Traits> 00774 std::basic_istream<_CharT, _Traits>& 00775 operator>>(std::basic_istream<_CharT, _Traits>& __is, 00776 rice_distribution<_RealType>& __x) 00777 { 00778 typedef std::basic_istream<_CharT, _Traits> __istream_type; 00779 typedef typename __istream_type::ios_base __ios_base; 00780 00781 const typename __ios_base::fmtflags __flags = __is.flags(); 00782 __is.flags(__ios_base::dec | __ios_base::skipws); 00783 00784 _RealType __nu_val, __sigma_val; 00785 __is >> __nu_val >> __sigma_val; 00786 __is >> __x._M_ndx; 00787 __is >> __x._M_ndy; 00788 __x.param(typename rice_distribution<_RealType>:: 00789 param_type(__nu_val, __sigma_val)); 00790 00791 __is.flags(__flags); 00792 return __is; 00793 } 00794 00795 00796 template<typename _RealType> 00797 template<typename _OutputIterator, 00798 typename _UniformRandomNumberGenerator> 00799 void 00800 nakagami_distribution<_RealType>:: 00801 __generate_impl(_OutputIterator __f, _OutputIterator __t, 00802 _UniformRandomNumberGenerator& __urng, 00803 const param_type& __p) 00804 { 00805 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, 00806 result_type>) 00807 00808 typename std::gamma_distribution<result_type>::param_type 00809 __pg(__p.mu(), __p.omega() / __p.mu()); 00810 while (__f != __t) 00811 *__f++ = std::sqrt(this->_M_gd(__pg, __urng)); 00812 } 00813 00814 template<typename _RealType, typename _CharT, typename _Traits> 00815 std::basic_ostream<_CharT, _Traits>& 00816 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 00817 const nakagami_distribution<_RealType>& __x) 00818 { 00819 typedef std::basic_ostream<_CharT, _Traits> __ostream_type; 00820 typedef typename __ostream_type::ios_base __ios_base; 00821 00822 const typename __ios_base::fmtflags __flags = __os.flags(); 00823 const _CharT __fill = __os.fill(); 00824 const std::streamsize __precision = __os.precision(); 00825 const _CharT __space = __os.widen(' '); 00826 __os.flags(__ios_base::scientific | __ios_base::left); 00827 __os.fill(__space); 00828 __os.precision(std::numeric_limits<_RealType>::max_digits10); 00829 00830 __os << __x.mu() << __space << __x.omega(); 00831 __os << __space << __x._M_gd; 00832 00833 __os.flags(__flags); 00834 __os.fill(__fill); 00835 __os.precision(__precision); 00836 return __os; 00837 } 00838 00839 template<typename _RealType, typename _CharT, typename _Traits> 00840 std::basic_istream<_CharT, _Traits>& 00841 operator>>(std::basic_istream<_CharT, _Traits>& __is, 00842 nakagami_distribution<_RealType>& __x) 00843 { 00844 typedef std::basic_istream<_CharT, _Traits> __istream_type; 00845 typedef typename __istream_type::ios_base __ios_base; 00846 00847 const typename __ios_base::fmtflags __flags = __is.flags(); 00848 __is.flags(__ios_base::dec | __ios_base::skipws); 00849 00850 _RealType __mu_val, __omega_val; 00851 __is >> __mu_val >> __omega_val; 00852 __is >> __x._M_gd; 00853 __x.param(typename nakagami_distribution<_RealType>:: 00854 param_type(__mu_val, __omega_val)); 00855 00856 __is.flags(__flags); 00857 return __is; 00858 } 00859 00860 00861 template<typename _RealType> 00862 template<typename _OutputIterator, 00863 typename _UniformRandomNumberGenerator> 00864 void 00865 pareto_distribution<_RealType>:: 00866 __generate_impl(_OutputIterator __f, _OutputIterator __t, 00867 _UniformRandomNumberGenerator& __urng, 00868 const param_type& __p) 00869 { 00870 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, 00871 result_type>) 00872 00873 result_type __mu_val = __p.mu(); 00874 result_type __malphinv = -result_type(1) / __p.alpha(); 00875 while (__f != __t) 00876 *__f++ = __mu_val * std::pow(this->_M_ud(__urng), __malphinv); 00877 } 00878 00879 template<typename _RealType, typename _CharT, typename _Traits> 00880 std::basic_ostream<_CharT, _Traits>& 00881 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 00882 const pareto_distribution<_RealType>& __x) 00883 { 00884 typedef std::basic_ostream<_CharT, _Traits> __ostream_type; 00885 typedef typename __ostream_type::ios_base __ios_base; 00886 00887 const typename __ios_base::fmtflags __flags = __os.flags(); 00888 const _CharT __fill = __os.fill(); 00889 const std::streamsize __precision = __os.precision(); 00890 const _CharT __space = __os.widen(' '); 00891 __os.flags(__ios_base::scientific | __ios_base::left); 00892 __os.fill(__space); 00893 __os.precision(std::numeric_limits<_RealType>::max_digits10); 00894 00895 __os << __x.alpha() << __space << __x.mu(); 00896 __os << __space << __x._M_ud; 00897 00898 __os.flags(__flags); 00899 __os.fill(__fill); 00900 __os.precision(__precision); 00901 return __os; 00902 } 00903 00904 template<typename _RealType, typename _CharT, typename _Traits> 00905 std::basic_istream<_CharT, _Traits>& 00906 operator>>(std::basic_istream<_CharT, _Traits>& __is, 00907 pareto_distribution<_RealType>& __x) 00908 { 00909 typedef std::basic_istream<_CharT, _Traits> __istream_type; 00910 typedef typename __istream_type::ios_base __ios_base; 00911 00912 const typename __ios_base::fmtflags __flags = __is.flags(); 00913 __is.flags(__ios_base::dec | __ios_base::skipws); 00914 00915 _RealType __alpha_val, __mu_val; 00916 __is >> __alpha_val >> __mu_val; 00917 __is >> __x._M_ud; 00918 __x.param(typename pareto_distribution<_RealType>:: 00919 param_type(__alpha_val, __mu_val)); 00920 00921 __is.flags(__flags); 00922 return __is; 00923 } 00924 00925 00926 template<typename _RealType> 00927 template<typename _UniformRandomNumberGenerator> 00928 typename k_distribution<_RealType>::result_type 00929 k_distribution<_RealType>:: 00930 operator()(_UniformRandomNumberGenerator& __urng) 00931 { 00932 result_type __x = this->_M_gd1(__urng); 00933 result_type __y = this->_M_gd2(__urng); 00934 return std::sqrt(__x * __y); 00935 } 00936 00937 template<typename _RealType> 00938 template<typename _UniformRandomNumberGenerator> 00939 typename k_distribution<_RealType>::result_type 00940 k_distribution<_RealType>:: 00941 operator()(_UniformRandomNumberGenerator& __urng, 00942 const param_type& __p) 00943 { 00944 typename std::gamma_distribution<result_type>::param_type 00945 __p1(__p.lambda(), result_type(1) / __p.lambda()), 00946 __p2(__p.nu(), __p.mu() / __p.nu()); 00947 result_type __x = this->_M_gd1(__p1, __urng); 00948 result_type __y = this->_M_gd2(__p2, __urng); 00949 return std::sqrt(__x * __y); 00950 } 00951 00952 template<typename _RealType> 00953 template<typename _OutputIterator, 00954 typename _UniformRandomNumberGenerator> 00955 void 00956 k_distribution<_RealType>:: 00957 __generate_impl(_OutputIterator __f, _OutputIterator __t, 00958 _UniformRandomNumberGenerator& __urng, 00959 const param_type& __p) 00960 { 00961 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, 00962 result_type>) 00963 00964 typename std::gamma_distribution<result_type>::param_type 00965 __p1(__p.lambda(), result_type(1) / __p.lambda()), 00966 __p2(__p.nu(), __p.mu() / __p.nu()); 00967 while (__f != __t) 00968 { 00969 result_type __x = this->_M_gd1(__p1, __urng); 00970 result_type __y = this->_M_gd2(__p2, __urng); 00971 *__f++ = std::sqrt(__x * __y); 00972 } 00973 } 00974 00975 template<typename _RealType, typename _CharT, typename _Traits> 00976 std::basic_ostream<_CharT, _Traits>& 00977 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 00978 const k_distribution<_RealType>& __x) 00979 { 00980 typedef std::basic_ostream<_CharT, _Traits> __ostream_type; 00981 typedef typename __ostream_type::ios_base __ios_base; 00982 00983 const typename __ios_base::fmtflags __flags = __os.flags(); 00984 const _CharT __fill = __os.fill(); 00985 const std::streamsize __precision = __os.precision(); 00986 const _CharT __space = __os.widen(' '); 00987 __os.flags(__ios_base::scientific | __ios_base::left); 00988 __os.fill(__space); 00989 __os.precision(std::numeric_limits<_RealType>::max_digits10); 00990 00991 __os << __x.lambda() << __space << __x.mu() << __space << __x.nu(); 00992 __os << __space << __x._M_gd1; 00993 __os << __space << __x._M_gd2; 00994 00995 __os.flags(__flags); 00996 __os.fill(__fill); 00997 __os.precision(__precision); 00998 return __os; 00999 } 01000 01001 template<typename _RealType, typename _CharT, typename _Traits> 01002 std::basic_istream<_CharT, _Traits>& 01003 operator>>(std::basic_istream<_CharT, _Traits>& __is, 01004 k_distribution<_RealType>& __x) 01005 { 01006 typedef std::basic_istream<_CharT, _Traits> __istream_type; 01007 typedef typename __istream_type::ios_base __ios_base; 01008 01009 const typename __ios_base::fmtflags __flags = __is.flags(); 01010 __is.flags(__ios_base::dec | __ios_base::skipws); 01011 01012 _RealType __lambda_val, __mu_val, __nu_val; 01013 __is >> __lambda_val >> __mu_val >> __nu_val; 01014 __is >> __x._M_gd1; 01015 __is >> __x._M_gd2; 01016 __x.param(typename k_distribution<_RealType>:: 01017 param_type(__lambda_val, __mu_val, __nu_val)); 01018 01019 __is.flags(__flags); 01020 return __is; 01021 } 01022 01023 01024 template<typename _RealType> 01025 template<typename _OutputIterator, 01026 typename _UniformRandomNumberGenerator> 01027 void 01028 arcsine_distribution<_RealType>:: 01029 __generate_impl(_OutputIterator __f, _OutputIterator __t, 01030 _UniformRandomNumberGenerator& __urng, 01031 const param_type& __p) 01032 { 01033 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, 01034 result_type>) 01035 01036 result_type __dif = __p.b() - __p.a(); 01037 result_type __sum = __p.a() + __p.b(); 01038 while (__f != __t) 01039 { 01040 result_type __x = std::sin(this->_M_ud(__urng)); 01041 *__f++ = (__x * __dif + __sum) / result_type(2); 01042 } 01043 } 01044 01045 template<typename _RealType, typename _CharT, typename _Traits> 01046 std::basic_ostream<_CharT, _Traits>& 01047 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 01048 const arcsine_distribution<_RealType>& __x) 01049 { 01050 typedef std::basic_ostream<_CharT, _Traits> __ostream_type; 01051 typedef typename __ostream_type::ios_base __ios_base; 01052 01053 const typename __ios_base::fmtflags __flags = __os.flags(); 01054 const _CharT __fill = __os.fill(); 01055 const std::streamsize __precision = __os.precision(); 01056 const _CharT __space = __os.widen(' '); 01057 __os.flags(__ios_base::scientific | __ios_base::left); 01058 __os.fill(__space); 01059 __os.precision(std::numeric_limits<_RealType>::max_digits10); 01060 01061 __os << __x.a() << __space << __x.b(); 01062 __os << __space << __x._M_ud; 01063 01064 __os.flags(__flags); 01065 __os.fill(__fill); 01066 __os.precision(__precision); 01067 return __os; 01068 } 01069 01070 template<typename _RealType, typename _CharT, typename _Traits> 01071 std::basic_istream<_CharT, _Traits>& 01072 operator>>(std::basic_istream<_CharT, _Traits>& __is, 01073 arcsine_distribution<_RealType>& __x) 01074 { 01075 typedef std::basic_istream<_CharT, _Traits> __istream_type; 01076 typedef typename __istream_type::ios_base __ios_base; 01077 01078 const typename __ios_base::fmtflags __flags = __is.flags(); 01079 __is.flags(__ios_base::dec | __ios_base::skipws); 01080 01081 _RealType __a, __b; 01082 __is >> __a >> __b; 01083 __is >> __x._M_ud; 01084 __x.param(typename arcsine_distribution<_RealType>:: 01085 param_type(__a, __b)); 01086 01087 __is.flags(__flags); 01088 return __is; 01089 } 01090 01091 01092 template<typename _RealType> 01093 template<typename _UniformRandomNumberGenerator> 01094 typename hoyt_distribution<_RealType>::result_type 01095 hoyt_distribution<_RealType>:: 01096 operator()(_UniformRandomNumberGenerator& __urng) 01097 { 01098 result_type __x = this->_M_ad(__urng); 01099 result_type __y = this->_M_ed(__urng); 01100 return (result_type(2) * this->q() 01101 / (result_type(1) + this->q() * this->q())) 01102 * std::sqrt(this->omega() * __x * __y); 01103 } 01104 01105 template<typename _RealType> 01106 template<typename _UniformRandomNumberGenerator> 01107 typename hoyt_distribution<_RealType>::result_type 01108 hoyt_distribution<_RealType>:: 01109 operator()(_UniformRandomNumberGenerator& __urng, 01110 const param_type& __p) 01111 { 01112 result_type __q2 = __p.q() * __p.q(); 01113 result_type __num = result_type(0.5L) * (result_type(1) + __q2); 01114 typename __gnu_cxx::arcsine_distribution<result_type>::param_type 01115 __pa(__num, __num / __q2); 01116 result_type __x = this->_M_ad(__pa, __urng); 01117 result_type __y = this->_M_ed(__urng); 01118 return (result_type(2) * __p.q() / (result_type(1) + __q2)) 01119 * std::sqrt(__p.omega() * __x * __y); 01120 } 01121 01122 template<typename _RealType> 01123 template<typename _OutputIterator, 01124 typename _UniformRandomNumberGenerator> 01125 void 01126 hoyt_distribution<_RealType>:: 01127 __generate_impl(_OutputIterator __f, _OutputIterator __t, 01128 _UniformRandomNumberGenerator& __urng, 01129 const param_type& __p) 01130 { 01131 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, 01132 result_type>) 01133 01134 result_type __2q = result_type(2) * __p.q(); 01135 result_type __q2 = __p.q() * __p.q(); 01136 result_type __q2p1 = result_type(1) + __q2; 01137 result_type __num = result_type(0.5L) * __q2p1; 01138 result_type __omega = __p.omega(); 01139 typename __gnu_cxx::arcsine_distribution<result_type>::param_type 01140 __pa(__num, __num / __q2); 01141 while (__f != __t) 01142 { 01143 result_type __x = this->_M_ad(__pa, __urng); 01144 result_type __y = this->_M_ed(__urng); 01145 *__f++ = (__2q / __q2p1) * std::sqrt(__omega * __x * __y); 01146 } 01147 } 01148 01149 template<typename _RealType, typename _CharT, typename _Traits> 01150 std::basic_ostream<_CharT, _Traits>& 01151 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 01152 const hoyt_distribution<_RealType>& __x) 01153 { 01154 typedef std::basic_ostream<_CharT, _Traits> __ostream_type; 01155 typedef typename __ostream_type::ios_base __ios_base; 01156 01157 const typename __ios_base::fmtflags __flags = __os.flags(); 01158 const _CharT __fill = __os.fill(); 01159 const std::streamsize __precision = __os.precision(); 01160 const _CharT __space = __os.widen(' '); 01161 __os.flags(__ios_base::scientific | __ios_base::left); 01162 __os.fill(__space); 01163 __os.precision(std::numeric_limits<_RealType>::max_digits10); 01164 01165 __os << __x.q() << __space << __x.omega(); 01166 __os << __space << __x._M_ad; 01167 __os << __space << __x._M_ed; 01168 01169 __os.flags(__flags); 01170 __os.fill(__fill); 01171 __os.precision(__precision); 01172 return __os; 01173 } 01174 01175 template<typename _RealType, typename _CharT, typename _Traits> 01176 std::basic_istream<_CharT, _Traits>& 01177 operator>>(std::basic_istream<_CharT, _Traits>& __is, 01178 hoyt_distribution<_RealType>& __x) 01179 { 01180 typedef std::basic_istream<_CharT, _Traits> __istream_type; 01181 typedef typename __istream_type::ios_base __ios_base; 01182 01183 const typename __ios_base::fmtflags __flags = __is.flags(); 01184 __is.flags(__ios_base::dec | __ios_base::skipws); 01185 01186 _RealType __q, __omega; 01187 __is >> __q >> __omega; 01188 __is >> __x._M_ad; 01189 __is >> __x._M_ed; 01190 __x.param(typename hoyt_distribution<_RealType>:: 01191 param_type(__q, __omega)); 01192 01193 __is.flags(__flags); 01194 return __is; 01195 } 01196 01197 01198 template<typename _RealType> 01199 template<typename _OutputIterator, 01200 typename _UniformRandomNumberGenerator> 01201 void 01202 triangular_distribution<_RealType>:: 01203 __generate_impl(_OutputIterator __f, _OutputIterator __t, 01204 _UniformRandomNumberGenerator& __urng, 01205 const param_type& __param) 01206 { 01207 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, 01208 result_type>) 01209 01210 while (__f != __t) 01211 *__f++ = this->operator()(__urng, __param); 01212 } 01213 01214 template<typename _RealType, typename _CharT, typename _Traits> 01215 std::basic_ostream<_CharT, _Traits>& 01216 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 01217 const __gnu_cxx::triangular_distribution<_RealType>& __x) 01218 { 01219 typedef std::basic_ostream<_CharT, _Traits> __ostream_type; 01220 typedef typename __ostream_type::ios_base __ios_base; 01221 01222 const typename __ios_base::fmtflags __flags = __os.flags(); 01223 const _CharT __fill = __os.fill(); 01224 const std::streamsize __precision = __os.precision(); 01225 const _CharT __space = __os.widen(' '); 01226 __os.flags(__ios_base::scientific | __ios_base::left); 01227 __os.fill(__space); 01228 __os.precision(std::numeric_limits<_RealType>::max_digits10); 01229 01230 __os << __x.a() << __space << __x.b() << __space << __x.c(); 01231 01232 __os.flags(__flags); 01233 __os.fill(__fill); 01234 __os.precision(__precision); 01235 return __os; 01236 } 01237 01238 template<typename _RealType, typename _CharT, typename _Traits> 01239 std::basic_istream<_CharT, _Traits>& 01240 operator>>(std::basic_istream<_CharT, _Traits>& __is, 01241 __gnu_cxx::triangular_distribution<_RealType>& __x) 01242 { 01243 typedef std::basic_istream<_CharT, _Traits> __istream_type; 01244 typedef typename __istream_type::ios_base __ios_base; 01245 01246 const typename __ios_base::fmtflags __flags = __is.flags(); 01247 __is.flags(__ios_base::dec | __ios_base::skipws); 01248 01249 _RealType __a, __b, __c; 01250 __is >> __a >> __b >> __c; 01251 __x.param(typename __gnu_cxx::triangular_distribution<_RealType>:: 01252 param_type(__a, __b, __c)); 01253 01254 __is.flags(__flags); 01255 return __is; 01256 } 01257 01258 01259 template<typename _RealType> 01260 template<typename _UniformRandomNumberGenerator> 01261 typename von_mises_distribution<_RealType>::result_type 01262 von_mises_distribution<_RealType>:: 01263 operator()(_UniformRandomNumberGenerator& __urng, 01264 const param_type& __p) 01265 { 01266 const result_type __pi 01267 = __gnu_cxx::__math_constants<result_type>::__pi; 01268 std::__detail::_Adaptor<_UniformRandomNumberGenerator, result_type> 01269 __aurng(__urng); 01270 01271 result_type __f; 01272 while (1) 01273 { 01274 result_type __rnd = std::cos(__pi * __aurng()); 01275 __f = (result_type(1) + __p._M_r * __rnd) / (__p._M_r + __rnd); 01276 result_type __c = __p._M_kappa * (__p._M_r - __f); 01277 01278 result_type __rnd2 = __aurng(); 01279 if (__c * (result_type(2) - __c) > __rnd2) 01280 break; 01281 if (std::log(__c / __rnd2) >= __c - result_type(1)) 01282 break; 01283 } 01284 01285 result_type __res = std::acos(__f); 01286 #if _GLIBCXX_USE_C99_MATH_TR1 01287 __res = std::copysign(__res, __aurng() - result_type(0.5)); 01288 #else 01289 if (__aurng() < result_type(0.5)) 01290 __res = -__res; 01291 #endif 01292 __res += __p._M_mu; 01293 if (__res > __pi) 01294 __res -= result_type(2) * __pi; 01295 else if (__res < -__pi) 01296 __res += result_type(2) * __pi; 01297 return __res; 01298 } 01299 01300 template<typename _RealType> 01301 template<typename _OutputIterator, 01302 typename _UniformRandomNumberGenerator> 01303 void 01304 von_mises_distribution<_RealType>:: 01305 __generate_impl(_OutputIterator __f, _OutputIterator __t, 01306 _UniformRandomNumberGenerator& __urng, 01307 const param_type& __param) 01308 { 01309 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, 01310 result_type>) 01311 01312 while (__f != __t) 01313 *__f++ = this->operator()(__urng, __param); 01314 } 01315 01316 template<typename _RealType, typename _CharT, typename _Traits> 01317 std::basic_ostream<_CharT, _Traits>& 01318 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 01319 const __gnu_cxx::von_mises_distribution<_RealType>& __x) 01320 { 01321 typedef std::basic_ostream<_CharT, _Traits> __ostream_type; 01322 typedef typename __ostream_type::ios_base __ios_base; 01323 01324 const typename __ios_base::fmtflags __flags = __os.flags(); 01325 const _CharT __fill = __os.fill(); 01326 const std::streamsize __precision = __os.precision(); 01327 const _CharT __space = __os.widen(' '); 01328 __os.flags(__ios_base::scientific | __ios_base::left); 01329 __os.fill(__space); 01330 __os.precision(std::numeric_limits<_RealType>::max_digits10); 01331 01332 __os << __x.mu() << __space << __x.kappa(); 01333 01334 __os.flags(__flags); 01335 __os.fill(__fill); 01336 __os.precision(__precision); 01337 return __os; 01338 } 01339 01340 template<typename _RealType, typename _CharT, typename _Traits> 01341 std::basic_istream<_CharT, _Traits>& 01342 operator>>(std::basic_istream<_CharT, _Traits>& __is, 01343 __gnu_cxx::von_mises_distribution<_RealType>& __x) 01344 { 01345 typedef std::basic_istream<_CharT, _Traits> __istream_type; 01346 typedef typename __istream_type::ios_base __ios_base; 01347 01348 const typename __ios_base::fmtflags __flags = __is.flags(); 01349 __is.flags(__ios_base::dec | __ios_base::skipws); 01350 01351 _RealType __mu, __kappa; 01352 __is >> __mu >> __kappa; 01353 __x.param(typename __gnu_cxx::von_mises_distribution<_RealType>:: 01354 param_type(__mu, __kappa)); 01355 01356 __is.flags(__flags); 01357 return __is; 01358 } 01359 01360 01361 template<typename _UIntType> 01362 template<typename _UniformRandomNumberGenerator> 01363 typename hypergeometric_distribution<_UIntType>::result_type 01364 hypergeometric_distribution<_UIntType>:: 01365 operator()(_UniformRandomNumberGenerator& __urng, 01366 const param_type& __param) 01367 { 01368 std::__detail::_Adaptor<_UniformRandomNumberGenerator, double> 01369 __aurng(__urng); 01370 01371 result_type __a = __param.successful_size(); 01372 result_type __b = __param.total_size(); 01373 result_type __k = 0; 01374 01375 if (__param.total_draws() < __param.total_size() / 2) 01376 { 01377 for (result_type __i = 0; __i < __param.total_draws(); ++__i) 01378 { 01379 if (__b * __aurng() < __a) 01380 { 01381 ++__k; 01382 if (__k == __param.successful_size()) 01383 return __k; 01384 --__a; 01385 } 01386 --__b; 01387 } 01388 return __k; 01389 } 01390 else 01391 { 01392 for (result_type __i = 0; __i < __param.unsuccessful_size(); ++__i) 01393 { 01394 if (__b * __aurng() < __a) 01395 { 01396 ++__k; 01397 if (__k == __param.successful_size()) 01398 return __param.successful_size() - __k; 01399 --__a; 01400 } 01401 --__b; 01402 } 01403 return __param.successful_size() - __k; 01404 } 01405 } 01406 01407 template<typename _UIntType> 01408 template<typename _OutputIterator, 01409 typename _UniformRandomNumberGenerator> 01410 void 01411 hypergeometric_distribution<_UIntType>:: 01412 __generate_impl(_OutputIterator __f, _OutputIterator __t, 01413 _UniformRandomNumberGenerator& __urng, 01414 const param_type& __param) 01415 { 01416 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, 01417 result_type>) 01418 01419 while (__f != __t) 01420 *__f++ = this->operator()(__urng); 01421 } 01422 01423 template<typename _UIntType, typename _CharT, typename _Traits> 01424 std::basic_ostream<_CharT, _Traits>& 01425 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 01426 const __gnu_cxx::hypergeometric_distribution<_UIntType>& __x) 01427 { 01428 typedef std::basic_ostream<_CharT, _Traits> __ostream_type; 01429 typedef typename __ostream_type::ios_base __ios_base; 01430 01431 const typename __ios_base::fmtflags __flags = __os.flags(); 01432 const _CharT __fill = __os.fill(); 01433 const std::streamsize __precision = __os.precision(); 01434 const _CharT __space = __os.widen(' '); 01435 __os.flags(__ios_base::scientific | __ios_base::left); 01436 __os.fill(__space); 01437 __os.precision(std::numeric_limits<_UIntType>::max_digits10); 01438 01439 __os << __x.total_size() << __space << __x.successful_size() << __space 01440 << __x.total_draws(); 01441 01442 __os.flags(__flags); 01443 __os.fill(__fill); 01444 __os.precision(__precision); 01445 return __os; 01446 } 01447 01448 template<typename _UIntType, typename _CharT, typename _Traits> 01449 std::basic_istream<_CharT, _Traits>& 01450 operator>>(std::basic_istream<_CharT, _Traits>& __is, 01451 __gnu_cxx::hypergeometric_distribution<_UIntType>& __x) 01452 { 01453 typedef std::basic_istream<_CharT, _Traits> __istream_type; 01454 typedef typename __istream_type::ios_base __ios_base; 01455 01456 const typename __ios_base::fmtflags __flags = __is.flags(); 01457 __is.flags(__ios_base::dec | __ios_base::skipws); 01458 01459 _UIntType __total_size, __successful_size, __total_draws; 01460 __is >> __total_size >> __successful_size >> __total_draws; 01461 __x.param(typename __gnu_cxx::hypergeometric_distribution<_UIntType>:: 01462 param_type(__total_size, __successful_size, __total_draws)); 01463 01464 __is.flags(__flags); 01465 return __is; 01466 } 01467 01468 01469 template<typename _RealType> 01470 template<typename _UniformRandomNumberGenerator> 01471 typename logistic_distribution<_RealType>::result_type 01472 logistic_distribution<_RealType>:: 01473 operator()(_UniformRandomNumberGenerator& __urng, 01474 const param_type& __p) 01475 { 01476 std::__detail::_Adaptor<_UniformRandomNumberGenerator, result_type> 01477 __aurng(__urng); 01478 01479 result_type __arg = result_type(1); 01480 while (__arg == result_type(1) || __arg == result_type(0)) 01481 __arg = __aurng(); 01482 return __p.a() 01483 + __p.b() * std::log(__arg / (result_type(1) - __arg)); 01484 } 01485 01486 template<typename _RealType> 01487 template<typename _OutputIterator, 01488 typename _UniformRandomNumberGenerator> 01489 void 01490 logistic_distribution<_RealType>:: 01491 __generate_impl(_OutputIterator __f, _OutputIterator __t, 01492 _UniformRandomNumberGenerator& __urng, 01493 const param_type& __p) 01494 { 01495 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, 01496 result_type>) 01497 01498 std::__detail::_Adaptor<_UniformRandomNumberGenerator, result_type> 01499 __aurng(__urng); 01500 01501 while (__f != __t) 01502 { 01503 result_type __arg = result_type(1); 01504 while (__arg == result_type(1) || __arg == result_type(0)) 01505 __arg = __aurng(); 01506 *__f++ = __p.a() 01507 + __p.b() * std::log(__arg / (result_type(1) - __arg)); 01508 } 01509 } 01510 01511 template<typename _RealType, typename _CharT, typename _Traits> 01512 std::basic_ostream<_CharT, _Traits>& 01513 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 01514 const logistic_distribution<_RealType>& __x) 01515 { 01516 typedef std::basic_ostream<_CharT, _Traits> __ostream_type; 01517 typedef typename __ostream_type::ios_base __ios_base; 01518 01519 const typename __ios_base::fmtflags __flags = __os.flags(); 01520 const _CharT __fill = __os.fill(); 01521 const std::streamsize __precision = __os.precision(); 01522 const _CharT __space = __os.widen(' '); 01523 __os.flags(__ios_base::scientific | __ios_base::left); 01524 __os.fill(__space); 01525 __os.precision(std::numeric_limits<_RealType>::max_digits10); 01526 01527 __os << __x.a() << __space << __x.b(); 01528 01529 __os.flags(__flags); 01530 __os.fill(__fill); 01531 __os.precision(__precision); 01532 return __os; 01533 } 01534 01535 template<typename _RealType, typename _CharT, typename _Traits> 01536 std::basic_istream<_CharT, _Traits>& 01537 operator>>(std::basic_istream<_CharT, _Traits>& __is, 01538 logistic_distribution<_RealType>& __x) 01539 { 01540 typedef std::basic_istream<_CharT, _Traits> __istream_type; 01541 typedef typename __istream_type::ios_base __ios_base; 01542 01543 const typename __ios_base::fmtflags __flags = __is.flags(); 01544 __is.flags(__ios_base::dec | __ios_base::skipws); 01545 01546 _RealType __a, __b; 01547 __is >> __a >> __b; 01548 __x.param(typename logistic_distribution<_RealType>:: 01549 param_type(__a, __b)); 01550 01551 __is.flags(__flags); 01552 return __is; 01553 } 01554 01555 01556 namespace { 01557 01558 // Helper class for the uniform_on_sphere_distribution generation 01559 // function. 01560 template<std::size_t _Dimen, typename _RealType> 01561 class uniform_on_sphere_helper 01562 { 01563 typedef typename uniform_on_sphere_distribution<_Dimen, _RealType>:: 01564 result_type result_type; 01565 01566 public: 01567 template<typename _NormalDistribution, 01568 typename _UniformRandomNumberGenerator> 01569 result_type operator()(_NormalDistribution& __nd, 01570 _UniformRandomNumberGenerator& __urng) 01571 { 01572 result_type __ret; 01573 typename result_type::value_type __norm; 01574 01575 do 01576 { 01577 auto __sum = _RealType(0); 01578 01579 std::generate(__ret.begin(), __ret.end(), 01580 [&__nd, &__urng, &__sum](){ 01581 _RealType __t = __nd(__urng); 01582 __sum += __t * __t; 01583 return __t; }); 01584 __norm = std::sqrt(__sum); 01585 } 01586 while (__norm == _RealType(0) || ! __builtin_isfinite(__norm)); 01587 01588 std::transform(__ret.begin(), __ret.end(), __ret.begin(), 01589 [__norm](_RealType __val){ return __val / __norm; }); 01590 01591 return __ret; 01592 } 01593 }; 01594 01595 01596 template<typename _RealType> 01597 class uniform_on_sphere_helper<2, _RealType> 01598 { 01599 typedef typename uniform_on_sphere_distribution<2, _RealType>:: 01600 result_type result_type; 01601 01602 public: 01603 template<typename _NormalDistribution, 01604 typename _UniformRandomNumberGenerator> 01605 result_type operator()(_NormalDistribution&, 01606 _UniformRandomNumberGenerator& __urng) 01607 { 01608 result_type __ret; 01609 _RealType __sq; 01610 std::__detail::_Adaptor<_UniformRandomNumberGenerator, 01611 _RealType> __aurng(__urng); 01612 01613 do 01614 { 01615 __ret[0] = _RealType(2) * __aurng() - _RealType(1); 01616 __ret[1] = _RealType(2) * __aurng() - _RealType(1); 01617 01618 __sq = __ret[0] * __ret[0] + __ret[1] * __ret[1]; 01619 } 01620 while (__sq == _RealType(0) || __sq > _RealType(1)); 01621 01622 #if _GLIBCXX_USE_C99_MATH_TR1 01623 // Yes, we do not just use sqrt(__sq) because hypot() is more 01624 // accurate. 01625 auto __norm = std::hypot(__ret[0], __ret[1]); 01626 #else 01627 auto __norm = std::sqrt(__sq); 01628 #endif 01629 __ret[0] /= __norm; 01630 __ret[1] /= __norm; 01631 01632 return __ret; 01633 } 01634 }; 01635 01636 } 01637 01638 01639 template<std::size_t _Dimen, typename _RealType> 01640 template<typename _UniformRandomNumberGenerator> 01641 typename uniform_on_sphere_distribution<_Dimen, _RealType>::result_type 01642 uniform_on_sphere_distribution<_Dimen, _RealType>:: 01643 operator()(_UniformRandomNumberGenerator& __urng, 01644 const param_type& __p) 01645 { 01646 uniform_on_sphere_helper<_Dimen, _RealType> __helper; 01647 return __helper(_M_nd, __urng); 01648 } 01649 01650 template<std::size_t _Dimen, typename _RealType> 01651 template<typename _OutputIterator, 01652 typename _UniformRandomNumberGenerator> 01653 void 01654 uniform_on_sphere_distribution<_Dimen, _RealType>:: 01655 __generate_impl(_OutputIterator __f, _OutputIterator __t, 01656 _UniformRandomNumberGenerator& __urng, 01657 const param_type& __param) 01658 { 01659 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, 01660 result_type>) 01661 01662 while (__f != __t) 01663 *__f++ = this->operator()(__urng, __param); 01664 } 01665 01666 template<std::size_t _Dimen, typename _RealType, typename _CharT, 01667 typename _Traits> 01668 std::basic_ostream<_CharT, _Traits>& 01669 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 01670 const __gnu_cxx::uniform_on_sphere_distribution<_Dimen, 01671 _RealType>& __x) 01672 { 01673 return __os << __x._M_nd; 01674 } 01675 01676 template<std::size_t _Dimen, typename _RealType, typename _CharT, 01677 typename _Traits> 01678 std::basic_istream<_CharT, _Traits>& 01679 operator>>(std::basic_istream<_CharT, _Traits>& __is, 01680 __gnu_cxx::uniform_on_sphere_distribution<_Dimen, 01681 _RealType>& __x) 01682 { 01683 return __is >> __x._M_nd; 01684 } 01685 01686 01687 namespace { 01688 01689 // Helper class for the uniform_inside_sphere_distribution generation 01690 // function. 01691 template<std::size_t _Dimen, bool _SmallDimen, typename _RealType> 01692 class uniform_inside_sphere_helper; 01693 01694 template<std::size_t _Dimen, typename _RealType> 01695 class uniform_inside_sphere_helper<_Dimen, false, _RealType> 01696 { 01697 using result_type 01698 = typename uniform_inside_sphere_distribution<_Dimen, _RealType>:: 01699 result_type; 01700 01701 public: 01702 template<typename _UniformOnSphereDistribution, 01703 typename _UniformRandomNumberGenerator> 01704 result_type 01705 operator()(_UniformOnSphereDistribution& __uosd, 01706 _UniformRandomNumberGenerator& __urng, 01707 _RealType __radius) 01708 { 01709 std::__detail::_Adaptor<_UniformRandomNumberGenerator, 01710 _RealType> __aurng(__urng); 01711 01712 _RealType __pow = 1 / _RealType(_Dimen); 01713 _RealType __urt = __radius * std::pow(__aurng(), __pow); 01714 result_type __ret = __uosd(__aurng); 01715 01716 std::transform(__ret.begin(), __ret.end(), __ret.begin(), 01717 [__urt](_RealType __val) 01718 { return __val * __urt; }); 01719 01720 return __ret; 01721 } 01722 }; 01723 01724 // Helper class for the uniform_inside_sphere_distribution generation 01725 // function specialized for small dimensions. 01726 template<std::size_t _Dimen, typename _RealType> 01727 class uniform_inside_sphere_helper<_Dimen, true, _RealType> 01728 { 01729 using result_type 01730 = typename uniform_inside_sphere_distribution<_Dimen, _RealType>:: 01731 result_type; 01732 01733 public: 01734 template<typename _UniformOnSphereDistribution, 01735 typename _UniformRandomNumberGenerator> 01736 result_type 01737 operator()(_UniformOnSphereDistribution&, 01738 _UniformRandomNumberGenerator& __urng, 01739 _RealType __radius) 01740 { 01741 result_type __ret; 01742 _RealType __sq; 01743 _RealType __radsq = __radius * __radius; 01744 std::__detail::_Adaptor<_UniformRandomNumberGenerator, 01745 _RealType> __aurng(__urng); 01746 01747 do 01748 { 01749 __sq = _RealType(0); 01750 for (int i = 0; i < _Dimen; ++i) 01751 { 01752 __ret[i] = _RealType(2) * __aurng() - _RealType(1); 01753 __sq += __ret[i] * __ret[i]; 01754 } 01755 } 01756 while (__sq > _RealType(1)); 01757 01758 for (int i = 0; i < _Dimen; ++i) 01759 __ret[i] *= __radius; 01760 01761 return __ret; 01762 } 01763 }; 01764 } // namespace 01765 01766 // 01767 // Experiments have shown that rejection is more efficient than transform 01768 // for dimensions less than 8. 01769 // 01770 template<std::size_t _Dimen, typename _RealType> 01771 template<typename _UniformRandomNumberGenerator> 01772 typename uniform_inside_sphere_distribution<_Dimen, _RealType>::result_type 01773 uniform_inside_sphere_distribution<_Dimen, _RealType>:: 01774 operator()(_UniformRandomNumberGenerator& __urng, 01775 const param_type& __p) 01776 { 01777 uniform_inside_sphere_helper<_Dimen, _Dimen < 8, _RealType> __helper; 01778 return __helper(_M_uosd, __urng, __p.radius()); 01779 } 01780 01781 template<std::size_t _Dimen, typename _RealType> 01782 template<typename _OutputIterator, 01783 typename _UniformRandomNumberGenerator> 01784 void 01785 uniform_inside_sphere_distribution<_Dimen, _RealType>:: 01786 __generate_impl(_OutputIterator __f, _OutputIterator __t, 01787 _UniformRandomNumberGenerator& __urng, 01788 const param_type& __param) 01789 { 01790 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, 01791 result_type>) 01792 01793 while (__f != __t) 01794 *__f++ = this->operator()(__urng, __param); 01795 } 01796 01797 template<std::size_t _Dimen, typename _RealType, typename _CharT, 01798 typename _Traits> 01799 std::basic_ostream<_CharT, _Traits>& 01800 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 01801 const __gnu_cxx::uniform_inside_sphere_distribution<_Dimen, 01802 _RealType>& __x) 01803 { 01804 typedef std::basic_ostream<_CharT, _Traits> __ostream_type; 01805 typedef typename __ostream_type::ios_base __ios_base; 01806 01807 const typename __ios_base::fmtflags __flags = __os.flags(); 01808 const _CharT __fill = __os.fill(); 01809 const std::streamsize __precision = __os.precision(); 01810 const _CharT __space = __os.widen(' '); 01811 __os.flags(__ios_base::scientific | __ios_base::left); 01812 __os.fill(__space); 01813 __os.precision(std::numeric_limits<_RealType>::max_digits10); 01814 01815 __os << __x.radius() << __space << __x._M_uosd; 01816 01817 __os.flags(__flags); 01818 __os.fill(__fill); 01819 __os.precision(__precision); 01820 01821 return __os; 01822 } 01823 01824 template<std::size_t _Dimen, typename _RealType, typename _CharT, 01825 typename _Traits> 01826 std::basic_istream<_CharT, _Traits>& 01827 operator>>(std::basic_istream<_CharT, _Traits>& __is, 01828 __gnu_cxx::uniform_inside_sphere_distribution<_Dimen, 01829 _RealType>& __x) 01830 { 01831 typedef std::basic_istream<_CharT, _Traits> __istream_type; 01832 typedef typename __istream_type::ios_base __ios_base; 01833 01834 const typename __ios_base::fmtflags __flags = __is.flags(); 01835 __is.flags(__ios_base::dec | __ios_base::skipws); 01836 01837 _RealType __radius_val; 01838 __is >> __radius_val >> __x._M_uosd; 01839 __x.param(typename uniform_inside_sphere_distribution<_Dimen, _RealType>:: 01840 param_type(__radius_val)); 01841 01842 __is.flags(__flags); 01843 01844 return __is; 01845 } 01846 01847 _GLIBCXX_END_NAMESPACE_VERSION 01848 } // namespace __gnu_cxx 01849 01850 01851 #endif // _EXT_RANDOM_TCC