numpy 2.4.0__cp313-cp313t-musllinux_1_2_aarch64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (915) hide show
  1. numpy/__config__.py +170 -0
  2. numpy/__config__.pyi +108 -0
  3. numpy/__init__.cython-30.pxd +1242 -0
  4. numpy/__init__.pxd +1155 -0
  5. numpy/__init__.py +942 -0
  6. numpy/__init__.pyi +6202 -0
  7. numpy/_array_api_info.py +346 -0
  8. numpy/_array_api_info.pyi +206 -0
  9. numpy/_configtool.py +39 -0
  10. numpy/_configtool.pyi +1 -0
  11. numpy/_core/__init__.py +201 -0
  12. numpy/_core/__init__.pyi +666 -0
  13. numpy/_core/_add_newdocs.py +7151 -0
  14. numpy/_core/_add_newdocs.pyi +2 -0
  15. numpy/_core/_add_newdocs_scalars.py +381 -0
  16. numpy/_core/_add_newdocs_scalars.pyi +16 -0
  17. numpy/_core/_asarray.py +130 -0
  18. numpy/_core/_asarray.pyi +43 -0
  19. numpy/_core/_dtype.py +366 -0
  20. numpy/_core/_dtype.pyi +56 -0
  21. numpy/_core/_dtype_ctypes.py +120 -0
  22. numpy/_core/_dtype_ctypes.pyi +83 -0
  23. numpy/_core/_exceptions.py +162 -0
  24. numpy/_core/_exceptions.pyi +54 -0
  25. numpy/_core/_internal.py +968 -0
  26. numpy/_core/_internal.pyi +61 -0
  27. numpy/_core/_methods.py +252 -0
  28. numpy/_core/_methods.pyi +22 -0
  29. numpy/_core/_multiarray_tests.cpython-313t-aarch64-linux-musl.so +0 -0
  30. numpy/_core/_multiarray_umath.cpython-313t-aarch64-linux-musl.so +0 -0
  31. numpy/_core/_operand_flag_tests.cpython-313t-aarch64-linux-musl.so +0 -0
  32. numpy/_core/_rational_tests.cpython-313t-aarch64-linux-musl.so +0 -0
  33. numpy/_core/_simd.cpython-313t-aarch64-linux-musl.so +0 -0
  34. numpy/_core/_simd.pyi +35 -0
  35. numpy/_core/_string_helpers.py +100 -0
  36. numpy/_core/_string_helpers.pyi +12 -0
  37. numpy/_core/_struct_ufunc_tests.cpython-313t-aarch64-linux-musl.so +0 -0
  38. numpy/_core/_type_aliases.py +131 -0
  39. numpy/_core/_type_aliases.pyi +86 -0
  40. numpy/_core/_ufunc_config.py +515 -0
  41. numpy/_core/_ufunc_config.pyi +69 -0
  42. numpy/_core/_umath_tests.cpython-313t-aarch64-linux-musl.so +0 -0
  43. numpy/_core/_umath_tests.pyi +47 -0
  44. numpy/_core/arrayprint.py +1779 -0
  45. numpy/_core/arrayprint.pyi +158 -0
  46. numpy/_core/cversions.py +13 -0
  47. numpy/_core/defchararray.py +1414 -0
  48. numpy/_core/defchararray.pyi +1150 -0
  49. numpy/_core/einsumfunc.py +1650 -0
  50. numpy/_core/einsumfunc.pyi +184 -0
  51. numpy/_core/fromnumeric.py +4233 -0
  52. numpy/_core/fromnumeric.pyi +1735 -0
  53. numpy/_core/function_base.py +547 -0
  54. numpy/_core/function_base.pyi +276 -0
  55. numpy/_core/getlimits.py +462 -0
  56. numpy/_core/getlimits.pyi +124 -0
  57. numpy/_core/include/numpy/__multiarray_api.c +376 -0
  58. numpy/_core/include/numpy/__multiarray_api.h +1628 -0
  59. numpy/_core/include/numpy/__ufunc_api.c +55 -0
  60. numpy/_core/include/numpy/__ufunc_api.h +349 -0
  61. numpy/_core/include/numpy/_neighborhood_iterator_imp.h +90 -0
  62. numpy/_core/include/numpy/_numpyconfig.h +33 -0
  63. numpy/_core/include/numpy/_public_dtype_api_table.h +86 -0
  64. numpy/_core/include/numpy/arrayobject.h +7 -0
  65. numpy/_core/include/numpy/arrayscalars.h +198 -0
  66. numpy/_core/include/numpy/dtype_api.h +547 -0
  67. numpy/_core/include/numpy/halffloat.h +70 -0
  68. numpy/_core/include/numpy/ndarrayobject.h +304 -0
  69. numpy/_core/include/numpy/ndarraytypes.h +1982 -0
  70. numpy/_core/include/numpy/npy_2_compat.h +249 -0
  71. numpy/_core/include/numpy/npy_2_complexcompat.h +28 -0
  72. numpy/_core/include/numpy/npy_3kcompat.h +374 -0
  73. numpy/_core/include/numpy/npy_common.h +989 -0
  74. numpy/_core/include/numpy/npy_cpu.h +126 -0
  75. numpy/_core/include/numpy/npy_endian.h +79 -0
  76. numpy/_core/include/numpy/npy_math.h +602 -0
  77. numpy/_core/include/numpy/npy_no_deprecated_api.h +20 -0
  78. numpy/_core/include/numpy/npy_os.h +42 -0
  79. numpy/_core/include/numpy/numpyconfig.h +185 -0
  80. numpy/_core/include/numpy/random/LICENSE.txt +21 -0
  81. numpy/_core/include/numpy/random/bitgen.h +20 -0
  82. numpy/_core/include/numpy/random/distributions.h +209 -0
  83. numpy/_core/include/numpy/random/libdivide.h +2079 -0
  84. numpy/_core/include/numpy/ufuncobject.h +343 -0
  85. numpy/_core/include/numpy/utils.h +37 -0
  86. numpy/_core/lib/libnpymath.a +0 -0
  87. numpy/_core/lib/npy-pkg-config/mlib.ini +12 -0
  88. numpy/_core/lib/npy-pkg-config/npymath.ini +20 -0
  89. numpy/_core/lib/pkgconfig/numpy.pc +7 -0
  90. numpy/_core/memmap.py +363 -0
  91. numpy/_core/memmap.pyi +3 -0
  92. numpy/_core/multiarray.py +1740 -0
  93. numpy/_core/multiarray.pyi +1316 -0
  94. numpy/_core/numeric.py +2758 -0
  95. numpy/_core/numeric.pyi +1276 -0
  96. numpy/_core/numerictypes.py +633 -0
  97. numpy/_core/numerictypes.pyi +196 -0
  98. numpy/_core/overrides.py +188 -0
  99. numpy/_core/overrides.pyi +47 -0
  100. numpy/_core/printoptions.py +32 -0
  101. numpy/_core/printoptions.pyi +28 -0
  102. numpy/_core/records.py +1088 -0
  103. numpy/_core/records.pyi +340 -0
  104. numpy/_core/shape_base.py +996 -0
  105. numpy/_core/shape_base.pyi +182 -0
  106. numpy/_core/strings.py +1813 -0
  107. numpy/_core/strings.pyi +536 -0
  108. numpy/_core/tests/_locales.py +72 -0
  109. numpy/_core/tests/_natype.py +144 -0
  110. numpy/_core/tests/data/astype_copy.pkl +0 -0
  111. numpy/_core/tests/data/generate_umath_validation_data.cpp +170 -0
  112. numpy/_core/tests/data/recarray_from_file.fits +0 -0
  113. numpy/_core/tests/data/umath-validation-set-README.txt +15 -0
  114. numpy/_core/tests/data/umath-validation-set-arccos.csv +1429 -0
  115. numpy/_core/tests/data/umath-validation-set-arccosh.csv +1429 -0
  116. numpy/_core/tests/data/umath-validation-set-arcsin.csv +1429 -0
  117. numpy/_core/tests/data/umath-validation-set-arcsinh.csv +1429 -0
  118. numpy/_core/tests/data/umath-validation-set-arctan.csv +1429 -0
  119. numpy/_core/tests/data/umath-validation-set-arctanh.csv +1429 -0
  120. numpy/_core/tests/data/umath-validation-set-cbrt.csv +1429 -0
  121. numpy/_core/tests/data/umath-validation-set-cos.csv +1375 -0
  122. numpy/_core/tests/data/umath-validation-set-cosh.csv +1429 -0
  123. numpy/_core/tests/data/umath-validation-set-exp.csv +412 -0
  124. numpy/_core/tests/data/umath-validation-set-exp2.csv +1429 -0
  125. numpy/_core/tests/data/umath-validation-set-expm1.csv +1429 -0
  126. numpy/_core/tests/data/umath-validation-set-log.csv +271 -0
  127. numpy/_core/tests/data/umath-validation-set-log10.csv +1629 -0
  128. numpy/_core/tests/data/umath-validation-set-log1p.csv +1429 -0
  129. numpy/_core/tests/data/umath-validation-set-log2.csv +1629 -0
  130. numpy/_core/tests/data/umath-validation-set-sin.csv +1370 -0
  131. numpy/_core/tests/data/umath-validation-set-sinh.csv +1429 -0
  132. numpy/_core/tests/data/umath-validation-set-tan.csv +1429 -0
  133. numpy/_core/tests/data/umath-validation-set-tanh.csv +1429 -0
  134. numpy/_core/tests/examples/cython/checks.pyx +373 -0
  135. numpy/_core/tests/examples/cython/meson.build +43 -0
  136. numpy/_core/tests/examples/cython/setup.py +39 -0
  137. numpy/_core/tests/examples/limited_api/limited_api1.c +17 -0
  138. numpy/_core/tests/examples/limited_api/limited_api2.pyx +11 -0
  139. numpy/_core/tests/examples/limited_api/limited_api_latest.c +19 -0
  140. numpy/_core/tests/examples/limited_api/meson.build +59 -0
  141. numpy/_core/tests/examples/limited_api/setup.py +24 -0
  142. numpy/_core/tests/test__exceptions.py +90 -0
  143. numpy/_core/tests/test_abc.py +54 -0
  144. numpy/_core/tests/test_api.py +655 -0
  145. numpy/_core/tests/test_argparse.py +90 -0
  146. numpy/_core/tests/test_array_api_info.py +113 -0
  147. numpy/_core/tests/test_array_coercion.py +928 -0
  148. numpy/_core/tests/test_array_interface.py +222 -0
  149. numpy/_core/tests/test_arraymethod.py +84 -0
  150. numpy/_core/tests/test_arrayobject.py +75 -0
  151. numpy/_core/tests/test_arrayprint.py +1324 -0
  152. numpy/_core/tests/test_casting_floatingpoint_errors.py +154 -0
  153. numpy/_core/tests/test_casting_unittests.py +955 -0
  154. numpy/_core/tests/test_conversion_utils.py +209 -0
  155. numpy/_core/tests/test_cpu_dispatcher.py +48 -0
  156. numpy/_core/tests/test_cpu_features.py +450 -0
  157. numpy/_core/tests/test_custom_dtypes.py +393 -0
  158. numpy/_core/tests/test_cython.py +352 -0
  159. numpy/_core/tests/test_datetime.py +2792 -0
  160. numpy/_core/tests/test_defchararray.py +858 -0
  161. numpy/_core/tests/test_deprecations.py +460 -0
  162. numpy/_core/tests/test_dlpack.py +190 -0
  163. numpy/_core/tests/test_dtype.py +2110 -0
  164. numpy/_core/tests/test_einsum.py +1351 -0
  165. numpy/_core/tests/test_errstate.py +131 -0
  166. numpy/_core/tests/test_extint128.py +217 -0
  167. numpy/_core/tests/test_finfo.py +86 -0
  168. numpy/_core/tests/test_function_base.py +504 -0
  169. numpy/_core/tests/test_getlimits.py +171 -0
  170. numpy/_core/tests/test_half.py +593 -0
  171. numpy/_core/tests/test_hashtable.py +36 -0
  172. numpy/_core/tests/test_indexerrors.py +122 -0
  173. numpy/_core/tests/test_indexing.py +1692 -0
  174. numpy/_core/tests/test_item_selection.py +167 -0
  175. numpy/_core/tests/test_limited_api.py +102 -0
  176. numpy/_core/tests/test_longdouble.py +370 -0
  177. numpy/_core/tests/test_mem_overlap.py +933 -0
  178. numpy/_core/tests/test_mem_policy.py +453 -0
  179. numpy/_core/tests/test_memmap.py +248 -0
  180. numpy/_core/tests/test_multiarray.py +11008 -0
  181. numpy/_core/tests/test_multiprocessing.py +55 -0
  182. numpy/_core/tests/test_multithreading.py +353 -0
  183. numpy/_core/tests/test_nditer.py +3533 -0
  184. numpy/_core/tests/test_nep50_promotions.py +287 -0
  185. numpy/_core/tests/test_numeric.py +4295 -0
  186. numpy/_core/tests/test_numerictypes.py +650 -0
  187. numpy/_core/tests/test_overrides.py +800 -0
  188. numpy/_core/tests/test_print.py +202 -0
  189. numpy/_core/tests/test_protocols.py +46 -0
  190. numpy/_core/tests/test_records.py +544 -0
  191. numpy/_core/tests/test_regression.py +2677 -0
  192. numpy/_core/tests/test_scalar_ctors.py +203 -0
  193. numpy/_core/tests/test_scalar_methods.py +328 -0
  194. numpy/_core/tests/test_scalarbuffer.py +153 -0
  195. numpy/_core/tests/test_scalarinherit.py +105 -0
  196. numpy/_core/tests/test_scalarmath.py +1168 -0
  197. numpy/_core/tests/test_scalarprint.py +403 -0
  198. numpy/_core/tests/test_shape_base.py +904 -0
  199. numpy/_core/tests/test_simd.py +1345 -0
  200. numpy/_core/tests/test_simd_module.py +105 -0
  201. numpy/_core/tests/test_stringdtype.py +1855 -0
  202. numpy/_core/tests/test_strings.py +1515 -0
  203. numpy/_core/tests/test_ufunc.py +3405 -0
  204. numpy/_core/tests/test_umath.py +4962 -0
  205. numpy/_core/tests/test_umath_accuracy.py +132 -0
  206. numpy/_core/tests/test_umath_complex.py +631 -0
  207. numpy/_core/tests/test_unicode.py +369 -0
  208. numpy/_core/umath.py +60 -0
  209. numpy/_core/umath.pyi +232 -0
  210. numpy/_distributor_init.py +15 -0
  211. numpy/_distributor_init.pyi +1 -0
  212. numpy/_expired_attrs_2_0.py +78 -0
  213. numpy/_expired_attrs_2_0.pyi +61 -0
  214. numpy/_globals.py +121 -0
  215. numpy/_globals.pyi +17 -0
  216. numpy/_pyinstaller/__init__.py +0 -0
  217. numpy/_pyinstaller/__init__.pyi +0 -0
  218. numpy/_pyinstaller/hook-numpy.py +36 -0
  219. numpy/_pyinstaller/hook-numpy.pyi +6 -0
  220. numpy/_pyinstaller/tests/__init__.py +16 -0
  221. numpy/_pyinstaller/tests/pyinstaller-smoke.py +32 -0
  222. numpy/_pyinstaller/tests/test_pyinstaller.py +35 -0
  223. numpy/_pytesttester.py +201 -0
  224. numpy/_pytesttester.pyi +18 -0
  225. numpy/_typing/__init__.py +173 -0
  226. numpy/_typing/_add_docstring.py +153 -0
  227. numpy/_typing/_array_like.py +106 -0
  228. numpy/_typing/_char_codes.py +213 -0
  229. numpy/_typing/_dtype_like.py +114 -0
  230. numpy/_typing/_extended_precision.py +15 -0
  231. numpy/_typing/_nbit.py +19 -0
  232. numpy/_typing/_nbit_base.py +94 -0
  233. numpy/_typing/_nbit_base.pyi +39 -0
  234. numpy/_typing/_nested_sequence.py +79 -0
  235. numpy/_typing/_scalars.py +20 -0
  236. numpy/_typing/_shape.py +8 -0
  237. numpy/_typing/_ufunc.py +7 -0
  238. numpy/_typing/_ufunc.pyi +975 -0
  239. numpy/_utils/__init__.py +95 -0
  240. numpy/_utils/__init__.pyi +28 -0
  241. numpy/_utils/_convertions.py +18 -0
  242. numpy/_utils/_convertions.pyi +4 -0
  243. numpy/_utils/_inspect.py +192 -0
  244. numpy/_utils/_inspect.pyi +70 -0
  245. numpy/_utils/_pep440.py +486 -0
  246. numpy/_utils/_pep440.pyi +118 -0
  247. numpy/char/__init__.py +2 -0
  248. numpy/char/__init__.pyi +111 -0
  249. numpy/conftest.py +248 -0
  250. numpy/core/__init__.py +33 -0
  251. numpy/core/__init__.pyi +0 -0
  252. numpy/core/_dtype.py +10 -0
  253. numpy/core/_dtype.pyi +0 -0
  254. numpy/core/_dtype_ctypes.py +10 -0
  255. numpy/core/_dtype_ctypes.pyi +0 -0
  256. numpy/core/_internal.py +27 -0
  257. numpy/core/_multiarray_umath.py +57 -0
  258. numpy/core/_utils.py +21 -0
  259. numpy/core/arrayprint.py +10 -0
  260. numpy/core/defchararray.py +10 -0
  261. numpy/core/einsumfunc.py +10 -0
  262. numpy/core/fromnumeric.py +10 -0
  263. numpy/core/function_base.py +10 -0
  264. numpy/core/getlimits.py +10 -0
  265. numpy/core/multiarray.py +25 -0
  266. numpy/core/numeric.py +12 -0
  267. numpy/core/numerictypes.py +10 -0
  268. numpy/core/overrides.py +10 -0
  269. numpy/core/overrides.pyi +7 -0
  270. numpy/core/records.py +10 -0
  271. numpy/core/shape_base.py +10 -0
  272. numpy/core/umath.py +10 -0
  273. numpy/ctypeslib/__init__.py +13 -0
  274. numpy/ctypeslib/__init__.pyi +15 -0
  275. numpy/ctypeslib/_ctypeslib.py +603 -0
  276. numpy/ctypeslib/_ctypeslib.pyi +236 -0
  277. numpy/doc/ufuncs.py +138 -0
  278. numpy/dtypes.py +41 -0
  279. numpy/dtypes.pyi +630 -0
  280. numpy/exceptions.py +246 -0
  281. numpy/exceptions.pyi +27 -0
  282. numpy/f2py/__init__.py +86 -0
  283. numpy/f2py/__init__.pyi +5 -0
  284. numpy/f2py/__main__.py +5 -0
  285. numpy/f2py/__version__.py +1 -0
  286. numpy/f2py/__version__.pyi +1 -0
  287. numpy/f2py/_backends/__init__.py +9 -0
  288. numpy/f2py/_backends/__init__.pyi +5 -0
  289. numpy/f2py/_backends/_backend.py +44 -0
  290. numpy/f2py/_backends/_backend.pyi +46 -0
  291. numpy/f2py/_backends/_distutils.py +76 -0
  292. numpy/f2py/_backends/_distutils.pyi +13 -0
  293. numpy/f2py/_backends/_meson.py +244 -0
  294. numpy/f2py/_backends/_meson.pyi +62 -0
  295. numpy/f2py/_backends/meson.build.template +58 -0
  296. numpy/f2py/_isocbind.py +62 -0
  297. numpy/f2py/_isocbind.pyi +13 -0
  298. numpy/f2py/_src_pyf.py +247 -0
  299. numpy/f2py/_src_pyf.pyi +28 -0
  300. numpy/f2py/auxfuncs.py +1004 -0
  301. numpy/f2py/auxfuncs.pyi +262 -0
  302. numpy/f2py/capi_maps.py +811 -0
  303. numpy/f2py/capi_maps.pyi +33 -0
  304. numpy/f2py/cb_rules.py +665 -0
  305. numpy/f2py/cb_rules.pyi +17 -0
  306. numpy/f2py/cfuncs.py +1563 -0
  307. numpy/f2py/cfuncs.pyi +31 -0
  308. numpy/f2py/common_rules.py +143 -0
  309. numpy/f2py/common_rules.pyi +9 -0
  310. numpy/f2py/crackfortran.py +3725 -0
  311. numpy/f2py/crackfortran.pyi +266 -0
  312. numpy/f2py/diagnose.py +149 -0
  313. numpy/f2py/diagnose.pyi +1 -0
  314. numpy/f2py/f2py2e.py +788 -0
  315. numpy/f2py/f2py2e.pyi +74 -0
  316. numpy/f2py/f90mod_rules.py +269 -0
  317. numpy/f2py/f90mod_rules.pyi +16 -0
  318. numpy/f2py/func2subr.py +329 -0
  319. numpy/f2py/func2subr.pyi +7 -0
  320. numpy/f2py/rules.py +1629 -0
  321. numpy/f2py/rules.pyi +41 -0
  322. numpy/f2py/setup.cfg +3 -0
  323. numpy/f2py/src/fortranobject.c +1436 -0
  324. numpy/f2py/src/fortranobject.h +173 -0
  325. numpy/f2py/symbolic.py +1518 -0
  326. numpy/f2py/symbolic.pyi +219 -0
  327. numpy/f2py/tests/__init__.py +16 -0
  328. numpy/f2py/tests/src/abstract_interface/foo.f90 +34 -0
  329. numpy/f2py/tests/src/abstract_interface/gh18403_mod.f90 +6 -0
  330. numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c +235 -0
  331. numpy/f2py/tests/src/assumed_shape/.f2py_f2cmap +1 -0
  332. numpy/f2py/tests/src/assumed_shape/foo_free.f90 +34 -0
  333. numpy/f2py/tests/src/assumed_shape/foo_mod.f90 +41 -0
  334. numpy/f2py/tests/src/assumed_shape/foo_use.f90 +19 -0
  335. numpy/f2py/tests/src/assumed_shape/precision.f90 +4 -0
  336. numpy/f2py/tests/src/block_docstring/foo.f +6 -0
  337. numpy/f2py/tests/src/callback/foo.f +62 -0
  338. numpy/f2py/tests/src/callback/gh17797.f90 +7 -0
  339. numpy/f2py/tests/src/callback/gh18335.f90 +17 -0
  340. numpy/f2py/tests/src/callback/gh25211.f +10 -0
  341. numpy/f2py/tests/src/callback/gh25211.pyf +18 -0
  342. numpy/f2py/tests/src/callback/gh26681.f90 +18 -0
  343. numpy/f2py/tests/src/cli/gh_22819.pyf +6 -0
  344. numpy/f2py/tests/src/cli/hi77.f +3 -0
  345. numpy/f2py/tests/src/cli/hiworld.f90 +3 -0
  346. numpy/f2py/tests/src/common/block.f +11 -0
  347. numpy/f2py/tests/src/common/gh19161.f90 +10 -0
  348. numpy/f2py/tests/src/crackfortran/accesstype.f90 +13 -0
  349. numpy/f2py/tests/src/crackfortran/common_with_division.f +17 -0
  350. numpy/f2py/tests/src/crackfortran/data_common.f +8 -0
  351. numpy/f2py/tests/src/crackfortran/data_multiplier.f +5 -0
  352. numpy/f2py/tests/src/crackfortran/data_stmts.f90 +20 -0
  353. numpy/f2py/tests/src/crackfortran/data_with_comments.f +8 -0
  354. numpy/f2py/tests/src/crackfortran/foo_deps.f90 +6 -0
  355. numpy/f2py/tests/src/crackfortran/gh15035.f +16 -0
  356. numpy/f2py/tests/src/crackfortran/gh17859.f +12 -0
  357. numpy/f2py/tests/src/crackfortran/gh22648.pyf +7 -0
  358. numpy/f2py/tests/src/crackfortran/gh23533.f +5 -0
  359. numpy/f2py/tests/src/crackfortran/gh23598.f90 +4 -0
  360. numpy/f2py/tests/src/crackfortran/gh23598Warn.f90 +11 -0
  361. numpy/f2py/tests/src/crackfortran/gh23879.f90 +20 -0
  362. numpy/f2py/tests/src/crackfortran/gh27697.f90 +12 -0
  363. numpy/f2py/tests/src/crackfortran/gh2848.f90 +13 -0
  364. numpy/f2py/tests/src/crackfortran/operators.f90 +49 -0
  365. numpy/f2py/tests/src/crackfortran/privatemod.f90 +11 -0
  366. numpy/f2py/tests/src/crackfortran/publicmod.f90 +10 -0
  367. numpy/f2py/tests/src/crackfortran/pubprivmod.f90 +10 -0
  368. numpy/f2py/tests/src/crackfortran/unicode_comment.f90 +4 -0
  369. numpy/f2py/tests/src/f2cmap/.f2py_f2cmap +1 -0
  370. numpy/f2py/tests/src/f2cmap/isoFortranEnvMap.f90 +9 -0
  371. numpy/f2py/tests/src/isocintrin/isoCtests.f90 +34 -0
  372. numpy/f2py/tests/src/kind/foo.f90 +20 -0
  373. numpy/f2py/tests/src/mixed/foo.f +5 -0
  374. numpy/f2py/tests/src/mixed/foo_fixed.f90 +8 -0
  375. numpy/f2py/tests/src/mixed/foo_free.f90 +8 -0
  376. numpy/f2py/tests/src/modules/gh25337/data.f90 +8 -0
  377. numpy/f2py/tests/src/modules/gh25337/use_data.f90 +6 -0
  378. numpy/f2py/tests/src/modules/gh26920/two_mods_with_no_public_entities.f90 +21 -0
  379. numpy/f2py/tests/src/modules/gh26920/two_mods_with_one_public_routine.f90 +21 -0
  380. numpy/f2py/tests/src/modules/module_data_docstring.f90 +12 -0
  381. numpy/f2py/tests/src/modules/use_modules.f90 +20 -0
  382. numpy/f2py/tests/src/negative_bounds/issue_20853.f90 +7 -0
  383. numpy/f2py/tests/src/parameter/constant_array.f90 +45 -0
  384. numpy/f2py/tests/src/parameter/constant_both.f90 +57 -0
  385. numpy/f2py/tests/src/parameter/constant_compound.f90 +15 -0
  386. numpy/f2py/tests/src/parameter/constant_integer.f90 +22 -0
  387. numpy/f2py/tests/src/parameter/constant_non_compound.f90 +23 -0
  388. numpy/f2py/tests/src/parameter/constant_real.f90 +23 -0
  389. numpy/f2py/tests/src/quoted_character/foo.f +14 -0
  390. numpy/f2py/tests/src/regression/AB.inc +1 -0
  391. numpy/f2py/tests/src/regression/assignOnlyModule.f90 +25 -0
  392. numpy/f2py/tests/src/regression/datonly.f90 +17 -0
  393. numpy/f2py/tests/src/regression/f77comments.f +26 -0
  394. numpy/f2py/tests/src/regression/f77fixedform.f95 +5 -0
  395. numpy/f2py/tests/src/regression/f90continuation.f90 +9 -0
  396. numpy/f2py/tests/src/regression/incfile.f90 +5 -0
  397. numpy/f2py/tests/src/regression/inout.f90 +9 -0
  398. numpy/f2py/tests/src/regression/lower_f2py_fortran.f90 +5 -0
  399. numpy/f2py/tests/src/regression/mod_derived_types.f90 +23 -0
  400. numpy/f2py/tests/src/return_character/foo77.f +45 -0
  401. numpy/f2py/tests/src/return_character/foo90.f90 +48 -0
  402. numpy/f2py/tests/src/return_complex/foo77.f +45 -0
  403. numpy/f2py/tests/src/return_complex/foo90.f90 +48 -0
  404. numpy/f2py/tests/src/return_integer/foo77.f +56 -0
  405. numpy/f2py/tests/src/return_integer/foo90.f90 +59 -0
  406. numpy/f2py/tests/src/return_logical/foo77.f +56 -0
  407. numpy/f2py/tests/src/return_logical/foo90.f90 +59 -0
  408. numpy/f2py/tests/src/return_real/foo77.f +45 -0
  409. numpy/f2py/tests/src/return_real/foo90.f90 +48 -0
  410. numpy/f2py/tests/src/routines/funcfortranname.f +5 -0
  411. numpy/f2py/tests/src/routines/funcfortranname.pyf +11 -0
  412. numpy/f2py/tests/src/routines/subrout.f +4 -0
  413. numpy/f2py/tests/src/routines/subrout.pyf +10 -0
  414. numpy/f2py/tests/src/size/foo.f90 +44 -0
  415. numpy/f2py/tests/src/string/char.f90 +29 -0
  416. numpy/f2py/tests/src/string/fixed_string.f90 +34 -0
  417. numpy/f2py/tests/src/string/gh24008.f +8 -0
  418. numpy/f2py/tests/src/string/gh24662.f90 +7 -0
  419. numpy/f2py/tests/src/string/gh25286.f90 +14 -0
  420. numpy/f2py/tests/src/string/gh25286.pyf +12 -0
  421. numpy/f2py/tests/src/string/gh25286_bc.pyf +12 -0
  422. numpy/f2py/tests/src/string/scalar_string.f90 +9 -0
  423. numpy/f2py/tests/src/string/string.f +12 -0
  424. numpy/f2py/tests/src/value_attrspec/gh21665.f90 +9 -0
  425. numpy/f2py/tests/test_abstract_interface.py +26 -0
  426. numpy/f2py/tests/test_array_from_pyobj.py +678 -0
  427. numpy/f2py/tests/test_assumed_shape.py +50 -0
  428. numpy/f2py/tests/test_block_docstring.py +20 -0
  429. numpy/f2py/tests/test_callback.py +263 -0
  430. numpy/f2py/tests/test_character.py +641 -0
  431. numpy/f2py/tests/test_common.py +23 -0
  432. numpy/f2py/tests/test_crackfortran.py +421 -0
  433. numpy/f2py/tests/test_data.py +71 -0
  434. numpy/f2py/tests/test_docs.py +66 -0
  435. numpy/f2py/tests/test_f2cmap.py +17 -0
  436. numpy/f2py/tests/test_f2py2e.py +983 -0
  437. numpy/f2py/tests/test_isoc.py +56 -0
  438. numpy/f2py/tests/test_kind.py +52 -0
  439. numpy/f2py/tests/test_mixed.py +35 -0
  440. numpy/f2py/tests/test_modules.py +83 -0
  441. numpy/f2py/tests/test_parameter.py +129 -0
  442. numpy/f2py/tests/test_pyf_src.py +43 -0
  443. numpy/f2py/tests/test_quoted_character.py +18 -0
  444. numpy/f2py/tests/test_regression.py +187 -0
  445. numpy/f2py/tests/test_return_character.py +48 -0
  446. numpy/f2py/tests/test_return_complex.py +67 -0
  447. numpy/f2py/tests/test_return_integer.py +55 -0
  448. numpy/f2py/tests/test_return_logical.py +65 -0
  449. numpy/f2py/tests/test_return_real.py +109 -0
  450. numpy/f2py/tests/test_routines.py +29 -0
  451. numpy/f2py/tests/test_semicolon_split.py +75 -0
  452. numpy/f2py/tests/test_size.py +45 -0
  453. numpy/f2py/tests/test_string.py +100 -0
  454. numpy/f2py/tests/test_symbolic.py +500 -0
  455. numpy/f2py/tests/test_value_attrspec.py +15 -0
  456. numpy/f2py/tests/util.py +442 -0
  457. numpy/f2py/use_rules.py +99 -0
  458. numpy/f2py/use_rules.pyi +9 -0
  459. numpy/fft/__init__.py +213 -0
  460. numpy/fft/__init__.pyi +38 -0
  461. numpy/fft/_helper.py +235 -0
  462. numpy/fft/_helper.pyi +44 -0
  463. numpy/fft/_pocketfft.py +1693 -0
  464. numpy/fft/_pocketfft.pyi +137 -0
  465. numpy/fft/_pocketfft_umath.cpython-313t-aarch64-linux-musl.so +0 -0
  466. numpy/fft/tests/__init__.py +0 -0
  467. numpy/fft/tests/test_helper.py +167 -0
  468. numpy/fft/tests/test_pocketfft.py +589 -0
  469. numpy/lib/__init__.py +97 -0
  470. numpy/lib/__init__.pyi +52 -0
  471. numpy/lib/_array_utils_impl.py +62 -0
  472. numpy/lib/_array_utils_impl.pyi +10 -0
  473. numpy/lib/_arraypad_impl.py +926 -0
  474. numpy/lib/_arraypad_impl.pyi +88 -0
  475. numpy/lib/_arraysetops_impl.py +1158 -0
  476. numpy/lib/_arraysetops_impl.pyi +462 -0
  477. numpy/lib/_arrayterator_impl.py +224 -0
  478. numpy/lib/_arrayterator_impl.pyi +45 -0
  479. numpy/lib/_datasource.py +700 -0
  480. numpy/lib/_datasource.pyi +30 -0
  481. numpy/lib/_format_impl.py +1036 -0
  482. numpy/lib/_format_impl.pyi +56 -0
  483. numpy/lib/_function_base_impl.py +5758 -0
  484. numpy/lib/_function_base_impl.pyi +2324 -0
  485. numpy/lib/_histograms_impl.py +1085 -0
  486. numpy/lib/_histograms_impl.pyi +40 -0
  487. numpy/lib/_index_tricks_impl.py +1048 -0
  488. numpy/lib/_index_tricks_impl.pyi +267 -0
  489. numpy/lib/_iotools.py +900 -0
  490. numpy/lib/_iotools.pyi +116 -0
  491. numpy/lib/_nanfunctions_impl.py +2001 -0
  492. numpy/lib/_nanfunctions_impl.pyi +48 -0
  493. numpy/lib/_npyio_impl.py +2583 -0
  494. numpy/lib/_npyio_impl.pyi +299 -0
  495. numpy/lib/_polynomial_impl.py +1465 -0
  496. numpy/lib/_polynomial_impl.pyi +338 -0
  497. numpy/lib/_scimath_impl.py +642 -0
  498. numpy/lib/_scimath_impl.pyi +93 -0
  499. numpy/lib/_shape_base_impl.py +1289 -0
  500. numpy/lib/_shape_base_impl.pyi +236 -0
  501. numpy/lib/_stride_tricks_impl.py +582 -0
  502. numpy/lib/_stride_tricks_impl.pyi +73 -0
  503. numpy/lib/_twodim_base_impl.py +1201 -0
  504. numpy/lib/_twodim_base_impl.pyi +408 -0
  505. numpy/lib/_type_check_impl.py +710 -0
  506. numpy/lib/_type_check_impl.pyi +348 -0
  507. numpy/lib/_ufunclike_impl.py +199 -0
  508. numpy/lib/_ufunclike_impl.pyi +60 -0
  509. numpy/lib/_user_array_impl.py +310 -0
  510. numpy/lib/_user_array_impl.pyi +226 -0
  511. numpy/lib/_utils_impl.py +784 -0
  512. numpy/lib/_utils_impl.pyi +22 -0
  513. numpy/lib/_version.py +153 -0
  514. numpy/lib/_version.pyi +17 -0
  515. numpy/lib/array_utils.py +7 -0
  516. numpy/lib/array_utils.pyi +6 -0
  517. numpy/lib/format.py +24 -0
  518. numpy/lib/format.pyi +24 -0
  519. numpy/lib/introspect.py +94 -0
  520. numpy/lib/introspect.pyi +3 -0
  521. numpy/lib/mixins.py +180 -0
  522. numpy/lib/mixins.pyi +78 -0
  523. numpy/lib/npyio.py +1 -0
  524. numpy/lib/npyio.pyi +5 -0
  525. numpy/lib/recfunctions.py +1681 -0
  526. numpy/lib/recfunctions.pyi +444 -0
  527. numpy/lib/scimath.py +13 -0
  528. numpy/lib/scimath.pyi +12 -0
  529. numpy/lib/stride_tricks.py +1 -0
  530. numpy/lib/stride_tricks.pyi +4 -0
  531. numpy/lib/tests/__init__.py +0 -0
  532. numpy/lib/tests/data/py2-np0-objarr.npy +0 -0
  533. numpy/lib/tests/data/py2-objarr.npy +0 -0
  534. numpy/lib/tests/data/py2-objarr.npz +0 -0
  535. numpy/lib/tests/data/py3-objarr.npy +0 -0
  536. numpy/lib/tests/data/py3-objarr.npz +0 -0
  537. numpy/lib/tests/data/python3.npy +0 -0
  538. numpy/lib/tests/data/win64python2.npy +0 -0
  539. numpy/lib/tests/test__datasource.py +328 -0
  540. numpy/lib/tests/test__iotools.py +358 -0
  541. numpy/lib/tests/test__version.py +64 -0
  542. numpy/lib/tests/test_array_utils.py +32 -0
  543. numpy/lib/tests/test_arraypad.py +1427 -0
  544. numpy/lib/tests/test_arraysetops.py +1302 -0
  545. numpy/lib/tests/test_arrayterator.py +45 -0
  546. numpy/lib/tests/test_format.py +1054 -0
  547. numpy/lib/tests/test_function_base.py +4705 -0
  548. numpy/lib/tests/test_histograms.py +855 -0
  549. numpy/lib/tests/test_index_tricks.py +693 -0
  550. numpy/lib/tests/test_io.py +2857 -0
  551. numpy/lib/tests/test_loadtxt.py +1099 -0
  552. numpy/lib/tests/test_mixins.py +215 -0
  553. numpy/lib/tests/test_nanfunctions.py +1438 -0
  554. numpy/lib/tests/test_packbits.py +376 -0
  555. numpy/lib/tests/test_polynomial.py +325 -0
  556. numpy/lib/tests/test_recfunctions.py +1042 -0
  557. numpy/lib/tests/test_regression.py +231 -0
  558. numpy/lib/tests/test_shape_base.py +813 -0
  559. numpy/lib/tests/test_stride_tricks.py +655 -0
  560. numpy/lib/tests/test_twodim_base.py +559 -0
  561. numpy/lib/tests/test_type_check.py +473 -0
  562. numpy/lib/tests/test_ufunclike.py +97 -0
  563. numpy/lib/tests/test_utils.py +80 -0
  564. numpy/lib/user_array.py +1 -0
  565. numpy/lib/user_array.pyi +1 -0
  566. numpy/linalg/__init__.py +95 -0
  567. numpy/linalg/__init__.pyi +71 -0
  568. numpy/linalg/_linalg.py +3657 -0
  569. numpy/linalg/_linalg.pyi +548 -0
  570. numpy/linalg/_umath_linalg.cpython-313t-aarch64-linux-musl.so +0 -0
  571. numpy/linalg/_umath_linalg.pyi +60 -0
  572. numpy/linalg/lapack_lite.cpython-313t-aarch64-linux-musl.so +0 -0
  573. numpy/linalg/lapack_lite.pyi +143 -0
  574. numpy/linalg/tests/__init__.py +0 -0
  575. numpy/linalg/tests/test_deprecations.py +21 -0
  576. numpy/linalg/tests/test_linalg.py +2442 -0
  577. numpy/linalg/tests/test_regression.py +182 -0
  578. numpy/ma/API_CHANGES.txt +135 -0
  579. numpy/ma/LICENSE +24 -0
  580. numpy/ma/README.rst +236 -0
  581. numpy/ma/__init__.py +53 -0
  582. numpy/ma/__init__.pyi +458 -0
  583. numpy/ma/core.py +8929 -0
  584. numpy/ma/core.pyi +3720 -0
  585. numpy/ma/extras.py +2266 -0
  586. numpy/ma/extras.pyi +297 -0
  587. numpy/ma/mrecords.py +762 -0
  588. numpy/ma/mrecords.pyi +96 -0
  589. numpy/ma/tests/__init__.py +0 -0
  590. numpy/ma/tests/test_arrayobject.py +40 -0
  591. numpy/ma/tests/test_core.py +6008 -0
  592. numpy/ma/tests/test_deprecations.py +65 -0
  593. numpy/ma/tests/test_extras.py +1945 -0
  594. numpy/ma/tests/test_mrecords.py +495 -0
  595. numpy/ma/tests/test_old_ma.py +939 -0
  596. numpy/ma/tests/test_regression.py +83 -0
  597. numpy/ma/tests/test_subclassing.py +469 -0
  598. numpy/ma/testutils.py +294 -0
  599. numpy/ma/testutils.pyi +69 -0
  600. numpy/matlib.py +380 -0
  601. numpy/matlib.pyi +580 -0
  602. numpy/matrixlib/__init__.py +12 -0
  603. numpy/matrixlib/__init__.pyi +3 -0
  604. numpy/matrixlib/defmatrix.py +1119 -0
  605. numpy/matrixlib/defmatrix.pyi +218 -0
  606. numpy/matrixlib/tests/__init__.py +0 -0
  607. numpy/matrixlib/tests/test_defmatrix.py +455 -0
  608. numpy/matrixlib/tests/test_interaction.py +360 -0
  609. numpy/matrixlib/tests/test_masked_matrix.py +240 -0
  610. numpy/matrixlib/tests/test_matrix_linalg.py +110 -0
  611. numpy/matrixlib/tests/test_multiarray.py +17 -0
  612. numpy/matrixlib/tests/test_numeric.py +18 -0
  613. numpy/matrixlib/tests/test_regression.py +31 -0
  614. numpy/polynomial/__init__.py +187 -0
  615. numpy/polynomial/__init__.pyi +31 -0
  616. numpy/polynomial/_polybase.py +1191 -0
  617. numpy/polynomial/_polybase.pyi +262 -0
  618. numpy/polynomial/_polytypes.pyi +501 -0
  619. numpy/polynomial/chebyshev.py +2001 -0
  620. numpy/polynomial/chebyshev.pyi +180 -0
  621. numpy/polynomial/hermite.py +1738 -0
  622. numpy/polynomial/hermite.pyi +106 -0
  623. numpy/polynomial/hermite_e.py +1640 -0
  624. numpy/polynomial/hermite_e.pyi +106 -0
  625. numpy/polynomial/laguerre.py +1673 -0
  626. numpy/polynomial/laguerre.pyi +100 -0
  627. numpy/polynomial/legendre.py +1603 -0
  628. numpy/polynomial/legendre.pyi +100 -0
  629. numpy/polynomial/polynomial.py +1625 -0
  630. numpy/polynomial/polynomial.pyi +109 -0
  631. numpy/polynomial/polyutils.py +759 -0
  632. numpy/polynomial/polyutils.pyi +307 -0
  633. numpy/polynomial/tests/__init__.py +0 -0
  634. numpy/polynomial/tests/test_chebyshev.py +618 -0
  635. numpy/polynomial/tests/test_classes.py +613 -0
  636. numpy/polynomial/tests/test_hermite.py +553 -0
  637. numpy/polynomial/tests/test_hermite_e.py +554 -0
  638. numpy/polynomial/tests/test_laguerre.py +535 -0
  639. numpy/polynomial/tests/test_legendre.py +566 -0
  640. numpy/polynomial/tests/test_polynomial.py +691 -0
  641. numpy/polynomial/tests/test_polyutils.py +123 -0
  642. numpy/polynomial/tests/test_printing.py +557 -0
  643. numpy/polynomial/tests/test_symbol.py +217 -0
  644. numpy/py.typed +0 -0
  645. numpy/random/LICENSE.md +71 -0
  646. numpy/random/__init__.pxd +14 -0
  647. numpy/random/__init__.py +213 -0
  648. numpy/random/__init__.pyi +124 -0
  649. numpy/random/_bounded_integers.cpython-313t-aarch64-linux-musl.so +0 -0
  650. numpy/random/_bounded_integers.pxd +29 -0
  651. numpy/random/_bounded_integers.pyi +1 -0
  652. numpy/random/_common.cpython-313t-aarch64-linux-musl.so +0 -0
  653. numpy/random/_common.pxd +107 -0
  654. numpy/random/_common.pyi +16 -0
  655. numpy/random/_examples/cffi/extending.py +44 -0
  656. numpy/random/_examples/cffi/parse.py +53 -0
  657. numpy/random/_examples/cython/extending.pyx +77 -0
  658. numpy/random/_examples/cython/extending_distributions.pyx +117 -0
  659. numpy/random/_examples/cython/meson.build +53 -0
  660. numpy/random/_examples/numba/extending.py +86 -0
  661. numpy/random/_examples/numba/extending_distributions.py +67 -0
  662. numpy/random/_generator.cpython-313t-aarch64-linux-musl.so +0 -0
  663. numpy/random/_generator.pyi +862 -0
  664. numpy/random/_mt19937.cpython-313t-aarch64-linux-musl.so +0 -0
  665. numpy/random/_mt19937.pyi +27 -0
  666. numpy/random/_pcg64.cpython-313t-aarch64-linux-musl.so +0 -0
  667. numpy/random/_pcg64.pyi +41 -0
  668. numpy/random/_philox.cpython-313t-aarch64-linux-musl.so +0 -0
  669. numpy/random/_philox.pyi +36 -0
  670. numpy/random/_pickle.py +88 -0
  671. numpy/random/_pickle.pyi +43 -0
  672. numpy/random/_sfc64.cpython-313t-aarch64-linux-musl.so +0 -0
  673. numpy/random/_sfc64.pyi +25 -0
  674. numpy/random/bit_generator.cpython-313t-aarch64-linux-musl.so +0 -0
  675. numpy/random/bit_generator.pxd +35 -0
  676. numpy/random/bit_generator.pyi +123 -0
  677. numpy/random/c_distributions.pxd +119 -0
  678. numpy/random/lib/libnpyrandom.a +0 -0
  679. numpy/random/mtrand.cpython-313t-aarch64-linux-musl.so +0 -0
  680. numpy/random/mtrand.pyi +759 -0
  681. numpy/random/tests/__init__.py +0 -0
  682. numpy/random/tests/data/__init__.py +0 -0
  683. numpy/random/tests/data/generator_pcg64_np121.pkl.gz +0 -0
  684. numpy/random/tests/data/generator_pcg64_np126.pkl.gz +0 -0
  685. numpy/random/tests/data/mt19937-testset-1.csv +1001 -0
  686. numpy/random/tests/data/mt19937-testset-2.csv +1001 -0
  687. numpy/random/tests/data/pcg64-testset-1.csv +1001 -0
  688. numpy/random/tests/data/pcg64-testset-2.csv +1001 -0
  689. numpy/random/tests/data/pcg64dxsm-testset-1.csv +1001 -0
  690. numpy/random/tests/data/pcg64dxsm-testset-2.csv +1001 -0
  691. numpy/random/tests/data/philox-testset-1.csv +1001 -0
  692. numpy/random/tests/data/philox-testset-2.csv +1001 -0
  693. numpy/random/tests/data/sfc64-testset-1.csv +1001 -0
  694. numpy/random/tests/data/sfc64-testset-2.csv +1001 -0
  695. numpy/random/tests/data/sfc64_np126.pkl.gz +0 -0
  696. numpy/random/tests/test_direct.py +595 -0
  697. numpy/random/tests/test_extending.py +131 -0
  698. numpy/random/tests/test_generator_mt19937.py +2825 -0
  699. numpy/random/tests/test_generator_mt19937_regressions.py +221 -0
  700. numpy/random/tests/test_random.py +1724 -0
  701. numpy/random/tests/test_randomstate.py +2099 -0
  702. numpy/random/tests/test_randomstate_regression.py +213 -0
  703. numpy/random/tests/test_regression.py +175 -0
  704. numpy/random/tests/test_seed_sequence.py +79 -0
  705. numpy/random/tests/test_smoke.py +882 -0
  706. numpy/rec/__init__.py +2 -0
  707. numpy/rec/__init__.pyi +23 -0
  708. numpy/strings/__init__.py +2 -0
  709. numpy/strings/__init__.pyi +97 -0
  710. numpy/testing/__init__.py +22 -0
  711. numpy/testing/__init__.pyi +107 -0
  712. numpy/testing/_private/__init__.py +0 -0
  713. numpy/testing/_private/__init__.pyi +0 -0
  714. numpy/testing/_private/extbuild.py +250 -0
  715. numpy/testing/_private/extbuild.pyi +25 -0
  716. numpy/testing/_private/utils.py +2830 -0
  717. numpy/testing/_private/utils.pyi +505 -0
  718. numpy/testing/overrides.py +84 -0
  719. numpy/testing/overrides.pyi +10 -0
  720. numpy/testing/print_coercion_tables.py +207 -0
  721. numpy/testing/print_coercion_tables.pyi +26 -0
  722. numpy/testing/tests/__init__.py +0 -0
  723. numpy/testing/tests/test_utils.py +2123 -0
  724. numpy/tests/__init__.py +0 -0
  725. numpy/tests/test__all__.py +10 -0
  726. numpy/tests/test_configtool.py +51 -0
  727. numpy/tests/test_ctypeslib.py +383 -0
  728. numpy/tests/test_lazyloading.py +42 -0
  729. numpy/tests/test_matlib.py +59 -0
  730. numpy/tests/test_numpy_config.py +47 -0
  731. numpy/tests/test_numpy_version.py +54 -0
  732. numpy/tests/test_public_api.py +804 -0
  733. numpy/tests/test_reloading.py +76 -0
  734. numpy/tests/test_scripts.py +48 -0
  735. numpy/tests/test_warnings.py +79 -0
  736. numpy/typing/__init__.py +233 -0
  737. numpy/typing/__init__.pyi +3 -0
  738. numpy/typing/mypy_plugin.py +200 -0
  739. numpy/typing/tests/__init__.py +0 -0
  740. numpy/typing/tests/data/fail/arithmetic.pyi +126 -0
  741. numpy/typing/tests/data/fail/array_constructors.pyi +34 -0
  742. numpy/typing/tests/data/fail/array_like.pyi +15 -0
  743. numpy/typing/tests/data/fail/array_pad.pyi +6 -0
  744. numpy/typing/tests/data/fail/arrayprint.pyi +15 -0
  745. numpy/typing/tests/data/fail/arrayterator.pyi +14 -0
  746. numpy/typing/tests/data/fail/bitwise_ops.pyi +17 -0
  747. numpy/typing/tests/data/fail/char.pyi +63 -0
  748. numpy/typing/tests/data/fail/chararray.pyi +61 -0
  749. numpy/typing/tests/data/fail/comparisons.pyi +27 -0
  750. numpy/typing/tests/data/fail/constants.pyi +3 -0
  751. numpy/typing/tests/data/fail/datasource.pyi +16 -0
  752. numpy/typing/tests/data/fail/dtype.pyi +17 -0
  753. numpy/typing/tests/data/fail/einsumfunc.pyi +12 -0
  754. numpy/typing/tests/data/fail/flatiter.pyi +38 -0
  755. numpy/typing/tests/data/fail/fromnumeric.pyi +148 -0
  756. numpy/typing/tests/data/fail/histograms.pyi +12 -0
  757. numpy/typing/tests/data/fail/index_tricks.pyi +14 -0
  758. numpy/typing/tests/data/fail/lib_function_base.pyi +60 -0
  759. numpy/typing/tests/data/fail/lib_polynomial.pyi +29 -0
  760. numpy/typing/tests/data/fail/lib_utils.pyi +3 -0
  761. numpy/typing/tests/data/fail/lib_version.pyi +6 -0
  762. numpy/typing/tests/data/fail/linalg.pyi +52 -0
  763. numpy/typing/tests/data/fail/ma.pyi +155 -0
  764. numpy/typing/tests/data/fail/memmap.pyi +5 -0
  765. numpy/typing/tests/data/fail/modules.pyi +17 -0
  766. numpy/typing/tests/data/fail/multiarray.pyi +52 -0
  767. numpy/typing/tests/data/fail/ndarray.pyi +11 -0
  768. numpy/typing/tests/data/fail/ndarray_misc.pyi +49 -0
  769. numpy/typing/tests/data/fail/nditer.pyi +8 -0
  770. numpy/typing/tests/data/fail/nested_sequence.pyi +17 -0
  771. numpy/typing/tests/data/fail/npyio.pyi +24 -0
  772. numpy/typing/tests/data/fail/numerictypes.pyi +5 -0
  773. numpy/typing/tests/data/fail/random.pyi +62 -0
  774. numpy/typing/tests/data/fail/rec.pyi +17 -0
  775. numpy/typing/tests/data/fail/scalars.pyi +86 -0
  776. numpy/typing/tests/data/fail/shape.pyi +7 -0
  777. numpy/typing/tests/data/fail/shape_base.pyi +8 -0
  778. numpy/typing/tests/data/fail/stride_tricks.pyi +9 -0
  779. numpy/typing/tests/data/fail/strings.pyi +52 -0
  780. numpy/typing/tests/data/fail/testing.pyi +28 -0
  781. numpy/typing/tests/data/fail/twodim_base.pyi +39 -0
  782. numpy/typing/tests/data/fail/type_check.pyi +12 -0
  783. numpy/typing/tests/data/fail/ufunc_config.pyi +21 -0
  784. numpy/typing/tests/data/fail/ufunclike.pyi +21 -0
  785. numpy/typing/tests/data/fail/ufuncs.pyi +17 -0
  786. numpy/typing/tests/data/fail/warnings_and_errors.pyi +5 -0
  787. numpy/typing/tests/data/misc/extended_precision.pyi +9 -0
  788. numpy/typing/tests/data/mypy.ini +8 -0
  789. numpy/typing/tests/data/pass/arithmetic.py +614 -0
  790. numpy/typing/tests/data/pass/array_constructors.py +138 -0
  791. numpy/typing/tests/data/pass/array_like.py +43 -0
  792. numpy/typing/tests/data/pass/arrayprint.py +37 -0
  793. numpy/typing/tests/data/pass/arrayterator.py +28 -0
  794. numpy/typing/tests/data/pass/bitwise_ops.py +131 -0
  795. numpy/typing/tests/data/pass/comparisons.py +316 -0
  796. numpy/typing/tests/data/pass/dtype.py +57 -0
  797. numpy/typing/tests/data/pass/einsumfunc.py +36 -0
  798. numpy/typing/tests/data/pass/flatiter.py +26 -0
  799. numpy/typing/tests/data/pass/fromnumeric.py +272 -0
  800. numpy/typing/tests/data/pass/index_tricks.py +62 -0
  801. numpy/typing/tests/data/pass/lib_user_array.py +22 -0
  802. numpy/typing/tests/data/pass/lib_utils.py +19 -0
  803. numpy/typing/tests/data/pass/lib_version.py +18 -0
  804. numpy/typing/tests/data/pass/literal.py +52 -0
  805. numpy/typing/tests/data/pass/ma.py +199 -0
  806. numpy/typing/tests/data/pass/mod.py +149 -0
  807. numpy/typing/tests/data/pass/modules.py +45 -0
  808. numpy/typing/tests/data/pass/multiarray.py +77 -0
  809. numpy/typing/tests/data/pass/ndarray_conversion.py +81 -0
  810. numpy/typing/tests/data/pass/ndarray_misc.py +199 -0
  811. numpy/typing/tests/data/pass/ndarray_shape_manipulation.py +47 -0
  812. numpy/typing/tests/data/pass/nditer.py +4 -0
  813. numpy/typing/tests/data/pass/numeric.py +90 -0
  814. numpy/typing/tests/data/pass/numerictypes.py +17 -0
  815. numpy/typing/tests/data/pass/random.py +1498 -0
  816. numpy/typing/tests/data/pass/recfunctions.py +164 -0
  817. numpy/typing/tests/data/pass/scalars.py +249 -0
  818. numpy/typing/tests/data/pass/shape.py +19 -0
  819. numpy/typing/tests/data/pass/simple.py +170 -0
  820. numpy/typing/tests/data/pass/ufunc_config.py +64 -0
  821. numpy/typing/tests/data/pass/ufunclike.py +52 -0
  822. numpy/typing/tests/data/pass/ufuncs.py +16 -0
  823. numpy/typing/tests/data/pass/warnings_and_errors.py +6 -0
  824. numpy/typing/tests/data/reveal/arithmetic.pyi +719 -0
  825. numpy/typing/tests/data/reveal/array_api_info.pyi +70 -0
  826. numpy/typing/tests/data/reveal/array_constructors.pyi +277 -0
  827. numpy/typing/tests/data/reveal/arraypad.pyi +27 -0
  828. numpy/typing/tests/data/reveal/arrayprint.pyi +25 -0
  829. numpy/typing/tests/data/reveal/arraysetops.pyi +74 -0
  830. numpy/typing/tests/data/reveal/arrayterator.pyi +27 -0
  831. numpy/typing/tests/data/reveal/bitwise_ops.pyi +166 -0
  832. numpy/typing/tests/data/reveal/char.pyi +225 -0
  833. numpy/typing/tests/data/reveal/chararray.pyi +138 -0
  834. numpy/typing/tests/data/reveal/comparisons.pyi +264 -0
  835. numpy/typing/tests/data/reveal/constants.pyi +14 -0
  836. numpy/typing/tests/data/reveal/ctypeslib.pyi +81 -0
  837. numpy/typing/tests/data/reveal/datasource.pyi +23 -0
  838. numpy/typing/tests/data/reveal/dtype.pyi +132 -0
  839. numpy/typing/tests/data/reveal/einsumfunc.pyi +39 -0
  840. numpy/typing/tests/data/reveal/emath.pyi +54 -0
  841. numpy/typing/tests/data/reveal/fft.pyi +37 -0
  842. numpy/typing/tests/data/reveal/flatiter.pyi +86 -0
  843. numpy/typing/tests/data/reveal/fromnumeric.pyi +347 -0
  844. numpy/typing/tests/data/reveal/getlimits.pyi +53 -0
  845. numpy/typing/tests/data/reveal/histograms.pyi +25 -0
  846. numpy/typing/tests/data/reveal/index_tricks.pyi +70 -0
  847. numpy/typing/tests/data/reveal/lib_function_base.pyi +409 -0
  848. numpy/typing/tests/data/reveal/lib_polynomial.pyi +147 -0
  849. numpy/typing/tests/data/reveal/lib_utils.pyi +17 -0
  850. numpy/typing/tests/data/reveal/lib_version.pyi +20 -0
  851. numpy/typing/tests/data/reveal/linalg.pyi +154 -0
  852. numpy/typing/tests/data/reveal/ma.pyi +1098 -0
  853. numpy/typing/tests/data/reveal/matrix.pyi +73 -0
  854. numpy/typing/tests/data/reveal/memmap.pyi +19 -0
  855. numpy/typing/tests/data/reveal/mod.pyi +178 -0
  856. numpy/typing/tests/data/reveal/modules.pyi +51 -0
  857. numpy/typing/tests/data/reveal/multiarray.pyi +197 -0
  858. numpy/typing/tests/data/reveal/nbit_base_example.pyi +20 -0
  859. numpy/typing/tests/data/reveal/ndarray_assignability.pyi +82 -0
  860. numpy/typing/tests/data/reveal/ndarray_conversion.pyi +83 -0
  861. numpy/typing/tests/data/reveal/ndarray_misc.pyi +246 -0
  862. numpy/typing/tests/data/reveal/ndarray_shape_manipulation.pyi +47 -0
  863. numpy/typing/tests/data/reveal/nditer.pyi +49 -0
  864. numpy/typing/tests/data/reveal/nested_sequence.pyi +25 -0
  865. numpy/typing/tests/data/reveal/npyio.pyi +83 -0
  866. numpy/typing/tests/data/reveal/numeric.pyi +170 -0
  867. numpy/typing/tests/data/reveal/numerictypes.pyi +16 -0
  868. numpy/typing/tests/data/reveal/polynomial_polybase.pyi +217 -0
  869. numpy/typing/tests/data/reveal/polynomial_polyutils.pyi +218 -0
  870. numpy/typing/tests/data/reveal/polynomial_series.pyi +138 -0
  871. numpy/typing/tests/data/reveal/random.pyi +1546 -0
  872. numpy/typing/tests/data/reveal/rec.pyi +171 -0
  873. numpy/typing/tests/data/reveal/scalars.pyi +191 -0
  874. numpy/typing/tests/data/reveal/shape.pyi +13 -0
  875. numpy/typing/tests/data/reveal/shape_base.pyi +52 -0
  876. numpy/typing/tests/data/reveal/stride_tricks.pyi +27 -0
  877. numpy/typing/tests/data/reveal/strings.pyi +196 -0
  878. numpy/typing/tests/data/reveal/testing.pyi +198 -0
  879. numpy/typing/tests/data/reveal/twodim_base.pyi +225 -0
  880. numpy/typing/tests/data/reveal/type_check.pyi +67 -0
  881. numpy/typing/tests/data/reveal/ufunc_config.pyi +29 -0
  882. numpy/typing/tests/data/reveal/ufunclike.pyi +31 -0
  883. numpy/typing/tests/data/reveal/ufuncs.pyi +142 -0
  884. numpy/typing/tests/data/reveal/warnings_and_errors.pyi +11 -0
  885. numpy/typing/tests/test_isfile.py +38 -0
  886. numpy/typing/tests/test_runtime.py +110 -0
  887. numpy/typing/tests/test_typing.py +205 -0
  888. numpy/version.py +11 -0
  889. numpy/version.pyi +9 -0
  890. numpy-2.4.0.dist-info/METADATA +139 -0
  891. numpy-2.4.0.dist-info/RECORD +915 -0
  892. numpy-2.4.0.dist-info/WHEEL +5 -0
  893. numpy-2.4.0.dist-info/entry_points.txt +13 -0
  894. numpy-2.4.0.dist-info/licenses/LICENSE.txt +935 -0
  895. numpy-2.4.0.dist-info/licenses/numpy/_core/include/numpy/libdivide/LICENSE.txt +21 -0
  896. numpy-2.4.0.dist-info/licenses/numpy/_core/src/common/pythoncapi-compat/COPYING +14 -0
  897. numpy-2.4.0.dist-info/licenses/numpy/_core/src/highway/LICENSE +371 -0
  898. numpy-2.4.0.dist-info/licenses/numpy/_core/src/multiarray/dragon4_LICENSE.txt +27 -0
  899. numpy-2.4.0.dist-info/licenses/numpy/_core/src/npysort/x86-simd-sort/LICENSE.md +28 -0
  900. numpy-2.4.0.dist-info/licenses/numpy/_core/src/umath/svml/LICENSE +30 -0
  901. numpy-2.4.0.dist-info/licenses/numpy/fft/pocketfft/LICENSE.md +25 -0
  902. numpy-2.4.0.dist-info/licenses/numpy/linalg/lapack_lite/LICENSE.txt +48 -0
  903. numpy-2.4.0.dist-info/licenses/numpy/ma/LICENSE +24 -0
  904. numpy-2.4.0.dist-info/licenses/numpy/random/LICENSE.md +71 -0
  905. numpy-2.4.0.dist-info/licenses/numpy/random/src/distributions/LICENSE.md +61 -0
  906. numpy-2.4.0.dist-info/licenses/numpy/random/src/mt19937/LICENSE.md +61 -0
  907. numpy-2.4.0.dist-info/licenses/numpy/random/src/pcg64/LICENSE.md +22 -0
  908. numpy-2.4.0.dist-info/licenses/numpy/random/src/philox/LICENSE.md +31 -0
  909. numpy-2.4.0.dist-info/licenses/numpy/random/src/sfc64/LICENSE.md +27 -0
  910. numpy-2.4.0.dist-info/licenses/numpy/random/src/splitmix64/LICENSE.md +9 -0
  911. numpy.libs/libgcc_s-2d945d6c-767fb991.so.1 +0 -0
  912. numpy.libs/libgcc_s-2d945d6c.so.1 +0 -0
  913. numpy.libs/libgfortran-67378ab2-e7e7cfab.so.5.0.0 +0 -0
  914. numpy.libs/libscipy_openblas64_-1fc386ee.so +0 -0
  915. numpy.libs/libstdc++-85f2cd6d.so.6.0.33 +0 -0
