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