libstdc++
|
00001 // Random number extensions -*- C++ -*- 00002 00003 // Copyright (C) 2012-2013 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 00036 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) 00037 { 00038 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00039 00040 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 00041 00042 template<typename _UIntType, size_t __m, 00043 size_t __pos1, size_t __sl1, size_t __sl2, 00044 size_t __sr1, size_t __sr2, 00045 uint32_t __msk1, uint32_t __msk2, 00046 uint32_t __msk3, uint32_t __msk4, 00047 uint32_t __parity1, uint32_t __parity2, 00048 uint32_t __parity3, uint32_t __parity4> 00049 void simd_fast_mersenne_twister_engine<_UIntType, __m, 00050 __pos1, __sl1, __sl2, __sr1, __sr2, 00051 __msk1, __msk2, __msk3, __msk4, 00052 __parity1, __parity2, __parity3, 00053 __parity4>:: 00054 seed(_UIntType __seed) 00055 { 00056 _M_state32[0] = static_cast<uint32_t>(__seed); 00057 for (size_t __i = 1; __i < _M_nstate32; ++__i) 00058 _M_state32[__i] = (1812433253UL 00059 * (_M_state32[__i - 1] ^ (_M_state32[__i - 1] >> 30)) 00060 + __i); 00061 _M_pos = state_size; 00062 _M_period_certification(); 00063 } 00064 00065 00066 namespace { 00067 00068 inline uint32_t _Func1(uint32_t __x) 00069 { 00070 return (__x ^ (__x >> 27)) * UINT32_C(1664525); 00071 } 00072 00073 inline uint32_t _Func2(uint32_t __x) 00074 { 00075 return (__x ^ (__x >> 27)) * UINT32_C(1566083941); 00076 } 00077 00078 } 00079 00080 00081 template<typename _UIntType, size_t __m, 00082 size_t __pos1, size_t __sl1, size_t __sl2, 00083 size_t __sr1, size_t __sr2, 00084 uint32_t __msk1, uint32_t __msk2, 00085 uint32_t __msk3, uint32_t __msk4, 00086 uint32_t __parity1, uint32_t __parity2, 00087 uint32_t __parity3, uint32_t __parity4> 00088 template<typename _Sseq> 00089 typename std::enable_if<std::is_class<_Sseq>::value>::type 00090 simd_fast_mersenne_twister_engine<_UIntType, __m, 00091 __pos1, __sl1, __sl2, __sr1, __sr2, 00092 __msk1, __msk2, __msk3, __msk4, 00093 __parity1, __parity2, __parity3, 00094 __parity4>:: 00095 seed(_Sseq& __q) 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 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 00731 while (__f != __t) 00732 { 00733 typename std::normal_distribution<result_type>::param_type 00734 __px(__p.nu(), __p.sigma()), __py(result_type(0), __p.sigma()); 00735 result_type __x = this->_M_ndx(__px, __urng); 00736 result_type __y = this->_M_ndy(__py, __urng); 00737 #if _GLIBCXX_USE_C99_MATH_TR1 00738 *__f++ = std::hypot(__x, __y); 00739 #else 00740 *__f++ = std::sqrt(__x * __x + __y * __y); 00741 #endif 00742 } 00743 } 00744 00745 template<typename _RealType, typename _CharT, typename _Traits> 00746 std::basic_ostream<_CharT, _Traits>& 00747 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 00748 const rice_distribution<_RealType>& __x) 00749 { 00750 typedef std::basic_ostream<_CharT, _Traits> __ostream_type; 00751 typedef typename __ostream_type::ios_base __ios_base; 00752 00753 const typename __ios_base::fmtflags __flags = __os.flags(); 00754 const _CharT __fill = __os.fill(); 00755 const std::streamsize __precision = __os.precision(); 00756 const _CharT __space = __os.widen(' '); 00757 __os.flags(__ios_base::scientific | __ios_base::left); 00758 __os.fill(__space); 00759 __os.precision(std::numeric_limits<_RealType>::max_digits10); 00760 00761 __os << __x.nu() << __space << __x.sigma(); 00762 __os << __space << __x._M_ndx; 00763 __os << __space << __x._M_ndy; 00764 00765 __os.flags(__flags); 00766 __os.fill(__fill); 00767 __os.precision(__precision); 00768 return __os; 00769 } 00770 00771 template<typename _RealType, typename _CharT, typename _Traits> 00772 std::basic_istream<_CharT, _Traits>& 00773 operator>>(std::basic_istream<_CharT, _Traits>& __is, 00774 rice_distribution<_RealType>& __x) 00775 { 00776 typedef std::basic_istream<_CharT, _Traits> __istream_type; 00777 typedef typename __istream_type::ios_base __ios_base; 00778 00779 const typename __ios_base::fmtflags __flags = __is.flags(); 00780 __is.flags(__ios_base::dec | __ios_base::skipws); 00781 00782 _RealType __nu_val, __sigma_val; 00783 __is >> __nu_val >> __sigma_val; 00784 __is >> __x._M_ndx; 00785 __is >> __x._M_ndy; 00786 __x.param(typename rice_distribution<_RealType>:: 00787 param_type(__nu_val, __sigma_val)); 00788 00789 __is.flags(__flags); 00790 return __is; 00791 } 00792 00793 00794 template<typename _RealType> 00795 template<typename _OutputIterator, 00796 typename _UniformRandomNumberGenerator> 00797 void 00798 nakagami_distribution<_RealType>:: 00799 __generate_impl(_OutputIterator __f, _OutputIterator __t, 00800 _UniformRandomNumberGenerator& __urng, 00801 const param_type& __p) 00802 { 00803 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator>) 00804 00805 typename std::gamma_distribution<result_type>::param_type 00806 __pg(__p.mu(), __p.omega() / __p.mu()); 00807 while (__f != __t) 00808 *__f++ = std::sqrt(this->_M_gd(__pg, __urng)); 00809 } 00810 00811 template<typename _RealType, typename _CharT, typename _Traits> 00812 std::basic_ostream<_CharT, _Traits>& 00813 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 00814 const nakagami_distribution<_RealType>& __x) 00815 { 00816 typedef std::basic_ostream<_CharT, _Traits> __ostream_type; 00817 typedef typename __ostream_type::ios_base __ios_base; 00818 00819 const typename __ios_base::fmtflags __flags = __os.flags(); 00820 const _CharT __fill = __os.fill(); 00821 const std::streamsize __precision = __os.precision(); 00822 const _CharT __space = __os.widen(' '); 00823 __os.flags(__ios_base::scientific | __ios_base::left); 00824 __os.fill(__space); 00825 __os.precision(std::numeric_limits<_RealType>::max_digits10); 00826 00827 __os << __x.mu() << __space << __x.omega(); 00828 __os << __space << __x._M_gd; 00829 00830 __os.flags(__flags); 00831 __os.fill(__fill); 00832 __os.precision(__precision); 00833 return __os; 00834 } 00835 00836 template<typename _RealType, typename _CharT, typename _Traits> 00837 std::basic_istream<_CharT, _Traits>& 00838 operator>>(std::basic_istream<_CharT, _Traits>& __is, 00839 nakagami_distribution<_RealType>& __x) 00840 { 00841 typedef std::basic_istream<_CharT, _Traits> __istream_type; 00842 typedef typename __istream_type::ios_base __ios_base; 00843 00844 const typename __ios_base::fmtflags __flags = __is.flags(); 00845 __is.flags(__ios_base::dec | __ios_base::skipws); 00846 00847 _RealType __mu_val, __omega_val; 00848 __is >> __mu_val >> __omega_val; 00849 __is >> __x._M_gd; 00850 __x.param(typename nakagami_distribution<_RealType>:: 00851 param_type(__mu_val, __omega_val)); 00852 00853 __is.flags(__flags); 00854 return __is; 00855 } 00856 00857 00858 template<typename _RealType> 00859 template<typename _OutputIterator, 00860 typename _UniformRandomNumberGenerator> 00861 void 00862 pareto_distribution<_RealType>:: 00863 __generate_impl(_OutputIterator __f, _OutputIterator __t, 00864 _UniformRandomNumberGenerator& __urng, 00865 const param_type& __p) 00866 { 00867 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator>) 00868 00869 result_type __mu_val = __p.mu(); 00870 result_type __malphinv = -result_type(1) / __p.alpha(); 00871 while (__f != __t) 00872 *__f++ = __mu_val * std::pow(this->_M_ud(__urng), __malphinv); 00873 } 00874 00875 template<typename _RealType, typename _CharT, typename _Traits> 00876 std::basic_ostream<_CharT, _Traits>& 00877 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 00878 const pareto_distribution<_RealType>& __x) 00879 { 00880 typedef std::basic_ostream<_CharT, _Traits> __ostream_type; 00881 typedef typename __ostream_type::ios_base __ios_base; 00882 00883 const typename __ios_base::fmtflags __flags = __os.flags(); 00884 const _CharT __fill = __os.fill(); 00885 const std::streamsize __precision = __os.precision(); 00886 const _CharT __space = __os.widen(' '); 00887 __os.flags(__ios_base::scientific | __ios_base::left); 00888 __os.fill(__space); 00889 __os.precision(std::numeric_limits<_RealType>::max_digits10); 00890 00891 __os << __x.alpha() << __space << __x.mu(); 00892 __os << __space << __x._M_ud; 00893 00894 __os.flags(__flags); 00895 __os.fill(__fill); 00896 __os.precision(__precision); 00897 return __os; 00898 } 00899 00900 template<typename _RealType, typename _CharT, typename _Traits> 00901 std::basic_istream<_CharT, _Traits>& 00902 operator>>(std::basic_istream<_CharT, _Traits>& __is, 00903 pareto_distribution<_RealType>& __x) 00904 { 00905 typedef std::basic_istream<_CharT, _Traits> __istream_type; 00906 typedef typename __istream_type::ios_base __ios_base; 00907 00908 const typename __ios_base::fmtflags __flags = __is.flags(); 00909 __is.flags(__ios_base::dec | __ios_base::skipws); 00910 00911 _RealType __alpha_val, __mu_val; 00912 __is >> __alpha_val >> __mu_val; 00913 __is >> __x._M_ud; 00914 __x.param(typename pareto_distribution<_RealType>:: 00915 param_type(__alpha_val, __mu_val)); 00916 00917 __is.flags(__flags); 00918 return __is; 00919 } 00920 00921 00922 template<typename _RealType> 00923 template<typename _UniformRandomNumberGenerator> 00924 typename k_distribution<_RealType>::result_type 00925 k_distribution<_RealType>:: 00926 operator()(_UniformRandomNumberGenerator& __urng) 00927 { 00928 result_type __x = this->_M_gd1(__urng); 00929 result_type __y = this->_M_gd2(__urng); 00930 return std::sqrt(__x * __y); 00931 } 00932 00933 template<typename _RealType> 00934 template<typename _UniformRandomNumberGenerator> 00935 typename k_distribution<_RealType>::result_type 00936 k_distribution<_RealType>:: 00937 operator()(_UniformRandomNumberGenerator& __urng, 00938 const param_type& __p) 00939 { 00940 typename std::gamma_distribution<result_type>::param_type 00941 __p1(__p.lambda(), result_type(1) / __p.lambda()), 00942 __p2(__p.nu(), __p.mu() / __p.nu()); 00943 result_type __x = this->_M_gd1(__p1, __urng); 00944 result_type __y = this->_M_gd2(__p2, __urng); 00945 return std::sqrt(__x * __y); 00946 } 00947 00948 template<typename _RealType> 00949 template<typename _OutputIterator, 00950 typename _UniformRandomNumberGenerator> 00951 void 00952 k_distribution<_RealType>:: 00953 __generate_impl(_OutputIterator __f, _OutputIterator __t, 00954 _UniformRandomNumberGenerator& __urng, 00955 const param_type& __p) 00956 { 00957 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator>) 00958 00959 typename std::gamma_distribution<result_type>::param_type 00960 __p1(__p.lambda(), result_type(1) / __p.lambda()), 00961 __p2(__p.nu(), __p.mu() / __p.nu()); 00962 while (__f != __t) 00963 { 00964 result_type __x = this->_M_gd1(__p1, __urng); 00965 result_type __y = this->_M_gd2(__p2, __urng); 00966 *__f++ = std::sqrt(__x * __y); 00967 } 00968 } 00969 00970 template<typename _RealType, typename _CharT, typename _Traits> 00971 std::basic_ostream<_CharT, _Traits>& 00972 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 00973 const k_distribution<_RealType>& __x) 00974 { 00975 typedef std::basic_ostream<_CharT, _Traits> __ostream_type; 00976 typedef typename __ostream_type::ios_base __ios_base; 00977 00978 const typename __ios_base::fmtflags __flags = __os.flags(); 00979 const _CharT __fill = __os.fill(); 00980 const std::streamsize __precision = __os.precision(); 00981 const _CharT __space = __os.widen(' '); 00982 __os.flags(__ios_base::scientific | __ios_base::left); 00983 __os.fill(__space); 00984 __os.precision(std::numeric_limits<_RealType>::max_digits10); 00985 00986 __os << __x.lambda() << __space << __x.mu() << __space << __x.nu(); 00987 __os << __space << __x._M_gd1; 00988 __os << __space << __x._M_gd2; 00989 00990 __os.flags(__flags); 00991 __os.fill(__fill); 00992 __os.precision(__precision); 00993 return __os; 00994 } 00995 00996 template<typename _RealType, typename _CharT, typename _Traits> 00997 std::basic_istream<_CharT, _Traits>& 00998 operator>>(std::basic_istream<_CharT, _Traits>& __is, 00999 k_distribution<_RealType>& __x) 01000 { 01001 typedef std::basic_istream<_CharT, _Traits> __istream_type; 01002 typedef typename __istream_type::ios_base __ios_base; 01003 01004 const typename __ios_base::fmtflags __flags = __is.flags(); 01005 __is.flags(__ios_base::dec | __ios_base::skipws); 01006 01007 _RealType __lambda_val, __mu_val, __nu_val; 01008 __is >> __lambda_val >> __mu_val >> __nu_val; 01009 __is >> __x._M_gd1; 01010 __is >> __x._M_gd2; 01011 __x.param(typename k_distribution<_RealType>:: 01012 param_type(__lambda_val, __mu_val, __nu_val)); 01013 01014 __is.flags(__flags); 01015 return __is; 01016 } 01017 01018 01019 template<typename _RealType> 01020 template<typename _OutputIterator, 01021 typename _UniformRandomNumberGenerator> 01022 void 01023 arcsine_distribution<_RealType>:: 01024 __generate_impl(_OutputIterator __f, _OutputIterator __t, 01025 _UniformRandomNumberGenerator& __urng, 01026 const param_type& __p) 01027 { 01028 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator>) 01029 01030 result_type __dif = __p.b() - __p.a(); 01031 result_type __sum = __p.a() + __p.b(); 01032 while (__f != __t) 01033 { 01034 result_type __x = std::sin(this->_M_ud(__urng)); 01035 *__f++ = (__x * __dif + __sum) / result_type(2); 01036 } 01037 } 01038 01039 template<typename _RealType, typename _CharT, typename _Traits> 01040 std::basic_ostream<_CharT, _Traits>& 01041 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 01042 const arcsine_distribution<_RealType>& __x) 01043 { 01044 typedef std::basic_ostream<_CharT, _Traits> __ostream_type; 01045 typedef typename __ostream_type::ios_base __ios_base; 01046 01047 const typename __ios_base::fmtflags __flags = __os.flags(); 01048 const _CharT __fill = __os.fill(); 01049 const std::streamsize __precision = __os.precision(); 01050 const _CharT __space = __os.widen(' '); 01051 __os.flags(__ios_base::scientific | __ios_base::left); 01052 __os.fill(__space); 01053 __os.precision(std::numeric_limits<_RealType>::max_digits10); 01054 01055 __os << __x.a() << __space << __x.b(); 01056 __os << __space << __x._M_ud; 01057 01058 __os.flags(__flags); 01059 __os.fill(__fill); 01060 __os.precision(__precision); 01061 return __os; 01062 } 01063 01064 template<typename _RealType, typename _CharT, typename _Traits> 01065 std::basic_istream<_CharT, _Traits>& 01066 operator>>(std::basic_istream<_CharT, _Traits>& __is, 01067 arcsine_distribution<_RealType>& __x) 01068 { 01069 typedef std::basic_istream<_CharT, _Traits> __istream_type; 01070 typedef typename __istream_type::ios_base __ios_base; 01071 01072 const typename __ios_base::fmtflags __flags = __is.flags(); 01073 __is.flags(__ios_base::dec | __ios_base::skipws); 01074 01075 _RealType __a, __b; 01076 __is >> __a >> __b; 01077 __is >> __x._M_ud; 01078 __x.param(typename arcsine_distribution<_RealType>:: 01079 param_type(__a, __b)); 01080 01081 __is.flags(__flags); 01082 return __is; 01083 } 01084 01085 01086 template<typename _RealType> 01087 template<typename _UniformRandomNumberGenerator> 01088 typename hoyt_distribution<_RealType>::result_type 01089 hoyt_distribution<_RealType>:: 01090 operator()(_UniformRandomNumberGenerator& __urng) 01091 { 01092 result_type __x = this->_M_ad(__urng); 01093 result_type __y = this->_M_ed(__urng); 01094 return (result_type(2) * this->q() 01095 / (result_type(1) + this->q() * this->q())) 01096 * std::sqrt(this->omega() * __x * __y); 01097 } 01098 01099 template<typename _RealType> 01100 template<typename _UniformRandomNumberGenerator> 01101 typename hoyt_distribution<_RealType>::result_type 01102 hoyt_distribution<_RealType>:: 01103 operator()(_UniformRandomNumberGenerator& __urng, 01104 const param_type& __p) 01105 { 01106 result_type __q2 = __p.q() * __p.q(); 01107 result_type __num = result_type(0.5L) * (result_type(1) + __q2); 01108 typename __gnu_cxx::arcsine_distribution<result_type>::param_type 01109 __pa(__num, __num / __q2); 01110 result_type __x = this->_M_ad(__pa, __urng); 01111 result_type __y = this->_M_ed(__urng); 01112 return (result_type(2) * __p.q() / (result_type(1) + __q2)) 01113 * std::sqrt(__p.omega() * __x * __y); 01114 } 01115 01116 template<typename _RealType> 01117 template<typename _OutputIterator, 01118 typename _UniformRandomNumberGenerator> 01119 void 01120 hoyt_distribution<_RealType>:: 01121 __generate_impl(_OutputIterator __f, _OutputIterator __t, 01122 _UniformRandomNumberGenerator& __urng, 01123 const param_type& __p) 01124 { 01125 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator>) 01126 01127 result_type __2q = result_type(2) * __p.q(); 01128 result_type __q2 = __p.q() * __p.q(); 01129 result_type __q2p1 = result_type(1) + __q2; 01130 result_type __num = result_type(0.5L) * __q2p1; 01131 result_type __omega = __p.omega(); 01132 typename __gnu_cxx::arcsine_distribution<result_type>::param_type 01133 __pa(__num, __num / __q2); 01134 while (__f != __t) 01135 { 01136 result_type __x = this->_M_ad(__pa, __urng); 01137 result_type __y = this->_M_ed(__urng); 01138 *__f++ = (__2q / __q2p1) * std::sqrt(__omega * __x * __y); 01139 } 01140 } 01141 01142 template<typename _RealType, typename _CharT, typename _Traits> 01143 std::basic_ostream<_CharT, _Traits>& 01144 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 01145 const hoyt_distribution<_RealType>& __x) 01146 { 01147 typedef std::basic_ostream<_CharT, _Traits> __ostream_type; 01148 typedef typename __ostream_type::ios_base __ios_base; 01149 01150 const typename __ios_base::fmtflags __flags = __os.flags(); 01151 const _CharT __fill = __os.fill(); 01152 const std::streamsize __precision = __os.precision(); 01153 const _CharT __space = __os.widen(' '); 01154 __os.flags(__ios_base::scientific | __ios_base::left); 01155 __os.fill(__space); 01156 __os.precision(std::numeric_limits<_RealType>::max_digits10); 01157 01158 __os << __x.q() << __space << __x.omega(); 01159 __os << __space << __x._M_ad; 01160 __os << __space << __x._M_ed; 01161 01162 __os.flags(__flags); 01163 __os.fill(__fill); 01164 __os.precision(__precision); 01165 return __os; 01166 } 01167 01168 template<typename _RealType, typename _CharT, typename _Traits> 01169 std::basic_istream<_CharT, _Traits>& 01170 operator>>(std::basic_istream<_CharT, _Traits>& __is, 01171 hoyt_distribution<_RealType>& __x) 01172 { 01173 typedef std::basic_istream<_CharT, _Traits> __istream_type; 01174 typedef typename __istream_type::ios_base __ios_base; 01175 01176 const typename __ios_base::fmtflags __flags = __is.flags(); 01177 __is.flags(__ios_base::dec | __ios_base::skipws); 01178 01179 _RealType __q, __omega; 01180 __is >> __q >> __omega; 01181 __is >> __x._M_ad; 01182 __is >> __x._M_ed; 01183 __x.param(typename hoyt_distribution<_RealType>:: 01184 param_type(__q, __omega)); 01185 01186 __is.flags(__flags); 01187 return __is; 01188 } 01189 01190 01191 template<typename _RealType> 01192 template<typename _OutputIterator, 01193 typename _UniformRandomNumberGenerator> 01194 void 01195 triangular_distribution<_RealType>:: 01196 __generate_impl(_OutputIterator __f, _OutputIterator __t, 01197 _UniformRandomNumberGenerator& __urng, 01198 const param_type& __param) 01199 { 01200 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator>) 01201 01202 while (__f != __t) 01203 *__f++ = this->operator()(__urng, __param); 01204 } 01205 01206 template<typename _RealType, typename _CharT, typename _Traits> 01207 std::basic_ostream<_CharT, _Traits>& 01208 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 01209 const __gnu_cxx::triangular_distribution<_RealType>& __x) 01210 { 01211 typedef std::basic_ostream<_CharT, _Traits> __ostream_type; 01212 typedef typename __ostream_type::ios_base __ios_base; 01213 01214 const typename __ios_base::fmtflags __flags = __os.flags(); 01215 const _CharT __fill = __os.fill(); 01216 const std::streamsize __precision = __os.precision(); 01217 const _CharT __space = __os.widen(' '); 01218 __os.flags(__ios_base::scientific | __ios_base::left); 01219 __os.fill(__space); 01220 __os.precision(std::numeric_limits<_RealType>::max_digits10); 01221 01222 __os << __x.a() << __space << __x.b() << __space << __x.c(); 01223 01224 __os.flags(__flags); 01225 __os.fill(__fill); 01226 __os.precision(__precision); 01227 return __os; 01228 } 01229 01230 template<typename _RealType, typename _CharT, typename _Traits> 01231 std::basic_istream<_CharT, _Traits>& 01232 operator>>(std::basic_istream<_CharT, _Traits>& __is, 01233 __gnu_cxx::triangular_distribution<_RealType>& __x) 01234 { 01235 typedef std::basic_istream<_CharT, _Traits> __istream_type; 01236 typedef typename __istream_type::ios_base __ios_base; 01237 01238 const typename __ios_base::fmtflags __flags = __is.flags(); 01239 __is.flags(__ios_base::dec | __ios_base::skipws); 01240 01241 _RealType __a, __b, __c; 01242 __is >> __a >> __b >> __c; 01243 __x.param(typename __gnu_cxx::triangular_distribution<_RealType>:: 01244 param_type(__a, __b, __c)); 01245 01246 __is.flags(__flags); 01247 return __is; 01248 } 01249 01250 01251 template<typename _RealType> 01252 template<typename _OutputIterator, 01253 typename _UniformRandomNumberGenerator> 01254 void 01255 von_mises_distribution<_RealType>:: 01256 __generate_impl(_OutputIterator __f, _OutputIterator __t, 01257 _UniformRandomNumberGenerator& __urng, 01258 const param_type& __param) 01259 { 01260 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator>) 01261 01262 while (__f != __t) 01263 *__f++ = this->operator()(__urng, __param); 01264 } 01265 01266 template<typename _RealType, typename _CharT, typename _Traits> 01267 std::basic_ostream<_CharT, _Traits>& 01268 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 01269 const __gnu_cxx::von_mises_distribution<_RealType>& __x) 01270 { 01271 typedef std::basic_ostream<_CharT, _Traits> __ostream_type; 01272 typedef typename __ostream_type::ios_base __ios_base; 01273 01274 const typename __ios_base::fmtflags __flags = __os.flags(); 01275 const _CharT __fill = __os.fill(); 01276 const std::streamsize __precision = __os.precision(); 01277 const _CharT __space = __os.widen(' '); 01278 __os.flags(__ios_base::scientific | __ios_base::left); 01279 __os.fill(__space); 01280 __os.precision(std::numeric_limits<_RealType>::max_digits10); 01281 01282 __os << __x.mu() << __space << __x.kappa(); 01283 01284 __os.flags(__flags); 01285 __os.fill(__fill); 01286 __os.precision(__precision); 01287 return __os; 01288 } 01289 01290 template<typename _RealType, typename _CharT, typename _Traits> 01291 std::basic_istream<_CharT, _Traits>& 01292 operator>>(std::basic_istream<_CharT, _Traits>& __is, 01293 __gnu_cxx::von_mises_distribution<_RealType>& __x) 01294 { 01295 typedef std::basic_istream<_CharT, _Traits> __istream_type; 01296 typedef typename __istream_type::ios_base __ios_base; 01297 01298 const typename __ios_base::fmtflags __flags = __is.flags(); 01299 __is.flags(__ios_base::dec | __ios_base::skipws); 01300 01301 _RealType __mu, __kappa; 01302 __is >> __mu >> __kappa; 01303 __x.param(typename __gnu_cxx::von_mises_distribution<_RealType>:: 01304 param_type(__mu, __kappa)); 01305 01306 __is.flags(__flags); 01307 return __is; 01308 } 01309 01310 _GLIBCXX_END_NAMESPACE_VERSION 01311 } // namespace 01312 01313 01314 #endif // _EXT_RANDOM_TCC