@@ -0,0 +1,2099 @@
1
+ import hashlib
2
+ import pickle
3
+ import sys
4
+ import warnings
5
+
6
+ import pytest
7
+
8
+ import numpy as np
9
+ from numpy import random
10
+ from numpy.random import MT19937, PCG64
11
+ from numpy.testing import (
12
+ IS_WASM,
13
+ assert_,
14
+ assert_array_almost_equal,
15
+ assert_array_equal,
16
+ assert_equal,
17
+ assert_no_warnings,
18
+ assert_raises,
19
+ )
20
+
21
+ INT_FUNCS = {'binomial': (100.0, 0.6),
22
+ 'geometric': (.5,),
23
+ 'hypergeometric': (20, 20, 10),
24
+ 'logseries': (.5,),
25
+ 'multinomial': (20, np.ones(6) / 6.0),
26
+ 'negative_binomial': (100, .5),
27
+ 'poisson': (10.0,),
28
+ 'zipf': (2,),
29
+ }
30
+
31
+ if np.iinfo(np.long).max < 2**32:
32
+ # Windows and some 32-bit platforms, e.g., ARM
33
+ INT_FUNC_HASHES = {'binomial': '2fbead005fc63942decb5326d36a1f32fe2c9d32c904ee61e46866b88447c263', # noqa: E501
34
+ 'logseries': '23ead5dcde35d4cfd4ef2c105e4c3d43304b45dc1b1444b7823b9ee4fa144ebb', # noqa: E501
35
+ 'geometric': '0d764db64f5c3bad48c8c33551c13b4d07a1e7b470f77629bef6c985cac76fcf', # noqa: E501
36
+ 'hypergeometric': '7b59bf2f1691626c5815cdcd9a49e1dd68697251d4521575219e4d2a1b8b2c67', # noqa: E501
37
+ 'multinomial': 'd754fa5b92943a38ec07630de92362dd2e02c43577fc147417dc5b9db94ccdd3', # noqa: E501
38
+ 'negative_binomial': '8eb216f7cb2a63cf55605422845caaff002fddc64a7dc8b2d45acd477a49e824', # noqa: E501
39
+ 'poisson': '70c891d76104013ebd6f6bcf30d403a9074b886ff62e4e6b8eb605bf1a4673b7', # noqa: E501
40
+ 'zipf': '01f074f97517cd5d21747148ac6ca4074dde7fcb7acbaec0a936606fecacd93f', # noqa: E501
41
+ }
42
+ else:
43
+ INT_FUNC_HASHES = {'binomial': '8626dd9d052cb608e93d8868de0a7b347258b199493871a1dc56e2a26cacb112', # noqa: E501
44
+ 'geometric': '8edd53d272e49c4fc8fbbe6c7d08d563d62e482921f3131d0a0e068af30f0db9', # noqa: E501
45
+ 'hypergeometric': '83496cc4281c77b786c9b7ad88b74d42e01603a55c60577ebab81c3ba8d45657', # noqa: E501
46
+ 'logseries': '65878a38747c176bc00e930ebafebb69d4e1e16cd3a704e264ea8f5e24f548db', # noqa: E501
47
+ 'multinomial': '7a984ae6dca26fd25374479e118b22f55db0aedccd5a0f2584ceada33db98605', # noqa: E501
48
+ 'negative_binomial': 'd636d968e6a24ae92ab52fe11c46ac45b0897e98714426764e820a7d77602a61', # noqa: E501
49
+ 'poisson': '956552176f77e7c9cb20d0118fc9cf690be488d790ed4b4c4747b965e61b0bb4', # noqa: E501
50
+ 'zipf': 'f84ba7feffda41e606e20b28dfc0f1ea9964a74574513d4a4cbc98433a8bfa45', # noqa: E501
51
+ }
52
+
53
+
54
+ @pytest.fixture(scope='module', params=INT_FUNCS)
55
+ def int_func(request):
56
+ return (request.param, INT_FUNCS[request.param],
57
+ INT_FUNC_HASHES[request.param])
58
+
59
+
60
+ @pytest.fixture
61
+ def restore_singleton_bitgen():
62
+ """Ensures that the singleton bitgen is restored after a test"""
63
+ orig_bitgen = np.random.get_bit_generator()
64
+ yield
65
+ np.random.set_bit_generator(orig_bitgen)
66
+
67
+
68
+ def assert_mt19937_state_equal(a, b):
69
+ assert_equal(a['bit_generator'], b['bit_generator'])
70
+ assert_array_equal(a['state']['key'], b['state']['key'])
71
+ assert_array_equal(a['state']['pos'], b['state']['pos'])
72
+ assert_equal(a['has_gauss'], b['has_gauss'])
73
+ assert_equal(a['gauss'], b['gauss'])
74
+
75
+
76
+ class TestSeed:
77
+ def test_scalar(self):
78
+ s = random.RandomState(0)
79
+ assert_equal(s.randint(1000), 684)
80
+ s = random.RandomState(4294967295)
81
+ assert_equal(s.randint(1000), 419)
82
+
83
+ def test_array(self):
84
+ s = random.RandomState(range(10))
85
+ assert_equal(s.randint(1000), 468)
86
+ s = random.RandomState(np.arange(10))
87
+ assert_equal(s.randint(1000), 468)
88
+ s = random.RandomState([0])
89
+ assert_equal(s.randint(1000), 973)
90
+ s = random.RandomState([4294967295])
91
+ assert_equal(s.randint(1000), 265)
92
+
93
+ def test_invalid_scalar(self):
94
+ # seed must be an unsigned 32 bit integer
95
+ assert_raises(TypeError, random.RandomState, -0.5)
96
+ assert_raises(ValueError, random.RandomState, -1)
97
+
98
+ def test_invalid_array(self):
99
+ # seed must be an unsigned 32 bit integer
100
+ assert_raises(TypeError, random.RandomState, [-0.5])
101
+ assert_raises(ValueError, random.RandomState, [-1])
102
+ assert_raises(ValueError, random.RandomState, [4294967296])
103
+ assert_raises(ValueError, random.RandomState, [1, 2, 4294967296])
104
+ assert_raises(ValueError, random.RandomState, [1, -2, 4294967296])
105
+
106
+ def test_invalid_array_shape(self):
107
+ # gh-9832
108
+ assert_raises(ValueError, random.RandomState, np.array([],
109
+ dtype=np.int64))
110
+ assert_raises(ValueError, random.RandomState, [[1, 2, 3]])
111
+ assert_raises(ValueError, random.RandomState, [[1, 2, 3],
112
+ [4, 5, 6]])
113
+
114
+ def test_cannot_seed(self):
115
+ rs = random.RandomState(PCG64(0))
116
+ with assert_raises(TypeError):
117
+ rs.seed(1234)
118
+
119
+ def test_invalid_initialization(self):
120
+ assert_raises(ValueError, random.RandomState, MT19937)
121
+
122
+
123
+ class TestBinomial:
124
+ def test_n_zero(self):
125
+ # Tests the corner case of n == 0 for the binomial distribution.
126
+ # binomial(0, p) should be zero for any p in [0, 1].
127
+ # This test addresses issue #3480.
128
+ zeros = np.zeros(2, dtype='int')
129
+ for p in [0, .5, 1]:
130
+ assert_(random.binomial(0, p) == 0)
131
+ assert_array_equal(random.binomial(zeros, p), zeros)
132
+
133
+ def test_p_is_nan(self):
134
+ # Issue #4571.
135
+ assert_raises(ValueError, random.binomial, 1, np.nan)
136
+
137
+
138
+ class TestMultinomial:
139
+ def test_basic(self):
140
+ random.multinomial(100, [0.2, 0.8])
141
+
142
+ def test_zero_probability(self):
143
+ random.multinomial(100, [0.2, 0.8, 0.0, 0.0, 0.0])
144
+
145
+ def test_int_negative_interval(self):
146
+ assert_(-5 <= random.randint(-5, -1) < -1)
147
+ x = random.randint(-5, -1, 5)
148
+ assert_(np.all(-5 <= x))
149
+ assert_(np.all(x < -1))
150
+
151
+ def test_size(self):
152
+ # gh-3173
153
+ p = [0.5, 0.5]
154
+ assert_equal(random.multinomial(1, p, np.uint32(1)).shape, (1, 2))
155
+ assert_equal(random.multinomial(1, p, np.uint32(1)).shape, (1, 2))
156
+ assert_equal(random.multinomial(1, p, np.uint32(1)).shape, (1, 2))
157
+ assert_equal(random.multinomial(1, p, [2, 2]).shape, (2, 2, 2))
158
+ assert_equal(random.multinomial(1, p, (2, 2)).shape, (2, 2, 2))
159
+ assert_equal(random.multinomial(1, p, np.array((2, 2))).shape,
160
+ (2, 2, 2))
161
+
162
+ assert_raises(TypeError, random.multinomial, 1, p,
163
+ float(1))
164
+
165
+ def test_invalid_prob(self):
166
+ assert_raises(ValueError, random.multinomial, 100, [1.1, 0.2])
167
+ assert_raises(ValueError, random.multinomial, 100, [-.1, 0.9])
168
+
169
+ def test_invalid_n(self):
170
+ assert_raises(ValueError, random.multinomial, -1, [0.8, 0.2])
171
+
172
+ def test_p_non_contiguous(self):
173
+ p = np.arange(15.)
174
+ p /= np.sum(p[1::3])
175
+ pvals = p[1::3]
176
+ rng = random.RandomState(1432985819)
177
+ non_contig = rng.multinomial(100, pvals=pvals)
178
+ rng = random.RandomState(1432985819)
179
+ contig = rng.multinomial(100, pvals=np.ascontiguousarray(pvals))
180
+ assert_array_equal(non_contig, contig)
181
+
182
+ def test_multinomial_pvals_float32(self):
183
+ x = np.array([9.9e-01, 9.9e-01, 1.0e-09, 1.0e-09, 1.0e-09, 1.0e-09,
184
+ 1.0e-09, 1.0e-09, 1.0e-09, 1.0e-09], dtype=np.float32)
185
+ pvals = x / x.sum()
186
+ match = r"[\w\s]*pvals array is cast to 64-bit floating"
187
+ with pytest.raises(ValueError, match=match):
188
+ random.multinomial(1, pvals)
189
+
190
+ def test_multinomial_n_float(self):
191
+ # Non-index integer types should gracefully truncate floats
192
+ random.multinomial(100.5, [0.2, 0.8])
193
+
194
+
195
+ class TestSetState:
196
+ def _create_state(self):
197
+ seed = 1234567890
198
+ random_state = random.RandomState(seed)
199
+ state = random_state.get_state()
200
+ return random_state, state
201
+
202
+ def test_basic(self):
203
+ random_state, state = self._create_state()
204
+ old = random_state.tomaxint(16)
205
+ random_state.set_state(state)
206
+ new = random_state.tomaxint(16)
207
+ assert_(np.all(old == new))
208
+
209
+ def test_gaussian_reset(self):
210
+ # Make sure the cached every-other-Gaussian is reset.
211
+ random_state, state = self._create_state()
212
+ old = random_state.standard_normal(size=3)
213
+ random_state.set_state(state)
214
+ new = random_state.standard_normal(size=3)
215
+ assert_(np.all(old == new))
216
+
217
+ def test_gaussian_reset_in_media_res(self):
218
+ # When the state is saved with a cached Gaussian, make sure the
219
+ # cached Gaussian is restored.
220
+ random_state, state = self._create_state()
221
+ random_state.standard_normal()
222
+ state = random_state.get_state()
223
+ old = random_state.standard_normal(size=3)
224
+ random_state.set_state(state)
225
+ new = random_state.standard_normal(size=3)
226
+ assert_(np.all(old == new))
227
+
228
+ def test_backwards_compatibility(self):
229
+ # Make sure we can accept old state tuples that do not have the
230
+ # cached Gaussian value.
231
+ random_state, state = self._create_state()
232
+ old_state = state[:-2]
233
+ x1 = random_state.standard_normal(size=16)
234
+ random_state.set_state(old_state)
235
+ x2 = random_state.standard_normal(size=16)
236
+ random_state.set_state(state)
237
+ x3 = random_state.standard_normal(size=16)
238
+ assert_(np.all(x1 == x2))
239
+ assert_(np.all(x1 == x3))
240
+
241
+ def test_negative_binomial(self):
242
+ # Ensure that the negative binomial results take floating point
243
+ # arguments without truncation.
244
+ random_state, _ = self._create_state()
245
+ random_state.negative_binomial(0.5, 0.5)
246
+
247
+ def test_get_state_warning(self):
248
+ rs = random.RandomState(PCG64())
249
+ with pytest.warns(RuntimeWarning):
250
+ state = rs.get_state()
251
+ assert isinstance(state, dict)
252
+ assert state['bit_generator'] == 'PCG64'
253
+
254
+ def test_invalid_legacy_state_setting(self):
255
+ random_state, state = self._create_state()
256
+ state = random_state.get_state()
257
+ new_state = ('Unknown', ) + state[1:]
258
+ assert_raises(ValueError, random_state.set_state, new_state)
259
+ assert_raises(TypeError, random_state.set_state,
260
+ np.array(new_state, dtype=object))
261
+ state = random_state.get_state(legacy=False)
262
+ del state['bit_generator']
263
+ assert_raises(ValueError, random_state.set_state, state)
264
+
265
+ def test_pickle(self):
266
+ random_state, _ = self._create_state()
267
+ random_state.seed(0)
268
+ random_state.random_sample(100)
269
+ random_state.standard_normal()
270
+ pickled = random_state.get_state(legacy=False)
271
+ assert_equal(pickled['has_gauss'], 1)
272
+ rs_unpick = pickle.loads(pickle.dumps(random_state))
273
+ unpickled = rs_unpick.get_state(legacy=False)
274
+ assert_mt19937_state_equal(pickled, unpickled)
275
+
276
+ def test_state_setting(self):
277
+ random_state, state = self._create_state()
278
+ attr_state = random_state.__getstate__()
279
+ random_state.standard_normal()
280
+ random_state.__setstate__(attr_state)
281
+ state = random_state.get_state(legacy=False)
282
+ assert_mt19937_state_equal(attr_state, state)
283
+
284
+ def test_repr(self):
285
+ random_state, _ = self._create_state()
286
+ assert repr(random_state).startswith('RandomState(MT19937)')
287
+
288
+
289
+ class TestRandint:
290
+
291
+ # valid integer/boolean types
292
+ itype = [np.bool, np.int8, np.uint8, np.int16, np.uint16,
293
+ np.int32, np.uint32, np.int64, np.uint64]
294
+
295
+ def test_unsupported_type(self):
296
+ rng = np.random.RandomState()
297
+ assert_raises(TypeError, rng.randint, 1, dtype=float)
298
+
299
+ def test_bounds_checking(self):
300
+ rng = np.random.RandomState()
301
+ for dt in self.itype:
302
+ lbnd = 0 if dt is np.bool else np.iinfo(dt).min
303
+ ubnd = 2 if dt is np.bool else np.iinfo(dt).max + 1
304
+ assert_raises(ValueError, rng.randint, lbnd - 1, ubnd, dtype=dt)
305
+ assert_raises(ValueError, rng.randint, lbnd, ubnd + 1, dtype=dt)
306
+ assert_raises(ValueError, rng.randint, ubnd, lbnd, dtype=dt)
307
+ assert_raises(ValueError, rng.randint, 1, 0, dtype=dt)
308
+
309
+ def test_rng_zero_and_extremes(self):
310
+ rng = np.random.RandomState()
311
+ for dt in self.itype:
312
+ lbnd = 0 if dt is np.bool else np.iinfo(dt).min
313
+ ubnd = 2 if dt is np.bool else np.iinfo(dt).max + 1
314
+
315
+ tgt = ubnd - 1
316
+ assert_equal(rng.randint(tgt, tgt + 1, size=1000, dtype=dt), tgt)
317
+
318
+ tgt = lbnd
319
+ assert_equal(rng.randint(tgt, tgt + 1, size=1000, dtype=dt), tgt)
320
+
321
+ tgt = (lbnd + ubnd) // 2
322
+ assert_equal(rng.randint(tgt, tgt + 1, size=1000, dtype=dt), tgt)
323
+
324
+ def test_full_range(self):
325
+ # Test for ticket #1690
326
+ rng = np.random.RandomState()
327
+
328
+ for dt in self.itype:
329
+ lbnd = 0 if dt is np.bool else np.iinfo(dt).min
330
+ ubnd = 2 if dt is np.bool else np.iinfo(dt).max + 1
331
+
332
+ try:
333
+ rng.randint(lbnd, ubnd, dtype=dt)
334
+ except Exception as e:
335
+ raise AssertionError("No error should have been raised, "
336
+ "but one was with the following "
337
+ "message:\n\n%s" % str(e))
338
+
339
+ def test_in_bounds_fuzz(self):
340
+ # Don't use fixed seed
341
+ rng = np.random.RandomState()
342
+
343
+ for dt in self.itype[1:]:
344
+ for ubnd in [4, 8, 16]:
345
+ vals = rng.randint(2, ubnd, size=2**16, dtype=dt)
346
+ assert_(vals.max() < ubnd)
347
+ assert_(vals.min() >= 2)
348
+
349
+ vals = rng.randint(0, 2, size=2**16, dtype=np.bool)
350
+
351
+ assert_(vals.max() < 2)
352
+ assert_(vals.min() >= 0)
353
+
354
+ def test_repeatability(self):
355
+ # We use a sha256 hash of generated sequences of 1000 samples
356
+ # in the range [0, 6) for all but bool, where the range
357
+ # is [0, 2). Hashes are for little endian numbers.
358
+ tgt = {'bool': '509aea74d792fb931784c4b0135392c65aec64beee12b0cc167548a2c3d31e71', # noqa: E501
359
+ 'int16': '7b07f1a920e46f6d0fe02314155a2330bcfd7635e708da50e536c5ebb631a7d4', # noqa: E501
360
+ 'int32': 'e577bfed6c935de944424667e3da285012e741892dcb7051a8f1ce68ab05c92f', # noqa: E501
361
+ 'int64': '0fbead0b06759df2cfb55e43148822d4a1ff953c7eb19a5b08445a63bb64fa9e', # noqa: E501
362
+ 'int8': '001aac3a5acb935a9b186cbe14a1ca064b8bb2dd0b045d48abeacf74d0203404', # noqa: E501
363
+ 'uint16': '7b07f1a920e46f6d0fe02314155a2330bcfd7635e708da50e536c5ebb631a7d4', # noqa: E501
364
+ 'uint32': 'e577bfed6c935de944424667e3da285012e741892dcb7051a8f1ce68ab05c92f', # noqa: E501
365
+ 'uint64': '0fbead0b06759df2cfb55e43148822d4a1ff953c7eb19a5b08445a63bb64fa9e', # noqa: E501
366
+ 'uint8': '001aac3a5acb935a9b186cbe14a1ca064b8bb2dd0b045d48abeacf74d0203404'} # noqa: E501
367
+
368
+ for dt in self.itype[1:]:
369
+ rng = random.RandomState(1234)
370
+
371
+ # view as little endian for hash
372
+ if sys.byteorder == 'little':
373
+ val = rng.randint(0, 6, size=1000, dtype=dt)
374
+ else:
375
+ val = rng.randint(0, 6, size=1000, dtype=dt).byteswap()
376
+
377
+ res = hashlib.sha256(val.view(np.int8)).hexdigest()
378
+ assert_(tgt[np.dtype(dt).name] == res)
379
+
380
+ # bools do not depend on endianness
381
+ rng = random.RandomState(1234)
382
+ val = rng.randint(0, 2, size=1000, dtype=bool).view(np.int8)
383
+ res = hashlib.sha256(val).hexdigest()
384
+ assert_(tgt[np.dtype(bool).name] == res)
385
+
386
+ @pytest.mark.skipif(np.iinfo('l').max < 2**32,
387
+ reason='Cannot test with 32-bit C long')
388
+ def test_repeatability_32bit_boundary_broadcasting(self):
389
+ desired = np.array([[[3992670689, 2438360420, 2557845020],
390
+ [4107320065, 4142558326, 3216529513],
391
+ [1605979228, 2807061240, 665605495]],
392
+ [[3211410639, 4128781000, 457175120],
393
+ [1712592594, 1282922662, 3081439808],
394
+ [3997822960, 2008322436, 1563495165]],
395
+ [[1398375547, 4269260146, 115316740],
396
+ [3414372578, 3437564012, 2112038651],
397
+ [3572980305, 2260248732, 3908238631]],
398
+ [[2561372503, 223155946, 3127879445],
399
+ [ 441282060, 3514786552, 2148440361],
400
+ [1629275283, 3479737011, 3003195987]],
401
+ [[ 412181688, 940383289, 3047321305],
402
+ [2978368172, 764731833, 2282559898],
403
+ [ 105711276, 720447391, 3596512484]]])
404
+ for size in [None, (5, 3, 3)]:
405
+ rng = random.RandomState(12345)
406
+ x = rng.randint([[-1], [0], [1]], [2**32 - 1, 2**32, 2**32 + 1],
407
+ size=size)
408
+ assert_array_equal(x, desired if size is not None else desired[0])
409
+
410
+ def test_int64_uint64_corner_case(self):
411
+ # When stored in Numpy arrays, `lbnd` is casted
412
+ # as np.int64, and `ubnd` is casted as np.uint64.
413
+ # Checking whether `lbnd` >= `ubnd` used to be
414
+ # done solely via direct comparison, which is incorrect
415
+ # because when Numpy tries to compare both numbers,
416
+ # it casts both to np.float64 because there is
417
+ # no integer superset of np.int64 and np.uint64. However,
418
+ # `ubnd` is too large to be represented in np.float64,
419
+ # causing it be round down to np.iinfo(np.int64).max,
420
+ # leading to a ValueError because `lbnd` now equals
421
+ # the new `ubnd`.
422
+
423
+ dt = np.int64
424
+ tgt = np.iinfo(np.int64).max
425
+ lbnd = np.int64(np.iinfo(np.int64).max)
426
+ ubnd = np.uint64(np.iinfo(np.int64).max + 1)
427
+
428
+ # None of these function calls should
429
+ # generate a ValueError now.
430
+ actual = random.randint(lbnd, ubnd, dtype=dt)
431
+ assert_equal(actual, tgt)
432
+
433
+ def test_respect_dtype_singleton(self):
434
+ # See gh-7203
435
+ rng = np.random.RandomState()
436
+
437
+ for dt in self.itype:
438
+ lbnd = 0 if dt is np.bool else np.iinfo(dt).min
439
+ ubnd = 2 if dt is np.bool else np.iinfo(dt).max + 1
440
+
441
+ sample = rng.randint(lbnd, ubnd, dtype=dt)
442
+ assert_equal(sample.dtype, np.dtype(dt))
443
+
444
+ for dt in (bool, int):
445
+ # The legacy random generation forces the use of "long" on this
446
+ # branch even when the input is `int` and the default dtype
447
+ # for int changed (dtype=int is also the functions default)
448
+ op_dtype = "long" if dt is int else "bool"
449
+ lbnd = 0 if dt is bool else np.iinfo(op_dtype).min
450
+ ubnd = 2 if dt is bool else np.iinfo(op_dtype).max + 1
451
+
452
+ sample = rng.randint(lbnd, ubnd, dtype=dt)
453
+ assert_(not hasattr(sample, 'dtype'))
454
+ assert_equal(type(sample), dt)
455
+
456
+
457
+ class TestRandomDist:
458
+ # Make sure the random distribution returns the correct value for a
459
+ # given seed
460
+ seed = 1234567890
461
+
462
+ def test_rand(self):
463
+ rng = random.RandomState(self.seed)
464
+ actual = rng.rand(3, 2)
465
+ desired = np.array([[0.61879477158567997, 0.59162362775974664],
466
+ [0.88868358904449662, 0.89165480011560816],
467
+ [0.4575674820298663, 0.7781880808593471]])
468
+ assert_array_almost_equal(actual, desired, decimal=15)
469
+
470
+ def test_rand_singleton(self):
471
+ rng = random.RandomState(self.seed)
472
+ actual = rng.rand()
473
+ desired = 0.61879477158567997
474
+ assert_array_almost_equal(actual, desired, decimal=15)
475
+
476
+ def test_randn(self):
477
+ rng = random.RandomState(self.seed)
478
+ actual = rng.randn(3, 2)
479
+ desired = np.array([[1.34016345771863121, 1.73759122771936081],
480
+ [1.498988344300628, -0.2286433324536169],
481
+ [2.031033998682787, 2.17032494605655257]])
482
+ assert_array_almost_equal(actual, desired, decimal=15)
483
+
484
+ rng = random.RandomState(self.seed)
485
+ actual = rng.randn()
486
+ assert_array_almost_equal(actual, desired[0, 0], decimal=15)
487
+
488
+ def test_randint(self):
489
+ rng = random.RandomState(self.seed)
490
+ actual = rng.randint(-99, 99, size=(3, 2))
491
+ desired = np.array([[31, 3],
492
+ [-52, 41],
493
+ [-48, -66]])
494
+ assert_array_equal(actual, desired)
495
+
496
+ def test_random_integers(self):
497
+ rng = random.RandomState(self.seed)
498
+ with pytest.warns(DeprecationWarning):
499
+ actual = rng.random_integers(-99, 99, size=(3, 2))
500
+ desired = np.array([[31, 3],
501
+ [-52, 41],
502
+ [-48, -66]])
503
+ assert_array_equal(actual, desired)
504
+
505
+ rng = random.RandomState(self.seed)
506
+ with pytest.warns(DeprecationWarning):
507
+ actual = rng.random_integers(198, size=(3, 2))
508
+ assert_array_equal(actual, desired + 100)
509
+
510
+ def test_tomaxint(self):
511
+ rs = random.RandomState(self.seed)
512
+ actual = rs.tomaxint(size=(3, 2))
513
+ if np.iinfo(np.long).max == 2147483647:
514
+ desired = np.array([[1328851649, 731237375],
515
+ [1270502067, 320041495],
516
+ [1908433478, 499156889]], dtype=np.int64)
517
+ else:
518
+ desired = np.array([[5707374374421908479, 5456764827585442327],
519
+ [8196659375100692377, 8224063923314595285],
520
+ [4220315081820346526, 7177518203184491332]],
521
+ dtype=np.int64)
522
+
523
+ assert_equal(actual, desired)
524
+
525
+ rs.seed(self.seed)
526
+ actual = rs.tomaxint()
527
+ assert_equal(actual, desired[0, 0])
528
+
529
+ def test_random_integers_max_int(self):
530
+ # Tests whether random_integers can generate the
531
+ # maximum allowed Python int that can be converted
532
+ # into a C long. Previous implementations of this
533
+ # method have thrown an OverflowError when attempting
534
+ # to generate this integer.
535
+ with pytest.warns(DeprecationWarning):
536
+ actual = random.random_integers(np.iinfo('l').max,
537
+ np.iinfo('l').max)
538
+
539
+ desired = np.iinfo('l').max
540
+ assert_equal(actual, desired)
541
+ with pytest.warns(DeprecationWarning):
542
+ typer = np.dtype('l').type
543
+ actual = random.random_integers(typer(np.iinfo('l').max),
544
+ typer(np.iinfo('l').max))
545
+ assert_equal(actual, desired)
546
+
547
+ def test_random_integers_deprecated(self):
548
+ with warnings.catch_warnings():
549
+ warnings.simplefilter("error", DeprecationWarning)
550
+
551
+ # DeprecationWarning raised with high == None
552
+ assert_raises(DeprecationWarning,
553
+ random.random_integers,
554
+ np.iinfo('l').max)
555
+
556
+ # DeprecationWarning raised with high != None
557
+ assert_raises(DeprecationWarning,
558
+ random.random_integers,
559
+ np.iinfo('l').max, np.iinfo('l').max)
560
+
561
+ def test_random_sample(self):
562
+ rng = random.RandomState(self.seed)
563
+ actual = rng.random_sample((3, 2))
564
+ desired = np.array([[0.61879477158567997, 0.59162362775974664],
565
+ [0.88868358904449662, 0.89165480011560816],
566
+ [0.4575674820298663, 0.7781880808593471]])
567
+ assert_array_almost_equal(actual, desired, decimal=15)
568
+
569
+ rng = random.RandomState(self.seed)
570
+ actual = rng.random_sample()
571
+ assert_array_almost_equal(actual, desired[0, 0], decimal=15)
572
+
573
+ def test_choice_uniform_replace(self):
574
+ rng = random.RandomState(self.seed)
575
+ actual = rng.choice(4, 4)
576
+ desired = np.array([2, 3, 2, 3])
577
+ assert_array_equal(actual, desired)
578
+
579
+ def test_choice_nonuniform_replace(self):
580
+ rng = random.RandomState(self.seed)
581
+ actual = rng.choice(4, 4, p=[0.4, 0.4, 0.1, 0.1])
582
+ desired = np.array([1, 1, 2, 2])
583
+ assert_array_equal(actual, desired)
584
+
585
+ def test_choice_uniform_noreplace(self):
586
+ rng = random.RandomState(self.seed)
587
+ actual = rng.choice(4, 3, replace=False)
588
+ desired = np.array([0, 1, 3])
589
+ assert_array_equal(actual, desired)
590
+
591
+ def test_choice_nonuniform_noreplace(self):
592
+ rng = random.RandomState(self.seed)
593
+ actual = rng.choice(4, 3, replace=False, p=[0.1, 0.3, 0.5, 0.1])
594
+ desired = np.array([2, 3, 1])
595
+ assert_array_equal(actual, desired)
596
+
597
+ def test_choice_noninteger(self):
598
+ rng = random.RandomState(self.seed)
599
+ actual = rng.choice(['a', 'b', 'c', 'd'], 4)
600
+ desired = np.array(['c', 'd', 'c', 'd'])
601
+ assert_array_equal(actual, desired)
602
+
603
+ def test_choice_exceptions(self):
604
+ sample = random.choice
605
+ assert_raises(ValueError, sample, -1, 3)
606
+ assert_raises(ValueError, sample, 3., 3)
607
+ assert_raises(ValueError, sample, [[1, 2], [3, 4]], 3)
608
+ assert_raises(ValueError, sample, [], 3)
609
+ assert_raises(ValueError, sample, [1, 2, 3, 4], 3,
610
+ p=[[0.25, 0.25], [0.25, 0.25]])
611
+ assert_raises(ValueError, sample, [1, 2], 3, p=[0.4, 0.4, 0.2])
612
+ assert_raises(ValueError, sample, [1, 2], 3, p=[1.1, -0.1])
613
+ assert_raises(ValueError, sample, [1, 2], 3, p=[0.4, 0.4])
614
+ assert_raises(ValueError, sample, [1, 2, 3], 4, replace=False)
615
+ # gh-13087
616
+ assert_raises(ValueError, sample, [1, 2, 3], -2, replace=False)
617
+ assert_raises(ValueError, sample, [1, 2, 3], (-1,), replace=False)
618
+ assert_raises(ValueError, sample, [1, 2, 3], (-1, 1), replace=False)
619
+ assert_raises(ValueError, sample, [1, 2, 3], 2,
620
+ replace=False, p=[1, 0, 0])
621
+
622
+ def test_choice_return_shape(self):
623
+ p = [0.1, 0.9]
624
+ # Check scalar
625
+ assert_(np.isscalar(random.choice(2, replace=True)))
626
+ assert_(np.isscalar(random.choice(2, replace=False)))
627
+ assert_(np.isscalar(random.choice(2, replace=True, p=p)))
628
+ assert_(np.isscalar(random.choice(2, replace=False, p=p)))
629
+ assert_(np.isscalar(random.choice([1, 2], replace=True)))
630
+ assert_(random.choice([None], replace=True) is None)
631
+ a = np.array([1, 2])
632
+ arr = np.empty(1, dtype=object)
633
+ arr[0] = a
634
+ assert_(random.choice(arr, replace=True) is a)
635
+
636
+ # Check 0-d array
637
+ s = ()
638
+ assert_(not np.isscalar(random.choice(2, s, replace=True)))
639
+ assert_(not np.isscalar(random.choice(2, s, replace=False)))
640
+ assert_(not np.isscalar(random.choice(2, s, replace=True, p=p)))
641
+ assert_(not np.isscalar(random.choice(2, s, replace=False, p=p)))
642
+ assert_(not np.isscalar(random.choice([1, 2], s, replace=True)))
643
+ assert_(random.choice([None], s, replace=True).ndim == 0)
644
+ a = np.array([1, 2])
645
+ arr = np.empty(1, dtype=object)
646
+ arr[0] = a
647
+ assert_(random.choice(arr, s, replace=True).item() is a)
648
+
649
+ # Check multi dimensional array
650
+ s = (2, 3)
651
+ p = [0.1, 0.1, 0.1, 0.1, 0.4, 0.2]
652
+ assert_equal(random.choice(6, s, replace=True).shape, s)
653
+ assert_equal(random.choice(6, s, replace=False).shape, s)
654
+ assert_equal(random.choice(6, s, replace=True, p=p).shape, s)
655
+ assert_equal(random.choice(6, s, replace=False, p=p).shape, s)
656
+ assert_equal(random.choice(np.arange(6), s, replace=True).shape, s)
657
+
658
+ # Check zero-size
659
+ assert_equal(random.randint(0, 0, size=(3, 0, 4)).shape, (3, 0, 4))
660
+ assert_equal(random.randint(0, -10, size=0).shape, (0,))
661
+ assert_equal(random.randint(10, 10, size=0).shape, (0,))
662
+ assert_equal(random.choice(0, size=0).shape, (0,))
663
+ assert_equal(random.choice([], size=(0,)).shape, (0,))
664
+ assert_equal(random.choice(['a', 'b'], size=(3, 0, 4)).shape,
665
+ (3, 0, 4))
666
+ assert_raises(ValueError, random.choice, [], 10)
667
+
668
+ def test_choice_nan_probabilities(self):
669
+ a = np.array([42, 1, 2])
670
+ p = [None, None, None]
671
+ assert_raises(ValueError, random.choice, a, p=p)
672
+
673
+ def test_choice_p_non_contiguous(self):
674
+ p = np.ones(10) / 5
675
+ p[1::2] = 3.0
676
+ rng = random.RandomState(self.seed)
677
+ non_contig = rng.choice(5, 3, p=p[::2])
678
+ rng = random.RandomState(self.seed)
679
+ contig = rng.choice(5, 3, p=np.ascontiguousarray(p[::2]))
680
+ assert_array_equal(non_contig, contig)
681
+
682
+ def test_bytes(self):
683
+ rng = random.RandomState(self.seed)
684
+ actual = rng.bytes(10)
685
+ desired = b'\x82Ui\x9e\xff\x97+Wf\xa5'
686
+ assert_equal(actual, desired)
687
+
688
+ def test_shuffle(self):
689
+ # Test lists, arrays (of various dtypes), and multidimensional versions
690
+ # of both, c-contiguous or not:
691
+ for conv in [lambda x: np.array([]),
692
+ lambda x: x,
693
+ lambda x: np.asarray(x).astype(np.int8),
694
+ lambda x: np.asarray(x).astype(np.float32),
695
+ lambda x: np.asarray(x).astype(np.complex64),
696
+ lambda x: np.asarray(x).astype(object),
697
+ lambda x: [(i, i) for i in x],
698
+ lambda x: np.asarray([[i, i] for i in x]),
699
+ lambda x: np.vstack([x, x]).T,
700
+ # gh-11442
701
+ lambda x: (np.asarray([(i, i) for i in x],
702
+ [("a", int), ("b", int)])
703
+ .view(np.recarray)),
704
+ # gh-4270
705
+ lambda x: np.asarray([(i, i) for i in x],
706
+ [("a", object, (1,)),
707
+ ("b", np.int32, (1,))])]:
708
+ rng = random.RandomState(self.seed)
709
+ alist = conv([1, 2, 3, 4, 5, 6, 7, 8, 9, 0])
710
+ rng.shuffle(alist)
711
+ actual = alist
712
+ desired = conv([0, 1, 9, 6, 2, 4, 5, 8, 7, 3])
713
+ assert_array_equal(actual, desired)
714
+
715
+ def test_shuffle_masked(self):
716
+ # gh-3263
717
+ a = np.ma.masked_values(np.reshape(range(20), (5, 4)) % 3 - 1, -1)
718
+ b = np.ma.masked_values(np.arange(20) % 3 - 1, -1)
719
+ a_orig = a.copy()
720
+ b_orig = b.copy()
721
+ for i in range(50):
722
+ random.shuffle(a)
723
+ assert_equal(
724
+ sorted(a.data[~a.mask]), sorted(a_orig.data[~a_orig.mask]))
725
+ random.shuffle(b)
726
+ assert_equal(
727
+ sorted(b.data[~b.mask]), sorted(b_orig.data[~b_orig.mask]))
728
+
729
+ def test_shuffle_invalid_objects(self):
730
+ x = np.array(3)
731
+ assert_raises(TypeError, random.shuffle, x)
732
+
733
+ def test_permutation(self):
734
+ rng = random.RandomState(self.seed)
735
+ alist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
736
+ actual = rng.permutation(alist)
737
+ desired = [0, 1, 9, 6, 2, 4, 5, 8, 7, 3]
738
+ assert_array_equal(actual, desired)
739
+
740
+ rng = random.RandomState(self.seed)
741
+ arr_2d = np.atleast_2d([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]).T
742
+ actual = rng.permutation(arr_2d)
743
+ assert_array_equal(actual, np.atleast_2d(desired).T)
744
+
745
+ rng = random.RandomState(self.seed)
746
+ bad_x_str = "abcd"
747
+ assert_raises(IndexError, random.permutation, bad_x_str)
748
+
749
+ rng = random.RandomState(self.seed)
750
+ bad_x_float = 1.2
751
+ assert_raises(IndexError, random.permutation, bad_x_float)
752
+
753
+ integer_val = 10
754
+ desired = [9, 0, 8, 5, 1, 3, 4, 7, 6, 2]
755
+
756
+ rng = random.RandomState(self.seed)
757
+ actual = rng.permutation(integer_val)
758
+ assert_array_equal(actual, desired)
759
+
760
+ def test_beta(self):
761
+ rng = random.RandomState(self.seed)
762
+ actual = rng.beta(.1, .9, size=(3, 2))
763
+ desired = np.array(
764
+ [[1.45341850513746058e-02, 5.31297615662868145e-04],
765
+ [1.85366619058432324e-06, 4.19214516800110563e-03],
766
+ [1.58405155108498093e-04, 1.26252891949397652e-04]])
767
+ assert_array_almost_equal(actual, desired, decimal=15)
768
+
769
+ def test_binomial(self):
770
+ rng = random.RandomState(self.seed)
771
+ actual = rng.binomial(100.123, .456, size=(3, 2))
772
+ desired = np.array([[37, 43],
773
+ [42, 48],
774
+ [46, 45]])
775
+ assert_array_equal(actual, desired)
776
+
777
+ rng = random.RandomState(self.seed)
778
+ actual = rng.binomial(100.123, .456)
779
+ desired = 37
780
+ assert_array_equal(actual, desired)
781
+
782
+ def test_chisquare(self):
783
+ rng = random.RandomState(self.seed)
784
+ actual = rng.chisquare(50, size=(3, 2))
785
+ desired = np.array([[63.87858175501090585, 68.68407748911370447],
786
+ [65.77116116901505904, 47.09686762438974483],
787
+ [72.3828403199695174, 74.18408615260374006]])
788
+ assert_array_almost_equal(actual, desired, decimal=13)
789
+
790
+ def test_dirichlet(self):
791
+ rng = random.RandomState(self.seed)
792
+ alpha = np.array([51.72840233779265162, 39.74494232180943953])
793
+ actual = rng.dirichlet(alpha, size=(3, 2))
794
+ desired = np.array([[[0.54539444573611562, 0.45460555426388438],
795
+ [0.62345816822039413, 0.37654183177960598]],
796
+ [[0.55206000085785778, 0.44793999914214233],
797
+ [0.58964023305154301, 0.41035976694845688]],
798
+ [[0.59266909280647828, 0.40733090719352177],
799
+ [0.56974431743975207, 0.43025568256024799]]])
800
+ assert_array_almost_equal(actual, desired, decimal=15)
801
+ bad_alpha = np.array([5.4e-01, -1.0e-16])
802
+ assert_raises(ValueError, random.dirichlet, bad_alpha)
803
+
804
+ rng = random.RandomState(self.seed)
805
+ alpha = np.array([51.72840233779265162, 39.74494232180943953])
806
+ actual = rng.dirichlet(alpha)
807
+ assert_array_almost_equal(actual, desired[0, 0], decimal=15)
808
+
809
+ def test_dirichlet_size(self):
810
+ # gh-3173
811
+ p = np.array([51.72840233779265162, 39.74494232180943953])
812
+ assert_equal(random.dirichlet(p, np.uint32(1)).shape, (1, 2))
813
+ assert_equal(random.dirichlet(p, np.uint32(1)).shape, (1, 2))
814
+ assert_equal(random.dirichlet(p, np.uint32(1)).shape, (1, 2))
815
+ assert_equal(random.dirichlet(p, [2, 2]).shape, (2, 2, 2))
816
+ assert_equal(random.dirichlet(p, (2, 2)).shape, (2, 2, 2))
817
+ assert_equal(random.dirichlet(p, np.array((2, 2))).shape, (2, 2, 2))
818
+
819
+ assert_raises(TypeError, random.dirichlet, p, float(1))
820
+
821
+ def test_dirichlet_bad_alpha(self):
822
+ # gh-2089
823
+ alpha = np.array([5.4e-01, -1.0e-16])
824
+ assert_raises(ValueError, random.dirichlet, alpha)
825
+
826
+ def test_dirichlet_alpha_non_contiguous(self):
827
+ a = np.array([51.72840233779265162, -1.0, 39.74494232180943953])
828
+ alpha = a[::2]
829
+ rng = random.RandomState(self.seed)
830
+ non_contig = rng.dirichlet(alpha, size=(3, 2))
831
+ rng = random.RandomState(self.seed)
832
+ contig = rng.dirichlet(np.ascontiguousarray(alpha),
833
+ size=(3, 2))
834
+ assert_array_almost_equal(non_contig, contig)
835
+
836
+ def test_exponential(self):
837
+ rng = random.RandomState(self.seed)
838
+ actual = rng.exponential(1.1234, size=(3, 2))
839
+ desired = np.array([[1.08342649775011624, 1.00607889924557314],
840
+ [2.46628830085216721, 2.49668106809923884],
841
+ [0.68717433461363442, 1.69175666993575979]])
842
+ assert_array_almost_equal(actual, desired, decimal=15)
843
+
844
+ def test_exponential_0(self):
845
+ assert_equal(random.exponential(scale=0), 0)
846
+ assert_raises(ValueError, random.exponential, scale=-0.)
847
+
848
+ def test_f(self):
849
+ rng = random.RandomState(self.seed)
850
+ actual = rng.f(12, 77, size=(3, 2))
851
+ desired = np.array([[1.21975394418575878, 1.75135759791559775],
852
+ [1.44803115017146489, 1.22108959480396262],
853
+ [1.02176975757740629, 1.34431827623300415]])
854
+ assert_array_almost_equal(actual, desired, decimal=15)
855
+
856
+ def test_gamma(self):
857
+ rng = random.RandomState(self.seed)
858
+ actual = rng.gamma(5, 3, size=(3, 2))
859
+ desired = np.array([[24.60509188649287182, 28.54993563207210627],
860
+ [26.13476110204064184, 12.56988482927716078],
861
+ [31.71863275789960568, 33.30143302795922011]])
862
+ assert_array_almost_equal(actual, desired, decimal=14)
863
+
864
+ def test_gamma_0(self):
865
+ assert_equal(random.gamma(shape=0, scale=0), 0)
866
+ assert_raises(ValueError, random.gamma, shape=-0., scale=-0.)
867
+
868
+ def test_geometric(self):
869
+ rng = random.RandomState(self.seed)
870
+ actual = rng.geometric(.123456789, size=(3, 2))
871
+ desired = np.array([[8, 7],
872
+ [17, 17],
873
+ [5, 12]])
874
+ assert_array_equal(actual, desired)
875
+
876
+ def test_geometric_exceptions(self):
877
+ assert_raises(ValueError, random.geometric, 1.1)
878
+ assert_raises(ValueError, random.geometric, [1.1] * 10)
879
+ assert_raises(ValueError, random.geometric, -0.1)
880
+ assert_raises(ValueError, random.geometric, [-0.1] * 10)
881
+ with warnings.catch_warnings():
882
+ warnings.simplefilter('ignore', RuntimeWarning)
883
+ assert_raises(ValueError, random.geometric, np.nan)
884
+ assert_raises(ValueError, random.geometric, [np.nan] * 10)
885
+
886
+ def test_gumbel(self):
887
+ rng = random.RandomState(self.seed)
888
+ actual = rng.gumbel(loc=.123456789, scale=2.0, size=(3, 2))
889
+ desired = np.array([[0.19591898743416816, 0.34405539668096674],
890
+ [-1.4492522252274278, -1.47374816298446865],
891
+ [1.10651090478803416, -0.69535848626236174]])
892
+ assert_array_almost_equal(actual, desired, decimal=15)
893
+
894
+ def test_gumbel_0(self):
895
+ assert_equal(random.gumbel(scale=0), 0)
896
+ assert_raises(ValueError, random.gumbel, scale=-0.)
897
+
898
+ def test_hypergeometric(self):
899
+ rng = random.RandomState(self.seed)
900
+ actual = rng.hypergeometric(10.1, 5.5, 14, size=(3, 2))
901
+ desired = np.array([[10, 10],
902
+ [10, 10],
903
+ [9, 9]])
904
+ assert_array_equal(actual, desired)
905
+
906
+ # Test nbad = 0
907
+ actual = rng.hypergeometric(5, 0, 3, size=4)
908
+ desired = np.array([3, 3, 3, 3])
909
+ assert_array_equal(actual, desired)
910
+
911
+ actual = rng.hypergeometric(15, 0, 12, size=4)
912
+ desired = np.array([12, 12, 12, 12])
913
+ assert_array_equal(actual, desired)
914
+
915
+ # Test ngood = 0
916
+ actual = rng.hypergeometric(0, 5, 3, size=4)
917
+ desired = np.array([0, 0, 0, 0])
918
+ assert_array_equal(actual, desired)
919
+
920
+ actual = rng.hypergeometric(0, 15, 12, size=4)
921
+ desired = np.array([0, 0, 0, 0])
922
+ assert_array_equal(actual, desired)
923
+
924
+ def test_laplace(self):
925
+ rng = random.RandomState(self.seed)
926
+ actual = rng.laplace(loc=.123456789, scale=2.0, size=(3, 2))
927
+ desired = np.array([[0.66599721112760157, 0.52829452552221945],
928
+ [3.12791959514407125, 3.18202813572992005],
929
+ [-0.05391065675859356, 1.74901336242837324]])
930
+ assert_array_almost_equal(actual, desired, decimal=15)
931
+
932
+ def test_laplace_0(self):
933
+ assert_equal(random.laplace(scale=0), 0)
934
+ assert_raises(ValueError, random.laplace, scale=-0.)
935
+
936
+ def test_logistic(self):
937
+ rng = random.RandomState(self.seed)
938
+ actual = rng.logistic(loc=.123456789, scale=2.0, size=(3, 2))
939
+ desired = np.array([[1.09232835305011444, 0.8648196662399954],
940
+ [4.27818590694950185, 4.33897006346929714],
941
+ [-0.21682183359214885, 2.63373365386060332]])
942
+ assert_array_almost_equal(actual, desired, decimal=15)
943
+
944
+ def test_lognormal(self):
945
+ rng = random.RandomState(self.seed)
946
+ actual = rng.lognormal(mean=.123456789, sigma=2.0, size=(3, 2))
947
+ desired = np.array([[16.50698631688883822, 36.54846706092654784],
948
+ [22.67886599981281748, 0.71617561058995771],
949
+ [65.72798501792723869, 86.84341601437161273]])
950
+ assert_array_almost_equal(actual, desired, decimal=13)
951
+
952
+ def test_lognormal_0(self):
953
+ assert_equal(random.lognormal(sigma=0), 1)
954
+ assert_raises(ValueError, random.lognormal, sigma=-0.)
955
+
956
+ def test_logseries(self):
957
+ rng = random.RandomState(self.seed)
958
+ actual = rng.logseries(p=.923456789, size=(3, 2))
959
+ desired = np.array([[2, 2],
960
+ [6, 17],
961
+ [3, 6]])
962
+ assert_array_equal(actual, desired)
963
+
964
+ def test_logseries_zero(self):
965
+ assert random.logseries(0) == 1
966
+
967
+ @pytest.mark.parametrize("value", [np.nextafter(0., -1), 1., np.nan, 5.])
968
+ def test_logseries_exceptions(self, value):
969
+ with np.errstate(invalid="ignore"):
970
+ with pytest.raises(ValueError):
971
+ random.logseries(value)
972
+ with pytest.raises(ValueError):
973
+ # contiguous path:
974
+ random.logseries(np.array([value] * 10))
975
+ with pytest.raises(ValueError):
976
+ # non-contiguous path:
977
+ random.logseries(np.array([value] * 10)[::2])
978
+
979
+ def test_multinomial(self):
980
+ rng = random.RandomState(self.seed)
981
+ actual = rng.multinomial(20, [1 / 6.] * 6, size=(3, 2))
982
+ desired = np.array([[[4, 3, 5, 4, 2, 2],
983
+ [5, 2, 8, 2, 2, 1]],
984
+ [[3, 4, 3, 6, 0, 4],
985
+ [2, 1, 4, 3, 6, 4]],
986
+ [[4, 4, 2, 5, 2, 3],
987
+ [4, 3, 4, 2, 3, 4]]])
988
+ assert_array_equal(actual, desired)
989
+
990
+ def test_multivariate_normal(self):
991
+ rng = random.RandomState(self.seed)
992
+ mean = (.123456789, 10)
993
+ cov = [[1, 0], [0, 1]]
994
+ size = (3, 2)
995
+ actual = rng.multivariate_normal(mean, cov, size)
996
+ desired = np.array([[[1.463620246718631, 11.73759122771936],
997
+ [1.622445133300628, 9.771356667546383]],
998
+ [[2.154490787682787, 12.170324946056553],
999
+ [1.719909438201865, 9.230548443648306]],
1000
+ [[0.689515026297799, 9.880729819607714],
1001
+ [-0.023054015651998, 9.201096623542879]]])
1002
+
1003
+ assert_array_almost_equal(actual, desired, decimal=15)
1004
+
1005
+ # Check for default size, was raising deprecation warning
1006
+ actual = rng.multivariate_normal(mean, cov)
1007
+ desired = np.array([0.895289569463708, 9.17180864067987])
1008
+ assert_array_almost_equal(actual, desired, decimal=15)
1009
+
1010
+ # Check that non positive-semidefinite covariance warns with
1011
+ # RuntimeWarning
1012
+ mean = [0, 0]
1013
+ cov = [[1, 2], [2, 1]]
1014
+ pytest.warns(RuntimeWarning, rng.multivariate_normal, mean, cov)
1015
+
1016
+ # and that it doesn't warn with RuntimeWarning check_valid='ignore'
1017
+ assert_no_warnings(rng.multivariate_normal, mean, cov,
1018
+ check_valid='ignore')
1019
+
1020
+ # and that it raises with RuntimeWarning check_valid='raises'
1021
+ assert_raises(ValueError, rng.multivariate_normal, mean, cov,
1022
+ check_valid='raise')
1023
+
1024
+ cov = np.array([[1, 0.1], [0.1, 1]], dtype=np.float32)
1025
+ with warnings.catch_warnings():
1026
+ warnings.simplefilter('error', RuntimeWarning)
1027
+ rng.multivariate_normal(mean, cov)
1028
+
1029
+ mu = np.zeros(2)
1030
+ cov = np.eye(2)
1031
+ assert_raises(ValueError, rng.multivariate_normal, mean, cov,
1032
+ check_valid='other')
1033
+ assert_raises(ValueError, rng.multivariate_normal,
1034
+ np.zeros((2, 1, 1)), cov)
1035
+ assert_raises(ValueError, rng.multivariate_normal,
1036
+ mu, np.empty((3, 2)))
1037
+ assert_raises(ValueError, rng.multivariate_normal,
1038
+ mu, np.eye(3))
1039
+
1040
+ def test_negative_binomial(self):
1041
+ rng = random.RandomState(self.seed)
1042
+ actual = rng.negative_binomial(n=100, p=.12345, size=(3, 2))
1043
+ desired = np.array([[848, 841],
1044
+ [892, 611],
1045
+ [779, 647]])
1046
+ assert_array_equal(actual, desired)
1047
+
1048
+ def test_negative_binomial_exceptions(self):
1049
+ with warnings.catch_warnings():
1050
+ warnings.simplefilter('ignore', RuntimeWarning)
1051
+ assert_raises(ValueError, random.negative_binomial, 100, np.nan)
1052
+ assert_raises(ValueError, random.negative_binomial, 100,
1053
+ [np.nan] * 10)
1054
+
1055
+ def test_noncentral_chisquare(self):
1056
+ rng = random.RandomState(self.seed)
1057
+ actual = rng.noncentral_chisquare(df=5, nonc=5, size=(3, 2))
1058
+ desired = np.array([[23.91905354498517511, 13.35324692733826346],
1059
+ [31.22452661329736401, 16.60047399466177254],
1060
+ [5.03461598262724586, 17.94973089023519464]])
1061
+ assert_array_almost_equal(actual, desired, decimal=14)
1062
+
1063
+ actual = rng.noncentral_chisquare(df=.5, nonc=.2, size=(3, 2))
1064
+ desired = np.array([[1.47145377828516666, 0.15052899268012659],
1065
+ [0.00943803056963588, 1.02647251615666169],
1066
+ [0.332334982684171, 0.15451287602753125]])
1067
+ assert_array_almost_equal(actual, desired, decimal=14)
1068
+
1069
+ rng = random.RandomState(self.seed)
1070
+ actual = rng.noncentral_chisquare(df=5, nonc=0, size=(3, 2))
1071
+ desired = np.array([[9.597154162763948, 11.725484450296079],
1072
+ [10.413711048138335, 3.694475922923986],
1073
+ [13.484222138963087, 14.377255424602957]])
1074
+ assert_array_almost_equal(actual, desired, decimal=14)
1075
+
1076
+ def test_noncentral_f(self):
1077
+ rng = random.RandomState(self.seed)
1078
+ actual = rng.noncentral_f(dfnum=5, dfden=2, nonc=1,
1079
+ size=(3, 2))
1080
+ desired = np.array([[1.40598099674926669, 0.34207973179285761],
1081
+ [3.57715069265772545, 7.92632662577829805],
1082
+ [0.43741599463544162, 1.1774208752428319]])
1083
+ assert_array_almost_equal(actual, desired, decimal=14)
1084
+
1085
+ def test_noncentral_f_nan(self):
1086
+ random.seed(self.seed)
1087
+ actual = random.noncentral_f(dfnum=5, dfden=2, nonc=np.nan)
1088
+ assert np.isnan(actual)
1089
+
1090
+ def test_normal(self):
1091
+ rng = random.RandomState(self.seed)
1092
+ actual = rng.normal(loc=.123456789, scale=2.0, size=(3, 2))
1093
+ desired = np.array([[2.80378370443726244, 3.59863924443872163],
1094
+ [3.121433477601256, -0.33382987590723379],
1095
+ [4.18552478636557357, 4.46410668111310471]])
1096
+ assert_array_almost_equal(actual, desired, decimal=15)
1097
+
1098
+ def test_normal_0(self):
1099
+ assert_equal(random.normal(scale=0), 0)
1100
+ assert_raises(ValueError, random.normal, scale=-0.)
1101
+
1102
+ def test_pareto(self):
1103
+ rng = random.RandomState(self.seed)
1104
+ actual = rng.pareto(a=.123456789, size=(3, 2))
1105
+ desired = np.array(
1106
+ [[2.46852460439034849e+03, 1.41286880810518346e+03],
1107
+ [5.28287797029485181e+07, 6.57720981047328785e+07],
1108
+ [1.40840323350391515e+02, 1.98390255135251704e+05]])
1109
+ # For some reason on 32-bit x86 Ubuntu 12.10 the [1, 0] entry in this
1110
+ # matrix differs by 24 nulps. Discussion:
1111
+ # https://mail.python.org/pipermail/numpy-discussion/2012-September/063801.html
1112
+ # Consensus is that this is probably some gcc quirk that affects
1113
+ # rounding but not in any important way, so we just use a looser
1114
+ # tolerance on this test:
1115
+ np.testing.assert_array_almost_equal_nulp(actual, desired, nulp=30)
1116
+
1117
+ def test_poisson(self):
1118
+ rng = random.RandomState(self.seed)
1119
+ actual = rng.poisson(lam=.123456789, size=(3, 2))
1120
+ desired = np.array([[0, 0],
1121
+ [1, 0],
1122
+ [0, 0]])
1123
+ assert_array_equal(actual, desired)
1124
+
1125
+ def test_poisson_exceptions(self):
1126
+ lambig = np.iinfo('l').max
1127
+ lamneg = -1
1128
+ assert_raises(ValueError, random.poisson, lamneg)
1129
+ assert_raises(ValueError, random.poisson, [lamneg] * 10)
1130
+ assert_raises(ValueError, random.poisson, lambig)
1131
+ assert_raises(ValueError, random.poisson, [lambig] * 10)
1132
+ with warnings.catch_warnings():
1133
+ warnings.simplefilter('ignore', RuntimeWarning)
1134
+ assert_raises(ValueError, random.poisson, np.nan)
1135
+ assert_raises(ValueError, random.poisson, [np.nan] * 10)
1136
+
1137
+ def test_power(self):
1138
+ rng = random.RandomState(self.seed)
1139
+ actual = rng.power(a=.123456789, size=(3, 2))
1140
+ desired = np.array([[0.02048932883240791, 0.01424192241128213],
1141
+ [0.38446073748535298, 0.39499689943484395],
1142
+ [0.00177699707563439, 0.13115505880863756]])
1143
+ assert_array_almost_equal(actual, desired, decimal=15)
1144
+
1145
+ def test_rayleigh(self):
1146
+ rng = random.RandomState(self.seed)
1147
+ actual = rng.rayleigh(scale=10, size=(3, 2))
1148
+ desired = np.array([[13.8882496494248393, 13.383318339044731],
1149
+ [20.95413364294492098, 21.08285015800712614],
1150
+ [11.06066537006854311, 17.35468505778271009]])
1151
+ assert_array_almost_equal(actual, desired, decimal=14)
1152
+
1153
+ def test_rayleigh_0(self):
1154
+ assert_equal(random.rayleigh(scale=0), 0)
1155
+ assert_raises(ValueError, random.rayleigh, scale=-0.)
1156
+
1157
+ def test_standard_cauchy(self):
1158
+ rng = random.RandomState(self.seed)
1159
+ actual = rng.standard_cauchy(size=(3, 2))
1160
+ desired = np.array([[0.77127660196445336, -6.55601161955910605],
1161
+ [0.93582023391158309, -2.07479293013759447],
1162
+ [-4.74601644297011926, 0.18338989290760804]])
1163
+ assert_array_almost_equal(actual, desired, decimal=15)
1164
+
1165
+ def test_standard_exponential(self):
1166
+ rng = random.RandomState(self.seed)
1167
+ actual = rng.standard_exponential(size=(3, 2))
1168
+ desired = np.array([[0.96441739162374596, 0.89556604882105506],
1169
+ [2.1953785836319808, 2.22243285392490542],
1170
+ [0.6116915921431676, 1.50592546727413201]])
1171
+ assert_array_almost_equal(actual, desired, decimal=15)
1172
+
1173
+ def test_standard_gamma(self):
1174
+ rng = random.RandomState(self.seed)
1175
+ actual = rng.standard_gamma(shape=3, size=(3, 2))
1176
+ desired = np.array([[5.50841531318455058, 6.62953470301903103],
1177
+ [5.93988484943779227, 2.31044849402133989],
1178
+ [7.54838614231317084, 8.012756093271868]])
1179
+ assert_array_almost_equal(actual, desired, decimal=14)
1180
+
1181
+ def test_standard_gamma_0(self):
1182
+ assert_equal(random.standard_gamma(shape=0), 0)
1183
+ assert_raises(ValueError, random.standard_gamma, shape=-0.)
1184
+
1185
+ def test_standard_normal(self):
1186
+ rng = random.RandomState(self.seed)
1187
+ actual = rng.standard_normal(size=(3, 2))
1188
+ desired = np.array([[1.34016345771863121, 1.73759122771936081],
1189
+ [1.498988344300628, -0.2286433324536169],
1190
+ [2.031033998682787, 2.17032494605655257]])
1191
+ assert_array_almost_equal(actual, desired, decimal=15)
1192
+
1193
+ def test_randn_singleton(self):
1194
+ rng = random.RandomState(self.seed)
1195
+ actual = rng.randn()
1196
+ desired = np.array(1.34016345771863121)
1197
+ assert_array_almost_equal(actual, desired, decimal=15)
1198
+
1199
+ def test_standard_t(self):
1200
+ rng = random.RandomState(self.seed)
1201
+ actual = rng.standard_t(df=10, size=(3, 2))
1202
+ desired = np.array([[0.97140611862659965, -0.08830486548450577],
1203
+ [1.36311143689505321, -0.55317463909867071],
1204
+ [-0.18473749069684214, 0.61181537341755321]])
1205
+ assert_array_almost_equal(actual, desired, decimal=15)
1206
+
1207
+ def test_triangular(self):
1208
+ rng = random.RandomState(self.seed)
1209
+ actual = rng.triangular(left=5.12, mode=10.23, right=20.34,
1210
+ size=(3, 2))
1211
+ desired = np.array([[12.68117178949215784, 12.4129206149193152],
1212
+ [16.20131377335158263, 16.25692138747600524],
1213
+ [11.20400690911820263, 14.4978144835829923]])
1214
+ assert_array_almost_equal(actual, desired, decimal=14)
1215
+
1216
+ def test_uniform(self):
1217
+ rng = random.RandomState(self.seed)
1218
+ actual = rng.uniform(low=1.23, high=10.54, size=(3, 2))
1219
+ desired = np.array([[6.99097932346268003, 6.73801597444323974],
1220
+ [9.50364421400426274, 9.53130618907631089],
1221
+ [5.48995325769805476, 8.47493103280052118]])
1222
+ assert_array_almost_equal(actual, desired, decimal=15)
1223
+
1224
+ def test_uniform_range_bounds(self):
1225
+ fmin = np.finfo('float').min
1226
+ fmax = np.finfo('float').max
1227
+
1228
+ func = random.uniform
1229
+ assert_raises(OverflowError, func, -np.inf, 0)
1230
+ assert_raises(OverflowError, func, 0, np.inf)
1231
+ assert_raises(OverflowError, func, fmin, fmax)
1232
+ assert_raises(OverflowError, func, [-np.inf], [0])
1233
+ assert_raises(OverflowError, func, [0], [np.inf])
1234
+
1235
+ # (fmax / 1e17) - fmin is within range, so this should not throw
1236
+ # account for i386 extended precision DBL_MAX / 1e17 + DBL_MAX >
1237
+ # DBL_MAX by increasing fmin a bit
1238
+ random.uniform(low=np.nextafter(fmin, 1), high=fmax / 1e17)
1239
+
1240
+ def test_scalar_exception_propagation(self):
1241
+ # Tests that exceptions are correctly propagated in distributions
1242
+ # when called with objects that throw exceptions when converted to
1243
+ # scalars.
1244
+ #
1245
+ # Regression test for gh: 8865
1246
+
1247
+ class ThrowingFloat(np.ndarray):
1248
+ def __float__(self):
1249
+ raise TypeError
1250
+
1251
+ throwing_float = np.array(1.0).view(ThrowingFloat)
1252
+ assert_raises(TypeError, random.uniform, throwing_float,
1253
+ throwing_float)
1254
+
1255
+ class ThrowingInteger(np.ndarray):
1256
+ def __int__(self):
1257
+ raise TypeError
1258
+
1259
+ throwing_int = np.array(1).view(ThrowingInteger)
1260
+ assert_raises(TypeError, random.hypergeometric, throwing_int, 1, 1)
1261
+
1262
+ def test_vonmises(self):
1263
+ rng = random.RandomState(self.seed)
1264
+ actual = rng.vonmises(mu=1.23, kappa=1.54, size=(3, 2))
1265
+ desired = np.array([[2.28567572673902042, 2.89163838442285037],
1266
+ [0.38198375564286025, 2.57638023113890746],
1267
+ [1.19153771588353052, 1.83509849681825354]])
1268
+ assert_array_almost_equal(actual, desired, decimal=15)
1269
+
1270
+ def test_vonmises_small(self):
1271
+ # check infinite loop, gh-4720
1272
+ random.seed(self.seed)
1273
+ r = random.vonmises(mu=0., kappa=1.1e-8, size=10**6)
1274
+ assert_(np.isfinite(r).all())
1275
+
1276
+ def test_vonmises_large(self):
1277
+ # guard against changes in RandomState when Generator is fixed
1278
+ rng = random.RandomState(self.seed)
1279
+ actual = rng.vonmises(mu=0., kappa=1e7, size=3)
1280
+ desired = np.array([4.634253748521111e-04,
1281
+ 3.558873596114509e-04,
1282
+ -2.337119622577433e-04])
1283
+ assert_array_almost_equal(actual, desired, decimal=8)
1284
+
1285
+ def test_vonmises_nan(self):
1286
+ random.seed(self.seed)
1287
+ r = random.vonmises(mu=0., kappa=np.nan)
1288
+ assert_(np.isnan(r))
1289
+
1290
+ def test_wald(self):
1291
+ rng = random.RandomState(self.seed)
1292
+ actual = rng.wald(mean=1.23, scale=1.54, size=(3, 2))
1293
+ desired = np.array([[3.82935265715889983, 5.13125249184285526],
1294
+ [0.35045403618358717, 1.50832396872003538],
1295
+ [0.24124319895843183, 0.22031101461955038]])
1296
+ assert_array_almost_equal(actual, desired, decimal=14)
1297
+
1298
+ def test_weibull(self):
1299
+ rng = random.RandomState(self.seed)
1300
+ actual = rng.weibull(a=1.23, size=(3, 2))
1301
+ desired = np.array([[0.97097342648766727, 0.91422896443565516],
1302
+ [1.89517770034962929, 1.91414357960479564],
1303
+ [0.67057783752390987, 1.39494046635066793]])
1304
+ assert_array_almost_equal(actual, desired, decimal=15)
1305
+
1306
+ def test_weibull_0(self):
1307
+ random.seed(self.seed)
1308
+ assert_equal(random.weibull(a=0, size=12), np.zeros(12))
1309
+ assert_raises(ValueError, random.weibull, a=-0.)
1310
+
1311
+ def test_zipf(self):
1312
+ rng = random.RandomState(self.seed)
1313
+ actual = rng.zipf(a=1.23, size=(3, 2))
1314
+ desired = np.array([[66, 29],
1315
+ [1, 1],
1316
+ [3, 13]])
1317
+ assert_array_equal(actual, desired)
1318
+
1319
+
1320
+ class TestBroadcast:
1321
+ # tests that functions that broadcast behave
1322
+ # correctly when presented with non-scalar arguments
1323
+ seed = 123456789
1324
+
1325
+ def test_uniform(self):
1326
+ low = [0]
1327
+ high = [1]
1328
+ desired = np.array([0.53283302478975902,
1329
+ 0.53413660089041659,
1330
+ 0.50955303552646702])
1331
+
1332
+ rng = random.RandomState(self.seed)
1333
+ actual = rng.uniform(low * 3, high)
1334
+ assert_array_almost_equal(actual, desired, decimal=14)
1335
+
1336
+ rng = random.RandomState(self.seed)
1337
+ actual = rng.uniform(low, high * 3)
1338
+ assert_array_almost_equal(actual, desired, decimal=14)
1339
+
1340
+ def test_normal(self):
1341
+ loc = [0]
1342
+ scale = [1]
1343
+ bad_scale = [-1]
1344
+ desired = np.array([2.2129019979039612,
1345
+ 2.1283977976520019,
1346
+ 1.8417114045748335])
1347
+
1348
+ rng = random.RandomState(self.seed)
1349
+ actual = rng.normal(loc * 3, scale)
1350
+ assert_array_almost_equal(actual, desired, decimal=14)
1351
+ assert_raises(ValueError, rng.normal, loc * 3, bad_scale)
1352
+
1353
+ rng = random.RandomState(self.seed)
1354
+ actual = rng.normal(loc, scale * 3)
1355
+ assert_array_almost_equal(actual, desired, decimal=14)
1356
+ assert_raises(ValueError, rng.normal, loc, bad_scale * 3)
1357
+
1358
+ def test_beta(self):
1359
+ a = [1]
1360
+ b = [2]
1361
+ bad_a = [-1]
1362
+ bad_b = [-2]
1363
+ desired = np.array([0.19843558305989056,
1364
+ 0.075230336409423643,
1365
+ 0.24976865978980844])
1366
+
1367
+ rng = random.RandomState(self.seed)
1368
+ actual = rng.beta(a * 3, b)
1369
+ assert_array_almost_equal(actual, desired, decimal=14)
1370
+ assert_raises(ValueError, rng.beta, bad_a * 3, b)
1371
+ assert_raises(ValueError, rng.beta, a * 3, bad_b)
1372
+
1373
+ rng = random.RandomState(self.seed)
1374
+ actual = rng.beta(a, b * 3)
1375
+ assert_array_almost_equal(actual, desired, decimal=14)
1376
+ assert_raises(ValueError, rng.beta, bad_a, b * 3)
1377
+ assert_raises(ValueError, rng.beta, a, bad_b * 3)
1378
+
1379
+ def test_exponential(self):
1380
+ scale = [1]
1381
+ bad_scale = [-1]
1382
+ desired = np.array([0.76106853658845242,
1383
+ 0.76386282278691653,
1384
+ 0.71243813125891797])
1385
+
1386
+ rng = random.RandomState(self.seed)
1387
+ actual = rng.exponential(scale * 3)
1388
+ assert_array_almost_equal(actual, desired, decimal=14)
1389
+ assert_raises(ValueError, rng.exponential, bad_scale * 3)
1390
+
1391
+ def test_standard_gamma(self):
1392
+ shape = [1]
1393
+ bad_shape = [-1]
1394
+ desired = np.array([0.76106853658845242,
1395
+ 0.76386282278691653,
1396
+ 0.71243813125891797])
1397
+
1398
+ rng = random.RandomState(self.seed)
1399
+ actual = rng.standard_gamma(shape * 3)
1400
+ assert_array_almost_equal(actual, desired, decimal=14)
1401
+ assert_raises(ValueError, rng.standard_gamma, bad_shape * 3)
1402
+
1403
+ def test_gamma(self):
1404
+ shape = [1]
1405
+ scale = [2]
1406
+ bad_shape = [-1]
1407
+ bad_scale = [-2]
1408
+ desired = np.array([1.5221370731769048,
1409
+ 1.5277256455738331,
1410
+ 1.4248762625178359])
1411
+
1412
+ rng = random.RandomState(self.seed)
1413
+ actual = rng.gamma(shape * 3, scale)
1414
+ assert_array_almost_equal(actual, desired, decimal=14)
1415
+ assert_raises(ValueError, rng.gamma, bad_shape * 3, scale)
1416
+ assert_raises(ValueError, rng.gamma, shape * 3, bad_scale)
1417
+
1418
+ rng = random.RandomState(self.seed)
1419
+ actual = rng.gamma(shape, scale * 3)
1420
+ assert_array_almost_equal(actual, desired, decimal=14)
1421
+ assert_raises(ValueError, rng.gamma, bad_shape, scale * 3)
1422
+ assert_raises(ValueError, rng.gamma, shape, bad_scale * 3)
1423
+
1424
+ def test_f(self):
1425
+ dfnum = [1]
1426
+ dfden = [2]
1427
+ bad_dfnum = [-1]
1428
+ bad_dfden = [-2]
1429
+ desired = np.array([0.80038951638264799,
1430
+ 0.86768719635363512,
1431
+ 2.7251095168386801])
1432
+
1433
+ rng = random.RandomState(self.seed)
1434
+ actual = rng.f(dfnum * 3, dfden)
1435
+ assert_array_almost_equal(actual, desired, decimal=14)
1436
+ assert_raises(ValueError, rng.f, bad_dfnum * 3, dfden)
1437
+ assert_raises(ValueError, rng.f, dfnum * 3, bad_dfden)
1438
+
1439
+ rng = random.RandomState(self.seed)
1440
+ actual = rng.f(dfnum, dfden * 3)
1441
+ assert_array_almost_equal(actual, desired, decimal=14)
1442
+ assert_raises(ValueError, rng.f, bad_dfnum, dfden * 3)
1443
+ assert_raises(ValueError, rng.f, dfnum, bad_dfden * 3)
1444
+
1445
+ def test_noncentral_f(self):
1446
+ dfnum = [2]
1447
+ dfden = [3]
1448
+ nonc = [4]
1449
+ bad_dfnum = [0]
1450
+ bad_dfden = [-1]
1451
+ bad_nonc = [-2]
1452
+ desired = np.array([9.1393943263705211,
1453
+ 13.025456344595602,
1454
+ 8.8018098359100545])
1455
+
1456
+ rng = random.RandomState(self.seed)
1457
+ actual = rng.noncentral_f(dfnum * 3, dfden, nonc)
1458
+ assert_array_almost_equal(actual, desired, decimal=14)
1459
+ assert np.all(np.isnan(rng.noncentral_f(dfnum, dfden, [np.nan] * 3)))
1460
+
1461
+ assert_raises(ValueError, rng.noncentral_f, bad_dfnum * 3, dfden, nonc)
1462
+ assert_raises(ValueError, rng.noncentral_f, dfnum * 3, bad_dfden, nonc)
1463
+ assert_raises(ValueError, rng.noncentral_f, dfnum * 3, dfden, bad_nonc)
1464
+
1465
+ rng = random.RandomState(self.seed)
1466
+ actual = rng.noncentral_f(dfnum, dfden * 3, nonc)
1467
+ assert_array_almost_equal(actual, desired, decimal=14)
1468
+ assert_raises(ValueError, rng.noncentral_f, bad_dfnum, dfden * 3, nonc)
1469
+ assert_raises(ValueError, rng.noncentral_f, dfnum, bad_dfden * 3, nonc)
1470
+ assert_raises(ValueError, rng.noncentral_f, dfnum, dfden * 3, bad_nonc)
1471
+
1472
+ rng = random.RandomState(self.seed)
1473
+ actual = rng.noncentral_f(dfnum, dfden, nonc * 3)
1474
+ assert_array_almost_equal(actual, desired, decimal=14)
1475
+ assert_raises(ValueError, rng.noncentral_f, bad_dfnum, dfden, nonc * 3)
1476
+ assert_raises(ValueError, rng.noncentral_f, dfnum, bad_dfden, nonc * 3)
1477
+ assert_raises(ValueError, rng.noncentral_f, dfnum, dfden, bad_nonc * 3)
1478
+
1479
+ def test_noncentral_f_small_df(self):
1480
+ rng = random.RandomState(self.seed)
1481
+ desired = np.array([6.869638627492048, 0.785880199263955])
1482
+ actual = rng.noncentral_f(0.9, 0.9, 2, size=2)
1483
+ assert_array_almost_equal(actual, desired, decimal=14)
1484
+
1485
+ def test_chisquare(self):
1486
+ df = [1]
1487
+ bad_df = [-1]
1488
+ desired = np.array([0.57022801133088286,
1489
+ 0.51947702108840776,
1490
+ 0.1320969254923558])
1491
+
1492
+ rng = random.RandomState(self.seed)
1493
+ actual = rng.chisquare(df * 3)
1494
+ assert_array_almost_equal(actual, desired, decimal=14)
1495
+ assert_raises(ValueError, rng.chisquare, bad_df * 3)
1496
+
1497
+ def test_noncentral_chisquare(self):
1498
+ df = [1]
1499
+ nonc = [2]
1500
+ bad_df = [-1]
1501
+ bad_nonc = [-2]
1502
+ desired = np.array([9.0015599467913763,
1503
+ 4.5804135049718742,
1504
+ 6.0872302432834564])
1505
+
1506
+ rng = random.RandomState(self.seed)
1507
+ actual = rng.noncentral_chisquare(df * 3, nonc)
1508
+ assert_array_almost_equal(actual, desired, decimal=14)
1509
+ assert_raises(ValueError, rng.noncentral_chisquare, bad_df * 3, nonc)
1510
+ assert_raises(ValueError, rng.noncentral_chisquare, df * 3, bad_nonc)
1511
+
1512
+ rng = random.RandomState(self.seed)
1513
+ actual = rng.noncentral_chisquare(df, nonc * 3)
1514
+ assert_array_almost_equal(actual, desired, decimal=14)
1515
+ assert_raises(ValueError, rng.noncentral_chisquare, bad_df, nonc * 3)
1516
+ assert_raises(ValueError, rng.noncentral_chisquare, df, bad_nonc * 3)
1517
+
1518
+ def test_standard_t(self):
1519
+ df = [1]
1520
+ bad_df = [-1]
1521
+ desired = np.array([3.0702872575217643,
1522
+ 5.8560725167361607,
1523
+ 1.0274791436474273])
1524
+
1525
+ rng = random.RandomState(self.seed)
1526
+ actual = rng.standard_t(df * 3)
1527
+ assert_array_almost_equal(actual, desired, decimal=14)
1528
+ assert_raises(ValueError, rng.standard_t, bad_df * 3)
1529
+ assert_raises(ValueError, random.standard_t, bad_df * 3)
1530
+
1531
+ def test_vonmises(self):
1532
+ mu = [2]
1533
+ kappa = [1]
1534
+ bad_kappa = [-1]
1535
+ desired = np.array([2.9883443664201312,
1536
+ -2.7064099483995943,
1537
+ -1.8672476700665914])
1538
+
1539
+ rng = random.RandomState(self.seed)
1540
+ actual = rng.vonmises(mu * 3, kappa)
1541
+ assert_array_almost_equal(actual, desired, decimal=14)
1542
+ assert_raises(ValueError, rng.vonmises, mu * 3, bad_kappa)
1543
+
1544
+ rng = random.RandomState(self.seed)
1545
+ actual = rng.vonmises(mu, kappa * 3)
1546
+ assert_array_almost_equal(actual, desired, decimal=14)
1547
+ assert_raises(ValueError, rng.vonmises, mu, bad_kappa * 3)
1548
+
1549
+ def test_pareto(self):
1550
+ a = [1]
1551
+ bad_a = [-1]
1552
+ desired = np.array([1.1405622680198362,
1553
+ 1.1465519762044529,
1554
+ 1.0389564467453547])
1555
+
1556
+ rng = random.RandomState(self.seed)
1557
+ actual = rng.pareto(a * 3)
1558
+ assert_array_almost_equal(actual, desired, decimal=14)
1559
+ assert_raises(ValueError, rng.pareto, bad_a * 3)
1560
+ assert_raises(ValueError, random.pareto, bad_a * 3)
1561
+
1562
+ def test_weibull(self):
1563
+ a = [1]
1564
+ bad_a = [-1]
1565
+ desired = np.array([0.76106853658845242,
1566
+ 0.76386282278691653,
1567
+ 0.71243813125891797])
1568
+
1569
+ rng = random.RandomState(self.seed)
1570
+ actual = rng.weibull(a * 3)
1571
+ assert_array_almost_equal(actual, desired, decimal=14)
1572
+ assert_raises(ValueError, rng.weibull, bad_a * 3)
1573
+ assert_raises(ValueError, random.weibull, bad_a * 3)
1574
+
1575
+ def test_power(self):
1576
+ a = [1]
1577
+ bad_a = [-1]
1578
+ desired = np.array([0.53283302478975902,
1579
+ 0.53413660089041659,
1580
+ 0.50955303552646702])
1581
+
1582
+ rng = random.RandomState(self.seed)
1583
+ actual = rng.power(a * 3)
1584
+ assert_array_almost_equal(actual, desired, decimal=14)
1585
+ assert_raises(ValueError, rng.power, bad_a * 3)
1586
+ assert_raises(ValueError, random.power, bad_a * 3)
1587
+
1588
+ def test_laplace(self):
1589
+ loc = [0]
1590
+ scale = [1]
1591
+ bad_scale = [-1]
1592
+ desired = np.array([0.067921356028507157,
1593
+ 0.070715642226971326,
1594
+ 0.019290950698972624])
1595
+
1596
+ rng = random.RandomState(self.seed)
1597
+ actual = rng.laplace(loc * 3, scale)
1598
+ assert_array_almost_equal(actual, desired, decimal=14)
1599
+ assert_raises(ValueError, rng.laplace, loc * 3, bad_scale)
1600
+
1601
+ rng = random.RandomState(self.seed)
1602
+ actual = rng.laplace(loc, scale * 3)
1603
+ assert_array_almost_equal(actual, desired, decimal=14)
1604
+ assert_raises(ValueError, rng.laplace, loc, bad_scale * 3)
1605
+
1606
+ def test_gumbel(self):
1607
+ loc = [0]
1608
+ scale = [1]
1609
+ bad_scale = [-1]
1610
+ desired = np.array([0.2730318639556768,
1611
+ 0.26936705726291116,
1612
+ 0.33906220393037939])
1613
+
1614
+ rng = random.RandomState(self.seed)
1615
+ actual = rng.gumbel(loc * 3, scale)
1616
+ assert_array_almost_equal(actual, desired, decimal=14)
1617
+ assert_raises(ValueError, rng.gumbel, loc * 3, bad_scale)
1618
+
1619
+ rng = random.RandomState(self.seed)
1620
+ actual = rng.gumbel(loc, scale * 3)
1621
+ assert_array_almost_equal(actual, desired, decimal=14)
1622
+ assert_raises(ValueError, rng.gumbel, loc, bad_scale * 3)
1623
+
1624
+ def test_logistic(self):
1625
+ loc = [0]
1626
+ scale = [1]
1627
+ bad_scale = [-1]
1628
+ desired = np.array([0.13152135837586171,
1629
+ 0.13675915696285773,
1630
+ 0.038216792802833396])
1631
+
1632
+ rng = random.RandomState(self.seed)
1633
+ actual = rng.logistic(loc * 3, scale)
1634
+ assert_array_almost_equal(actual, desired, decimal=14)
1635
+ assert_raises(ValueError, rng.logistic, loc * 3, bad_scale)
1636
+
1637
+ rng = random.RandomState(self.seed)
1638
+ actual = rng.logistic(loc, scale * 3)
1639
+ assert_array_almost_equal(actual, desired, decimal=14)
1640
+ assert_raises(ValueError, rng.logistic, loc, bad_scale * 3)
1641
+ assert_equal(rng.logistic(1.0, 0.0), 1.0)
1642
+
1643
+ def test_lognormal(self):
1644
+ mean = [0]
1645
+ sigma = [1]
1646
+ bad_sigma = [-1]
1647
+ desired = np.array([9.1422086044848427,
1648
+ 8.4013952870126261,
1649
+ 6.3073234116578671])
1650
+
1651
+ rng = random.RandomState(self.seed)
1652
+ actual = rng.lognormal(mean * 3, sigma)
1653
+ assert_array_almost_equal(actual, desired, decimal=14)
1654
+ assert_raises(ValueError, rng.lognormal, mean * 3, bad_sigma)
1655
+ assert_raises(ValueError, random.lognormal, mean * 3, bad_sigma)
1656
+
1657
+ rng = random.RandomState(self.seed)
1658
+ actual = rng.lognormal(mean, sigma * 3)
1659
+ assert_array_almost_equal(actual, desired, decimal=14)
1660
+ assert_raises(ValueError, rng.lognormal, mean, bad_sigma * 3)
1661
+ assert_raises(ValueError, random.lognormal, mean, bad_sigma * 3)
1662
+
1663
+ def test_rayleigh(self):
1664
+ scale = [1]
1665
+ bad_scale = [-1]
1666
+ desired = np.array([1.2337491937897689,
1667
+ 1.2360119924878694,
1668
+ 1.1936818095781789])
1669
+
1670
+ rng = random.RandomState(self.seed)
1671
+ actual = rng.rayleigh(scale * 3)
1672
+ assert_array_almost_equal(actual, desired, decimal=14)
1673
+ assert_raises(ValueError, rng.rayleigh, bad_scale * 3)
1674
+
1675
+ def test_wald(self):
1676
+ mean = [0.5]
1677
+ scale = [1]
1678
+ bad_mean = [0]
1679
+ bad_scale = [-2]
1680
+ desired = np.array([0.11873681120271318,
1681
+ 0.12450084820795027,
1682
+ 0.9096122728408238])
1683
+
1684
+ rng = random.RandomState(self.seed)
1685
+ actual = rng.wald(mean * 3, scale)
1686
+ assert_array_almost_equal(actual, desired, decimal=14)
1687
+ assert_raises(ValueError, rng.wald, bad_mean * 3, scale)
1688
+ assert_raises(ValueError, rng.wald, mean * 3, bad_scale)
1689
+ assert_raises(ValueError, random.wald, bad_mean * 3, scale)
1690
+ assert_raises(ValueError, random.wald, mean * 3, bad_scale)
1691
+
1692
+ rng = random.RandomState(self.seed)
1693
+ actual = rng.wald(mean, scale * 3)
1694
+ assert_array_almost_equal(actual, desired, decimal=14)
1695
+ assert_raises(ValueError, rng.wald, bad_mean, scale * 3)
1696
+ assert_raises(ValueError, rng.wald, mean, bad_scale * 3)
1697
+ assert_raises(ValueError, rng.wald, 0.0, 1)
1698
+ assert_raises(ValueError, rng.wald, 0.5, 0.0)
1699
+
1700
+ def test_triangular(self):
1701
+ left = [1]
1702
+ right = [3]
1703
+ mode = [2]
1704
+ bad_left_one = [3]
1705
+ bad_mode_one = [4]
1706
+ bad_left_two, bad_mode_two = right * 2
1707
+ desired = np.array([2.03339048710429,
1708
+ 2.0347400359389356,
1709
+ 2.0095991069536208])
1710
+
1711
+ rng = random.RandomState(self.seed)
1712
+ actual = rng.triangular(left * 3, mode, right)
1713
+ assert_array_almost_equal(actual, desired, decimal=14)
1714
+ assert_raises(ValueError, rng.triangular, bad_left_one * 3, mode, right)
1715
+ assert_raises(ValueError, rng.triangular, left * 3, bad_mode_one, right)
1716
+ assert_raises(ValueError, rng.triangular, bad_left_two * 3, bad_mode_two,
1717
+ right)
1718
+
1719
+ rng = random.RandomState(self.seed)
1720
+ actual = rng.triangular(left, mode * 3, right)
1721
+ assert_array_almost_equal(actual, desired, decimal=14)
1722
+ assert_raises(ValueError, rng.triangular, bad_left_one, mode * 3, right)
1723
+ assert_raises(ValueError, rng.triangular, left, bad_mode_one * 3, right)
1724
+ assert_raises(ValueError, rng.triangular, bad_left_two, bad_mode_two * 3,
1725
+ right)
1726
+
1727
+ rng = random.RandomState(self.seed)
1728
+ actual = rng.triangular(left, mode, right * 3)
1729
+ assert_array_almost_equal(actual, desired, decimal=14)
1730
+ assert_raises(ValueError, rng.triangular, bad_left_one, mode, right * 3)
1731
+ assert_raises(ValueError, rng.triangular, left, bad_mode_one, right * 3)
1732
+ assert_raises(ValueError, rng.triangular, bad_left_two, bad_mode_two,
1733
+ right * 3)
1734
+
1735
+ assert_raises(ValueError, rng.triangular, 10., 0., 20.)
1736
+ assert_raises(ValueError, rng.triangular, 10., 25., 20.)
1737
+ assert_raises(ValueError, rng.triangular, 10., 10., 10.)
1738
+
1739
+ def test_binomial(self):
1740
+ n = [1]
1741
+ p = [0.5]
1742
+ bad_n = [-1]
1743
+ bad_p_one = [-1]
1744
+ bad_p_two = [1.5]
1745
+ desired = np.array([1, 1, 1])
1746
+
1747
+ rng = random.RandomState(self.seed)
1748
+ actual = rng.binomial(n * 3, p)
1749
+ assert_array_equal(actual, desired)
1750
+ assert_raises(ValueError, rng.binomial, bad_n * 3, p)
1751
+ assert_raises(ValueError, rng.binomial, n * 3, bad_p_one)
1752
+ assert_raises(ValueError, rng.binomial, n * 3, bad_p_two)
1753
+
1754
+ rng = random.RandomState(self.seed)
1755
+ actual = rng.binomial(n, p * 3)
1756
+ assert_array_equal(actual, desired)
1757
+ assert_raises(ValueError, rng.binomial, bad_n, p * 3)
1758
+ assert_raises(ValueError, rng.binomial, n, bad_p_one * 3)
1759
+ assert_raises(ValueError, rng.binomial, n, bad_p_two * 3)
1760
+
1761
+ def test_negative_binomial(self):
1762
+ n = [1]
1763
+ p = [0.5]
1764
+ bad_n = [-1]
1765
+ bad_p_one = [-1]
1766
+ bad_p_two = [1.5]
1767
+ desired = np.array([1, 0, 1])
1768
+
1769
+ rng = random.RandomState(self.seed)
1770
+ actual = rng.negative_binomial(n * 3, p)
1771
+ assert_array_equal(actual, desired)
1772
+ assert_raises(ValueError, rng.negative_binomial, bad_n * 3, p)
1773
+ assert_raises(ValueError, rng.negative_binomial, n * 3, bad_p_one)
1774
+ assert_raises(ValueError, rng.negative_binomial, n * 3, bad_p_two)
1775
+
1776
+ rng = random.RandomState(self.seed)
1777
+ actual = rng.negative_binomial(n, p * 3)
1778
+ assert_array_equal(actual, desired)
1779
+ assert_raises(ValueError, rng.negative_binomial, bad_n, p * 3)
1780
+ assert_raises(ValueError, rng.negative_binomial, n, bad_p_one * 3)
1781
+ assert_raises(ValueError, rng.negative_binomial, n, bad_p_two * 3)
1782
+
1783
+ def test_poisson(self):
1784
+ max_lam = random.RandomState()._poisson_lam_max
1785
+
1786
+ lam = [1]
1787
+ bad_lam_one = [-1]
1788
+ bad_lam_two = [max_lam * 2]
1789
+ desired = np.array([1, 1, 0])
1790
+
1791
+ rng = random.RandomState(self.seed)
1792
+ actual = rng.poisson(lam * 3)
1793
+ assert_array_equal(actual, desired)
1794
+ assert_raises(ValueError, rng.poisson, bad_lam_one * 3)
1795
+ assert_raises(ValueError, rng.poisson, bad_lam_two * 3)
1796
+
1797
+ def test_zipf(self):
1798
+ a = [2]
1799
+ bad_a = [0]
1800
+ desired = np.array([2, 2, 1])
1801
+
1802
+ rng = random.RandomState(self.seed)
1803
+ actual = rng.zipf(a * 3)
1804
+ assert_array_equal(actual, desired)
1805
+ assert_raises(ValueError, rng.zipf, bad_a * 3)
1806
+ with np.errstate(invalid='ignore'):
1807
+ assert_raises(ValueError, rng.zipf, np.nan)
1808
+ assert_raises(ValueError, rng.zipf, [0, 0, np.nan])
1809
+
1810
+ def test_geometric(self):
1811
+ p = [0.5]
1812
+ bad_p_one = [-1]
1813
+ bad_p_two = [1.5]
1814
+ desired = np.array([2, 2, 2])
1815
+
1816
+ rng = random.RandomState(self.seed)
1817
+ actual = rng.geometric(p * 3)
1818
+ assert_array_equal(actual, desired)
1819
+ assert_raises(ValueError, rng.geometric, bad_p_one * 3)
1820
+ assert_raises(ValueError, rng.geometric, bad_p_two * 3)
1821
+
1822
+ def test_hypergeometric(self):
1823
+ ngood = [1]
1824
+ nbad = [2]
1825
+ nsample = [2]
1826
+ bad_ngood = [-1]
1827
+ bad_nbad = [-2]
1828
+ bad_nsample_one = [0]
1829
+ bad_nsample_two = [4]
1830
+ desired = np.array([1, 1, 1])
1831
+
1832
+ rng = random.RandomState(self.seed)
1833
+ actual = rng.hypergeometric(ngood * 3, nbad, nsample)
1834
+ assert_array_equal(actual, desired)
1835
+ assert_raises(ValueError, rng.hypergeometric, bad_ngood * 3, nbad, nsample)
1836
+ assert_raises(ValueError, rng.hypergeometric, ngood * 3, bad_nbad, nsample)
1837
+ assert_raises(ValueError, rng.hypergeometric, ngood * 3, nbad, bad_nsample_one)
1838
+ assert_raises(ValueError, rng.hypergeometric, ngood * 3, nbad, bad_nsample_two)
1839
+
1840
+ rng = random.RandomState(self.seed)
1841
+ actual = rng.hypergeometric(ngood, nbad * 3, nsample)
1842
+ assert_array_equal(actual, desired)
1843
+ assert_raises(ValueError, rng.hypergeometric, bad_ngood, nbad * 3, nsample)
1844
+ assert_raises(ValueError, rng.hypergeometric, ngood, bad_nbad * 3, nsample)
1845
+ assert_raises(ValueError, rng.hypergeometric, ngood, nbad * 3, bad_nsample_one)
1846
+ assert_raises(ValueError, rng.hypergeometric, ngood, nbad * 3, bad_nsample_two)
1847
+
1848
+ rng = random.RandomState(self.seed)
1849
+ actual = rng.hypergeometric(ngood, nbad, nsample * 3)
1850
+ assert_array_equal(actual, desired)
1851
+ assert_raises(ValueError, rng.hypergeometric, bad_ngood, nbad, nsample * 3)
1852
+ assert_raises(ValueError, rng.hypergeometric, ngood, bad_nbad, nsample * 3)
1853
+ assert_raises(ValueError, rng.hypergeometric, ngood, nbad, bad_nsample_one * 3)
1854
+ assert_raises(ValueError, rng.hypergeometric, ngood, nbad, bad_nsample_two * 3)
1855
+
1856
+ assert_raises(ValueError, rng.hypergeometric, -1, 10, 20)
1857
+ assert_raises(ValueError, rng.hypergeometric, 10, -1, 20)
1858
+ assert_raises(ValueError, rng.hypergeometric, 10, 10, 0)
1859
+ assert_raises(ValueError, rng.hypergeometric, 10, 10, 25)
1860
+
1861
+ def test_logseries(self):
1862
+ p = [0.5]
1863
+ bad_p_one = [2]
1864
+ bad_p_two = [-1]
1865
+ desired = np.array([1, 1, 1])
1866
+
1867
+ rng = random.RandomState(self.seed)
1868
+ actual = rng.logseries(p * 3)
1869
+ assert_array_equal(actual, desired)
1870
+ assert_raises(ValueError, rng.logseries, bad_p_one * 3)
1871
+ assert_raises(ValueError, rng.logseries, bad_p_two * 3)
1872
+
1873
+
1874
+ @pytest.mark.skipif(IS_WASM, reason="can't start thread")
1875
+ class TestThread:
1876
+ # make sure each state produces the same sequence even in threads
1877
+ seeds = range(4)
1878
+
1879
+ def check_function(self, function, sz):
1880
+ from threading import Thread
1881
+
1882
+ out1 = np.empty((len(self.seeds),) + sz)
1883
+ out2 = np.empty((len(self.seeds),) + sz)
1884
+
1885
+ # threaded generation
1886
+ t = [Thread(target=function, args=(random.RandomState(s), o))
1887
+ for s, o in zip(self.seeds, out1)]
1888
+ [x.start() for x in t]
1889
+ [x.join() for x in t]
1890
+
1891
+ # the same serial
1892
+ for s, o in zip(self.seeds, out2):
1893
+ function(random.RandomState(s), o)
1894
+
1895
+ # these platforms change x87 fpu precision mode in threads
1896
+ if np.intp().dtype.itemsize == 4 and sys.platform == "win32":
1897
+ assert_array_almost_equal(out1, out2)
1898
+ else:
1899
+ assert_array_equal(out1, out2)
1900
+
1901
+ def test_normal(self):
1902
+ def gen_random(state, out):
1903
+ out[...] = state.normal(size=10000)
1904
+
1905
+ self.check_function(gen_random, sz=(10000,))
1906
+
1907
+ def test_exp(self):
1908
+ def gen_random(state, out):
1909
+ out[...] = state.exponential(scale=np.ones((100, 1000)))
1910
+
1911
+ self.check_function(gen_random, sz=(100, 1000))
1912
+
1913
+ def test_multinomial(self):
1914
+ def gen_random(state, out):
1915
+ out[...] = state.multinomial(10, [1 / 6.] * 6, size=10000)
1916
+
1917
+ self.check_function(gen_random, sz=(10000, 6))
1918
+
1919
+
1920
+ # See Issue #4263
1921
+ class TestSingleEltArrayInput:
1922
+ def _create_arrays(self):
1923
+ return np.array([2]), np.array([3]), np.array([4]), (1,)
1924
+
1925
+ def test_one_arg_funcs(self):
1926
+ argOne, _, _, tgtShape = self._create_arrays()
1927
+ funcs = (random.exponential, random.standard_gamma,
1928
+ random.chisquare, random.standard_t,
1929
+ random.pareto, random.weibull,
1930
+ random.power, random.rayleigh,
1931
+ random.poisson, random.zipf,
1932
+ random.geometric, random.logseries)
1933
+
1934
+ probfuncs = (random.geometric, random.logseries)
1935
+
1936
+ for func in funcs:
1937
+ if func in probfuncs: # p < 1.0
1938
+ out = func(np.array([0.5]))
1939
+
1940
+ else:
1941
+ out = func(argOne)
1942
+
1943
+ assert_equal(out.shape, tgtShape)
1944
+
1945
+ def test_two_arg_funcs(self):
1946
+ argOne, argTwo, _, tgtShape = self._create_arrays()
1947
+ funcs = (random.uniform, random.normal,
1948
+ random.beta, random.gamma,
1949
+ random.f, random.noncentral_chisquare,
1950
+ random.vonmises, random.laplace,
1951
+ random.gumbel, random.logistic,
1952
+ random.lognormal, random.wald,
1953
+ random.binomial, random.negative_binomial)
1954
+
1955
+ probfuncs = (random.binomial, random.negative_binomial)
1956
+
1957
+ for func in funcs:
1958
+ if func in probfuncs: # p <= 1
1959
+ argTwo = np.array([0.5])
1960
+
1961
+ else:
1962
+ argTwo = argTwo
1963
+
1964
+ out = func(argOne, argTwo)
1965
+ assert_equal(out.shape, tgtShape)
1966
+
1967
+ out = func(argOne[0], argTwo)
1968
+ assert_equal(out.shape, tgtShape)
1969
+
1970
+ out = func(argOne, argTwo[0])
1971
+ assert_equal(out.shape, tgtShape)
1972
+
1973
+ def test_three_arg_funcs(self):
1974
+ argOne, argTwo, argThree, tgtShape = self._create_arrays()
1975
+ funcs = [random.noncentral_f, random.triangular,
1976
+ random.hypergeometric]
1977
+
1978
+ for func in funcs:
1979
+ out = func(argOne, argTwo, argThree)
1980
+ assert_equal(out.shape, tgtShape)
1981
+
1982
+ out = func(argOne[0], argTwo, argThree)
1983
+ assert_equal(out.shape, tgtShape)
1984
+
1985
+ out = func(argOne, argTwo[0], argThree)
1986
+ assert_equal(out.shape, tgtShape)
1987
+
1988
+
1989
+ # Ensure returned array dtype is correct for platform
1990
+ def test_integer_dtype(int_func):
1991
+ random.seed(123456789)
1992
+ fname, args, sha256 = int_func
1993
+ f = getattr(random, fname)
1994
+ actual = f(*args, size=2)
1995
+ assert_(actual.dtype == np.dtype('l'))
1996
+
1997
+
1998
+ def test_integer_repeat(int_func):
1999
+ rng = random.RandomState(123456789)
2000
+ fname, args, sha256 = int_func
2001
+ f = getattr(rng, fname)
2002
+ val = f(*args, size=1000000)
2003
+ if sys.byteorder != 'little':
2004
+ val = val.byteswap()
2005
+ res = hashlib.sha256(val.view(np.int8)).hexdigest()
2006
+ assert_(res == sha256)
2007
+
2008
+
2009
+ def test_broadcast_size_error():
2010
+ # GH-16833
2011
+ with pytest.raises(ValueError):
2012
+ random.binomial(1, [0.3, 0.7], size=(2, 1))
2013
+ with pytest.raises(ValueError):
2014
+ random.binomial([1, 2], 0.3, size=(2, 1))
2015
+ with pytest.raises(ValueError):
2016
+ random.binomial([1, 2], [0.3, 0.7], size=(2, 1))
2017
+
2018
+
2019
+ def test_randomstate_ctor_old_style_pickle():
2020
+ rs = np.random.RandomState(MT19937(0))
2021
+ rs.standard_normal(1)
2022
+ # Directly call reduce which is used in pickling
2023
+ ctor, args, state_a = rs.__reduce__()
2024
+ # Simulate unpickling an old pickle that only has the name
2025
+ assert args[0].__class__.__name__ == "MT19937"
2026
+ b = ctor(*("MT19937",))
2027
+ b.set_state(state_a)
2028
+ state_b = b.get_state(legacy=False)
2029
+
2030
+ assert_equal(state_a['bit_generator'], state_b['bit_generator'])
2031
+ assert_array_equal(state_a['state']['key'], state_b['state']['key'])
2032
+ assert_array_equal(state_a['state']['pos'], state_b['state']['pos'])
2033
+ assert_equal(state_a['has_gauss'], state_b['has_gauss'])
2034
+ assert_equal(state_a['gauss'], state_b['gauss'])
2035
+
2036
+
2037
+ @pytest.mark.thread_unsafe(reason="np.random.set_bit_generator affects global state")
2038
+ def test_hot_swap(restore_singleton_bitgen):
2039
+ # GH 21808
2040
+ def_bg = np.random.default_rng(0)
2041
+ bg = def_bg.bit_generator
2042
+ np.random.set_bit_generator(bg)
2043
+ assert isinstance(np.random.mtrand._rand._bit_generator, type(bg))
2044
+
2045
+ second_bg = np.random.get_bit_generator()
2046
+ assert bg is second_bg
2047
+
2048
+
2049
+ @pytest.mark.thread_unsafe(reason="np.random.set_bit_generator affects global state")
2050
+ def test_seed_alt_bit_gen(restore_singleton_bitgen):
2051
+ # GH 21808
2052
+ bg = PCG64(0)
2053
+ np.random.set_bit_generator(bg)
2054
+ state = np.random.get_state(legacy=False)
2055
+ np.random.seed(1)
2056
+ new_state = np.random.get_state(legacy=False)
2057
+ print(state)
2058
+ print(new_state)
2059
+ assert state["bit_generator"] == "PCG64"
2060
+ assert state["state"]["state"] != new_state["state"]["state"]
2061
+ assert state["state"]["inc"] != new_state["state"]["inc"]
2062
+
2063
+
2064
+ @pytest.mark.thread_unsafe(reason="np.random.set_bit_generator affects global state")
2065
+ def test_state_error_alt_bit_gen(restore_singleton_bitgen):
2066
+ # GH 21808
2067
+ state = np.random.get_state()
2068
+ bg = PCG64(0)
2069
+ np.random.set_bit_generator(bg)
2070
+ with pytest.raises(ValueError, match="state must be for a PCG64"):
2071
+ np.random.set_state(state)
2072
+
2073
+
2074
+ @pytest.mark.thread_unsafe(reason="np.random.set_bit_generator affects global state")
2075
+ def test_swap_worked(restore_singleton_bitgen):
2076
+ # GH 21808
2077
+ np.random.seed(98765)
2078
+ vals = np.random.randint(0, 2 ** 30, 10)
2079
+ bg = PCG64(0)
2080
+ state = bg.state
2081
+ np.random.set_bit_generator(bg)
2082
+ state_direct = np.random.get_state(legacy=False)
2083
+ for field in state:
2084
+ assert state[field] == state_direct[field]
2085
+ np.random.seed(98765)
2086
+ pcg_vals = np.random.randint(0, 2 ** 30, 10)
2087
+ assert not np.all(vals == pcg_vals)
2088
+ new_state = bg.state
2089
+ assert new_state["state"]["state"] != state["state"]["state"]
2090
+ assert new_state["state"]["inc"] == new_state["state"]["inc"]
2091
+
2092
+
2093
+ @pytest.mark.thread_unsafe(reason="np.random.set_bit_generator affects global state")
2094
+ def test_swapped_singleton_against_direct(restore_singleton_bitgen):
2095
+ np.random.set_bit_generator(PCG64(98765))
2096
+ singleton_vals = np.random.randint(0, 2 ** 30, 10)
2097
+ rg = np.random.RandomState(PCG64(98765))
2098
+ non_singleton_vals = rg.randint(0, 2 ** 30, 10)
2099
+ assert_equal(non_singleton_vals, singleton_vals)