You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1854 line
59KB

  1. // Random number extensions -*- C++ -*-
  2. // Copyright (C) 2012-2020 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file ext/random.tcc
  21. * This is an internal header file, included by other library headers.
  22. * Do not attempt to use it directly. @headername{ext/random}
  23. */
  24. #ifndef _EXT_RANDOM_TCC
  25. #define _EXT_RANDOM_TCC 1
  26. #pragma GCC system_header
  27. namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
  28. {
  29. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  30. #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
  31. template<typename _UIntType, size_t __m,
  32. size_t __pos1, size_t __sl1, size_t __sl2,
  33. size_t __sr1, size_t __sr2,
  34. uint32_t __msk1, uint32_t __msk2,
  35. uint32_t __msk3, uint32_t __msk4,
  36. uint32_t __parity1, uint32_t __parity2,
  37. uint32_t __parity3, uint32_t __parity4>
  38. void simd_fast_mersenne_twister_engine<_UIntType, __m,
  39. __pos1, __sl1, __sl2, __sr1, __sr2,
  40. __msk1, __msk2, __msk3, __msk4,
  41. __parity1, __parity2, __parity3,
  42. __parity4>::
  43. seed(_UIntType __seed)
  44. {
  45. _M_state32[0] = static_cast<uint32_t>(__seed);
  46. for (size_t __i = 1; __i < _M_nstate32; ++__i)
  47. _M_state32[__i] = (1812433253UL
  48. * (_M_state32[__i - 1] ^ (_M_state32[__i - 1] >> 30))
  49. + __i);
  50. _M_pos = state_size;
  51. _M_period_certification();
  52. }
  53. namespace {
  54. inline uint32_t _Func1(uint32_t __x)
  55. {
  56. return (__x ^ (__x >> 27)) * UINT32_C(1664525);
  57. }
  58. inline uint32_t _Func2(uint32_t __x)
  59. {
  60. return (__x ^ (__x >> 27)) * UINT32_C(1566083941);
  61. }
  62. }
  63. template<typename _UIntType, size_t __m,
  64. size_t __pos1, size_t __sl1, size_t __sl2,
  65. size_t __sr1, size_t __sr2,
  66. uint32_t __msk1, uint32_t __msk2,
  67. uint32_t __msk3, uint32_t __msk4,
  68. uint32_t __parity1, uint32_t __parity2,
  69. uint32_t __parity3, uint32_t __parity4>
  70. template<typename _Sseq>
  71. auto
  72. simd_fast_mersenne_twister_engine<_UIntType, __m,
  73. __pos1, __sl1, __sl2, __sr1, __sr2,
  74. __msk1, __msk2, __msk3, __msk4,
  75. __parity1, __parity2, __parity3,
  76. __parity4>::
  77. seed(_Sseq& __q)
  78. -> _If_seed_seq<_Sseq>
  79. {
  80. size_t __lag;
  81. if (_M_nstate32 >= 623)
  82. __lag = 11;
  83. else if (_M_nstate32 >= 68)
  84. __lag = 7;
  85. else if (_M_nstate32 >= 39)
  86. __lag = 5;
  87. else
  88. __lag = 3;
  89. const size_t __mid = (_M_nstate32 - __lag) / 2;
  90. std::fill(_M_state32, _M_state32 + _M_nstate32, UINT32_C(0x8b8b8b8b));
  91. uint32_t __arr[_M_nstate32];
  92. __q.generate(__arr + 0, __arr + _M_nstate32);
  93. uint32_t __r = _Func1(_M_state32[0] ^ _M_state32[__mid]
  94. ^ _M_state32[_M_nstate32 - 1]);
  95. _M_state32[__mid] += __r;
  96. __r += _M_nstate32;
  97. _M_state32[__mid + __lag] += __r;
  98. _M_state32[0] = __r;
  99. for (size_t __i = 1, __j = 0; __j < _M_nstate32; ++__j)
  100. {
  101. __r = _Func1(_M_state32[__i]
  102. ^ _M_state32[(__i + __mid) % _M_nstate32]
  103. ^ _M_state32[(__i + _M_nstate32 - 1) % _M_nstate32]);
  104. _M_state32[(__i + __mid) % _M_nstate32] += __r;
  105. __r += __arr[__j] + __i;
  106. _M_state32[(__i + __mid + __lag) % _M_nstate32] += __r;
  107. _M_state32[__i] = __r;
  108. __i = (__i + 1) % _M_nstate32;
  109. }
  110. for (size_t __j = 0; __j < _M_nstate32; ++__j)
  111. {
  112. const size_t __i = (__j + 1) % _M_nstate32;
  113. __r = _Func2(_M_state32[__i]
  114. + _M_state32[(__i + __mid) % _M_nstate32]
  115. + _M_state32[(__i + _M_nstate32 - 1) % _M_nstate32]);
  116. _M_state32[(__i + __mid) % _M_nstate32] ^= __r;
  117. __r -= __i;
  118. _M_state32[(__i + __mid + __lag) % _M_nstate32] ^= __r;
  119. _M_state32[__i] = __r;
  120. }
  121. _M_pos = state_size;
  122. _M_period_certification();
  123. }
  124. template<typename _UIntType, size_t __m,
  125. size_t __pos1, size_t __sl1, size_t __sl2,
  126. size_t __sr1, size_t __sr2,
  127. uint32_t __msk1, uint32_t __msk2,
  128. uint32_t __msk3, uint32_t __msk4,
  129. uint32_t __parity1, uint32_t __parity2,
  130. uint32_t __parity3, uint32_t __parity4>
  131. void simd_fast_mersenne_twister_engine<_UIntType, __m,
  132. __pos1, __sl1, __sl2, __sr1, __sr2,
  133. __msk1, __msk2, __msk3, __msk4,
  134. __parity1, __parity2, __parity3,
  135. __parity4>::
  136. _M_period_certification(void)
  137. {
  138. static const uint32_t __parity[4] = { __parity1, __parity2,
  139. __parity3, __parity4 };
  140. uint32_t __inner = 0;
  141. for (size_t __i = 0; __i < 4; ++__i)
  142. if (__parity[__i] != 0)
  143. __inner ^= _M_state32[__i] & __parity[__i];
  144. if (__builtin_parity(__inner) & 1)
  145. return;
  146. for (size_t __i = 0; __i < 4; ++__i)
  147. if (__parity[__i] != 0)
  148. {
  149. _M_state32[__i] ^= 1 << (__builtin_ffs(__parity[__i]) - 1);
  150. return;
  151. }
  152. __builtin_unreachable();
  153. }
  154. template<typename _UIntType, size_t __m,
  155. size_t __pos1, size_t __sl1, size_t __sl2,
  156. size_t __sr1, size_t __sr2,
  157. uint32_t __msk1, uint32_t __msk2,
  158. uint32_t __msk3, uint32_t __msk4,
  159. uint32_t __parity1, uint32_t __parity2,
  160. uint32_t __parity3, uint32_t __parity4>
  161. void simd_fast_mersenne_twister_engine<_UIntType, __m,
  162. __pos1, __sl1, __sl2, __sr1, __sr2,
  163. __msk1, __msk2, __msk3, __msk4,
  164. __parity1, __parity2, __parity3,
  165. __parity4>::
  166. discard(unsigned long long __z)
  167. {
  168. while (__z > state_size - _M_pos)
  169. {
  170. __z -= state_size - _M_pos;
  171. _M_gen_rand();
  172. }
  173. _M_pos += __z;
  174. }
  175. #ifndef _GLIBCXX_OPT_HAVE_RANDOM_SFMT_GEN_READ
  176. namespace {
  177. template<size_t __shift>
  178. inline void __rshift(uint32_t *__out, const uint32_t *__in)
  179. {
  180. uint64_t __th = ((static_cast<uint64_t>(__in[3]) << 32)
  181. | static_cast<uint64_t>(__in[2]));
  182. uint64_t __tl = ((static_cast<uint64_t>(__in[1]) << 32)
  183. | static_cast<uint64_t>(__in[0]));
  184. uint64_t __oh = __th >> (__shift * 8);
  185. uint64_t __ol = __tl >> (__shift * 8);
  186. __ol |= __th << (64 - __shift * 8);
  187. __out[1] = static_cast<uint32_t>(__ol >> 32);
  188. __out[0] = static_cast<uint32_t>(__ol);
  189. __out[3] = static_cast<uint32_t>(__oh >> 32);
  190. __out[2] = static_cast<uint32_t>(__oh);
  191. }
  192. template<size_t __shift>
  193. inline void __lshift(uint32_t *__out, const uint32_t *__in)
  194. {
  195. uint64_t __th = ((static_cast<uint64_t>(__in[3]) << 32)
  196. | static_cast<uint64_t>(__in[2]));
  197. uint64_t __tl = ((static_cast<uint64_t>(__in[1]) << 32)
  198. | static_cast<uint64_t>(__in[0]));
  199. uint64_t __oh = __th << (__shift * 8);
  200. uint64_t __ol = __tl << (__shift * 8);
  201. __oh |= __tl >> (64 - __shift * 8);
  202. __out[1] = static_cast<uint32_t>(__ol >> 32);
  203. __out[0] = static_cast<uint32_t>(__ol);
  204. __out[3] = static_cast<uint32_t>(__oh >> 32);
  205. __out[2] = static_cast<uint32_t>(__oh);
  206. }
  207. template<size_t __sl1, size_t __sl2, size_t __sr1, size_t __sr2,
  208. uint32_t __msk1, uint32_t __msk2, uint32_t __msk3, uint32_t __msk4>
  209. inline void __recursion(uint32_t *__r,
  210. const uint32_t *__a, const uint32_t *__b,
  211. const uint32_t *__c, const uint32_t *__d)
  212. {
  213. uint32_t __x[4];
  214. uint32_t __y[4];
  215. __lshift<__sl2>(__x, __a);
  216. __rshift<__sr2>(__y, __c);
  217. __r[0] = (__a[0] ^ __x[0] ^ ((__b[0] >> __sr1) & __msk1)
  218. ^ __y[0] ^ (__d[0] << __sl1));
  219. __r[1] = (__a[1] ^ __x[1] ^ ((__b[1] >> __sr1) & __msk2)
  220. ^ __y[1] ^ (__d[1] << __sl1));
  221. __r[2] = (__a[2] ^ __x[2] ^ ((__b[2] >> __sr1) & __msk3)
  222. ^ __y[2] ^ (__d[2] << __sl1));
  223. __r[3] = (__a[3] ^ __x[3] ^ ((__b[3] >> __sr1) & __msk4)
  224. ^ __y[3] ^ (__d[3] << __sl1));
  225. }
  226. }
  227. template<typename _UIntType, size_t __m,
  228. size_t __pos1, size_t __sl1, size_t __sl2,
  229. size_t __sr1, size_t __sr2,
  230. uint32_t __msk1, uint32_t __msk2,
  231. uint32_t __msk3, uint32_t __msk4,
  232. uint32_t __parity1, uint32_t __parity2,
  233. uint32_t __parity3, uint32_t __parity4>
  234. void simd_fast_mersenne_twister_engine<_UIntType, __m,
  235. __pos1, __sl1, __sl2, __sr1, __sr2,
  236. __msk1, __msk2, __msk3, __msk4,
  237. __parity1, __parity2, __parity3,
  238. __parity4>::
  239. _M_gen_rand(void)
  240. {
  241. const uint32_t *__r1 = &_M_state32[_M_nstate32 - 8];
  242. const uint32_t *__r2 = &_M_state32[_M_nstate32 - 4];
  243. static constexpr size_t __pos1_32 = __pos1 * 4;
  244. size_t __i;
  245. for (__i = 0; __i < _M_nstate32 - __pos1_32; __i += 4)
  246. {
  247. __recursion<__sl1, __sl2, __sr1, __sr2,
  248. __msk1, __msk2, __msk3, __msk4>
  249. (&_M_state32[__i], &_M_state32[__i],
  250. &_M_state32[__i + __pos1_32], __r1, __r2);
  251. __r1 = __r2;
  252. __r2 = &_M_state32[__i];
  253. }
  254. for (; __i < _M_nstate32; __i += 4)
  255. {
  256. __recursion<__sl1, __sl2, __sr1, __sr2,
  257. __msk1, __msk2, __msk3, __msk4>
  258. (&_M_state32[__i], &_M_state32[__i],
  259. &_M_state32[__i + __pos1_32 - _M_nstate32], __r1, __r2);
  260. __r1 = __r2;
  261. __r2 = &_M_state32[__i];
  262. }
  263. _M_pos = 0;
  264. }
  265. #endif
  266. #ifndef _GLIBCXX_OPT_HAVE_RANDOM_SFMT_OPERATOREQUAL
  267. template<typename _UIntType, size_t __m,
  268. size_t __pos1, size_t __sl1, size_t __sl2,
  269. size_t __sr1, size_t __sr2,
  270. uint32_t __msk1, uint32_t __msk2,
  271. uint32_t __msk3, uint32_t __msk4,
  272. uint32_t __parity1, uint32_t __parity2,
  273. uint32_t __parity3, uint32_t __parity4>
  274. bool
  275. operator==(const __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType,
  276. __m, __pos1, __sl1, __sl2, __sr1, __sr2,
  277. __msk1, __msk2, __msk3, __msk4,
  278. __parity1, __parity2, __parity3, __parity4>& __lhs,
  279. const __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType,
  280. __m, __pos1, __sl1, __sl2, __sr1, __sr2,
  281. __msk1, __msk2, __msk3, __msk4,
  282. __parity1, __parity2, __parity3, __parity4>& __rhs)
  283. {
  284. typedef __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType,
  285. __m, __pos1, __sl1, __sl2, __sr1, __sr2,
  286. __msk1, __msk2, __msk3, __msk4,
  287. __parity1, __parity2, __parity3, __parity4> __engine;
  288. return (std::equal(__lhs._M_stateT,
  289. __lhs._M_stateT + __engine::state_size,
  290. __rhs._M_stateT)
  291. && __lhs._M_pos == __rhs._M_pos);
  292. }
  293. #endif
  294. template<typename _UIntType, size_t __m,
  295. size_t __pos1, size_t __sl1, size_t __sl2,
  296. size_t __sr1, size_t __sr2,
  297. uint32_t __msk1, uint32_t __msk2,
  298. uint32_t __msk3, uint32_t __msk4,
  299. uint32_t __parity1, uint32_t __parity2,
  300. uint32_t __parity3, uint32_t __parity4,
  301. typename _CharT, typename _Traits>
  302. std::basic_ostream<_CharT, _Traits>&
  303. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  304. const __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType,
  305. __m, __pos1, __sl1, __sl2, __sr1, __sr2,
  306. __msk1, __msk2, __msk3, __msk4,
  307. __parity1, __parity2, __parity3, __parity4>& __x)
  308. {
  309. typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
  310. typedef typename __ostream_type::ios_base __ios_base;
  311. const typename __ios_base::fmtflags __flags = __os.flags();
  312. const _CharT __fill = __os.fill();
  313. const _CharT __space = __os.widen(' ');
  314. __os.flags(__ios_base::dec | __ios_base::fixed | __ios_base::left);
  315. __os.fill(__space);
  316. for (size_t __i = 0; __i < __x._M_nstate32; ++__i)
  317. __os << __x._M_state32[__i] << __space;
  318. __os << __x._M_pos;
  319. __os.flags(__flags);
  320. __os.fill(__fill);
  321. return __os;
  322. }
  323. template<typename _UIntType, size_t __m,
  324. size_t __pos1, size_t __sl1, size_t __sl2,
  325. size_t __sr1, size_t __sr2,
  326. uint32_t __msk1, uint32_t __msk2,
  327. uint32_t __msk3, uint32_t __msk4,
  328. uint32_t __parity1, uint32_t __parity2,
  329. uint32_t __parity3, uint32_t __parity4,
  330. typename _CharT, typename _Traits>
  331. std::basic_istream<_CharT, _Traits>&
  332. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  333. __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType,
  334. __m, __pos1, __sl1, __sl2, __sr1, __sr2,
  335. __msk1, __msk2, __msk3, __msk4,
  336. __parity1, __parity2, __parity3, __parity4>& __x)
  337. {
  338. typedef std::basic_istream<_CharT, _Traits> __istream_type;
  339. typedef typename __istream_type::ios_base __ios_base;
  340. const typename __ios_base::fmtflags __flags = __is.flags();
  341. __is.flags(__ios_base::dec | __ios_base::skipws);
  342. for (size_t __i = 0; __i < __x._M_nstate32; ++__i)
  343. __is >> __x._M_state32[__i];
  344. __is >> __x._M_pos;
  345. __is.flags(__flags);
  346. return __is;
  347. }
  348. #endif // __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
  349. /**
  350. * Iteration method due to M.D. J<o:>hnk.
  351. *
  352. * M.D. J<o:>hnk, Erzeugung von betaverteilten und gammaverteilten
  353. * Zufallszahlen, Metrika, Volume 8, 1964
  354. */
  355. template<typename _RealType>
  356. template<typename _UniformRandomNumberGenerator>
  357. typename beta_distribution<_RealType>::result_type
  358. beta_distribution<_RealType>::
  359. operator()(_UniformRandomNumberGenerator& __urng,
  360. const param_type& __param)
  361. {
  362. std::__detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
  363. __aurng(__urng);
  364. result_type __x, __y;
  365. do
  366. {
  367. __x = std::exp(std::log(__aurng()) / __param.alpha());
  368. __y = std::exp(std::log(__aurng()) / __param.beta());
  369. }
  370. while (__x + __y > result_type(1));
  371. return __x / (__x + __y);
  372. }
  373. template<typename _RealType>
  374. template<typename _OutputIterator,
  375. typename _UniformRandomNumberGenerator>
  376. void
  377. beta_distribution<_RealType>::
  378. __generate_impl(_OutputIterator __f, _OutputIterator __t,
  379. _UniformRandomNumberGenerator& __urng,
  380. const param_type& __param)
  381. {
  382. __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
  383. result_type>)
  384. std::__detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
  385. __aurng(__urng);
  386. while (__f != __t)
  387. {
  388. result_type __x, __y;
  389. do
  390. {
  391. __x = std::exp(std::log(__aurng()) / __param.alpha());
  392. __y = std::exp(std::log(__aurng()) / __param.beta());
  393. }
  394. while (__x + __y > result_type(1));
  395. *__f++ = __x / (__x + __y);
  396. }
  397. }
  398. template<typename _RealType, typename _CharT, typename _Traits>
  399. std::basic_ostream<_CharT, _Traits>&
  400. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  401. const __gnu_cxx::beta_distribution<_RealType>& __x)
  402. {
  403. typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
  404. typedef typename __ostream_type::ios_base __ios_base;
  405. const typename __ios_base::fmtflags __flags = __os.flags();
  406. const _CharT __fill = __os.fill();
  407. const std::streamsize __precision = __os.precision();
  408. const _CharT __space = __os.widen(' ');
  409. __os.flags(__ios_base::scientific | __ios_base::left);
  410. __os.fill(__space);
  411. __os.precision(std::numeric_limits<_RealType>::max_digits10);
  412. __os << __x.alpha() << __space << __x.beta();
  413. __os.flags(__flags);
  414. __os.fill(__fill);
  415. __os.precision(__precision);
  416. return __os;
  417. }
  418. template<typename _RealType, typename _CharT, typename _Traits>
  419. std::basic_istream<_CharT, _Traits>&
  420. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  421. __gnu_cxx::beta_distribution<_RealType>& __x)
  422. {
  423. typedef std::basic_istream<_CharT, _Traits> __istream_type;
  424. typedef typename __istream_type::ios_base __ios_base;
  425. const typename __ios_base::fmtflags __flags = __is.flags();
  426. __is.flags(__ios_base::dec | __ios_base::skipws);
  427. _RealType __alpha_val, __beta_val;
  428. __is >> __alpha_val >> __beta_val;
  429. __x.param(typename __gnu_cxx::beta_distribution<_RealType>::
  430. param_type(__alpha_val, __beta_val));
  431. __is.flags(__flags);
  432. return __is;
  433. }
  434. template<std::size_t _Dimen, typename _RealType>
  435. template<typename _InputIterator1, typename _InputIterator2>
  436. void
  437. normal_mv_distribution<_Dimen, _RealType>::param_type::
  438. _M_init_full(_InputIterator1 __meanbegin, _InputIterator1 __meanend,
  439. _InputIterator2 __varcovbegin, _InputIterator2 __varcovend)
  440. {
  441. __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
  442. __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
  443. std::fill(std::copy(__meanbegin, __meanend, _M_mean.begin()),
  444. _M_mean.end(), _RealType(0));
  445. // Perform the Cholesky decomposition
  446. auto __w = _M_t.begin();
  447. for (size_t __j = 0; __j < _Dimen; ++__j)
  448. {
  449. _RealType __sum = _RealType(0);
  450. auto __slitbegin = __w;
  451. auto __cit = _M_t.begin();
  452. for (size_t __i = 0; __i < __j; ++__i)
  453. {
  454. auto __slit = __slitbegin;
  455. _RealType __s = *__varcovbegin++;
  456. for (size_t __k = 0; __k < __i; ++__k)
  457. __s -= *__slit++ * *__cit++;
  458. *__w++ = __s /= *__cit++;
  459. __sum += __s * __s;
  460. }
  461. __sum = *__varcovbegin - __sum;
  462. if (__builtin_expect(__sum <= _RealType(0), 0))
  463. std::__throw_runtime_error(__N("normal_mv_distribution::"
  464. "param_type::_M_init_full"));
  465. *__w++ = std::sqrt(__sum);
  466. std::advance(__varcovbegin, _Dimen - __j);
  467. }
  468. }
  469. template<std::size_t _Dimen, typename _RealType>
  470. template<typename _InputIterator1, typename _InputIterator2>
  471. void
  472. normal_mv_distribution<_Dimen, _RealType>::param_type::
  473. _M_init_lower(_InputIterator1 __meanbegin, _InputIterator1 __meanend,
  474. _InputIterator2 __varcovbegin, _InputIterator2 __varcovend)
  475. {
  476. __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
  477. __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
  478. std::fill(std::copy(__meanbegin, __meanend, _M_mean.begin()),
  479. _M_mean.end(), _RealType(0));
  480. // Perform the Cholesky decomposition
  481. auto __w = _M_t.begin();
  482. for (size_t __j = 0; __j < _Dimen; ++__j)
  483. {
  484. _RealType __sum = _RealType(0);
  485. auto __slitbegin = __w;
  486. auto __cit = _M_t.begin();
  487. for (size_t __i = 0; __i < __j; ++__i)
  488. {
  489. auto __slit = __slitbegin;
  490. _RealType __s = *__varcovbegin++;
  491. for (size_t __k = 0; __k < __i; ++__k)
  492. __s -= *__slit++ * *__cit++;
  493. *__w++ = __s /= *__cit++;
  494. __sum += __s * __s;
  495. }
  496. __sum = *__varcovbegin++ - __sum;
  497. if (__builtin_expect(__sum <= _RealType(0), 0))
  498. std::__throw_runtime_error(__N("normal_mv_distribution::"
  499. "param_type::_M_init_lower"));
  500. *__w++ = std::sqrt(__sum);
  501. }
  502. }
  503. template<std::size_t _Dimen, typename _RealType>
  504. template<typename _InputIterator1, typename _InputIterator2>
  505. void
  506. normal_mv_distribution<_Dimen, _RealType>::param_type::
  507. _M_init_diagonal(_InputIterator1 __meanbegin, _InputIterator1 __meanend,
  508. _InputIterator2 __varbegin, _InputIterator2 __varend)
  509. {
  510. __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
  511. __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
  512. std::fill(std::copy(__meanbegin, __meanend, _M_mean.begin()),
  513. _M_mean.end(), _RealType(0));
  514. auto __w = _M_t.begin();
  515. size_t __step = 0;
  516. while (__varbegin != __varend)
  517. {
  518. std::fill_n(__w, __step, _RealType(0));
  519. __w += __step++;
  520. if (__builtin_expect(*__varbegin < _RealType(0), 0))
  521. std::__throw_runtime_error(__N("normal_mv_distribution::"
  522. "param_type::_M_init_diagonal"));
  523. *__w++ = std::sqrt(*__varbegin++);
  524. }
  525. }
  526. template<std::size_t _Dimen, typename _RealType>
  527. template<typename _UniformRandomNumberGenerator>
  528. typename normal_mv_distribution<_Dimen, _RealType>::result_type
  529. normal_mv_distribution<_Dimen, _RealType>::
  530. operator()(_UniformRandomNumberGenerator& __urng,
  531. const param_type& __param)
  532. {
  533. result_type __ret;
  534. _M_nd.__generate(__ret.begin(), __ret.end(), __urng);
  535. auto __t_it = __param._M_t.crbegin();
  536. for (size_t __i = _Dimen; __i > 0; --__i)
  537. {
  538. _RealType __sum = _RealType(0);
  539. for (size_t __j = __i; __j > 0; --__j)
  540. __sum += __ret[__j - 1] * *__t_it++;
  541. __ret[__i - 1] = __sum;
  542. }
  543. return __ret;
  544. }
  545. template<std::size_t _Dimen, typename _RealType>
  546. template<typename _ForwardIterator, typename _UniformRandomNumberGenerator>
  547. void
  548. normal_mv_distribution<_Dimen, _RealType>::
  549. __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
  550. _UniformRandomNumberGenerator& __urng,
  551. const param_type& __param)
  552. {
  553. __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
  554. _ForwardIterator>)
  555. while (__f != __t)
  556. *__f++ = this->operator()(__urng, __param);
  557. }
  558. template<size_t _Dimen, typename _RealType>
  559. bool
  560. operator==(const __gnu_cxx::normal_mv_distribution<_Dimen, _RealType>&
  561. __d1,
  562. const __gnu_cxx::normal_mv_distribution<_Dimen, _RealType>&
  563. __d2)
  564. {
  565. return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd;
  566. }
  567. template<size_t _Dimen, typename _RealType, typename _CharT, typename _Traits>
  568. std::basic_ostream<_CharT, _Traits>&
  569. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  570. const __gnu_cxx::normal_mv_distribution<_Dimen, _RealType>& __x)
  571. {
  572. typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
  573. typedef typename __ostream_type::ios_base __ios_base;
  574. const typename __ios_base::fmtflags __flags = __os.flags();
  575. const _CharT __fill = __os.fill();
  576. const std::streamsize __precision = __os.precision();
  577. const _CharT __space = __os.widen(' ');
  578. __os.flags(__ios_base::scientific | __ios_base::left);
  579. __os.fill(__space);
  580. __os.precision(std::numeric_limits<_RealType>::max_digits10);
  581. auto __mean = __x._M_param.mean();
  582. for (auto __it : __mean)
  583. __os << __it << __space;
  584. auto __t = __x._M_param.varcov();
  585. for (auto __it : __t)
  586. __os << __it << __space;
  587. __os << __x._M_nd;
  588. __os.flags(__flags);
  589. __os.fill(__fill);
  590. __os.precision(__precision);
  591. return __os;
  592. }
  593. template<size_t _Dimen, typename _RealType, typename _CharT, typename _Traits>
  594. std::basic_istream<_CharT, _Traits>&
  595. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  596. __gnu_cxx::normal_mv_distribution<_Dimen, _RealType>& __x)
  597. {
  598. typedef std::basic_istream<_CharT, _Traits> __istream_type;
  599. typedef typename __istream_type::ios_base __ios_base;
  600. const typename __ios_base::fmtflags __flags = __is.flags();
  601. __is.flags(__ios_base::dec | __ios_base::skipws);
  602. std::array<_RealType, _Dimen> __mean;
  603. for (auto& __it : __mean)
  604. __is >> __it;
  605. std::array<_RealType, _Dimen * (_Dimen + 1) / 2> __varcov;
  606. for (auto& __it : __varcov)
  607. __is >> __it;
  608. __is >> __x._M_nd;
  609. // The param_type temporary is built with a private constructor,
  610. // to skip the Cholesky decomposition that would be performed
  611. // otherwise.
  612. __x.param(typename normal_mv_distribution<_Dimen, _RealType>::
  613. param_type(__mean, __varcov));
  614. __is.flags(__flags);
  615. return __is;
  616. }
  617. template<typename _RealType>
  618. template<typename _OutputIterator,
  619. typename _UniformRandomNumberGenerator>
  620. void
  621. rice_distribution<_RealType>::
  622. __generate_impl(_OutputIterator __f, _OutputIterator __t,
  623. _UniformRandomNumberGenerator& __urng,
  624. const param_type& __p)
  625. {
  626. __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
  627. result_type>)
  628. while (__f != __t)
  629. {
  630. typename std::normal_distribution<result_type>::param_type
  631. __px(__p.nu(), __p.sigma()), __py(result_type(0), __p.sigma());
  632. result_type __x = this->_M_ndx(__px, __urng);
  633. result_type __y = this->_M_ndy(__py, __urng);
  634. #if _GLIBCXX_USE_C99_MATH_TR1
  635. *__f++ = std::hypot(__x, __y);
  636. #else
  637. *__f++ = std::sqrt(__x * __x + __y * __y);
  638. #endif
  639. }
  640. }
  641. template<typename _RealType, typename _CharT, typename _Traits>
  642. std::basic_ostream<_CharT, _Traits>&
  643. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  644. const rice_distribution<_RealType>& __x)
  645. {
  646. typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
  647. typedef typename __ostream_type::ios_base __ios_base;
  648. const typename __ios_base::fmtflags __flags = __os.flags();
  649. const _CharT __fill = __os.fill();
  650. const std::streamsize __precision = __os.precision();
  651. const _CharT __space = __os.widen(' ');
  652. __os.flags(__ios_base::scientific | __ios_base::left);
  653. __os.fill(__space);
  654. __os.precision(std::numeric_limits<_RealType>::max_digits10);
  655. __os << __x.nu() << __space << __x.sigma();
  656. __os << __space << __x._M_ndx;
  657. __os << __space << __x._M_ndy;
  658. __os.flags(__flags);
  659. __os.fill(__fill);
  660. __os.precision(__precision);
  661. return __os;
  662. }
  663. template<typename _RealType, typename _CharT, typename _Traits>
  664. std::basic_istream<_CharT, _Traits>&
  665. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  666. rice_distribution<_RealType>& __x)
  667. {
  668. typedef std::basic_istream<_CharT, _Traits> __istream_type;
  669. typedef typename __istream_type::ios_base __ios_base;
  670. const typename __ios_base::fmtflags __flags = __is.flags();
  671. __is.flags(__ios_base::dec | __ios_base::skipws);
  672. _RealType __nu_val, __sigma_val;
  673. __is >> __nu_val >> __sigma_val;
  674. __is >> __x._M_ndx;
  675. __is >> __x._M_ndy;
  676. __x.param(typename rice_distribution<_RealType>::
  677. param_type(__nu_val, __sigma_val));
  678. __is.flags(__flags);
  679. return __is;
  680. }
  681. template<typename _RealType>
  682. template<typename _OutputIterator,
  683. typename _UniformRandomNumberGenerator>
  684. void
  685. nakagami_distribution<_RealType>::
  686. __generate_impl(_OutputIterator __f, _OutputIterator __t,
  687. _UniformRandomNumberGenerator& __urng,
  688. const param_type& __p)
  689. {
  690. __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
  691. result_type>)
  692. typename std::gamma_distribution<result_type>::param_type
  693. __pg(__p.mu(), __p.omega() / __p.mu());
  694. while (__f != __t)
  695. *__f++ = std::sqrt(this->_M_gd(__pg, __urng));
  696. }
  697. template<typename _RealType, typename _CharT, typename _Traits>
  698. std::basic_ostream<_CharT, _Traits>&
  699. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  700. const nakagami_distribution<_RealType>& __x)
  701. {
  702. typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
  703. typedef typename __ostream_type::ios_base __ios_base;
  704. const typename __ios_base::fmtflags __flags = __os.flags();
  705. const _CharT __fill = __os.fill();
  706. const std::streamsize __precision = __os.precision();
  707. const _CharT __space = __os.widen(' ');
  708. __os.flags(__ios_base::scientific | __ios_base::left);
  709. __os.fill(__space);
  710. __os.precision(std::numeric_limits<_RealType>::max_digits10);
  711. __os << __x.mu() << __space << __x.omega();
  712. __os << __space << __x._M_gd;
  713. __os.flags(__flags);
  714. __os.fill(__fill);
  715. __os.precision(__precision);
  716. return __os;
  717. }
  718. template<typename _RealType, typename _CharT, typename _Traits>
  719. std::basic_istream<_CharT, _Traits>&
  720. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  721. nakagami_distribution<_RealType>& __x)
  722. {
  723. typedef std::basic_istream<_CharT, _Traits> __istream_type;
  724. typedef typename __istream_type::ios_base __ios_base;
  725. const typename __ios_base::fmtflags __flags = __is.flags();
  726. __is.flags(__ios_base::dec | __ios_base::skipws);
  727. _RealType __mu_val, __omega_val;
  728. __is >> __mu_val >> __omega_val;
  729. __is >> __x._M_gd;
  730. __x.param(typename nakagami_distribution<_RealType>::
  731. param_type(__mu_val, __omega_val));
  732. __is.flags(__flags);
  733. return __is;
  734. }
  735. template<typename _RealType>
  736. template<typename _OutputIterator,
  737. typename _UniformRandomNumberGenerator>
  738. void
  739. pareto_distribution<_RealType>::
  740. __generate_impl(_OutputIterator __f, _OutputIterator __t,
  741. _UniformRandomNumberGenerator& __urng,
  742. const param_type& __p)
  743. {
  744. __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
  745. result_type>)
  746. result_type __mu_val = __p.mu();
  747. result_type __malphinv = -result_type(1) / __p.alpha();
  748. while (__f != __t)
  749. *__f++ = __mu_val * std::pow(this->_M_ud(__urng), __malphinv);
  750. }
  751. template<typename _RealType, typename _CharT, typename _Traits>
  752. std::basic_ostream<_CharT, _Traits>&
  753. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  754. const pareto_distribution<_RealType>& __x)
  755. {
  756. typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
  757. typedef typename __ostream_type::ios_base __ios_base;
  758. const typename __ios_base::fmtflags __flags = __os.flags();
  759. const _CharT __fill = __os.fill();
  760. const std::streamsize __precision = __os.precision();
  761. const _CharT __space = __os.widen(' ');
  762. __os.flags(__ios_base::scientific | __ios_base::left);
  763. __os.fill(__space);
  764. __os.precision(std::numeric_limits<_RealType>::max_digits10);
  765. __os << __x.alpha() << __space << __x.mu();
  766. __os << __space << __x._M_ud;
  767. __os.flags(__flags);
  768. __os.fill(__fill);
  769. __os.precision(__precision);
  770. return __os;
  771. }
  772. template<typename _RealType, typename _CharT, typename _Traits>
  773. std::basic_istream<_CharT, _Traits>&
  774. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  775. pareto_distribution<_RealType>& __x)
  776. {
  777. typedef std::basic_istream<_CharT, _Traits> __istream_type;
  778. typedef typename __istream_type::ios_base __ios_base;
  779. const typename __ios_base::fmtflags __flags = __is.flags();
  780. __is.flags(__ios_base::dec | __ios_base::skipws);
  781. _RealType __alpha_val, __mu_val;
  782. __is >> __alpha_val >> __mu_val;
  783. __is >> __x._M_ud;
  784. __x.param(typename pareto_distribution<_RealType>::
  785. param_type(__alpha_val, __mu_val));
  786. __is.flags(__flags);
  787. return __is;
  788. }
  789. template<typename _RealType>
  790. template<typename _UniformRandomNumberGenerator>
  791. typename k_distribution<_RealType>::result_type
  792. k_distribution<_RealType>::
  793. operator()(_UniformRandomNumberGenerator& __urng)
  794. {
  795. result_type __x = this->_M_gd1(__urng);
  796. result_type __y = this->_M_gd2(__urng);
  797. return std::sqrt(__x * __y);
  798. }
  799. template<typename _RealType>
  800. template<typename _UniformRandomNumberGenerator>
  801. typename k_distribution<_RealType>::result_type
  802. k_distribution<_RealType>::
  803. operator()(_UniformRandomNumberGenerator& __urng,
  804. const param_type& __p)
  805. {
  806. typename std::gamma_distribution<result_type>::param_type
  807. __p1(__p.lambda(), result_type(1) / __p.lambda()),
  808. __p2(__p.nu(), __p.mu() / __p.nu());
  809. result_type __x = this->_M_gd1(__p1, __urng);
  810. result_type __y = this->_M_gd2(__p2, __urng);
  811. return std::sqrt(__x * __y);
  812. }
  813. template<typename _RealType>
  814. template<typename _OutputIterator,
  815. typename _UniformRandomNumberGenerator>
  816. void
  817. k_distribution<_RealType>::
  818. __generate_impl(_OutputIterator __f, _OutputIterator __t,
  819. _UniformRandomNumberGenerator& __urng,
  820. const param_type& __p)
  821. {
  822. __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
  823. result_type>)
  824. typename std::gamma_distribution<result_type>::param_type
  825. __p1(__p.lambda(), result_type(1) / __p.lambda()),
  826. __p2(__p.nu(), __p.mu() / __p.nu());
  827. while (__f != __t)
  828. {
  829. result_type __x = this->_M_gd1(__p1, __urng);
  830. result_type __y = this->_M_gd2(__p2, __urng);
  831. *__f++ = std::sqrt(__x * __y);
  832. }
  833. }
  834. template<typename _RealType, typename _CharT, typename _Traits>
  835. std::basic_ostream<_CharT, _Traits>&
  836. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  837. const k_distribution<_RealType>& __x)
  838. {
  839. typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
  840. typedef typename __ostream_type::ios_base __ios_base;
  841. const typename __ios_base::fmtflags __flags = __os.flags();
  842. const _CharT __fill = __os.fill();
  843. const std::streamsize __precision = __os.precision();
  844. const _CharT __space = __os.widen(' ');
  845. __os.flags(__ios_base::scientific | __ios_base::left);
  846. __os.fill(__space);
  847. __os.precision(std::numeric_limits<_RealType>::max_digits10);
  848. __os << __x.lambda() << __space << __x.mu() << __space << __x.nu();
  849. __os << __space << __x._M_gd1;
  850. __os << __space << __x._M_gd2;
  851. __os.flags(__flags);
  852. __os.fill(__fill);
  853. __os.precision(__precision);
  854. return __os;
  855. }
  856. template<typename _RealType, typename _CharT, typename _Traits>
  857. std::basic_istream<_CharT, _Traits>&
  858. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  859. k_distribution<_RealType>& __x)
  860. {
  861. typedef std::basic_istream<_CharT, _Traits> __istream_type;
  862. typedef typename __istream_type::ios_base __ios_base;
  863. const typename __ios_base::fmtflags __flags = __is.flags();
  864. __is.flags(__ios_base::dec | __ios_base::skipws);
  865. _RealType __lambda_val, __mu_val, __nu_val;
  866. __is >> __lambda_val >> __mu_val >> __nu_val;
  867. __is >> __x._M_gd1;
  868. __is >> __x._M_gd2;
  869. __x.param(typename k_distribution<_RealType>::
  870. param_type(__lambda_val, __mu_val, __nu_val));
  871. __is.flags(__flags);
  872. return __is;
  873. }
  874. template<typename _RealType>
  875. template<typename _OutputIterator,
  876. typename _UniformRandomNumberGenerator>
  877. void
  878. arcsine_distribution<_RealType>::
  879. __generate_impl(_OutputIterator __f, _OutputIterator __t,
  880. _UniformRandomNumberGenerator& __urng,
  881. const param_type& __p)
  882. {
  883. __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
  884. result_type>)
  885. result_type __dif = __p.b() - __p.a();
  886. result_type __sum = __p.a() + __p.b();
  887. while (__f != __t)
  888. {
  889. result_type __x = std::sin(this->_M_ud(__urng));
  890. *__f++ = (__x * __dif + __sum) / result_type(2);
  891. }
  892. }
  893. template<typename _RealType, typename _CharT, typename _Traits>
  894. std::basic_ostream<_CharT, _Traits>&
  895. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  896. const arcsine_distribution<_RealType>& __x)
  897. {
  898. typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
  899. typedef typename __ostream_type::ios_base __ios_base;
  900. const typename __ios_base::fmtflags __flags = __os.flags();
  901. const _CharT __fill = __os.fill();
  902. const std::streamsize __precision = __os.precision();
  903. const _CharT __space = __os.widen(' ');
  904. __os.flags(__ios_base::scientific | __ios_base::left);
  905. __os.fill(__space);
  906. __os.precision(std::numeric_limits<_RealType>::max_digits10);
  907. __os << __x.a() << __space << __x.b();
  908. __os << __space << __x._M_ud;
  909. __os.flags(__flags);
  910. __os.fill(__fill);
  911. __os.precision(__precision);
  912. return __os;
  913. }
  914. template<typename _RealType, typename _CharT, typename _Traits>
  915. std::basic_istream<_CharT, _Traits>&
  916. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  917. arcsine_distribution<_RealType>& __x)
  918. {
  919. typedef std::basic_istream<_CharT, _Traits> __istream_type;
  920. typedef typename __istream_type::ios_base __ios_base;
  921. const typename __ios_base::fmtflags __flags = __is.flags();
  922. __is.flags(__ios_base::dec | __ios_base::skipws);
  923. _RealType __a, __b;
  924. __is >> __a >> __b;
  925. __is >> __x._M_ud;
  926. __x.param(typename arcsine_distribution<_RealType>::
  927. param_type(__a, __b));
  928. __is.flags(__flags);
  929. return __is;
  930. }
  931. template<typename _RealType>
  932. template<typename _UniformRandomNumberGenerator>
  933. typename hoyt_distribution<_RealType>::result_type
  934. hoyt_distribution<_RealType>::
  935. operator()(_UniformRandomNumberGenerator& __urng)
  936. {
  937. result_type __x = this->_M_ad(__urng);
  938. result_type __y = this->_M_ed(__urng);
  939. return (result_type(2) * this->q()
  940. / (result_type(1) + this->q() * this->q()))
  941. * std::sqrt(this->omega() * __x * __y);
  942. }
  943. template<typename _RealType>
  944. template<typename _UniformRandomNumberGenerator>
  945. typename hoyt_distribution<_RealType>::result_type
  946. hoyt_distribution<_RealType>::
  947. operator()(_UniformRandomNumberGenerator& __urng,
  948. const param_type& __p)
  949. {
  950. result_type __q2 = __p.q() * __p.q();
  951. result_type __num = result_type(0.5L) * (result_type(1) + __q2);
  952. typename __gnu_cxx::arcsine_distribution<result_type>::param_type
  953. __pa(__num, __num / __q2);
  954. result_type __x = this->_M_ad(__pa, __urng);
  955. result_type __y = this->_M_ed(__urng);
  956. return (result_type(2) * __p.q() / (result_type(1) + __q2))
  957. * std::sqrt(__p.omega() * __x * __y);
  958. }
  959. template<typename _RealType>
  960. template<typename _OutputIterator,
  961. typename _UniformRandomNumberGenerator>
  962. void
  963. hoyt_distribution<_RealType>::
  964. __generate_impl(_OutputIterator __f, _OutputIterator __t,
  965. _UniformRandomNumberGenerator& __urng,
  966. const param_type& __p)
  967. {
  968. __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
  969. result_type>)
  970. result_type __2q = result_type(2) * __p.q();
  971. result_type __q2 = __p.q() * __p.q();
  972. result_type __q2p1 = result_type(1) + __q2;
  973. result_type __num = result_type(0.5L) * __q2p1;
  974. result_type __omega = __p.omega();
  975. typename __gnu_cxx::arcsine_distribution<result_type>::param_type
  976. __pa(__num, __num / __q2);
  977. while (__f != __t)
  978. {
  979. result_type __x = this->_M_ad(__pa, __urng);
  980. result_type __y = this->_M_ed(__urng);
  981. *__f++ = (__2q / __q2p1) * std::sqrt(__omega * __x * __y);
  982. }
  983. }
  984. template<typename _RealType, typename _CharT, typename _Traits>
  985. std::basic_ostream<_CharT, _Traits>&
  986. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  987. const hoyt_distribution<_RealType>& __x)
  988. {
  989. typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
  990. typedef typename __ostream_type::ios_base __ios_base;
  991. const typename __ios_base::fmtflags __flags = __os.flags();
  992. const _CharT __fill = __os.fill();
  993. const std::streamsize __precision = __os.precision();
  994. const _CharT __space = __os.widen(' ');
  995. __os.flags(__ios_base::scientific | __ios_base::left);
  996. __os.fill(__space);
  997. __os.precision(std::numeric_limits<_RealType>::max_digits10);
  998. __os << __x.q() << __space << __x.omega();
  999. __os << __space << __x._M_ad;
  1000. __os << __space << __x._M_ed;
  1001. __os.flags(__flags);
  1002. __os.fill(__fill);
  1003. __os.precision(__precision);
  1004. return __os;
  1005. }
  1006. template<typename _RealType, typename _CharT, typename _Traits>
  1007. std::basic_istream<_CharT, _Traits>&
  1008. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  1009. hoyt_distribution<_RealType>& __x)
  1010. {
  1011. typedef std::basic_istream<_CharT, _Traits> __istream_type;
  1012. typedef typename __istream_type::ios_base __ios_base;
  1013. const typename __ios_base::fmtflags __flags = __is.flags();
  1014. __is.flags(__ios_base::dec | __ios_base::skipws);
  1015. _RealType __q, __omega;
  1016. __is >> __q >> __omega;
  1017. __is >> __x._M_ad;
  1018. __is >> __x._M_ed;
  1019. __x.param(typename hoyt_distribution<_RealType>::
  1020. param_type(__q, __omega));
  1021. __is.flags(__flags);
  1022. return __is;
  1023. }
  1024. template<typename _RealType>
  1025. template<typename _OutputIterator,
  1026. typename _UniformRandomNumberGenerator>
  1027. void
  1028. triangular_distribution<_RealType>::
  1029. __generate_impl(_OutputIterator __f, _OutputIterator __t,
  1030. _UniformRandomNumberGenerator& __urng,
  1031. const param_type& __param)
  1032. {
  1033. __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
  1034. result_type>)
  1035. while (__f != __t)
  1036. *__f++ = this->operator()(__urng, __param);
  1037. }
  1038. template<typename _RealType, typename _CharT, typename _Traits>
  1039. std::basic_ostream<_CharT, _Traits>&
  1040. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  1041. const __gnu_cxx::triangular_distribution<_RealType>& __x)
  1042. {
  1043. typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
  1044. typedef typename __ostream_type::ios_base __ios_base;
  1045. const typename __ios_base::fmtflags __flags = __os.flags();
  1046. const _CharT __fill = __os.fill();
  1047. const std::streamsize __precision = __os.precision();
  1048. const _CharT __space = __os.widen(' ');
  1049. __os.flags(__ios_base::scientific | __ios_base::left);
  1050. __os.fill(__space);
  1051. __os.precision(std::numeric_limits<_RealType>::max_digits10);
  1052. __os << __x.a() << __space << __x.b() << __space << __x.c();
  1053. __os.flags(__flags);
  1054. __os.fill(__fill);
  1055. __os.precision(__precision);
  1056. return __os;
  1057. }
  1058. template<typename _RealType, typename _CharT, typename _Traits>
  1059. std::basic_istream<_CharT, _Traits>&
  1060. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  1061. __gnu_cxx::triangular_distribution<_RealType>& __x)
  1062. {
  1063. typedef std::basic_istream<_CharT, _Traits> __istream_type;
  1064. typedef typename __istream_type::ios_base __ios_base;
  1065. const typename __ios_base::fmtflags __flags = __is.flags();
  1066. __is.flags(__ios_base::dec | __ios_base::skipws);
  1067. _RealType __a, __b, __c;
  1068. __is >> __a >> __b >> __c;
  1069. __x.param(typename __gnu_cxx::triangular_distribution<_RealType>::
  1070. param_type(__a, __b, __c));
  1071. __is.flags(__flags);
  1072. return __is;
  1073. }
  1074. template<typename _RealType>
  1075. template<typename _UniformRandomNumberGenerator>
  1076. typename von_mises_distribution<_RealType>::result_type
  1077. von_mises_distribution<_RealType>::
  1078. operator()(_UniformRandomNumberGenerator& __urng,
  1079. const param_type& __p)
  1080. {
  1081. const result_type __pi
  1082. = __gnu_cxx::__math_constants<result_type>::__pi;
  1083. std::__detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
  1084. __aurng(__urng);
  1085. result_type __f;
  1086. while (1)
  1087. {
  1088. result_type __rnd = std::cos(__pi * __aurng());
  1089. __f = (result_type(1) + __p._M_r * __rnd) / (__p._M_r + __rnd);
  1090. result_type __c = __p._M_kappa * (__p._M_r - __f);
  1091. result_type __rnd2 = __aurng();
  1092. if (__c * (result_type(2) - __c) > __rnd2)
  1093. break;
  1094. if (std::log(__c / __rnd2) >= __c - result_type(1))
  1095. break;
  1096. }
  1097. result_type __res = std::acos(__f);
  1098. #if _GLIBCXX_USE_C99_MATH_TR1
  1099. __res = std::copysign(__res, __aurng() - result_type(0.5));
  1100. #else
  1101. if (__aurng() < result_type(0.5))
  1102. __res = -__res;
  1103. #endif
  1104. __res += __p._M_mu;
  1105. if (__res > __pi)
  1106. __res -= result_type(2) * __pi;
  1107. else if (__res < -__pi)
  1108. __res += result_type(2) * __pi;
  1109. return __res;
  1110. }
  1111. template<typename _RealType>
  1112. template<typename _OutputIterator,
  1113. typename _UniformRandomNumberGenerator>
  1114. void
  1115. von_mises_distribution<_RealType>::
  1116. __generate_impl(_OutputIterator __f, _OutputIterator __t,
  1117. _UniformRandomNumberGenerator& __urng,
  1118. const param_type& __param)
  1119. {
  1120. __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
  1121. result_type>)
  1122. while (__f != __t)
  1123. *__f++ = this->operator()(__urng, __param);
  1124. }
  1125. template<typename _RealType, typename _CharT, typename _Traits>
  1126. std::basic_ostream<_CharT, _Traits>&
  1127. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  1128. const __gnu_cxx::von_mises_distribution<_RealType>& __x)
  1129. {
  1130. typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
  1131. typedef typename __ostream_type::ios_base __ios_base;
  1132. const typename __ios_base::fmtflags __flags = __os.flags();
  1133. const _CharT __fill = __os.fill();
  1134. const std::streamsize __precision = __os.precision();
  1135. const _CharT __space = __os.widen(' ');
  1136. __os.flags(__ios_base::scientific | __ios_base::left);
  1137. __os.fill(__space);
  1138. __os.precision(std::numeric_limits<_RealType>::max_digits10);
  1139. __os << __x.mu() << __space << __x.kappa();
  1140. __os.flags(__flags);
  1141. __os.fill(__fill);
  1142. __os.precision(__precision);
  1143. return __os;
  1144. }
  1145. template<typename _RealType, typename _CharT, typename _Traits>
  1146. std::basic_istream<_CharT, _Traits>&
  1147. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  1148. __gnu_cxx::von_mises_distribution<_RealType>& __x)
  1149. {
  1150. typedef std::basic_istream<_CharT, _Traits> __istream_type;
  1151. typedef typename __istream_type::ios_base __ios_base;
  1152. const typename __ios_base::fmtflags __flags = __is.flags();
  1153. __is.flags(__ios_base::dec | __ios_base::skipws);
  1154. _RealType __mu, __kappa;
  1155. __is >> __mu >> __kappa;
  1156. __x.param(typename __gnu_cxx::von_mises_distribution<_RealType>::
  1157. param_type(__mu, __kappa));
  1158. __is.flags(__flags);
  1159. return __is;
  1160. }
  1161. template<typename _UIntType>
  1162. template<typename _UniformRandomNumberGenerator>
  1163. typename hypergeometric_distribution<_UIntType>::result_type
  1164. hypergeometric_distribution<_UIntType>::
  1165. operator()(_UniformRandomNumberGenerator& __urng,
  1166. const param_type& __param)
  1167. {
  1168. std::__detail::_Adaptor<_UniformRandomNumberGenerator, double>
  1169. __aurng(__urng);
  1170. result_type __a = __param.successful_size();
  1171. result_type __b = __param.total_size();
  1172. result_type __k = 0;
  1173. if (__param.total_draws() < __param.total_size() / 2)
  1174. {
  1175. for (result_type __i = 0; __i < __param.total_draws(); ++__i)
  1176. {
  1177. if (__b * __aurng() < __a)
  1178. {
  1179. ++__k;
  1180. if (__k == __param.successful_size())
  1181. return __k;
  1182. --__a;
  1183. }
  1184. --__b;
  1185. }
  1186. return __k;
  1187. }
  1188. else
  1189. {
  1190. for (result_type __i = 0; __i < __param.unsuccessful_size(); ++__i)
  1191. {
  1192. if (__b * __aurng() < __a)
  1193. {
  1194. ++__k;
  1195. if (__k == __param.successful_size())
  1196. return __param.successful_size() - __k;
  1197. --__a;
  1198. }
  1199. --__b;
  1200. }
  1201. return __param.successful_size() - __k;
  1202. }
  1203. }
  1204. template<typename _UIntType>
  1205. template<typename _OutputIterator,
  1206. typename _UniformRandomNumberGenerator>
  1207. void
  1208. hypergeometric_distribution<_UIntType>::
  1209. __generate_impl(_OutputIterator __f, _OutputIterator __t,
  1210. _UniformRandomNumberGenerator& __urng,
  1211. const param_type& __param)
  1212. {
  1213. __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
  1214. result_type>)
  1215. while (__f != __t)
  1216. *__f++ = this->operator()(__urng);
  1217. }
  1218. template<typename _UIntType, typename _CharT, typename _Traits>
  1219. std::basic_ostream<_CharT, _Traits>&
  1220. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  1221. const __gnu_cxx::hypergeometric_distribution<_UIntType>& __x)
  1222. {
  1223. typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
  1224. typedef typename __ostream_type::ios_base __ios_base;
  1225. const typename __ios_base::fmtflags __flags = __os.flags();
  1226. const _CharT __fill = __os.fill();
  1227. const std::streamsize __precision = __os.precision();
  1228. const _CharT __space = __os.widen(' ');
  1229. __os.flags(__ios_base::scientific | __ios_base::left);
  1230. __os.fill(__space);
  1231. __os.precision(std::numeric_limits<_UIntType>::max_digits10);
  1232. __os << __x.total_size() << __space << __x.successful_size() << __space
  1233. << __x.total_draws();
  1234. __os.flags(__flags);
  1235. __os.fill(__fill);
  1236. __os.precision(__precision);
  1237. return __os;
  1238. }
  1239. template<typename _UIntType, typename _CharT, typename _Traits>
  1240. std::basic_istream<_CharT, _Traits>&
  1241. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  1242. __gnu_cxx::hypergeometric_distribution<_UIntType>& __x)
  1243. {
  1244. typedef std::basic_istream<_CharT, _Traits> __istream_type;
  1245. typedef typename __istream_type::ios_base __ios_base;
  1246. const typename __ios_base::fmtflags __flags = __is.flags();
  1247. __is.flags(__ios_base::dec | __ios_base::skipws);
  1248. _UIntType __total_size, __successful_size, __total_draws;
  1249. __is >> __total_size >> __successful_size >> __total_draws;
  1250. __x.param(typename __gnu_cxx::hypergeometric_distribution<_UIntType>::
  1251. param_type(__total_size, __successful_size, __total_draws));
  1252. __is.flags(__flags);
  1253. return __is;
  1254. }
  1255. template<typename _RealType>
  1256. template<typename _UniformRandomNumberGenerator>
  1257. typename logistic_distribution<_RealType>::result_type
  1258. logistic_distribution<_RealType>::
  1259. operator()(_UniformRandomNumberGenerator& __urng,
  1260. const param_type& __p)
  1261. {
  1262. std::__detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
  1263. __aurng(__urng);
  1264. result_type __arg = result_type(1);
  1265. while (__arg == result_type(1) || __arg == result_type(0))
  1266. __arg = __aurng();
  1267. return __p.a()
  1268. + __p.b() * std::log(__arg / (result_type(1) - __arg));
  1269. }
  1270. template<typename _RealType>
  1271. template<typename _OutputIterator,
  1272. typename _UniformRandomNumberGenerator>
  1273. void
  1274. logistic_distribution<_RealType>::
  1275. __generate_impl(_OutputIterator __f, _OutputIterator __t,
  1276. _UniformRandomNumberGenerator& __urng,
  1277. const param_type& __p)
  1278. {
  1279. __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
  1280. result_type>)
  1281. std::__detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
  1282. __aurng(__urng);
  1283. while (__f != __t)
  1284. {
  1285. result_type __arg = result_type(1);
  1286. while (__arg == result_type(1) || __arg == result_type(0))
  1287. __arg = __aurng();
  1288. *__f++ = __p.a()
  1289. + __p.b() * std::log(__arg / (result_type(1) - __arg));
  1290. }
  1291. }
  1292. template<typename _RealType, typename _CharT, typename _Traits>
  1293. std::basic_ostream<_CharT, _Traits>&
  1294. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  1295. const logistic_distribution<_RealType>& __x)
  1296. {
  1297. typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
  1298. typedef typename __ostream_type::ios_base __ios_base;
  1299. const typename __ios_base::fmtflags __flags = __os.flags();
  1300. const _CharT __fill = __os.fill();
  1301. const std::streamsize __precision = __os.precision();
  1302. const _CharT __space = __os.widen(' ');
  1303. __os.flags(__ios_base::scientific | __ios_base::left);
  1304. __os.fill(__space);
  1305. __os.precision(std::numeric_limits<_RealType>::max_digits10);
  1306. __os << __x.a() << __space << __x.b();
  1307. __os.flags(__flags);
  1308. __os.fill(__fill);
  1309. __os.precision(__precision);
  1310. return __os;
  1311. }
  1312. template<typename _RealType, typename _CharT, typename _Traits>
  1313. std::basic_istream<_CharT, _Traits>&
  1314. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  1315. logistic_distribution<_RealType>& __x)
  1316. {
  1317. typedef std::basic_istream<_CharT, _Traits> __istream_type;
  1318. typedef typename __istream_type::ios_base __ios_base;
  1319. const typename __ios_base::fmtflags __flags = __is.flags();
  1320. __is.flags(__ios_base::dec | __ios_base::skipws);
  1321. _RealType __a, __b;
  1322. __is >> __a >> __b;
  1323. __x.param(typename logistic_distribution<_RealType>::
  1324. param_type(__a, __b));
  1325. __is.flags(__flags);
  1326. return __is;
  1327. }
  1328. namespace {
  1329. // Helper class for the uniform_on_sphere_distribution generation
  1330. // function.
  1331. template<std::size_t _Dimen, typename _RealType>
  1332. class uniform_on_sphere_helper
  1333. {
  1334. typedef typename uniform_on_sphere_distribution<_Dimen, _RealType>::
  1335. result_type result_type;
  1336. public:
  1337. template<typename _NormalDistribution,
  1338. typename _UniformRandomNumberGenerator>
  1339. result_type operator()(_NormalDistribution& __nd,
  1340. _UniformRandomNumberGenerator& __urng)
  1341. {
  1342. result_type __ret;
  1343. typename result_type::value_type __norm;
  1344. do
  1345. {
  1346. auto __sum = _RealType(0);
  1347. std::generate(__ret.begin(), __ret.end(),
  1348. [&__nd, &__urng, &__sum](){
  1349. _RealType __t = __nd(__urng);
  1350. __sum += __t * __t;
  1351. return __t; });
  1352. __norm = std::sqrt(__sum);
  1353. }
  1354. while (__norm == _RealType(0) || ! __builtin_isfinite(__norm));
  1355. std::transform(__ret.begin(), __ret.end(), __ret.begin(),
  1356. [__norm](_RealType __val){ return __val / __norm; });
  1357. return __ret;
  1358. }
  1359. };
  1360. template<typename _RealType>
  1361. class uniform_on_sphere_helper<2, _RealType>
  1362. {
  1363. typedef typename uniform_on_sphere_distribution<2, _RealType>::
  1364. result_type result_type;
  1365. public:
  1366. template<typename _NormalDistribution,
  1367. typename _UniformRandomNumberGenerator>
  1368. result_type operator()(_NormalDistribution&,
  1369. _UniformRandomNumberGenerator& __urng)
  1370. {
  1371. result_type __ret;
  1372. _RealType __sq;
  1373. std::__detail::_Adaptor<_UniformRandomNumberGenerator,
  1374. _RealType> __aurng(__urng);
  1375. do
  1376. {
  1377. __ret[0] = _RealType(2) * __aurng() - _RealType(1);
  1378. __ret[1] = _RealType(2) * __aurng() - _RealType(1);
  1379. __sq = __ret[0] * __ret[0] + __ret[1] * __ret[1];
  1380. }
  1381. while (__sq == _RealType(0) || __sq > _RealType(1));
  1382. #if _GLIBCXX_USE_C99_MATH_TR1
  1383. // Yes, we do not just use sqrt(__sq) because hypot() is more
  1384. // accurate.
  1385. auto __norm = std::hypot(__ret[0], __ret[1]);
  1386. #else
  1387. auto __norm = std::sqrt(__sq);
  1388. #endif
  1389. __ret[0] /= __norm;
  1390. __ret[1] /= __norm;
  1391. return __ret;
  1392. }
  1393. };
  1394. }
  1395. template<std::size_t _Dimen, typename _RealType>
  1396. template<typename _UniformRandomNumberGenerator>
  1397. typename uniform_on_sphere_distribution<_Dimen, _RealType>::result_type
  1398. uniform_on_sphere_distribution<_Dimen, _RealType>::
  1399. operator()(_UniformRandomNumberGenerator& __urng,
  1400. const param_type& __p)
  1401. {
  1402. uniform_on_sphere_helper<_Dimen, _RealType> __helper;
  1403. return __helper(_M_nd, __urng);
  1404. }
  1405. template<std::size_t _Dimen, typename _RealType>
  1406. template<typename _OutputIterator,
  1407. typename _UniformRandomNumberGenerator>
  1408. void
  1409. uniform_on_sphere_distribution<_Dimen, _RealType>::
  1410. __generate_impl(_OutputIterator __f, _OutputIterator __t,
  1411. _UniformRandomNumberGenerator& __urng,
  1412. const param_type& __param)
  1413. {
  1414. __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
  1415. result_type>)
  1416. while (__f != __t)
  1417. *__f++ = this->operator()(__urng, __param);
  1418. }
  1419. template<std::size_t _Dimen, typename _RealType, typename _CharT,
  1420. typename _Traits>
  1421. std::basic_ostream<_CharT, _Traits>&
  1422. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  1423. const __gnu_cxx::uniform_on_sphere_distribution<_Dimen,
  1424. _RealType>& __x)
  1425. {
  1426. return __os << __x._M_nd;
  1427. }
  1428. template<std::size_t _Dimen, typename _RealType, typename _CharT,
  1429. typename _Traits>
  1430. std::basic_istream<_CharT, _Traits>&
  1431. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  1432. __gnu_cxx::uniform_on_sphere_distribution<_Dimen,
  1433. _RealType>& __x)
  1434. {
  1435. return __is >> __x._M_nd;
  1436. }
  1437. namespace {
  1438. // Helper class for the uniform_inside_sphere_distribution generation
  1439. // function.
  1440. template<std::size_t _Dimen, bool _SmallDimen, typename _RealType>
  1441. class uniform_inside_sphere_helper;
  1442. template<std::size_t _Dimen, typename _RealType>
  1443. class uniform_inside_sphere_helper<_Dimen, false, _RealType>
  1444. {
  1445. using result_type
  1446. = typename uniform_inside_sphere_distribution<_Dimen, _RealType>::
  1447. result_type;
  1448. public:
  1449. template<typename _UniformOnSphereDistribution,
  1450. typename _UniformRandomNumberGenerator>
  1451. result_type
  1452. operator()(_UniformOnSphereDistribution& __uosd,
  1453. _UniformRandomNumberGenerator& __urng,
  1454. _RealType __radius)
  1455. {
  1456. std::__detail::_Adaptor<_UniformRandomNumberGenerator,
  1457. _RealType> __aurng(__urng);
  1458. _RealType __pow = 1 / _RealType(_Dimen);
  1459. _RealType __urt = __radius * std::pow(__aurng(), __pow);
  1460. result_type __ret = __uosd(__aurng);
  1461. std::transform(__ret.begin(), __ret.end(), __ret.begin(),
  1462. [__urt](_RealType __val)
  1463. { return __val * __urt; });
  1464. return __ret;
  1465. }
  1466. };
  1467. // Helper class for the uniform_inside_sphere_distribution generation
  1468. // function specialized for small dimensions.
  1469. template<std::size_t _Dimen, typename _RealType>
  1470. class uniform_inside_sphere_helper<_Dimen, true, _RealType>
  1471. {
  1472. using result_type
  1473. = typename uniform_inside_sphere_distribution<_Dimen, _RealType>::
  1474. result_type;
  1475. public:
  1476. template<typename _UniformOnSphereDistribution,
  1477. typename _UniformRandomNumberGenerator>
  1478. result_type
  1479. operator()(_UniformOnSphereDistribution&,
  1480. _UniformRandomNumberGenerator& __urng,
  1481. _RealType __radius)
  1482. {
  1483. result_type __ret;
  1484. _RealType __sq;
  1485. _RealType __radsq = __radius * __radius;
  1486. std::__detail::_Adaptor<_UniformRandomNumberGenerator,
  1487. _RealType> __aurng(__urng);
  1488. do
  1489. {
  1490. __sq = _RealType(0);
  1491. for (int i = 0; i < _Dimen; ++i)
  1492. {
  1493. __ret[i] = _RealType(2) * __aurng() - _RealType(1);
  1494. __sq += __ret[i] * __ret[i];
  1495. }
  1496. }
  1497. while (__sq > _RealType(1));
  1498. for (int i = 0; i < _Dimen; ++i)
  1499. __ret[i] *= __radius;
  1500. return __ret;
  1501. }
  1502. };
  1503. } // namespace
  1504. //
  1505. // Experiments have shown that rejection is more efficient than transform
  1506. // for dimensions less than 8.
  1507. //
  1508. template<std::size_t _Dimen, typename _RealType>
  1509. template<typename _UniformRandomNumberGenerator>
  1510. typename uniform_inside_sphere_distribution<_Dimen, _RealType>::result_type
  1511. uniform_inside_sphere_distribution<_Dimen, _RealType>::
  1512. operator()(_UniformRandomNumberGenerator& __urng,
  1513. const param_type& __p)
  1514. {
  1515. uniform_inside_sphere_helper<_Dimen, _Dimen < 8, _RealType> __helper;
  1516. return __helper(_M_uosd, __urng, __p.radius());
  1517. }
  1518. template<std::size_t _Dimen, typename _RealType>
  1519. template<typename _OutputIterator,
  1520. typename _UniformRandomNumberGenerator>
  1521. void
  1522. uniform_inside_sphere_distribution<_Dimen, _RealType>::
  1523. __generate_impl(_OutputIterator __f, _OutputIterator __t,
  1524. _UniformRandomNumberGenerator& __urng,
  1525. const param_type& __param)
  1526. {
  1527. __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
  1528. result_type>)
  1529. while (__f != __t)
  1530. *__f++ = this->operator()(__urng, __param);
  1531. }
  1532. template<std::size_t _Dimen, typename _RealType, typename _CharT,
  1533. typename _Traits>
  1534. std::basic_ostream<_CharT, _Traits>&
  1535. operator<<(std::basic_ostream<_CharT, _Traits>& __os,
  1536. const __gnu_cxx::uniform_inside_sphere_distribution<_Dimen,
  1537. _RealType>& __x)
  1538. {
  1539. typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
  1540. typedef typename __ostream_type::ios_base __ios_base;
  1541. const typename __ios_base::fmtflags __flags = __os.flags();
  1542. const _CharT __fill = __os.fill();
  1543. const std::streamsize __precision = __os.precision();
  1544. const _CharT __space = __os.widen(' ');
  1545. __os.flags(__ios_base::scientific | __ios_base::left);
  1546. __os.fill(__space);
  1547. __os.precision(std::numeric_limits<_RealType>::max_digits10);
  1548. __os << __x.radius() << __space << __x._M_uosd;
  1549. __os.flags(__flags);
  1550. __os.fill(__fill);
  1551. __os.precision(__precision);
  1552. return __os;
  1553. }
  1554. template<std::size_t _Dimen, typename _RealType, typename _CharT,
  1555. typename _Traits>
  1556. std::basic_istream<_CharT, _Traits>&
  1557. operator>>(std::basic_istream<_CharT, _Traits>& __is,
  1558. __gnu_cxx::uniform_inside_sphere_distribution<_Dimen,
  1559. _RealType>& __x)
  1560. {
  1561. typedef std::basic_istream<_CharT, _Traits> __istream_type;
  1562. typedef typename __istream_type::ios_base __ios_base;
  1563. const typename __ios_base::fmtflags __flags = __is.flags();
  1564. __is.flags(__ios_base::dec | __ios_base::skipws);
  1565. _RealType __radius_val;
  1566. __is >> __radius_val >> __x._M_uosd;
  1567. __x.param(typename uniform_inside_sphere_distribution<_Dimen, _RealType>::
  1568. param_type(__radius_val));
  1569. __is.flags(__flags);
  1570. return __is;
  1571. }
  1572. _GLIBCXX_END_NAMESPACE_VERSION
  1573. } // namespace __gnu_cxx
  1574. #endif // _EXT_RANDOM_TCC