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,2677 @@
1
+ import copy
2
+ import gc
3
+ import pickle
4
+ import sys
5
+ import tempfile
6
+ import warnings
7
+ from io import BytesIO
8
+ from itertools import chain
9
+ from os import path
10
+
11
+ import pytest
12
+
13
+ import numpy as np
14
+ from numpy._utils import asbytes, asunicode
15
+ from numpy.exceptions import AxisError, ComplexWarning
16
+ from numpy.lib.stride_tricks import as_strided
17
+ from numpy.testing import (
18
+ HAS_REFCOUNT,
19
+ IS_64BIT,
20
+ IS_PYPY,
21
+ IS_PYSTON,
22
+ IS_WASM,
23
+ _assert_valid_refcount,
24
+ assert_,
25
+ assert_almost_equal,
26
+ assert_array_almost_equal,
27
+ assert_array_equal,
28
+ assert_equal,
29
+ assert_raises,
30
+ assert_raises_regex,
31
+ )
32
+ from numpy.testing._private.utils import _no_tracing, requires_memory
33
+
34
+
35
+ class TestRegression:
36
+ def test_invalid_round(self):
37
+ # Ticket #3
38
+ v = 4.7599999999999998
39
+ assert_array_equal(np.array([v]), np.array(v))
40
+
41
+ def test_mem_empty(self):
42
+ # Ticket #7
43
+ np.empty((1,), dtype=[('x', np.int64)])
44
+
45
+ def test_pickle_transposed(self):
46
+ # Ticket #16
47
+ a = np.transpose(np.array([[2, 9], [7, 0], [3, 8]]))
48
+ for proto in range(2, pickle.HIGHEST_PROTOCOL + 1):
49
+ with BytesIO() as f:
50
+ pickle.dump(a, f, protocol=proto)
51
+ f.seek(0)
52
+ b = pickle.load(f)
53
+ assert_array_equal(a, b)
54
+
55
+ def test_dtype_names(self):
56
+ # Ticket #35
57
+ # Should succeed
58
+ np.dtype([(('name', 'label'), np.int32, 3)])
59
+
60
+ def test_reduce(self):
61
+ # Ticket #40
62
+ assert_almost_equal(np.add.reduce([1., .5], dtype=None), 1.5)
63
+
64
+ def test_zeros_order(self):
65
+ # Ticket #43
66
+ np.zeros([3], int, 'C')
67
+ np.zeros([3], order='C')
68
+ np.zeros([3], int, order='C')
69
+
70
+ def test_asarray_with_order(self):
71
+ # Check that nothing is done when order='F' and array C/F-contiguous
72
+ a = np.ones(2)
73
+ assert_(a is np.asarray(a, order='F'))
74
+
75
+ def test_ravel_with_order(self):
76
+ # Check that ravel works when order='F' and array C/F-contiguous
77
+ a = np.ones(2)
78
+ assert_(not a.ravel('F').flags.owndata)
79
+
80
+ def test_sort_bigendian(self):
81
+ # Ticket #47
82
+ a = np.linspace(0, 10, 11)
83
+ c = a.astype(np.dtype('<f8'))
84
+ c.sort()
85
+ assert_array_almost_equal(c, a)
86
+
87
+ def test_negative_nd_indexing(self):
88
+ # Ticket #49
89
+ c = np.arange(125).reshape((5, 5, 5))
90
+ origidx = np.array([-1, 0, 1])
91
+ idx = np.array(origidx)
92
+ c[idx]
93
+ assert_array_equal(idx, origidx)
94
+
95
+ def test_char_dump(self):
96
+ # Ticket #50
97
+ ca = np.char.array(np.arange(1000, 1010), itemsize=4)
98
+ for proto in range(2, pickle.HIGHEST_PROTOCOL + 1):
99
+ with BytesIO() as f:
100
+ pickle.dump(ca, f, protocol=proto)
101
+ f.seek(0)
102
+ ca = np.load(f, allow_pickle=True)
103
+
104
+ def test_noncontiguous_fill(self):
105
+ # Ticket #58.
106
+ a = np.zeros((5, 3))
107
+ b = a[:, :2,]
108
+
109
+ def rs():
110
+ b.shape = (10,)
111
+
112
+ assert_raises(AttributeError, rs)
113
+
114
+ def test_bool(self):
115
+ # Ticket #60
116
+ np.bool(1) # Should succeed
117
+
118
+ def test_indexing1(self):
119
+ # Ticket #64
120
+ descr = [('x', [('y', [('z', 'c16', (2,)),]),]),]
121
+ buffer = ((([6j, 4j],),),)
122
+ h = np.array(buffer, dtype=descr)
123
+ h['x']['y']['z']
124
+
125
+ def test_indexing2(self):
126
+ # Ticket #65
127
+ descr = [('x', 'i4', (2,))]
128
+ buffer = ([3, 2],)
129
+ h = np.array(buffer, dtype=descr)
130
+ h['x']
131
+
132
+ def test_round(self):
133
+ # Ticket #67
134
+ x = np.array([1 + 2j])
135
+ assert_almost_equal(x**(-1), [1 / (1 + 2j)])
136
+
137
+ def test_scalar_compare(self):
138
+ # Trac Ticket #72
139
+ # https://github.com/numpy/numpy/issues/565
140
+ a = np.array(['test', 'auto'])
141
+ assert_array_equal(a == 'auto', np.array([False, True]))
142
+ assert_(a[1] == 'auto')
143
+ assert_(a[0] != 'auto')
144
+ b = np.linspace(0, 10, 11)
145
+ assert_array_equal(b != 'auto', np.ones(11, dtype=bool))
146
+ assert_(b[0] != 'auto')
147
+
148
+ def test_unicode_swapping(self):
149
+ # Ticket #79
150
+ ulen = 1
151
+ ucs_value = '\U0010FFFF'
152
+ ua = np.array([[[ucs_value * ulen] * 2] * 3] * 4, dtype=f'U{ulen}')
153
+ ua.view(ua.dtype.newbyteorder()) # Should succeed.
154
+
155
+ def test_object_array_fill(self):
156
+ # Ticket #86
157
+ x = np.zeros(1, 'O')
158
+ x.fill([])
159
+
160
+ def test_mem_dtype_align(self):
161
+ # Ticket #93
162
+ with pytest.raises(TypeError):
163
+ np.dtype({'names': ['a'], 'formats': ['foo']}, align=True)
164
+
165
+ def test_endian_bool_indexing(self):
166
+ # Ticket #105
167
+ a = np.arange(10., dtype='>f8')
168
+ b = np.arange(10., dtype='<f8')
169
+ xa = np.where((a > 2) & (a < 6))
170
+ xb = np.where((b > 2) & (b < 6))
171
+ ya = ((a > 2) & (a < 6))
172
+ yb = ((b > 2) & (b < 6))
173
+ assert_array_almost_equal(xa, ya.nonzero())
174
+ assert_array_almost_equal(xb, yb.nonzero())
175
+ assert_(np.all(a[ya] > 0.5))
176
+ assert_(np.all(b[yb] > 0.5))
177
+
178
+ def test_endian_where(self):
179
+ # GitHub issue #369
180
+ net = np.zeros(3, dtype='>f4')
181
+ net[1] = 0.00458849
182
+ net[2] = 0.605202
183
+ max_net = net.max()
184
+ test = np.where(net <= 0., max_net, net)
185
+ correct = np.array([0.60520202, 0.00458849, 0.60520202])
186
+ assert_array_almost_equal(test, correct)
187
+
188
+ def test_endian_recarray(self):
189
+ # Ticket #2185
190
+ dt = np.dtype([
191
+ ('head', '>u4'),
192
+ ('data', '>u4', 2),
193
+ ])
194
+ buf = np.recarray(1, dtype=dt)
195
+ buf[0]['head'] = 1
196
+ buf[0]['data'][:] = [1, 1]
197
+
198
+ h = buf[0]['head']
199
+ d = buf[0]['data'][0]
200
+ buf[0]['head'] = h
201
+ buf[0]['data'][0] = d
202
+ assert_(buf[0]['head'] == 1)
203
+
204
+ def test_mem_dot(self):
205
+ # Ticket #106
206
+ x = np.random.randn(0, 1)
207
+ y = np.random.randn(10, 1)
208
+ # Dummy array to detect bad memory access:
209
+ _z = np.ones(10)
210
+ _dummy = np.empty((0, 10))
211
+ z = as_strided(_z, _dummy.shape, _dummy.strides)
212
+ np.dot(x, np.transpose(y), out=z)
213
+ assert_equal(_z, np.ones(10))
214
+ # Do the same for the built-in dot:
215
+ np._core.multiarray.dot(x, np.transpose(y), out=z)
216
+ assert_equal(_z, np.ones(10))
217
+
218
+ def test_arange_endian(self):
219
+ # Ticket #111
220
+ ref = np.arange(10)
221
+ x = np.arange(10, dtype='<f8')
222
+ assert_array_equal(ref, x)
223
+ x = np.arange(10, dtype='>f8')
224
+ assert_array_equal(ref, x)
225
+
226
+ def test_arange_inf_step(self):
227
+ ref = np.arange(0, 1, 10)
228
+ x = np.arange(0, 1, np.inf)
229
+ assert_array_equal(ref, x)
230
+
231
+ ref = np.arange(0, 1, -10)
232
+ x = np.arange(0, 1, -np.inf)
233
+ assert_array_equal(ref, x)
234
+
235
+ ref = np.arange(0, -1, -10)
236
+ x = np.arange(0, -1, -np.inf)
237
+ assert_array_equal(ref, x)
238
+
239
+ ref = np.arange(0, -1, 10)
240
+ x = np.arange(0, -1, np.inf)
241
+ assert_array_equal(ref, x)
242
+
243
+ def test_arange_underflow_stop_and_step(self):
244
+ finfo = np.finfo(np.float64)
245
+
246
+ ref = np.arange(0, finfo.eps, 2 * finfo.eps)
247
+ x = np.arange(0, finfo.eps, finfo.max)
248
+ assert_array_equal(ref, x)
249
+
250
+ ref = np.arange(0, finfo.eps, -2 * finfo.eps)
251
+ x = np.arange(0, finfo.eps, -finfo.max)
252
+ assert_array_equal(ref, x)
253
+
254
+ ref = np.arange(0, -finfo.eps, -2 * finfo.eps)
255
+ x = np.arange(0, -finfo.eps, -finfo.max)
256
+ assert_array_equal(ref, x)
257
+
258
+ ref = np.arange(0, -finfo.eps, 2 * finfo.eps)
259
+ x = np.arange(0, -finfo.eps, finfo.max)
260
+ assert_array_equal(ref, x)
261
+
262
+ def test_argmax(self):
263
+ # Ticket #119
264
+ a = np.random.normal(0, 1, (4, 5, 6, 7, 8))
265
+ for i in range(a.ndim):
266
+ a.argmax(i) # Should succeed
267
+
268
+ def test_mem_divmod(self):
269
+ # Ticket #126
270
+ for i in range(10):
271
+ divmod(np.array([i])[0], 10)
272
+
273
+ def test_hstack_invalid_dims(self):
274
+ # Ticket #128
275
+ x = np.arange(9).reshape((3, 3))
276
+ y = np.array([0, 0, 0])
277
+ assert_raises(ValueError, np.hstack, (x, y))
278
+
279
+ def test_squeeze_type(self):
280
+ # Ticket #133
281
+ a = np.array([3])
282
+ b = np.array(3)
283
+ assert_(type(a.squeeze()) is np.ndarray)
284
+ assert_(type(b.squeeze()) is np.ndarray)
285
+
286
+ def test_add_identity(self):
287
+ # Ticket #143
288
+ assert_equal(0, np.add.identity)
289
+
290
+ def test_numpy_float_python_long_addition(self):
291
+ # Check that numpy float and python longs can be added correctly.
292
+ a = np.float64(23.) + 2**135
293
+ assert_equal(a, 23. + 2**135)
294
+
295
+ def test_binary_repr_0(self):
296
+ # Ticket #151
297
+ assert_equal('0', np.binary_repr(0))
298
+
299
+ def test_rec_iterate(self):
300
+ # Ticket #160
301
+ descr = np.dtype([('i', int), ('f', float), ('s', '|S3')])
302
+ x = np.rec.array([(1, 1.1, '1.0'),
303
+ (2, 2.2, '2.0')], dtype=descr)
304
+ x[0].tolist()
305
+ list(x[0])
306
+
307
+ def test_unicode_string_comparison(self):
308
+ # Ticket #190
309
+ a = np.array('hello', np.str_)
310
+ b = np.array('world')
311
+ a == b
312
+
313
+ def test_tobytes_FORTRANORDER_discontiguous(self):
314
+ # Fix in r2836
315
+ # Create non-contiguous Fortran ordered array
316
+ x = np.array(np.random.rand(3, 3), order='F')[:, :2]
317
+ assert_array_almost_equal(x.ravel(), np.frombuffer(x.tobytes()))
318
+
319
+ def test_flat_assignment(self):
320
+ # Correct behaviour of ticket #194
321
+ x = np.empty((3, 1))
322
+ x.flat = np.arange(3)
323
+ assert_array_almost_equal(x, [[0], [1], [2]])
324
+ x.flat = np.arange(3, dtype=float)
325
+ assert_array_almost_equal(x, [[0], [1], [2]])
326
+
327
+ def test_broadcast_flat_assignment(self):
328
+ # Ticket #194
329
+ x = np.empty((3, 1))
330
+
331
+ def bfa():
332
+ x[:] = np.arange(3)
333
+
334
+ def bfb():
335
+ x[:] = np.arange(3, dtype=float)
336
+
337
+ assert_raises(ValueError, bfa)
338
+ assert_raises(ValueError, bfb)
339
+
340
+ @pytest.mark.xfail(IS_WASM, reason="not sure why")
341
+ @pytest.mark.parametrize("index",
342
+ [np.ones(10, dtype=bool), np.arange(10)],
343
+ ids=["boolean-arr-index", "integer-arr-index"])
344
+ def test_nonarray_assignment(self, index):
345
+ # See also Issue gh-2870, test for non-array assignment
346
+ # and equivalent unsafe casted array assignment
347
+ a = np.arange(10)
348
+
349
+ with pytest.raises(ValueError):
350
+ a[index] = np.nan
351
+
352
+ with np.errstate(invalid="warn"):
353
+ with pytest.warns(RuntimeWarning, match="invalid value"):
354
+ a[index] = np.array(np.nan) # Only warns
355
+
356
+ def test_unpickle_dtype_with_object(self):
357
+ # Implemented in r2840
358
+ dt = np.dtype([('x', int), ('y', np.object_), ('z', 'O')])
359
+ for proto in range(2, pickle.HIGHEST_PROTOCOL + 1):
360
+ with BytesIO() as f:
361
+ pickle.dump(dt, f, protocol=proto)
362
+ f.seek(0)
363
+ dt_ = pickle.load(f)
364
+ assert_equal(dt, dt_)
365
+
366
+ def test_mem_array_creation_invalid_specification(self):
367
+ # Ticket #196
368
+ dt = np.dtype([('x', int), ('y', np.object_)])
369
+ # Wrong way
370
+ assert_raises(ValueError, np.array, [1, 'object'], dt)
371
+ # Correct way
372
+ np.array([(1, 'object')], dt)
373
+
374
+ def test_recarray_single_element(self):
375
+ # Ticket #202
376
+ a = np.array([1, 2, 3], dtype=np.int32)
377
+ b = a.copy()
378
+ r = np.rec.array(a, shape=1, formats=['3i4'], names=['d'])
379
+ assert_array_equal(a, b)
380
+ assert_equal(a, r[0][0])
381
+
382
+ def test_zero_sized_array_indexing(self):
383
+ # Ticket #205
384
+ tmp = np.array([])
385
+
386
+ def index_tmp():
387
+ tmp[np.array(10)]
388
+
389
+ assert_raises(IndexError, index_tmp)
390
+
391
+ def test_chararray_rstrip(self):
392
+ # Ticket #222
393
+ x = np.char.chararray((1,), 5)
394
+ x[0] = b'a '
395
+ x = x.rstrip()
396
+ assert_equal(x[0], b'a')
397
+
398
+ def test_object_array_shape(self):
399
+ # Ticket #239
400
+ assert_equal(np.array([[1, 2], 3, 4], dtype=object).shape, (3,))
401
+ assert_equal(np.array([[1, 2], [3, 4]], dtype=object).shape, (2, 2))
402
+ assert_equal(np.array([(1, 2), (3, 4)], dtype=object).shape, (2, 2))
403
+ assert_equal(np.array([], dtype=object).shape, (0,))
404
+ assert_equal(np.array([[], [], []], dtype=object).shape, (3, 0))
405
+ assert_equal(np.array([[3, 4], [5, 6], None], dtype=object).shape, (3,))
406
+
407
+ def test_mem_around(self):
408
+ # Ticket #243
409
+ x = np.zeros((1,))
410
+ y = [0]
411
+ decimal = 6
412
+ np.around(abs(x - y), decimal) <= 10.0**(-decimal)
413
+
414
+ def test_character_array_strip(self):
415
+ # Ticket #246
416
+ x = np.char.array(("x", "x ", "x "))
417
+ for c in x:
418
+ assert_equal(c, "x")
419
+
420
+ def test_lexsort(self):
421
+ # Lexsort memory error
422
+ v = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
423
+ assert_equal(np.lexsort(v), 0)
424
+
425
+ def test_lexsort_invalid_sequence(self):
426
+ # Issue gh-4123
427
+ class BuggySequence:
428
+ def __len__(self):
429
+ return 4
430
+
431
+ def __getitem__(self, key):
432
+ raise KeyError
433
+
434
+ assert_raises(KeyError, np.lexsort, BuggySequence())
435
+
436
+ def test_lexsort_zerolen_custom_strides(self):
437
+ # Ticket #14228
438
+ xs = np.array([], dtype='i8')
439
+ assert np.lexsort((xs,)).shape[0] == 0 # Works
440
+
441
+ xs = as_strided(xs, strides=(16,))
442
+ assert np.lexsort((xs,)).shape[0] == 0 # Was: MemoryError
443
+
444
+ def test_lexsort_zerolen_custom_strides_2d(self):
445
+ xs = np.array([], dtype='i8')
446
+ xt = as_strided(xs, shape=(0, 2), strides=(16, 16))
447
+ assert np.lexsort((xt,), axis=0).shape[0] == 0
448
+
449
+ xt = as_strided(xs, shape=(2, 0), strides=(16, 16))
450
+ assert np.lexsort((xt,), axis=0).shape[0] == 2
451
+
452
+ def test_lexsort_invalid_axis(self):
453
+ assert_raises(AxisError, np.lexsort, (np.arange(1),), axis=2)
454
+ assert_raises(AxisError, np.lexsort, (np.array([]),), axis=1)
455
+ assert_raises(AxisError, np.lexsort, (np.array(1),), axis=10)
456
+
457
+ def test_lexsort_zerolen_element(self):
458
+ dt = np.dtype([]) # a void dtype with no fields
459
+ xs = np.empty(4, dt)
460
+
461
+ assert np.lexsort((xs,)).shape[0] == xs.shape[0]
462
+
463
+ @pytest.mark.filterwarnings(
464
+ "ignore:.*align should be passed:numpy.exceptions.VisibleDeprecationWarning")
465
+ def test_pickle_py2_bytes_encoding(self):
466
+ # Check that arrays and scalars pickled on Py2 are
467
+ # unpickleable on Py3 using encoding='bytes'
468
+
469
+ test_data = [
470
+ # (original, py2_pickle)
471
+ (
472
+ np.str_('\u6f2c'),
473
+ b"cnumpy.core.multiarray\nscalar\np0\n(cnumpy\ndtype\np1\n(S'U1'\np2\nI0\nI1\ntp3\nRp4\n(I3\nS'<'\np5\nNNNI4\nI4\nI0\ntp6\nbS',o\\x00\\x00'\np7\ntp8\nRp9\n."
474
+ ),
475
+
476
+ (
477
+ np.array([9e123], dtype=np.float64),
478
+ b"cnumpy.core.multiarray\n_reconstruct\np0\n(cnumpy\nndarray\np1\n(I0\ntp2\nS'b'\np3\ntp4\nRp5\n(I1\n(I1\ntp6\ncnumpy\ndtype\np7\n(S'f8'\np8\nI0\nI1\ntp9\nRp10\n(I3\nS'<'\np11\nNNNI-1\nI-1\nI0\ntp12\nbI00\nS'O\\x81\\xb7Z\\xaa:\\xabY'\np13\ntp14\nb."
479
+ ),
480
+
481
+ (
482
+ np.array([(9e123,)], dtype=[('name', float)]),
483
+ b"cnumpy.core.multiarray\n_reconstruct\np0\n(cnumpy\nndarray\np1\n(I0\ntp2\nS'b'\np3\ntp4\nRp5\n(I1\n(I1\ntp6\ncnumpy\ndtype\np7\n(S'V8'\np8\nI0\nI1\ntp9\nRp10\n(I3\nS'|'\np11\nN(S'name'\np12\ntp13\n(dp14\ng12\n(g7\n(S'f8'\np15\nI0\nI1\ntp16\nRp17\n(I3\nS'<'\np18\nNNNI-1\nI-1\nI0\ntp19\nbI0\ntp20\nsI8\nI1\nI0\ntp21\nbI00\nS'O\\x81\\xb7Z\\xaa:\\xabY'\np22\ntp23\nb."
484
+ ),
485
+ ]
486
+
487
+ for original, data in test_data:
488
+ result = pickle.loads(data, encoding='bytes')
489
+ assert_equal(result, original)
490
+
491
+ if isinstance(result, np.ndarray) and result.dtype.names is not None:
492
+ for name in result.dtype.names:
493
+ assert_(isinstance(name, str))
494
+
495
+ def test_pickle_dtype(self):
496
+ # Ticket #251
497
+ for proto in range(2, pickle.HIGHEST_PROTOCOL + 1):
498
+ pickle.dumps(float, protocol=proto)
499
+
500
+ def test_swap_real(self):
501
+ # Ticket #265
502
+ assert_equal(np.arange(4, dtype='>c8').imag.max(), 0.0)
503
+ assert_equal(np.arange(4, dtype='<c8').imag.max(), 0.0)
504
+ assert_equal(np.arange(4, dtype='>c8').real.max(), 3.0)
505
+ assert_equal(np.arange(4, dtype='<c8').real.max(), 3.0)
506
+
507
+ def test_object_array_from_list(self):
508
+ # Ticket #270 (gh-868)
509
+ assert_(np.array([1, None, 'A']).shape == (3,))
510
+
511
+ def test_multiple_assign(self):
512
+ # Ticket #273
513
+ a = np.zeros((3, 1), int)
514
+ a[[1, 2]] = 1
515
+
516
+ def test_empty_array_type(self):
517
+ assert_equal(np.array([]).dtype, np.zeros(0).dtype)
518
+
519
+ def test_void_copyswap(self):
520
+ dt = np.dtype([('one', '<i4'), ('two', '<i4')])
521
+ x = np.array((1, 2), dtype=dt)
522
+ x = x.byteswap()
523
+ assert_(x['one'] > 1 and x['two'] > 2)
524
+
525
+ def test_method_args(self):
526
+ # Make sure methods and functions have same default axis
527
+ # keyword and arguments
528
+ funcs1 = ['argmax', 'argmin', 'sum', 'any', 'all', 'cumsum',
529
+ 'cumprod', 'prod', 'std', 'var', 'mean',
530
+ 'round', 'min', 'max', 'argsort', 'sort']
531
+ funcs2 = ['compress', 'take', 'repeat']
532
+
533
+ for func in funcs1:
534
+ arr = np.random.rand(8, 7)
535
+ arr2 = arr.copy()
536
+ res1 = getattr(arr, func)()
537
+ res2 = getattr(np, func)(arr2)
538
+ if res1 is None:
539
+ res1 = arr
540
+
541
+ if res1.dtype.kind in 'uib':
542
+ assert_((res1 == res2).all(), func)
543
+ else:
544
+ assert_(abs(res1 - res2).max() < 1e-8, func)
545
+
546
+ for func in funcs2:
547
+ arr1 = np.random.rand(8, 7)
548
+ arr2 = np.random.rand(8, 7)
549
+ res1 = None
550
+ if func == 'compress':
551
+ arr1 = arr1.ravel()
552
+ res1 = getattr(arr2, func)(arr1)
553
+ else:
554
+ arr2 = (15 * arr2).astype(int).ravel()
555
+ if res1 is None:
556
+ res1 = getattr(arr1, func)(arr2)
557
+ res2 = getattr(np, func)(arr1, arr2)
558
+ assert_(abs(res1 - res2).max() < 1e-8, func)
559
+
560
+ def test_mem_lexsort_strings(self):
561
+ # Ticket #298
562
+ lst = ['abc', 'cde', 'fgh']
563
+ np.lexsort((lst,))
564
+
565
+ def test_fancy_index(self):
566
+ # Ticket #302
567
+ x = np.array([1, 2])[np.array([0])]
568
+ assert_equal(x.shape, (1,))
569
+
570
+ def test_recarray_copy(self):
571
+ # Ticket #312
572
+ dt = [('x', np.int16), ('y', np.float64)]
573
+ ra = np.array([(1, 2.3)], dtype=dt)
574
+ rb = np.rec.array(ra, dtype=dt)
575
+ rb['x'] = 2.
576
+ assert_(ra['x'] != rb['x'])
577
+
578
+ def test_rec_fromarray(self):
579
+ # Ticket #322
580
+ x1 = np.array([[1, 2], [3, 4], [5, 6]])
581
+ x2 = np.array(['a', 'dd', 'xyz'])
582
+ x3 = np.array([1.1, 2, 3])
583
+ np.rec.fromarrays([x1, x2, x3], formats="(2,)i4,S3,f8")
584
+
585
+ def test_object_array_assign(self):
586
+ x = np.empty((2, 2), object)
587
+ x.flat[2] = (1, 2, 3)
588
+ assert_equal(x.flat[2], (1, 2, 3))
589
+
590
+ def test_ndmin_float64(self):
591
+ # Ticket #324
592
+ x = np.array([1, 2, 3], dtype=np.float64)
593
+ assert_equal(np.array(x, dtype=np.float32, ndmin=2).ndim, 2)
594
+ assert_equal(np.array(x, dtype=np.float64, ndmin=2).ndim, 2)
595
+
596
+ def test_ndmin_order(self):
597
+ # Issue #465 and related checks
598
+ assert_(np.array([1, 2], order='C', ndmin=3).flags.c_contiguous)
599
+ assert_(np.array([1, 2], order='F', ndmin=3).flags.f_contiguous)
600
+ assert_(np.array(np.ones((2, 2), order='F'), ndmin=3).flags.f_contiguous)
601
+ assert_(np.array(np.ones((2, 2), order='C'), ndmin=3).flags.c_contiguous)
602
+
603
+ def test_mem_axis_minimization(self):
604
+ # Ticket #327
605
+ data = np.arange(5)
606
+ data = np.add.outer(data, data)
607
+
608
+ def test_mem_float_imag(self):
609
+ # Ticket #330
610
+ np.float64(1.0).imag
611
+
612
+ def test_dtype_tuple(self):
613
+ # Ticket #334
614
+ assert_(np.dtype('i4') == np.dtype(('i4', ())))
615
+
616
+ def test_dtype_posttuple(self):
617
+ # Ticket #335
618
+ np.dtype([('col1', '()i4')])
619
+
620
+ def test_numeric_carray_compare(self):
621
+ # Ticket #341
622
+ assert_equal(np.array(['X'], 'c'), b'X')
623
+
624
+ def test_string_array_size(self):
625
+ # Ticket #342
626
+ assert_raises(ValueError,
627
+ np.array, [['X'], ['X', 'X', 'X']], '|S1')
628
+
629
+ def test_dtype_repr(self):
630
+ # Ticket #344
631
+ dt1 = np.dtype(('uint32', 2))
632
+ dt2 = np.dtype(('uint32', (2,)))
633
+ assert_equal(dt1.__repr__(), dt2.__repr__())
634
+
635
+ def test_reshape_order(self):
636
+ # Make sure reshape order works.
637
+ a = np.arange(6).reshape(2, 3, order='F')
638
+ assert_equal(a, [[0, 2, 4], [1, 3, 5]])
639
+ a = np.array([[1, 2], [3, 4], [5, 6], [7, 8]])
640
+ b = a[:, 1]
641
+ assert_equal(b.reshape(2, 2, order='F'), [[2, 6], [4, 8]])
642
+
643
+ def test_reshape_zero_strides(self):
644
+ # Issue #380, test reshaping of zero strided arrays
645
+ a = np.ones(1)
646
+ a = as_strided(a, shape=(5,), strides=(0,))
647
+ assert_(a.reshape(5, 1).strides[0] == 0)
648
+
649
+ def test_reshape_zero_size(self):
650
+ # GitHub Issue #2700, setting shape failed for 0-sized arrays
651
+ a = np.ones((0, 2))
652
+ a.shape = (-1, 2)
653
+
654
+ def test_reshape_trailing_ones_strides(self):
655
+ # GitHub issue gh-2949, bad strides for trailing ones of new shape
656
+ a = np.zeros(12, dtype=np.int32)[::2] # not contiguous
657
+ strides_c = (16, 8, 8, 8)
658
+ strides_f = (8, 24, 48, 48)
659
+ assert_equal(a.reshape(3, 2, 1, 1).strides, strides_c)
660
+ assert_equal(a.reshape(3, 2, 1, 1, order='F').strides, strides_f)
661
+ assert_equal(np.array(0, dtype=np.int32).reshape(1, 1).strides, (4, 4))
662
+
663
+ def test_repeat_discont(self):
664
+ # Ticket #352
665
+ a = np.arange(12).reshape(4, 3)[:, 2]
666
+ assert_equal(a.repeat(3), [2, 2, 2, 5, 5, 5, 8, 8, 8, 11, 11, 11])
667
+
668
+ def test_array_index(self):
669
+ # Make sure optimization is not called in this case.
670
+ a = np.array([1, 2, 3])
671
+ a2 = np.array([[1, 2, 3]])
672
+ assert_equal(a[np.where(a == 3)], a2[np.where(a2 == 3)])
673
+
674
+ def test_object_argmax(self):
675
+ a = np.array([1, 2, 3], dtype=object)
676
+ assert_(a.argmax() == 2)
677
+
678
+ def test_recarray_fields(self):
679
+ # Ticket #372
680
+ dt0 = np.dtype([('f0', 'i4'), ('f1', 'i4')])
681
+ dt1 = np.dtype([('f0', 'i8'), ('f1', 'i8')])
682
+ for a in [np.array([(1, 2), (3, 4)], "i4,i4"),
683
+ np.rec.array([(1, 2), (3, 4)], "i4,i4"),
684
+ np.rec.array([(1, 2), (3, 4)]),
685
+ np.rec.fromarrays([(1, 2), (3, 4)], "i4,i4"),
686
+ np.rec.fromarrays([(1, 2), (3, 4)])]:
687
+ assert_(a.dtype in [dt0, dt1])
688
+
689
+ def test_random_shuffle(self):
690
+ # Ticket #374
691
+ a = np.arange(5).reshape((5, 1))
692
+ b = a.copy()
693
+ np.random.shuffle(b)
694
+ assert_equal(np.sort(b, axis=0), a)
695
+
696
+ def test_refcount_vdot(self):
697
+ # Changeset #3443
698
+ _assert_valid_refcount(np.vdot)
699
+
700
+ def test_startswith(self):
701
+ ca = np.char.array(['Hi', 'There'])
702
+ assert_equal(ca.startswith('H'), [True, False])
703
+
704
+ def test_noncommutative_reduce_accumulate(self):
705
+ # Ticket #413
706
+ tosubtract = np.arange(5)
707
+ todivide = np.array([2.0, 0.5, 0.25])
708
+ assert_equal(np.subtract.reduce(tosubtract), -10)
709
+ assert_equal(np.divide.reduce(todivide), 16.0)
710
+ assert_array_equal(np.subtract.accumulate(tosubtract),
711
+ np.array([0, -1, -3, -6, -10]))
712
+ assert_array_equal(np.divide.accumulate(todivide),
713
+ np.array([2., 4., 16.]))
714
+
715
+ def test_convolve_empty(self):
716
+ # Convolve should raise an error for empty input array.
717
+ assert_raises(ValueError, np.convolve, [], [1])
718
+ assert_raises(ValueError, np.convolve, [1], [])
719
+
720
+ def test_multidim_byteswap(self):
721
+ # Ticket #449
722
+ r = np.array([(1, (0, 1, 2))], dtype="i2,3i2")
723
+ assert_array_equal(r.byteswap(),
724
+ np.array([(256, (0, 256, 512))], r.dtype))
725
+
726
+ def test_string_NULL(self):
727
+ # Changeset 3557
728
+ assert_equal(np.array("a\x00\x0b\x0c\x00").item(),
729
+ 'a\x00\x0b\x0c')
730
+
731
+ def test_junk_in_string_fields_of_recarray(self):
732
+ # Ticket #483
733
+ r = np.array([[b'abc']], dtype=[('var1', '|S20')])
734
+ assert_(asbytes(r['var1'][0][0]) == b'abc')
735
+
736
+ def test_take_output(self):
737
+ # Ensure that 'take' honours output parameter.
738
+ x = np.arange(12).reshape((3, 4))
739
+ a = np.take(x, [0, 2], axis=1)
740
+ b = np.zeros_like(a)
741
+ np.take(x, [0, 2], axis=1, out=b)
742
+ assert_array_equal(a, b)
743
+
744
+ def test_take_object_fail(self):
745
+ # Issue gh-3001
746
+ d = 123.
747
+ a = np.array([d, 1], dtype=object)
748
+ if HAS_REFCOUNT:
749
+ ref_d = sys.getrefcount(d)
750
+ try:
751
+ a.take([0, 100])
752
+ except IndexError:
753
+ pass
754
+ if HAS_REFCOUNT:
755
+ assert_(ref_d == sys.getrefcount(d))
756
+
757
+ def test_array_str_64bit(self):
758
+ # Ticket #501
759
+ s = np.array([1, np.nan], dtype=np.float64)
760
+ with np.errstate(all='raise'):
761
+ np.array_str(s) # Should succeed
762
+
763
+ def test_frompyfunc_endian(self):
764
+ # Ticket #503
765
+ from math import radians
766
+ uradians = np.frompyfunc(radians, 1, 1)
767
+ big_endian = np.array([83.4, 83.5], dtype='>f8')
768
+ little_endian = np.array([83.4, 83.5], dtype='<f8')
769
+ assert_almost_equal(uradians(big_endian).astype(float),
770
+ uradians(little_endian).astype(float))
771
+
772
+ def test_mem_string_arr(self):
773
+ # Ticket #514
774
+ s = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
775
+ t = []
776
+ np.hstack((t, s))
777
+
778
+ def test_arr_transpose(self):
779
+ # Ticket #516
780
+ x = np.random.rand(*(2,) * 16)
781
+ x.transpose(list(range(16))) # Should succeed
782
+
783
+ def test_string_mergesort(self):
784
+ # Ticket #540
785
+ x = np.array(['a'] * 32)
786
+ assert_array_equal(x.argsort(kind='m'), np.arange(32))
787
+
788
+ def test_argmax_byteorder(self):
789
+ # Ticket #546
790
+ a = np.arange(3, dtype='>f')
791
+ assert_(a[a.argmax()] == a.max())
792
+
793
+ def test_rand_seed(self):
794
+ # Ticket #555
795
+ for l in np.arange(4):
796
+ np.random.seed(l)
797
+
798
+ def test_mem_deallocation_leak(self):
799
+ # Ticket #562
800
+ a = np.zeros(5, dtype=float)
801
+ b = np.array(a, dtype=float)
802
+ del a, b
803
+
804
+ def test_mem_on_invalid_dtype(self):
805
+ "Ticket #583"
806
+ assert_raises(ValueError, np.fromiter, [['12', ''], ['13', '']], str)
807
+
808
+ def test_dot_negative_stride(self):
809
+ # Ticket #588
810
+ x = np.array([[1, 5, 25, 125., 625]])
811
+ y = np.array([[20.], [160.], [640.], [1280.], [1024.]])
812
+ z = y[::-1].copy()
813
+ y2 = y[::-1]
814
+ assert_equal(np.dot(x, z), np.dot(x, y2))
815
+
816
+ def test_object_casting(self):
817
+ # This used to trigger the object-type version of
818
+ # the bitwise_or operation, because float64 -> object
819
+ # casting succeeds
820
+ def rs():
821
+ x = np.ones([484, 286])
822
+ y = np.zeros([484, 286])
823
+ x |= y
824
+
825
+ assert_raises(TypeError, rs)
826
+
827
+ def test_unicode_scalar(self):
828
+ # Ticket #600
829
+ x = np.array(["DROND", "DROND1"], dtype="U6")
830
+ el = x[1]
831
+ for proto in range(2, pickle.HIGHEST_PROTOCOL + 1):
832
+ new = pickle.loads(pickle.dumps(el, protocol=proto))
833
+ assert_equal(new, el)
834
+
835
+ def test_arange_non_native_dtype(self):
836
+ # Ticket #616
837
+ for T in ('>f4', '<f4'):
838
+ dt = np.dtype(T)
839
+ assert_equal(np.arange(0, dtype=dt).dtype, dt)
840
+ assert_equal(np.arange(0.5, dtype=dt).dtype, dt)
841
+ assert_equal(np.arange(5, dtype=dt).dtype, dt)
842
+
843
+ def test_bool_flat_indexing_invalid_nr_elements(self):
844
+ s = np.ones(10, dtype=float)
845
+ x = np.array((15,), dtype=float)
846
+
847
+ def ia(x, s, v):
848
+ x[(s > 0)] = v
849
+
850
+ assert_raises(IndexError, ia, x, s, np.zeros(9, dtype=float))
851
+ assert_raises(IndexError, ia, x, s, np.zeros(11, dtype=float))
852
+
853
+ # Old special case (different code path):
854
+ assert_raises(IndexError, ia, x.flat, s, np.zeros(9, dtype=float))
855
+ assert_raises(IndexError, ia, x.flat, s, np.zeros(11, dtype=float))
856
+
857
+ def test_mem_scalar_indexing(self):
858
+ # Ticket #603
859
+ x = np.array([0], dtype=float)
860
+ index = np.array(0, dtype=np.int32)
861
+ x[index]
862
+
863
+ def test_binary_repr_0_width(self):
864
+ assert_equal(np.binary_repr(0, width=3), '000')
865
+
866
+ def test_fromstring(self):
867
+ assert_equal(np.fromstring("12:09:09", dtype=int, sep=":"),
868
+ [12, 9, 9])
869
+
870
+ def test_searchsorted_variable_length(self):
871
+ x = np.array(['a', 'aa', 'b'])
872
+ y = np.array(['d', 'e'])
873
+ assert_equal(x.searchsorted(y), [3, 3])
874
+
875
+ def test_string_argsort_with_zeros(self):
876
+ # Check argsort for strings containing zeros.
877
+ x = np.frombuffer(b"\x00\x02\x00\x01", dtype="|S2")
878
+ assert_array_equal(x.argsort(kind='m'), np.array([1, 0]))
879
+ assert_array_equal(x.argsort(kind='q'), np.array([1, 0]))
880
+
881
+ def test_string_sort_with_zeros(self):
882
+ # Check sort for strings containing zeros.
883
+ x = np.frombuffer(b"\x00\x02\x00\x01", dtype="|S2")
884
+ y = np.frombuffer(b"\x00\x01\x00\x02", dtype="|S2")
885
+ assert_array_equal(np.sort(x, kind="q"), y)
886
+
887
+ def test_copy_detection_zero_dim(self):
888
+ # Ticket #658
889
+ np.indices((0, 3, 4)).T.reshape(-1, 3)
890
+
891
+ def test_flat_byteorder(self):
892
+ # Ticket #657
893
+ x = np.arange(10)
894
+ assert_array_equal(x.astype('>i4'), x.astype('<i4').flat[:])
895
+ assert_array_equal(x.astype('>i4').flat[:], x.astype('<i4'))
896
+
897
+ def test_sign_bit(self):
898
+ x = np.array([0, -0.0, 0])
899
+ assert_equal(str(np.abs(x)), '[0. 0. 0.]')
900
+
901
+ def test_flat_index_byteswap(self):
902
+ for dt in (np.dtype('<i4'), np.dtype('>i4')):
903
+ x = np.array([-1, 0, 1], dtype=dt)
904
+ assert_equal(x.flat[0].dtype, x[0].dtype)
905
+
906
+ def test_copy_detection_corner_case(self):
907
+ # Ticket #658
908
+ np.indices((0, 3, 4)).T.reshape(-1, 3)
909
+
910
+ def test_object_array_refcounting(self):
911
+ # Ticket #633
912
+ if not hasattr(sys, 'getrefcount'):
913
+ return
914
+
915
+ # NB. this is probably CPython-specific
916
+
917
+ cnt = sys.getrefcount
918
+
919
+ a = object()
920
+ b = object()
921
+ c = object()
922
+
923
+ cnt0_a = cnt(a)
924
+ cnt0_b = cnt(b)
925
+ cnt0_c = cnt(c)
926
+
927
+ # -- 0d -> 1-d broadcast slice assignment
928
+
929
+ arr = np.zeros(5, dtype=np.object_)
930
+
931
+ arr[:] = a
932
+ assert_equal(cnt(a), cnt0_a + 5)
933
+
934
+ arr[:] = b
935
+ assert_equal(cnt(a), cnt0_a)
936
+ assert_equal(cnt(b), cnt0_b + 5)
937
+
938
+ arr[:2] = c
939
+ assert_equal(cnt(b), cnt0_b + 3)
940
+ assert_equal(cnt(c), cnt0_c + 2)
941
+
942
+ del arr
943
+
944
+ # -- 1-d -> 2-d broadcast slice assignment
945
+
946
+ arr = np.zeros((5, 2), dtype=np.object_)
947
+ arr0 = np.zeros(2, dtype=np.object_)
948
+
949
+ arr0[0] = a
950
+ assert_(cnt(a) == cnt0_a + 1)
951
+ arr0[1] = b
952
+ assert_(cnt(b) == cnt0_b + 1)
953
+
954
+ arr[:, :] = arr0
955
+ assert_(cnt(a) == cnt0_a + 6)
956
+ assert_(cnt(b) == cnt0_b + 6)
957
+
958
+ arr[:, 0] = None
959
+ assert_(cnt(a) == cnt0_a + 1)
960
+
961
+ del arr, arr0
962
+
963
+ # -- 2-d copying + flattening
964
+
965
+ arr = np.zeros((5, 2), dtype=np.object_)
966
+
967
+ arr[:, 0] = a
968
+ arr[:, 1] = b
969
+ assert_(cnt(a) == cnt0_a + 5)
970
+ assert_(cnt(b) == cnt0_b + 5)
971
+
972
+ arr2 = arr.copy()
973
+ assert_(cnt(a) == cnt0_a + 10)
974
+ assert_(cnt(b) == cnt0_b + 10)
975
+
976
+ arr2 = arr[:, 0].copy()
977
+ assert_(cnt(a) == cnt0_a + 10)
978
+ assert_(cnt(b) == cnt0_b + 5)
979
+
980
+ arr2 = arr.flatten()
981
+ assert_(cnt(a) == cnt0_a + 10)
982
+ assert_(cnt(b) == cnt0_b + 10)
983
+
984
+ del arr, arr2
985
+
986
+ # -- concatenate, repeat, take, choose
987
+
988
+ arr1 = np.zeros((5, 1), dtype=np.object_)
989
+ arr2 = np.zeros((5, 1), dtype=np.object_)
990
+
991
+ arr1[...] = a
992
+ arr2[...] = b
993
+ assert_(cnt(a) == cnt0_a + 5)
994
+ assert_(cnt(b) == cnt0_b + 5)
995
+
996
+ tmp = np.concatenate((arr1, arr2))
997
+ assert_(cnt(a) == cnt0_a + 5 + 5)
998
+ assert_(cnt(b) == cnt0_b + 5 + 5)
999
+
1000
+ tmp = arr1.repeat(3, axis=0)
1001
+ assert_(cnt(a) == cnt0_a + 5 + 3 * 5)
1002
+
1003
+ tmp = arr1.take([1, 2, 3], axis=0)
1004
+ assert_(cnt(a) == cnt0_a + 5 + 3)
1005
+
1006
+ x = np.array([[0], [1], [0], [1], [1]], int)
1007
+ tmp = x.choose(arr1, arr2)
1008
+ assert_(cnt(a) == cnt0_a + 5 + 2)
1009
+ assert_(cnt(b) == cnt0_b + 5 + 3)
1010
+
1011
+ def test_mem_custom_float_to_array(self):
1012
+ # Ticket 702
1013
+ class MyFloat:
1014
+ def __float__(self):
1015
+ return 1.0
1016
+
1017
+ tmp = np.atleast_1d([MyFloat()])
1018
+ tmp.astype(float) # Should succeed
1019
+
1020
+ def test_object_array_refcount_self_assign(self):
1021
+ # Ticket #711
1022
+ class VictimObject:
1023
+ deleted = False
1024
+
1025
+ def __del__(self):
1026
+ self.deleted = True
1027
+
1028
+ d = VictimObject()
1029
+ arr = np.zeros(5, dtype=np.object_)
1030
+ arr[:] = d
1031
+ del d
1032
+ arr[:] = arr # refcount of 'd' might hit zero here
1033
+ assert_(not arr[0].deleted)
1034
+ arr[:] = arr # trying to induce a segfault by doing it again...
1035
+ assert_(not arr[0].deleted)
1036
+
1037
+ def test_mem_fromiter_invalid_dtype_string(self):
1038
+ x = [1, 2, 3]
1039
+ assert_raises(ValueError,
1040
+ np.fromiter, list(x), dtype='S')
1041
+
1042
+ def test_reduce_big_object_array(self):
1043
+ # Ticket #713
1044
+ oldsize = np.setbufsize(10 * 16)
1045
+ a = np.array([None] * 161, object)
1046
+ assert_(not np.any(a))
1047
+ np.setbufsize(oldsize)
1048
+
1049
+ def test_mem_0d_array_index(self):
1050
+ # Ticket #714
1051
+ np.zeros(10)[np.array(0)]
1052
+
1053
+ def test_nonnative_endian_fill(self):
1054
+ # Non-native endian arrays were incorrectly filled with scalars
1055
+ # before r5034.
1056
+ if sys.byteorder == 'little':
1057
+ dtype = np.dtype('>i4')
1058
+ else:
1059
+ dtype = np.dtype('<i4')
1060
+ x = np.empty([1], dtype=dtype)
1061
+ x.fill(1)
1062
+ assert_equal(x, np.array([1], dtype=dtype))
1063
+
1064
+ def test_dot_alignment_sse2(self):
1065
+ # Test for ticket #551, changeset r5140
1066
+ x = np.zeros((30, 40))
1067
+ for proto in range(2, pickle.HIGHEST_PROTOCOL + 1):
1068
+ y = pickle.loads(pickle.dumps(x, protocol=proto))
1069
+ # y is now typically not aligned on a 8-byte boundary
1070
+ z = np.ones((1, y.shape[0]))
1071
+ # This shouldn't cause a segmentation fault:
1072
+ np.dot(z, y)
1073
+
1074
+ @pytest.mark.filterwarnings(
1075
+ "ignore:.*align should be passed:numpy.exceptions.VisibleDeprecationWarning")
1076
+ def test_astype_copy(self):
1077
+ # Ticket #788, changeset r5155
1078
+ # The test data file was generated by scipy.io.savemat.
1079
+ # The dtype is float64, but the isbuiltin attribute is 0.
1080
+ data_dir = path.join(path.dirname(__file__), 'data')
1081
+ filename = path.join(data_dir, "astype_copy.pkl")
1082
+ with open(filename, 'rb') as f:
1083
+ xp = pickle.load(f, encoding='latin1')
1084
+ xpd = xp.astype(np.float64)
1085
+ assert_(xp.__array_interface__['data'][0] !=
1086
+ xpd.__array_interface__['data'][0])
1087
+
1088
+ def test_compress_small_type(self):
1089
+ # Ticket #789, changeset 5217.
1090
+ # compress with out argument segfaulted if cannot cast safely
1091
+ import numpy as np
1092
+ a = np.array([[1, 2], [3, 4]])
1093
+ b = np.zeros((2, 1), dtype=np.single)
1094
+ try:
1095
+ a.compress([True, False], axis=1, out=b)
1096
+ raise AssertionError("compress with an out which cannot be "
1097
+ "safely casted should not return "
1098
+ "successfully")
1099
+ except TypeError:
1100
+ pass
1101
+
1102
+ def test_attributes(self):
1103
+ # Ticket #791
1104
+ class TestArray(np.ndarray):
1105
+ def __new__(cls, data, info):
1106
+ result = np.array(data)
1107
+ result = result.view(cls)
1108
+ result.info = info
1109
+ return result
1110
+
1111
+ def __array_finalize__(self, obj):
1112
+ self.info = getattr(obj, 'info', '')
1113
+
1114
+ dat = TestArray([[1, 2, 3, 4], [5, 6, 7, 8]], 'jubba')
1115
+ assert_(dat.info == 'jubba')
1116
+ dat.resize((4, 2))
1117
+ assert_(dat.info == 'jubba')
1118
+ dat.sort()
1119
+ assert_(dat.info == 'jubba')
1120
+ dat.fill(2)
1121
+ assert_(dat.info == 'jubba')
1122
+ dat.put([2, 3, 4], [6, 3, 4])
1123
+ assert_(dat.info == 'jubba')
1124
+ dat.setfield(4, np.int32, 0)
1125
+ assert_(dat.info == 'jubba')
1126
+ dat.setflags()
1127
+ assert_(dat.info == 'jubba')
1128
+ assert_(dat.all(1).info == 'jubba')
1129
+ assert_(dat.any(1).info == 'jubba')
1130
+ assert_(dat.argmax(1).info == 'jubba')
1131
+ assert_(dat.argmin(1).info == 'jubba')
1132
+ assert_(dat.argsort(1).info == 'jubba')
1133
+ assert_(dat.astype(TestArray).info == 'jubba')
1134
+ assert_(dat.byteswap().info == 'jubba')
1135
+ assert_(dat.clip(2, 7).info == 'jubba')
1136
+ assert_(dat.compress([0, 1, 1]).info == 'jubba')
1137
+ assert_(dat.conj().info == 'jubba')
1138
+ assert_(dat.conjugate().info == 'jubba')
1139
+ assert_(dat.copy().info == 'jubba')
1140
+ dat2 = TestArray([2, 3, 1, 0], 'jubba')
1141
+ choices = [[0, 1, 2, 3], [10, 11, 12, 13],
1142
+ [20, 21, 22, 23], [30, 31, 32, 33]]
1143
+ assert_(dat2.choose(choices).info == 'jubba')
1144
+ assert_(dat.cumprod(1).info == 'jubba')
1145
+ assert_(dat.cumsum(1).info == 'jubba')
1146
+ assert_(dat.diagonal().info == 'jubba')
1147
+ assert_(dat.flatten().info == 'jubba')
1148
+ assert_(dat.getfield(np.int32, 0).info == 'jubba')
1149
+ assert_(dat.imag.info == 'jubba')
1150
+ assert_(dat.max(1).info == 'jubba')
1151
+ assert_(dat.mean(1).info == 'jubba')
1152
+ assert_(dat.min(1).info == 'jubba')
1153
+ assert_(dat.prod(1).info == 'jubba')
1154
+ assert_(dat.ravel().info == 'jubba')
1155
+ assert_(dat.real.info == 'jubba')
1156
+ assert_(dat.repeat(2).info == 'jubba')
1157
+ assert_(dat.reshape((2, 4)).info == 'jubba')
1158
+ assert_(dat.round().info == 'jubba')
1159
+ assert_(dat.squeeze().info == 'jubba')
1160
+ assert_(dat.std(1).info == 'jubba')
1161
+ assert_(dat.sum(1).info == 'jubba')
1162
+ assert_(dat.swapaxes(0, 1).info == 'jubba')
1163
+ assert_(dat.take([2, 3, 5]).info == 'jubba')
1164
+ assert_(dat.transpose().info == 'jubba')
1165
+ assert_(dat.T.info == 'jubba')
1166
+ assert_(dat.var(1).info == 'jubba')
1167
+ assert_(dat.view(TestArray).info == 'jubba')
1168
+ # These methods do not preserve subclasses
1169
+ assert_(type(dat.nonzero()[0]) is np.ndarray)
1170
+ assert_(type(dat.nonzero()[1]) is np.ndarray)
1171
+
1172
+ def test_recarray_tolist(self):
1173
+ # Ticket #793, changeset r5215
1174
+ # Comparisons fail for NaN, so we can't use random memory
1175
+ # for the test.
1176
+ buf = np.zeros(40, dtype=np.int8)
1177
+ a = np.recarray(2, formats="i4,f8,f8", names="id,x,y", buf=buf)
1178
+ b = a.tolist()
1179
+ assert_(a[0].tolist() == b[0])
1180
+ assert_(a[1].tolist() == b[1])
1181
+
1182
+ def test_nonscalar_item_method(self):
1183
+ # Make sure that .item() fails graciously when it should
1184
+ a = np.arange(5)
1185
+ assert_raises(ValueError, a.item)
1186
+
1187
+ def test_char_array_creation(self):
1188
+ a = np.array('123', dtype='c')
1189
+ b = np.array([b'1', b'2', b'3'])
1190
+ assert_equal(a, b)
1191
+
1192
+ def test_unaligned_unicode_access(self):
1193
+ # Ticket #825
1194
+ for i in range(1, 9):
1195
+ msg = 'unicode offset: %d chars' % i
1196
+ t = np.dtype([('a', 'S%d' % i), ('b', 'U2')])
1197
+ x = np.array([(b'a', 'b')], dtype=t)
1198
+ assert_equal(str(x), "[(b'a', 'b')]", err_msg=msg)
1199
+
1200
+ def test_sign_for_complex_nan(self):
1201
+ # Ticket 794.
1202
+ with np.errstate(invalid='ignore'):
1203
+ C = np.array([-np.inf, -3 + 4j, 0, 4 - 3j, np.inf, np.nan])
1204
+ have = np.sign(C)
1205
+ want = np.array([-1 + 0j, -0.6 + 0.8j, 0 + 0j, 0.8 - 0.6j, 1 + 0j,
1206
+ complex(np.nan, np.nan)])
1207
+ assert_equal(have, want)
1208
+
1209
+ def test_for_equal_names(self):
1210
+ # Ticket #674
1211
+ dt = np.dtype([('foo', float), ('bar', float)])
1212
+ a = np.zeros(10, dt)
1213
+ b = list(a.dtype.names)
1214
+ b[0] = "notfoo"
1215
+ a.dtype.names = b
1216
+ assert_(a.dtype.names[0] == "notfoo")
1217
+ assert_(a.dtype.names[1] == "bar")
1218
+
1219
+ def test_for_object_scalar_creation(self):
1220
+ # Ticket #816
1221
+ a = np.object_()
1222
+ b = np.object_(3)
1223
+ b2 = np.object_(3.0)
1224
+ c = np.object_([4, 5])
1225
+ d = np.object_([None, {}, []])
1226
+ assert_(a is None)
1227
+ assert_(type(b) is int)
1228
+ assert_(type(b2) is float)
1229
+ assert_(type(c) is np.ndarray)
1230
+ assert_(c.dtype == object)
1231
+ assert_(d.dtype == object)
1232
+
1233
+ def test_array_resize_method_system_error(self):
1234
+ # Ticket #840 - order should be an invalid keyword.
1235
+ x = np.array([[0, 1], [2, 3]])
1236
+ assert_raises(TypeError, x.resize, (2, 2), order='C')
1237
+
1238
+ def test_for_zero_length_in_choose(self):
1239
+ "Ticket #882"
1240
+ a = np.array(1)
1241
+ assert_raises(ValueError, lambda x: x.choose([]), a)
1242
+
1243
+ def test_array_ndmin_overflow(self):
1244
+ "Ticket #947."
1245
+ assert_raises(ValueError, lambda: np.array([1], ndmin=65))
1246
+
1247
+ def test_void_scalar_with_titles(self):
1248
+ # No ticket
1249
+ data = [('john', 4), ('mary', 5)]
1250
+ dtype1 = [(('source:yy', 'name'), 'O'), (('source:xx', 'id'), int)]
1251
+ arr = np.array(data, dtype=dtype1)
1252
+ assert_(arr[0][0] == 'john')
1253
+ assert_(arr[0][1] == 4)
1254
+
1255
+ def test_void_scalar_constructor(self):
1256
+ # Issue #1550
1257
+
1258
+ # Create test string data, construct void scalar from data and assert
1259
+ # that void scalar contains original data.
1260
+ test_string = np.array("test")
1261
+ test_string_void_scalar = np._core.multiarray.scalar(
1262
+ np.dtype(("V", test_string.dtype.itemsize)), test_string.tobytes())
1263
+
1264
+ assert_(test_string_void_scalar.view(test_string.dtype) == test_string)
1265
+
1266
+ # Create record scalar, construct from data and assert that
1267
+ # reconstructed scalar is correct.
1268
+ test_record = np.ones((), "i,i")
1269
+ test_record_void_scalar = np._core.multiarray.scalar(
1270
+ test_record.dtype, test_record.tobytes())
1271
+
1272
+ assert_(test_record_void_scalar == test_record)
1273
+
1274
+ # Test pickle and unpickle of void and record scalars
1275
+ for proto in range(2, pickle.HIGHEST_PROTOCOL + 1):
1276
+ assert_(pickle.loads(
1277
+ pickle.dumps(test_string, protocol=proto)) == test_string)
1278
+ assert_(pickle.loads(
1279
+ pickle.dumps(test_record, protocol=proto)) == test_record)
1280
+
1281
+ @_no_tracing
1282
+ def test_blasdot_uninitialized_memory(self):
1283
+ # Ticket #950
1284
+ for m in [0, 1, 2]:
1285
+ for n in [0, 1, 2]:
1286
+ for k in range(3):
1287
+ # Try to ensure that x->data contains non-zero floats
1288
+ x = np.array([123456789e199], dtype=np.float64)
1289
+ if IS_PYPY:
1290
+ x.resize((m, 0), refcheck=False)
1291
+ else:
1292
+ x.resize((m, 0))
1293
+ y = np.array([123456789e199], dtype=np.float64)
1294
+ if IS_PYPY:
1295
+ y.resize((0, n), refcheck=False)
1296
+ else:
1297
+ y.resize((0, n))
1298
+
1299
+ # `dot` should just return zero (m, n) matrix
1300
+ z = np.dot(x, y)
1301
+ assert_(np.all(z == 0))
1302
+ assert_(z.shape == (m, n))
1303
+
1304
+ def test_zeros(self):
1305
+ # Regression test for #1061.
1306
+ # Set a size which cannot fit into a 64 bits signed integer
1307
+ sz = 2 ** 64
1308
+ with assert_raises_regex(ValueError,
1309
+ 'Maximum allowed dimension exceeded'):
1310
+ np.empty(sz)
1311
+
1312
+ def test_huge_arange(self):
1313
+ # Regression test for #1062.
1314
+ # Set a size which cannot fit into a 64 bits signed integer
1315
+ sz = 2 ** 64
1316
+ with assert_raises_regex(ValueError,
1317
+ 'Maximum allowed size exceeded'):
1318
+ np.arange(sz)
1319
+ assert_(np.size == sz)
1320
+
1321
+ def test_fromiter_bytes(self):
1322
+ # Ticket #1058
1323
+ a = np.fromiter(list(range(10)), dtype='b')
1324
+ b = np.fromiter(list(range(10)), dtype='B')
1325
+ assert_(np.all(a == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))
1326
+ assert_(np.all(b == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))
1327
+
1328
+ def test_array_from_sequence_scalar_array(self):
1329
+ # Ticket #1078: segfaults when creating an array with a sequence of
1330
+ # 0d arrays.
1331
+ a = np.array((np.ones(2), np.array(2)), dtype=object)
1332
+ assert_equal(a.shape, (2,))
1333
+ assert_equal(a.dtype, np.dtype(object))
1334
+ assert_equal(a[0], np.ones(2))
1335
+ assert_equal(a[1], np.array(2))
1336
+
1337
+ a = np.array(((1,), np.array(1)), dtype=object)
1338
+ assert_equal(a.shape, (2,))
1339
+ assert_equal(a.dtype, np.dtype(object))
1340
+ assert_equal(a[0], (1,))
1341
+ assert_equal(a[1], np.array(1))
1342
+
1343
+ def test_array_from_sequence_scalar_array2(self):
1344
+ # Ticket #1081: weird array with strange input...
1345
+ t = np.array([np.array([]), np.array(0, object)], dtype=object)
1346
+ assert_equal(t.shape, (2,))
1347
+ assert_equal(t.dtype, np.dtype(object))
1348
+
1349
+ def test_array_too_big(self):
1350
+ # Ticket #1080.
1351
+ assert_raises(ValueError, np.zeros, [975] * 7, np.int8)
1352
+ assert_raises(ValueError, np.zeros, [26244] * 5, np.int8)
1353
+
1354
+ def test_dtype_keyerrors_(self):
1355
+ # Ticket #1106.
1356
+ dt = np.dtype([('f1', np.uint)])
1357
+ assert_raises(KeyError, dt.__getitem__, "f2")
1358
+ assert_raises(IndexError, dt.__getitem__, 1)
1359
+ assert_raises(TypeError, dt.__getitem__, 0.0)
1360
+
1361
+ def test_lexsort_buffer_length(self):
1362
+ # Ticket #1217, don't segfault.
1363
+ a = np.ones(100, dtype=np.int8)
1364
+ b = np.ones(100, dtype=np.int32)
1365
+ i = np.lexsort((a[::-1], b))
1366
+ assert_equal(i, np.arange(100, dtype=int))
1367
+
1368
+ def test_object_array_to_fixed_string(self):
1369
+ # Ticket #1235.
1370
+ a = np.array(['abcdefgh', 'ijklmnop'], dtype=np.object_)
1371
+ b = np.array(a, dtype=(np.str_, 8))
1372
+ assert_equal(a, b)
1373
+ c = np.array(a, dtype=(np.str_, 5))
1374
+ assert_equal(c, np.array(['abcde', 'ijklm']))
1375
+ d = np.array(a, dtype=(np.str_, 12))
1376
+ assert_equal(a, d)
1377
+ e = np.empty((2, ), dtype=(np.str_, 8))
1378
+ e[:] = a[:]
1379
+ assert_equal(a, e)
1380
+
1381
+ def test_unicode_to_string_cast(self):
1382
+ # Ticket #1240.
1383
+ a = np.array([['abc', '\u03a3'],
1384
+ ['asdf', 'erw']],
1385
+ dtype='U')
1386
+ assert_raises(UnicodeEncodeError, np.array, a, 'S4')
1387
+
1388
+ def test_unicode_to_string_cast_error(self):
1389
+ # gh-15790
1390
+ a = np.array(['\x80'] * 129, dtype='U3')
1391
+ assert_raises(UnicodeEncodeError, np.array, a, 'S')
1392
+ b = a.reshape(3, 43)[:-1, :-1]
1393
+ assert_raises(UnicodeEncodeError, np.array, b, 'S')
1394
+
1395
+ def test_mixed_string_byte_array_creation(self):
1396
+ a = np.array(['1234', b'123'])
1397
+ assert_(a.itemsize == 16)
1398
+ a = np.array([b'123', '1234'])
1399
+ assert_(a.itemsize == 16)
1400
+ a = np.array(['1234', b'123', '12345'])
1401
+ assert_(a.itemsize == 20)
1402
+ a = np.array([b'123', '1234', b'12345'])
1403
+ assert_(a.itemsize == 20)
1404
+ a = np.array([b'123', '1234', b'1234'])
1405
+ assert_(a.itemsize == 16)
1406
+
1407
+ def test_misaligned_objects_segfault(self):
1408
+ # Ticket #1198 and #1267
1409
+ a1 = np.zeros((10,), dtype='O,c')
1410
+ a2 = np.array(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'], 'S10')
1411
+ a1['f0'] = a2
1412
+ repr(a1)
1413
+ np.argmax(a1['f0'])
1414
+ a1['f0'][1] = "FOO"
1415
+ a1['f0'] = "FOO"
1416
+ np.array(a1['f0'], dtype='S')
1417
+ np.nonzero(a1['f0'])
1418
+ a1.sort()
1419
+ copy.deepcopy(a1)
1420
+
1421
+ def test_misaligned_scalars_segfault(self):
1422
+ # Ticket #1267
1423
+ s1 = np.array(('a', 'Foo'), dtype='c,O')
1424
+ s2 = np.array(('b', 'Bar'), dtype='c,O')
1425
+ s1['f1'] = s2['f1']
1426
+ s1['f1'] = 'Baz'
1427
+
1428
+ def test_misaligned_dot_product_objects(self):
1429
+ # Ticket #1267
1430
+ # This didn't require a fix, but it's worth testing anyway, because
1431
+ # it may fail if .dot stops enforcing the arrays to be BEHAVED
1432
+ a = np.array([[(1, 'a'), (0, 'a')], [(0, 'a'), (1, 'a')]], dtype='O,c')
1433
+ b = np.array([[(4, 'a'), (1, 'a')], [(2, 'a'), (2, 'a')]], dtype='O,c')
1434
+ np.dot(a['f0'], b['f0'])
1435
+
1436
+ def test_byteswap_complex_scalar(self):
1437
+ # Ticket #1259 and gh-441
1438
+ for dtype in [np.dtype('<' + t) for t in np.typecodes['Complex']]:
1439
+ z = np.array([2.2 - 1.1j], dtype)
1440
+ x = z[0] # always native-endian
1441
+ y = x.byteswap()
1442
+ if x.dtype.byteorder == z.dtype.byteorder:
1443
+ # little-endian machine
1444
+ assert_equal(x, np.frombuffer(y.tobytes(), dtype=dtype.newbyteorder()))
1445
+ else:
1446
+ # big-endian machine
1447
+ assert_equal(x, np.frombuffer(y.tobytes(), dtype=dtype))
1448
+ # double check real and imaginary parts:
1449
+ assert_equal(x.real, y.real.byteswap())
1450
+ assert_equal(x.imag, y.imag.byteswap())
1451
+
1452
+ def test_structured_arrays_with_objects1(self):
1453
+ # Ticket #1299
1454
+ stra = 'aaaa'
1455
+ strb = 'bbbb'
1456
+ x = np.array([[(0, stra), (1, strb)]], 'i8,O')
1457
+ x[x.nonzero()] = x.ravel()[:1]
1458
+ assert_(x[0, 1] == x[0, 0])
1459
+
1460
+ @pytest.mark.skipif(
1461
+ sys.version_info >= (3, 12),
1462
+ reason="Python 3.12 has immortal refcounts, this test no longer works."
1463
+ )
1464
+ @pytest.mark.skipif(not HAS_REFCOUNT, reason="Python lacks refcounts")
1465
+ def test_structured_arrays_with_objects2(self):
1466
+ # Ticket #1299 second test
1467
+ stra = 'aaaa'
1468
+ strb = 'bbbb'
1469
+ numb = sys.getrefcount(strb)
1470
+ numa = sys.getrefcount(stra)
1471
+ x = np.array([[(0, stra), (1, strb)]], 'i8,O')
1472
+ x[x.nonzero()] = x.ravel()[:1]
1473
+ assert_(sys.getrefcount(strb) == numb)
1474
+ assert_(sys.getrefcount(stra) == numa + 2)
1475
+
1476
+ def test_duplicate_title_and_name(self):
1477
+ # Ticket #1254
1478
+ dtspec = [(('a', 'a'), 'i'), ('b', 'i')]
1479
+ assert_raises(ValueError, np.dtype, dtspec)
1480
+
1481
+ def test_signed_integer_division_overflow(self):
1482
+ # Ticket #1317.
1483
+ def test_type(t):
1484
+ min = np.array([np.iinfo(t).min])
1485
+ min //= -1
1486
+
1487
+ with np.errstate(over="ignore"):
1488
+ for t in (np.int8, np.int16, np.int32, np.int64, int):
1489
+ test_type(t)
1490
+
1491
+ def test_buffer_hashlib(self):
1492
+ from hashlib import sha256
1493
+
1494
+ x = np.array([1, 2, 3], dtype=np.dtype('<i4'))
1495
+ assert_equal(
1496
+ sha256(x).hexdigest(),
1497
+ '4636993d3e1da4e9d6b8f87b79e8f7c6d018580d52661950eabc3845c5897a4d'
1498
+ )
1499
+
1500
+ def test_0d_string_scalar(self):
1501
+ # Bug #1436; the following should succeed
1502
+ np.asarray('x', '>c')
1503
+
1504
+ def test_log1p_compiler_shenanigans(self):
1505
+ # Check if log1p is behaving on 32 bit intel systems.
1506
+ assert_(np.isfinite(np.log1p(np.exp2(-53))))
1507
+
1508
+ def test_fromiter_comparison(self):
1509
+ a = np.fromiter(list(range(10)), dtype='b')
1510
+ b = np.fromiter(list(range(10)), dtype='B')
1511
+ assert_(np.all(a == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))
1512
+ assert_(np.all(b == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))
1513
+
1514
+ def test_fromstring_crash(self):
1515
+ with assert_raises(ValueError):
1516
+ np.fromstring(b'aa, aa, 1.0', sep=',')
1517
+
1518
+ def test_ticket_1539(self):
1519
+ dtypes = [x for x in np._core.sctypeDict.values()
1520
+ if (issubclass(x, np.number)
1521
+ and not issubclass(x, np.timedelta64))]
1522
+ a = np.array([], np.bool) # not x[0] because it is unordered
1523
+ failures = []
1524
+
1525
+ for x in dtypes:
1526
+ b = a.astype(x)
1527
+ for y in dtypes:
1528
+ c = a.astype(y)
1529
+ try:
1530
+ d = np.dot(b, c)
1531
+ except TypeError:
1532
+ failures.append((x, y))
1533
+ else:
1534
+ if d != 0:
1535
+ failures.append((x, y))
1536
+ if failures:
1537
+ raise AssertionError(f"Failures: {failures!r}")
1538
+
1539
+ def test_ticket_1538(self):
1540
+ x = np.finfo(np.float32)
1541
+ for name in ('eps', 'epsneg', 'max', 'min', 'resolution', 'tiny'):
1542
+ assert_equal(type(getattr(x, name)), np.float32,
1543
+ err_msg=name)
1544
+
1545
+ def test_ticket_1434(self):
1546
+ # Check that the out= argument in var and std has an effect
1547
+ data = np.array(((1, 2, 3), (4, 5, 6), (7, 8, 9)))
1548
+ out = np.zeros((3,))
1549
+
1550
+ ret = data.var(axis=1, out=out)
1551
+ assert_(ret is out)
1552
+ assert_array_equal(ret, data.var(axis=1))
1553
+
1554
+ ret = data.std(axis=1, out=out)
1555
+ assert_(ret is out)
1556
+ assert_array_equal(ret, data.std(axis=1))
1557
+
1558
+ def test_complex_nan_maximum(self):
1559
+ cnan = complex(0, np.nan)
1560
+ assert_equal(np.maximum(1, cnan), cnan)
1561
+
1562
+ def test_subclass_int_tuple_assignment(self):
1563
+ # ticket #1563
1564
+ class Subclass(np.ndarray):
1565
+ def __new__(cls, i):
1566
+ return np.ones((i,)).view(cls)
1567
+
1568
+ x = Subclass(5)
1569
+ x[(0,)] = 2 # shouldn't raise an exception
1570
+ assert_equal(x[0], 2)
1571
+
1572
+ def test_ufunc_no_unnecessary_views(self):
1573
+ # ticket #1548
1574
+ class Subclass(np.ndarray):
1575
+ pass
1576
+ x = np.array([1, 2, 3]).view(Subclass)
1577
+ y = np.add(x, x, x)
1578
+ assert_equal(id(x), id(y))
1579
+
1580
+ @pytest.mark.skipif(not HAS_REFCOUNT, reason="Python lacks refcounts")
1581
+ def test_take_refcount(self):
1582
+ # ticket #939
1583
+ a = np.arange(16, dtype=float)
1584
+ a.shape = (4, 4)
1585
+ lut = np.ones((5 + 3, 4), float)
1586
+ rgba = np.empty(shape=a.shape + (4,), dtype=lut.dtype)
1587
+ c1 = sys.getrefcount(rgba)
1588
+ try:
1589
+ lut.take(a, axis=0, mode='clip', out=rgba)
1590
+ except TypeError:
1591
+ pass
1592
+ c2 = sys.getrefcount(rgba)
1593
+ assert_equal(c1, c2)
1594
+
1595
+ def test_fromfile_tofile_seeks(self):
1596
+ # tofile/fromfile used to get (#1610) the Python file handle out of sync
1597
+ with tempfile.NamedTemporaryFile() as f:
1598
+ f.write(np.arange(255, dtype='u1').tobytes())
1599
+
1600
+ f.seek(20)
1601
+ ret = np.fromfile(f, count=4, dtype='u1')
1602
+ assert_equal(ret, np.array([20, 21, 22, 23], dtype='u1'))
1603
+ assert_equal(f.tell(), 24)
1604
+
1605
+ f.seek(40)
1606
+ np.array([1, 2, 3], dtype='u1').tofile(f)
1607
+ assert_equal(f.tell(), 43)
1608
+
1609
+ f.seek(40)
1610
+ data = f.read(3)
1611
+ assert_equal(data, b"\x01\x02\x03")
1612
+
1613
+ f.seek(80)
1614
+ f.read(4)
1615
+ data = np.fromfile(f, dtype='u1', count=4)
1616
+ assert_equal(data, np.array([84, 85, 86, 87], dtype='u1'))
1617
+
1618
+ def test_complex_scalar_warning(self):
1619
+ for tp in [np.csingle, np.cdouble, np.clongdouble]:
1620
+ x = tp(1 + 2j)
1621
+ pytest.warns(ComplexWarning, float, x)
1622
+ with warnings.catch_warnings():
1623
+ warnings.simplefilter('ignore', ComplexWarning)
1624
+ assert_equal(float(x), float(x.real))
1625
+
1626
+ def test_complex_scalar_complex_cast(self):
1627
+ for tp in [np.csingle, np.cdouble, np.clongdouble]:
1628
+ x = tp(1 + 2j)
1629
+ assert_equal(complex(x), 1 + 2j)
1630
+
1631
+ def test_complex_boolean_cast(self):
1632
+ # Ticket #2218
1633
+ for tp in [np.csingle, np.cdouble, np.clongdouble]:
1634
+ x = np.array([0, 0 + 0.5j, 0.5 + 0j], dtype=tp)
1635
+ assert_equal(x.astype(bool), np.array([0, 1, 1], dtype=bool))
1636
+ assert_(np.any(x))
1637
+ assert_(np.all(x[1:]))
1638
+
1639
+ def test_uint_int_conversion(self):
1640
+ x = 2**64 - 1
1641
+ assert_equal(int(np.uint64(x)), x)
1642
+
1643
+ def test_duplicate_field_names_assign(self):
1644
+ ra = np.fromiter(((i * 3, i * 2) for i in range(10)), dtype='i8,f8')
1645
+ ra.dtype.names = ('f1', 'f2')
1646
+ repr(ra) # should not cause a segmentation fault
1647
+ assert_raises(ValueError, setattr, ra.dtype, 'names', ('f1', 'f1'))
1648
+
1649
+ def test_eq_string_and_object_array(self):
1650
+ # From e-mail thread "__eq__ with str and object" (Keith Goodman)
1651
+ a1 = np.array(['a', 'b'], dtype=object)
1652
+ a2 = np.array(['a', 'c'])
1653
+ assert_array_equal(a1 == a2, [True, False])
1654
+ assert_array_equal(a2 == a1, [True, False])
1655
+
1656
+ def test_nonzero_byteswap(self):
1657
+ a = np.array([0x80000000, 0x00000080, 0], dtype=np.uint32)
1658
+ a = a.view(np.float32)
1659
+ assert_equal(a.nonzero()[0], [1])
1660
+ a = a.byteswap()
1661
+ a = a.view(a.dtype.newbyteorder())
1662
+ assert_equal(a.nonzero()[0], [1]) # [0] if nonzero() ignores swap
1663
+
1664
+ def test_empty_mul(self):
1665
+ a = np.array([1.])
1666
+ a[1:1] *= 2
1667
+ assert_equal(a, [1.])
1668
+
1669
+ def test_array_side_effect(self):
1670
+ # The second use of itemsize was throwing an exception because in
1671
+ # ctors.c, discover_itemsize was calling PyObject_Length without
1672
+ # checking the return code. This failed to get the length of the
1673
+ # number 2, and the exception hung around until something checked
1674
+ # PyErr_Occurred() and returned an error.
1675
+ assert_equal(np.dtype('S10').itemsize, 10)
1676
+ np.array([['abc', 2], ['long ', '0123456789']], dtype=np.bytes_)
1677
+ assert_equal(np.dtype('S10').itemsize, 10)
1678
+
1679
+ def test_any_float(self):
1680
+ # all and any for floats
1681
+ a = np.array([0.1, 0.9])
1682
+ assert_(np.any(a))
1683
+ assert_(np.all(a))
1684
+
1685
+ def test_large_float_sum(self):
1686
+ a = np.arange(10000, dtype='f')
1687
+ assert_equal(a.sum(dtype='d'), a.astype('d').sum())
1688
+
1689
+ def test_ufunc_casting_out(self):
1690
+ a = np.array(1.0, dtype=np.float32)
1691
+ b = np.array(1.0, dtype=np.float64)
1692
+ c = np.array(1.0, dtype=np.float32)
1693
+ np.add(a, b, out=c)
1694
+ assert_equal(c, 2.0)
1695
+
1696
+ def test_array_scalar_contiguous(self):
1697
+ # Array scalars are both C and Fortran contiguous
1698
+ assert_(np.array(1.0).flags.c_contiguous)
1699
+ assert_(np.array(1.0).flags.f_contiguous)
1700
+ assert_(np.array(np.float32(1.0)).flags.c_contiguous)
1701
+ assert_(np.array(np.float32(1.0)).flags.f_contiguous)
1702
+
1703
+ def test_squeeze_contiguous(self):
1704
+ # Similar to GitHub issue #387
1705
+ a = np.zeros((1, 2)).squeeze()
1706
+ b = np.zeros((2, 2, 2), order='F')[:, :, ::2].squeeze()
1707
+ assert_(a.flags.c_contiguous)
1708
+ assert_(a.flags.f_contiguous)
1709
+ assert_(b.flags.f_contiguous)
1710
+
1711
+ def test_squeeze_axis_handling(self):
1712
+ # Issue #10779
1713
+ # Ensure proper handling of objects
1714
+ # that don't support axis specification
1715
+ # when squeezing
1716
+
1717
+ class OldSqueeze(np.ndarray):
1718
+
1719
+ def __new__(cls,
1720
+ input_array):
1721
+ obj = np.asarray(input_array).view(cls)
1722
+ return obj
1723
+
1724
+ # it is perfectly reasonable that prior
1725
+ # to numpy version 1.7.0 a subclass of ndarray
1726
+ # might have been created that did not expect
1727
+ # squeeze to have an axis argument
1728
+ # NOTE: this example is somewhat artificial;
1729
+ # it is designed to simulate an old API
1730
+ # expectation to guard against regression
1731
+ def squeeze(self):
1732
+ return super().squeeze()
1733
+
1734
+ oldsqueeze = OldSqueeze(np.array([[1], [2], [3]]))
1735
+
1736
+ # if no axis argument is specified the old API
1737
+ # expectation should give the correct result
1738
+ assert_equal(np.squeeze(oldsqueeze),
1739
+ np.array([1, 2, 3]))
1740
+
1741
+ # likewise, axis=None should work perfectly well
1742
+ # with the old API expectation
1743
+ assert_equal(np.squeeze(oldsqueeze, axis=None),
1744
+ np.array([1, 2, 3]))
1745
+
1746
+ # however, specification of any particular axis
1747
+ # should raise a TypeError in the context of the
1748
+ # old API specification, even when using a valid
1749
+ # axis specification like 1 for this array
1750
+ with assert_raises(TypeError):
1751
+ # this would silently succeed for array
1752
+ # subclasses / objects that did not support
1753
+ # squeeze axis argument handling before fixing
1754
+ # Issue #10779
1755
+ np.squeeze(oldsqueeze, axis=1)
1756
+
1757
+ # check for the same behavior when using an invalid
1758
+ # axis specification -- in this case axis=0 does not
1759
+ # have size 1, but the priority should be to raise
1760
+ # a TypeError for the axis argument and NOT a
1761
+ # ValueError for squeezing a non-empty dimension
1762
+ with assert_raises(TypeError):
1763
+ np.squeeze(oldsqueeze, axis=0)
1764
+
1765
+ # the new API knows how to handle the axis
1766
+ # argument and will return a ValueError if
1767
+ # attempting to squeeze an axis that is not
1768
+ # of length 1
1769
+ with assert_raises(ValueError):
1770
+ np.squeeze(np.array([[1], [2], [3]]), axis=0)
1771
+
1772
+ def test_reduce_contiguous(self):
1773
+ # GitHub issue #387
1774
+ a = np.add.reduce(np.zeros((2, 1, 2)), (0, 1))
1775
+ b = np.add.reduce(np.zeros((2, 1, 2)), 1)
1776
+ assert_(a.flags.c_contiguous)
1777
+ assert_(a.flags.f_contiguous)
1778
+ assert_(b.flags.c_contiguous)
1779
+
1780
+ @pytest.mark.skipif(IS_PYSTON, reason="Pyston disables recursion checking")
1781
+ @pytest.mark.skipif(IS_WASM, reason="Pyodide/WASM has limited stack size")
1782
+ def test_object_array_self_reference(self):
1783
+ # Object arrays with references to themselves can cause problems
1784
+ a = np.array(0, dtype=object)
1785
+ a[()] = a
1786
+ assert_raises(RecursionError, int, a)
1787
+ assert_raises(RecursionError, float, a)
1788
+ a[()] = None
1789
+
1790
+ @pytest.mark.skipif(IS_PYSTON, reason="Pyston disables recursion checking")
1791
+ @pytest.mark.skipif(IS_WASM, reason="Pyodide/WASM has limited stack size")
1792
+ def test_object_array_circular_reference(self):
1793
+ # Test the same for a circular reference.
1794
+ a = np.array(0, dtype=object)
1795
+ b = np.array(0, dtype=object)
1796
+ a[()] = b
1797
+ b[()] = a
1798
+ assert_raises(RecursionError, int, a)
1799
+ # NumPy has no tp_traverse currently, so circular references
1800
+ # cannot be detected. So resolve it:
1801
+ a[()] = None
1802
+
1803
+ # This was causing a to become like the above
1804
+ a = np.array(0, dtype=object)
1805
+ a[...] += 1
1806
+ assert_equal(a, 1)
1807
+
1808
+ def test_object_array_nested(self):
1809
+ # but is fine with a reference to a different array
1810
+ a = np.array(0, dtype=object)
1811
+ b = np.array(0, dtype=object)
1812
+ a[()] = b
1813
+ assert_equal(int(a), int(0)) # noqa: UP018
1814
+ assert_equal(float(a), float(0))
1815
+
1816
+ def test_object_array_self_copy(self):
1817
+ # An object array being copied into itself DECREF'ed before INCREF'ing
1818
+ # causing segmentation faults (gh-3787)
1819
+ a = np.array(object(), dtype=object)
1820
+ np.copyto(a, a)
1821
+ if HAS_REFCOUNT:
1822
+ assert_(sys.getrefcount(a[()]) == 2)
1823
+ a[()].__class__ # will segfault if object was deleted
1824
+
1825
+ def test_zerosize_accumulate(self):
1826
+ "Ticket #1733"
1827
+ x = np.array([[42, 0]], dtype=np.uint32)
1828
+ assert_equal(np.add.accumulate(x[:-1, 0]), [])
1829
+
1830
+ def test_objectarray_setfield(self):
1831
+ # Setfield should not overwrite Object fields with non-Object data
1832
+ x = np.array([1, 2, 3], dtype=object)
1833
+ assert_raises(TypeError, x.setfield, 4, np.int32, 0)
1834
+
1835
+ def test_setting_rank0_string(self):
1836
+ "Ticket #1736"
1837
+ s1 = b"hello1"
1838
+ s2 = b"hello2"
1839
+ a = np.zeros((), dtype="S10")
1840
+ a[()] = s1
1841
+ assert_equal(a, np.array(s1))
1842
+ a[()] = np.array(s2)
1843
+ assert_equal(a, np.array(s2))
1844
+
1845
+ a = np.zeros((), dtype='f4')
1846
+ a[()] = 3
1847
+ assert_equal(a, np.array(3))
1848
+ a[()] = np.array(4)
1849
+ assert_equal(a, np.array(4))
1850
+
1851
+ def test_string_astype(self):
1852
+ "Ticket #1748"
1853
+ s1 = b'black'
1854
+ s2 = b'white'
1855
+ s3 = b'other'
1856
+ a = np.array([[s1], [s2], [s3]])
1857
+ assert_equal(a.dtype, np.dtype('S5'))
1858
+ b = a.astype(np.dtype('S0'))
1859
+ assert_equal(b.dtype, np.dtype('S5'))
1860
+
1861
+ def test_ticket_1756(self):
1862
+ # Ticket #1756
1863
+ s = b'0123456789abcdef'
1864
+ a = np.array([s] * 5)
1865
+ for i in range(1, 17):
1866
+ a1 = np.array(a, "|S%d" % i)
1867
+ a2 = np.array([s[:i]] * 5)
1868
+ assert_equal(a1, a2)
1869
+
1870
+ def test_fields_strides(self):
1871
+ "gh-2355"
1872
+ r = np.frombuffer(b'abcdefghijklmnop' * 4 * 3, dtype='i4,(2,3)u2')
1873
+ assert_equal(r[0:3:2]['f1'], r['f1'][0:3:2])
1874
+ assert_equal(r[0:3:2]['f1'][0], r[0:3:2][0]['f1'])
1875
+ assert_equal(r[0:3:2]['f1'][0][()], r[0:3:2][0]['f1'][()])
1876
+ assert_equal(r[0:3:2]['f1'][0].strides, r[0:3:2][0]['f1'].strides)
1877
+
1878
+ def test_alignment_update(self):
1879
+ # Check that alignment flag is updated on stride setting
1880
+ a = np.arange(10)
1881
+ assert_(a.flags.aligned)
1882
+ with pytest.warns(DeprecationWarning):
1883
+ a.strides = 3
1884
+ assert_(not a.flags.aligned)
1885
+
1886
+ def test_ticket_1770(self):
1887
+ "Should not segfault on python 3k"
1888
+ import numpy as np
1889
+ try:
1890
+ a = np.zeros((1,), dtype=[('f1', 'f')])
1891
+ a['f1'] = 1
1892
+ a['f2'] = 1
1893
+ except ValueError:
1894
+ pass
1895
+ except Exception:
1896
+ raise AssertionError
1897
+
1898
+ def test_ticket_1608(self):
1899
+ "x.flat shouldn't modify data"
1900
+ x = np.array([[1, 2], [3, 4]]).T
1901
+ np.array(x.flat)
1902
+ assert_equal(x, [[1, 3], [2, 4]])
1903
+
1904
+ def test_pickle_string_overwrite(self):
1905
+ import re
1906
+
1907
+ data = np.array([1], dtype='b')
1908
+ blob = pickle.dumps(data, protocol=1)
1909
+ data = pickle.loads(blob)
1910
+
1911
+ # Check that loads does not clobber interned strings
1912
+ s = re.sub(r"a(.)", "\x01\\1", "a_")
1913
+ assert_equal(s[0], "\x01")
1914
+ data[0] = 0x6a
1915
+ s = re.sub(r"a(.)", "\x01\\1", "a_")
1916
+ assert_equal(s[0], "\x01")
1917
+
1918
+ def test_pickle_bytes_overwrite(self):
1919
+ for proto in range(2, pickle.HIGHEST_PROTOCOL + 1):
1920
+ data = np.array([1], dtype='b')
1921
+ data = pickle.loads(pickle.dumps(data, protocol=proto))
1922
+ data[0] = 0x7d
1923
+ bytestring = "\x01 ".encode('ascii')
1924
+ assert_equal(bytestring[0:1], '\x01'.encode('ascii'))
1925
+
1926
+ @pytest.mark.filterwarnings(
1927
+ "ignore:.*align should be passed:numpy.exceptions.VisibleDeprecationWarning")
1928
+ def test_pickle_py2_array_latin1_hack(self):
1929
+ # Check that unpickling hacks in Py3 that support
1930
+ # encoding='latin1' work correctly.
1931
+
1932
+ # Python2 output for pickle.dumps(numpy.array([129], dtype='b'))
1933
+ data = b"cnumpy.core.multiarray\n_reconstruct\np0\n(cnumpy\nndarray\np1\n(I0\ntp2\nS'b'\np3\ntp4\nRp5\n(I1\n(I1\ntp6\ncnumpy\ndtype\np7\n(S'i1'\np8\nI0\nI1\ntp9\nRp10\n(I3\nS'|'\np11\nNNNI-1\nI-1\nI0\ntp12\nbI00\nS'\\x81'\np13\ntp14\nb."
1934
+ # This should work:
1935
+ result = pickle.loads(data, encoding='latin1')
1936
+ assert_array_equal(result, np.array([129]).astype('b'))
1937
+ # Should not segfault:
1938
+ assert_raises(Exception, pickle.loads, data, encoding='koi8-r')
1939
+
1940
+ @pytest.mark.filterwarnings(
1941
+ "ignore:.*align should be passed:numpy.exceptions.VisibleDeprecationWarning")
1942
+ def test_pickle_py2_scalar_latin1_hack(self):
1943
+ # Check that scalar unpickling hack in Py3 that supports
1944
+ # encoding='latin1' work correctly.
1945
+
1946
+ # Python2 output for pickle.dumps(...)
1947
+ datas = [
1948
+ # (original, python2_pickle, koi8r_validity)
1949
+ (np.str_('\u6bd2'),
1950
+ b"cnumpy.core.multiarray\nscalar\np0\n(cnumpy\ndtype\np1\n(S'U1'\np2\nI0\nI1\ntp3\nRp4\n(I3\nS'<'\np5\nNNNI4\nI4\nI0\ntp6\nbS'\\xd2k\\x00\\x00'\np7\ntp8\nRp9\n.",
1951
+ 'invalid'),
1952
+
1953
+ (np.float64(9e123),
1954
+ b"cnumpy.core.multiarray\nscalar\np0\n(cnumpy\ndtype\np1\n(S'f8'\np2\nI0\nI1\ntp3\nRp4\n(I3\nS'<'\np5\nNNNI-1\nI-1\nI0\ntp6\nbS'O\\x81\\xb7Z\\xaa:\\xabY'\np7\ntp8\nRp9\n.",
1955
+ 'invalid'),
1956
+
1957
+ # different 8-bit code point in KOI8-R vs latin1
1958
+ (np.bytes_(b'\x9c'),
1959
+ b"cnumpy.core.multiarray\nscalar\np0\n(cnumpy\ndtype\np1\n(S'S1'\np2\nI0\nI1\ntp3\nRp4\n(I3\nS'|'\np5\nNNNI1\nI1\nI0\ntp6\nbS'\\x9c'\np7\ntp8\nRp9\n.",
1960
+ 'different'),
1961
+ ]
1962
+ for original, data, koi8r_validity in datas:
1963
+ result = pickle.loads(data, encoding='latin1')
1964
+ assert_equal(result, original)
1965
+
1966
+ # Decoding under non-latin1 encoding (e.g.) KOI8-R can
1967
+ # produce bad results, but should not segfault.
1968
+ if koi8r_validity == 'different':
1969
+ # Unicode code points happen to lie within latin1,
1970
+ # but are different in koi8-r, resulting to silent
1971
+ # bogus results
1972
+ result = pickle.loads(data, encoding='koi8-r')
1973
+ assert_(result != original)
1974
+ elif koi8r_validity == 'invalid':
1975
+ # Unicode code points outside latin1, so results
1976
+ # to an encoding exception
1977
+ assert_raises(
1978
+ ValueError, pickle.loads, data, encoding='koi8-r'
1979
+ )
1980
+ else:
1981
+ raise ValueError(koi8r_validity)
1982
+
1983
+ def test_structured_type_to_object(self):
1984
+ a_rec = np.array([(0, 1), (3, 2)], dtype='i4,i8')
1985
+ a_obj = np.empty((2,), dtype=object)
1986
+ a_obj[0] = (0, 1)
1987
+ a_obj[1] = (3, 2)
1988
+ # astype records -> object
1989
+ assert_equal(a_rec.astype(object), a_obj)
1990
+ # '=' records -> object
1991
+ b = np.empty_like(a_obj)
1992
+ b[...] = a_rec
1993
+ assert_equal(b, a_obj)
1994
+ # '=' object -> records
1995
+ b = np.empty_like(a_rec)
1996
+ b[...] = a_obj
1997
+ assert_equal(b, a_rec)
1998
+
1999
+ def test_assign_obj_listoflists(self):
2000
+ # Ticket # 1870
2001
+ # The inner list should get assigned to the object elements
2002
+ a = np.zeros(4, dtype=object)
2003
+ b = a.copy()
2004
+ a[0] = [1]
2005
+ a[1] = [2]
2006
+ a[2] = [3]
2007
+ a[3] = [4]
2008
+ b[...] = [[1], [2], [3], [4]]
2009
+ assert_equal(a, b)
2010
+ # The first dimension should get broadcast
2011
+ a = np.zeros((2, 2), dtype=object)
2012
+ a[...] = [[1, 2]]
2013
+ assert_equal(a, [[1, 2], [1, 2]])
2014
+
2015
+ @pytest.mark.slow_pypy
2016
+ def test_memoryleak(self):
2017
+ # Ticket #1917 - ensure that array data doesn't leak
2018
+ for i in range(1000):
2019
+ # 100MB times 1000 would give 100GB of memory usage if it leaks
2020
+ a = np.empty((100000000,), dtype='i1')
2021
+ del a
2022
+
2023
+ @pytest.mark.skipif(not HAS_REFCOUNT, reason="Python lacks refcounts")
2024
+ def test_ufunc_reduce_memoryleak(self):
2025
+ a = np.arange(6)
2026
+ acnt = sys.getrefcount(a)
2027
+ np.add.reduce(a)
2028
+ assert_equal(sys.getrefcount(a), acnt)
2029
+
2030
+ def test_search_sorted_invalid_arguments(self):
2031
+ # Ticket #2021, should not segfault.
2032
+ x = np.arange(0, 4, dtype='datetime64[D]')
2033
+ assert_raises(TypeError, x.searchsorted, 1)
2034
+
2035
+ def test_string_truncation(self):
2036
+ # Ticket #1990 - Data can be truncated in creation of an array from a
2037
+ # mixed sequence of numeric values and strings (gh-2583)
2038
+ for val in [True, 1234, 123.4, complex(1, 234)]:
2039
+ for tostr, dtype in [(asunicode, "U"), (asbytes, "S")]:
2040
+ b = np.array([val, tostr('xx')], dtype=dtype)
2041
+ assert_equal(tostr(b[0]), tostr(val))
2042
+ b = np.array([tostr('xx'), val], dtype=dtype)
2043
+ assert_equal(tostr(b[1]), tostr(val))
2044
+
2045
+ # test also with longer strings
2046
+ b = np.array([val, tostr('xxxxxxxxxx')], dtype=dtype)
2047
+ assert_equal(tostr(b[0]), tostr(val))
2048
+ b = np.array([tostr('xxxxxxxxxx'), val], dtype=dtype)
2049
+ assert_equal(tostr(b[1]), tostr(val))
2050
+
2051
+ def test_string_truncation_ucs2(self):
2052
+ # Ticket #2081. Python compiled with two byte unicode
2053
+ # can lead to truncation if itemsize is not properly
2054
+ # adjusted for NumPy's four byte unicode.
2055
+ a = np.array(['abcd'])
2056
+ assert_equal(a.dtype.itemsize, 16)
2057
+
2058
+ def test_unique_stable(self):
2059
+ # Ticket #2063 must always choose stable sort for argsort to
2060
+ # get consistent results
2061
+ v = np.array(([0] * 5 + [1] * 6 + [2] * 6) * 4)
2062
+ res = np.unique(v, return_index=True)
2063
+ tgt = (np.array([0, 1, 2]), np.array([0, 5, 11]))
2064
+ assert_equal(res, tgt)
2065
+
2066
+ def test_unicode_alloc_dealloc_match(self):
2067
+ # Ticket #1578, the mismatch only showed up when running
2068
+ # python-debug for python versions >= 2.7, and then as
2069
+ # a core dump and error message.
2070
+ a = np.array(['abc'], dtype=np.str_)[0]
2071
+ del a
2072
+
2073
+ def test_refcount_error_in_clip(self):
2074
+ # Ticket #1588
2075
+ a = np.zeros((2,), dtype='>i2').clip(min=0)
2076
+ x = a + a
2077
+ # This used to segfault:
2078
+ y = str(x)
2079
+ # Check the final string:
2080
+ assert_(y == "[0 0]")
2081
+
2082
+ def test_searchsorted_wrong_dtype(self):
2083
+ # Ticket #2189, it used to segfault, so we check that it raises the
2084
+ # proper exception.
2085
+ a = np.array([('a', 1)], dtype='S1, int')
2086
+ assert_raises(TypeError, np.searchsorted, a, 1.2)
2087
+ # Ticket #2066, similar problem:
2088
+ dtype = np.rec.format_parser(['i4', 'i4'], [], [])
2089
+ a = np.recarray((2,), dtype)
2090
+ a[...] = [(1, 2), (3, 4)]
2091
+ assert_raises(TypeError, np.searchsorted, a, 1)
2092
+
2093
+ def test_complex64_alignment(self):
2094
+ # Issue gh-2668 (trac 2076), segfault on sparc due to misalignment
2095
+ dtt = np.complex64
2096
+ arr = np.arange(10, dtype=dtt)
2097
+ # 2D array
2098
+ arr2 = np.reshape(arr, (2, 5))
2099
+ # Fortran write followed by (C or F) read caused bus error
2100
+ data_str = arr2.tobytes('F')
2101
+ data_back = np.ndarray(arr2.shape,
2102
+ arr2.dtype,
2103
+ buffer=data_str,
2104
+ order='F')
2105
+ assert_array_equal(arr2, data_back)
2106
+
2107
+ def test_structured_count_nonzero(self):
2108
+ arr = np.array([0, 1]).astype('i4, 2i4')[:1]
2109
+ count = np.count_nonzero(arr)
2110
+ assert_equal(count, 0)
2111
+
2112
+ def test_copymodule_preserves_f_contiguity(self):
2113
+ a = np.empty((2, 2), order='F')
2114
+ b = copy.copy(a)
2115
+ c = copy.deepcopy(a)
2116
+ assert_(b.flags.fortran)
2117
+ assert_(b.flags.f_contiguous)
2118
+ assert_(c.flags.fortran)
2119
+ assert_(c.flags.f_contiguous)
2120
+
2121
+ def test_fortran_order_buffer(self):
2122
+ import numpy as np
2123
+ a = np.array([['Hello', 'Foob']], dtype='U5', order='F')
2124
+ arr = np.ndarray(shape=[1, 2, 5], dtype='U1', buffer=a)
2125
+ arr2 = np.array([[['H', 'e', 'l', 'l', 'o'],
2126
+ ['F', 'o', 'o', 'b', '']]])
2127
+ assert_array_equal(arr, arr2)
2128
+
2129
+ def test_assign_from_sequence_error(self):
2130
+ # Ticket #4024.
2131
+ arr = np.array([1, 2, 3])
2132
+ assert_raises(ValueError, arr.__setitem__, slice(None), [9, 9])
2133
+ arr.__setitem__(slice(None), [9])
2134
+ assert_equal(arr, [9, 9, 9])
2135
+
2136
+ def test_format_on_flex_array_element(self):
2137
+ # Ticket #4369.
2138
+ dt = np.dtype([('date', '<M8[D]'), ('val', '<f8')])
2139
+ arr = np.array([('2000-01-01', 1)], dt)
2140
+ formatted = f'{arr[0]}'
2141
+ assert_equal(formatted, str(arr[0]))
2142
+
2143
+ def test_deepcopy_on_0d_array(self):
2144
+ # Ticket #3311.
2145
+ arr = np.array(3)
2146
+ arr_cp = copy.deepcopy(arr)
2147
+
2148
+ assert_equal(arr, arr_cp)
2149
+ assert_equal(arr.shape, arr_cp.shape)
2150
+ assert_equal(int(arr), int(arr_cp))
2151
+ assert_(arr is not arr_cp)
2152
+ assert_(isinstance(arr_cp, type(arr)))
2153
+
2154
+ def test_deepcopy_F_order_object_array(self):
2155
+ # Ticket #6456.
2156
+ a = {'a': 1}
2157
+ b = {'b': 2}
2158
+ arr = np.array([[a, b], [a, b]], order='F')
2159
+ arr_cp = copy.deepcopy(arr)
2160
+
2161
+ assert_equal(arr, arr_cp)
2162
+ assert_(arr is not arr_cp)
2163
+ # Ensure that we have actually copied the item.
2164
+ assert_(arr[0, 1] is not arr_cp[1, 1])
2165
+ # Ensure we are allowed to have references to the same object.
2166
+ assert_(arr[0, 1] is arr[1, 1])
2167
+ # Check the references hold for the copied objects.
2168
+ assert_(arr_cp[0, 1] is arr_cp[1, 1])
2169
+
2170
+ def test_deepcopy_empty_object_array(self):
2171
+ # Ticket #8536.
2172
+ # Deepcopy should succeed
2173
+ a = np.array([], dtype=object)
2174
+ b = copy.deepcopy(a)
2175
+ assert_(a.shape == b.shape)
2176
+
2177
+ def test_bool_subscript_crash(self):
2178
+ # gh-4494
2179
+ c = np.rec.array([(1, 2, 3), (4, 5, 6)])
2180
+ masked = c[np.array([True, False])]
2181
+ base = masked.base
2182
+ del masked, c
2183
+ base.dtype
2184
+
2185
+ def test_richcompare_crash(self):
2186
+ # gh-4613
2187
+ import operator as op
2188
+
2189
+ # dummy class where __array__ throws exception
2190
+ class Foo:
2191
+ __array_priority__ = 1002
2192
+
2193
+ def __array__(self, *args, **kwargs):
2194
+ raise Exception
2195
+
2196
+ rhs = Foo()
2197
+ lhs = np.array(1)
2198
+ for f in [op.lt, op.le, op.gt, op.ge]:
2199
+ assert_raises(TypeError, f, lhs, rhs)
2200
+ assert_(not op.eq(lhs, rhs))
2201
+ assert_(op.ne(lhs, rhs))
2202
+
2203
+ def test_richcompare_scalar_and_subclass(self):
2204
+ # gh-4709
2205
+ class Foo(np.ndarray):
2206
+ def __eq__(self, other):
2207
+ return "OK"
2208
+
2209
+ x = np.array([1, 2, 3]).view(Foo)
2210
+ assert_equal(10 == x, "OK")
2211
+ assert_equal(np.int32(10) == x, "OK")
2212
+ assert_equal(np.array([10]) == x, "OK")
2213
+
2214
+ def test_pickle_empty_string(self):
2215
+ # gh-3926
2216
+ for proto in range(2, pickle.HIGHEST_PROTOCOL + 1):
2217
+ test_string = np.bytes_('')
2218
+ assert_equal(pickle.loads(
2219
+ pickle.dumps(test_string, protocol=proto)), test_string)
2220
+
2221
+ def test_frompyfunc_many_args(self):
2222
+ # gh-5672
2223
+
2224
+ def passer(*args):
2225
+ pass
2226
+
2227
+ assert_raises(ValueError, np.frompyfunc, passer, 64, 1)
2228
+
2229
+ def test_repeat_broadcasting(self):
2230
+ # gh-5743
2231
+ a = np.arange(60).reshape(3, 4, 5)
2232
+ for axis in chain(range(-a.ndim, a.ndim), [None]):
2233
+ assert_equal(a.repeat(2, axis=axis), a.repeat([2], axis=axis))
2234
+
2235
+ def test_frompyfunc_nout_0(self):
2236
+ # gh-2014
2237
+
2238
+ def f(x):
2239
+ x[0], x[-1] = x[-1], x[0]
2240
+
2241
+ uf = np.frompyfunc(f, 1, 0)
2242
+ a = np.array([[1, 2, 3], [4, 5], [6, 7, 8, 9]], dtype=object)
2243
+ assert_equal(uf(a), ())
2244
+ expected = np.array([[3, 2, 1], [5, 4], [9, 7, 8, 6]], dtype=object)
2245
+ assert_array_equal(a, expected)
2246
+
2247
+ @pytest.mark.skipif(not HAS_REFCOUNT, reason="Python lacks refcounts")
2248
+ def test_leak_in_structured_dtype_comparison(self):
2249
+ # gh-6250
2250
+ recordtype = np.dtype([('a', np.float64),
2251
+ ('b', np.int32),
2252
+ ('d', (str, 5))])
2253
+
2254
+ # Simple case
2255
+ a = np.zeros(2, dtype=recordtype)
2256
+ for i in range(100):
2257
+ a == a
2258
+ assert_(sys.getrefcount(a) < 10)
2259
+
2260
+ # The case in the bug report.
2261
+ before = sys.getrefcount(a)
2262
+ u, v = a[0], a[1]
2263
+ u == v
2264
+ del u, v
2265
+ gc.collect()
2266
+ after = sys.getrefcount(a)
2267
+ assert_equal(before, after)
2268
+
2269
+ def test_empty_percentile(self):
2270
+ # gh-6530 / gh-6553
2271
+ assert_array_equal(np.percentile(np.arange(10), []), np.array([]))
2272
+
2273
+ def test_void_compare_segfault(self):
2274
+ # gh-6922. The following should not segfault
2275
+ a = np.ones(3, dtype=[('object', 'O'), ('int', '<i2')])
2276
+ a.sort()
2277
+
2278
+ def test_reshape_size_overflow(self):
2279
+ # gh-7455
2280
+ a = np.ones(20)[::2]
2281
+ if IS_64BIT:
2282
+ # 64 bit. The following are the prime factors of 2**63 + 5,
2283
+ # plus a leading 2, so when multiplied together as int64,
2284
+ # the result overflows to a total size of 10.
2285
+ new_shape = (2, 13, 419, 691, 823, 2977518503)
2286
+ else:
2287
+ # 32 bit. The following are the prime factors of 2**31 + 5,
2288
+ # plus a leading 2, so when multiplied together as int32,
2289
+ # the result overflows to a total size of 10.
2290
+ new_shape = (2, 7, 7, 43826197)
2291
+ assert_raises(ValueError, a.reshape, new_shape)
2292
+
2293
+ @pytest.mark.skipif(IS_PYPY and sys.implementation.version <= (7, 3, 8),
2294
+ reason="PyPy bug in error formatting")
2295
+ def test_invalid_structured_dtypes(self):
2296
+ # gh-2865
2297
+ # mapping python objects to other dtypes
2298
+ assert_raises(ValueError, np.dtype, ('O', [('name', 'i8')]))
2299
+ assert_raises(ValueError, np.dtype, ('i8', [('name', 'O')]))
2300
+ assert_raises(ValueError, np.dtype,
2301
+ ('i8', [('name', [('name', 'O')])]))
2302
+ assert_raises(ValueError, np.dtype, ([('a', 'i4'), ('b', 'i4')], 'O'))
2303
+ assert_raises(ValueError, np.dtype, ('i8', 'O'))
2304
+ # wrong number/type of tuple elements in dict
2305
+ assert_raises(ValueError, np.dtype,
2306
+ ('i', {'name': ('i', 0, 'title', 'oops')}))
2307
+ assert_raises(ValueError, np.dtype,
2308
+ ('i', {'name': ('i', 'wrongtype', 'title')}))
2309
+ # disallowed as of 1.13
2310
+ assert_raises(ValueError, np.dtype,
2311
+ ([('a', 'O'), ('b', 'O')], [('c', 'O'), ('d', 'O')]))
2312
+ # allowed as a special case due to existing use, see gh-2798
2313
+ a = np.ones(1, dtype=('O', [('name', 'O')]))
2314
+ assert_equal(a[0], 1)
2315
+ # In particular, the above union dtype (and union dtypes in general)
2316
+ # should mainly behave like the main (object) dtype:
2317
+ assert a[0] is a.item()
2318
+ assert type(a[0]) is int
2319
+
2320
+ def test_correct_hash_dict(self):
2321
+ # gh-8887 - __hash__ would be None despite tp_hash being set
2322
+ all_types = set(np._core.sctypeDict.values()) - {np.void}
2323
+ for t in all_types:
2324
+ val = t()
2325
+
2326
+ try:
2327
+ hash(val)
2328
+ except TypeError:
2329
+ assert_(t.__hash__ is None)
2330
+ except ValueError:
2331
+ assert_(t is np.timedelta64)
2332
+ assert_(t.__hash__ is not None)
2333
+ else:
2334
+ assert_(t.__hash__ is not None)
2335
+
2336
+ def test_scalar_copy(self):
2337
+ scalar_types = set(np._core.sctypeDict.values())
2338
+ values = {
2339
+ np.void: b"a",
2340
+ np.bytes_: b"a",
2341
+ np.str_: "a",
2342
+ np.datetime64: "2017-08-25",
2343
+ }
2344
+ for sctype in scalar_types:
2345
+ item = sctype(values.get(sctype, 1))
2346
+ item2 = copy.copy(item)
2347
+ assert_equal(item, item2)
2348
+
2349
+ def test_void_item_memview(self):
2350
+ va = np.zeros(10, 'V4')
2351
+ x = va[:1].item()
2352
+ va[0] = b'\xff\xff\xff\xff'
2353
+ del va
2354
+ assert_equal(x, b'\x00\x00\x00\x00')
2355
+
2356
+ def test_void_getitem(self):
2357
+ # Test fix for gh-11668.
2358
+ assert_(np.array([b'a'], 'V1').astype('O') == b'a')
2359
+ assert_(np.array([b'ab'], 'V2').astype('O') == b'ab')
2360
+ assert_(np.array([b'abc'], 'V3').astype('O') == b'abc')
2361
+ assert_(np.array([b'abcd'], 'V4').astype('O') == b'abcd')
2362
+
2363
+ def test_structarray_title(self):
2364
+ # The following used to segfault on pypy, due to NPY_TITLE_KEY
2365
+ # not working properly and resulting to double-decref of the
2366
+ # structured array field items:
2367
+ # See: https://bitbucket.org/pypy/pypy/issues/2789
2368
+ for j in range(5):
2369
+ structure = np.array([1], dtype=[(('x', 'X'), np.object_)])
2370
+ structure[0]['x'] = np.array([2])
2371
+ gc.collect()
2372
+
2373
+ def test_dtype_scalar_squeeze(self):
2374
+ # gh-11384
2375
+ values = {
2376
+ 'S': b"a",
2377
+ 'M': "2018-06-20",
2378
+ }
2379
+ for ch in np.typecodes['All']:
2380
+ if ch in 'O':
2381
+ continue
2382
+ sctype = np.dtype(ch).type
2383
+ scvalue = sctype(values.get(ch, 3))
2384
+ for axis in [None, ()]:
2385
+ squeezed = scvalue.squeeze(axis=axis)
2386
+ assert_equal(squeezed, scvalue)
2387
+ assert_equal(type(squeezed), type(scvalue))
2388
+
2389
+ def test_field_access_by_title(self):
2390
+ # gh-11507
2391
+ s = 'Some long field name'
2392
+ if HAS_REFCOUNT:
2393
+ base = sys.getrefcount(s)
2394
+ t = np.dtype([((s, 'f1'), np.float64)])
2395
+ data = np.zeros(10, t)
2396
+ for i in range(10):
2397
+ str(data[['f1']])
2398
+ if HAS_REFCOUNT:
2399
+ assert_(base <= sys.getrefcount(s))
2400
+
2401
+ @pytest.mark.parametrize('val', [
2402
+ # arrays and scalars
2403
+ np.ones((10, 10), dtype='int32'),
2404
+ np.uint64(10),
2405
+ ])
2406
+ @pytest.mark.parametrize('protocol',
2407
+ range(2, pickle.HIGHEST_PROTOCOL + 1)
2408
+ )
2409
+ def test_pickle_module(self, protocol, val):
2410
+ # gh-12837
2411
+ s = pickle.dumps(val, protocol)
2412
+ assert b'_multiarray_umath' not in s
2413
+ if protocol == 5 and len(val.shape) > 0:
2414
+ # unpickling ndarray goes through _frombuffer for protocol 5
2415
+ assert b'numpy._core.numeric' in s
2416
+ else:
2417
+ assert b'numpy._core.multiarray' in s
2418
+
2419
+ def test_object_casting_errors(self):
2420
+ # gh-11993 update to ValueError (see gh-16909), since strings can in
2421
+ # principle be converted to complex, but this string cannot.
2422
+ arr = np.array(['AAAAA', 18465886.0, 18465886.0], dtype=object)
2423
+ assert_raises(ValueError, arr.astype, 'c8')
2424
+
2425
+ def test_eff1d_casting(self):
2426
+ # gh-12711
2427
+ x = np.array([1, 2, 4, 7, 0], dtype=np.int16)
2428
+ res = np.ediff1d(x, to_begin=-99, to_end=np.array([88, 99]))
2429
+ assert_equal(res, [-99, 1, 2, 3, -7, 88, 99])
2430
+
2431
+ # The use of safe casting means, that 1<<20 is cast unsafely, an
2432
+ # error may be better, but currently there is no mechanism for it.
2433
+ res = np.ediff1d(x, to_begin=(1 << 20), to_end=(1 << 20))
2434
+ assert_equal(res, [0, 1, 2, 3, -7, 0])
2435
+
2436
+ def test_pickle_datetime64_array(self):
2437
+ # gh-12745 (would fail with pickle5 installed)
2438
+ d = np.datetime64('2015-07-04 12:59:59.50', 'ns')
2439
+ arr = np.array([d])
2440
+ for proto in range(2, pickle.HIGHEST_PROTOCOL + 1):
2441
+ dumped = pickle.dumps(arr, protocol=proto)
2442
+ assert_equal(pickle.loads(dumped), arr)
2443
+
2444
+ def test_bad_array_interface(self):
2445
+ class T:
2446
+ __array_interface__ = {}
2447
+
2448
+ with assert_raises(ValueError):
2449
+ np.array([T()])
2450
+
2451
+ def test_2d__array__shape(self):
2452
+ class T:
2453
+ def __array__(self, dtype=None, copy=None):
2454
+ return np.ndarray(shape=(0, 0))
2455
+
2456
+ # Make sure __array__ is used instead of Sequence methods.
2457
+ def __iter__(self):
2458
+ return iter([])
2459
+
2460
+ def __getitem__(self, idx):
2461
+ raise AssertionError("__getitem__ was called")
2462
+
2463
+ def __len__(self):
2464
+ return 0
2465
+
2466
+ t = T()
2467
+ # gh-13659, would raise in broadcasting [x=t for x in result]
2468
+ arr = np.array([t])
2469
+ assert arr.shape == (1, 0, 0)
2470
+
2471
+ @pytest.mark.skipif(sys.maxsize < 2 ** 31 + 1, reason='overflows 32-bit python')
2472
+ def test_to_ctypes(self):
2473
+ # gh-14214
2474
+ arr = np.zeros((2 ** 31 + 1,), 'b')
2475
+ assert arr.size * arr.itemsize > 2 ** 31
2476
+ c_arr = np.ctypeslib.as_ctypes(arr)
2477
+ assert_equal(c_arr._length_, arr.size)
2478
+
2479
+ def test_complex_conversion_error(self):
2480
+ # gh-17068
2481
+ with pytest.raises(TypeError, match=r"Unable to convert dtype.*"):
2482
+ complex(np.array("now", np.datetime64))
2483
+
2484
+ def test__array_interface__descr(self):
2485
+ # gh-17068
2486
+ dt = np.dtype({'names': ['a', 'b'],
2487
+ 'offsets': [0, 0],
2488
+ 'formats': [np.int64, np.int64]})
2489
+ descr = np.array((1, 1), dtype=dt).__array_interface__['descr']
2490
+ assert descr == [('', '|V8')] # instead of [(b'', '|V8')]
2491
+
2492
+ @pytest.mark.skipif(sys.maxsize < 2 ** 31 + 1, reason='overflows 32-bit python')
2493
+ @requires_memory(free_bytes=9e9)
2494
+ @pytest.mark.thread_unsafe(reason="crashes with low memory")
2495
+ def test_dot_big_stride(self):
2496
+ # gh-17111
2497
+ # blas stride = stride//itemsize > int32 max
2498
+ int32_max = np.iinfo(np.int32).max
2499
+ n = int32_max + 3
2500
+ a = np.empty([n], dtype=np.float32)
2501
+ b = a[::n - 1]
2502
+ b[...] = 1
2503
+ assert b.strides[0] > int32_max * b.dtype.itemsize
2504
+ assert np.dot(b, b) == 2.0
2505
+
2506
+ def test_frompyfunc_name(self):
2507
+ # name conversion was failing for python 3 strings
2508
+ # resulting in the default '?' name. Also test utf-8
2509
+ # encoding using non-ascii name.
2510
+ def cassé(x):
2511
+ return x
2512
+
2513
+ f = np.frompyfunc(cassé, 1, 1)
2514
+ assert str(f) == "<ufunc 'cassé (vectorized)'>"
2515
+
2516
+ @pytest.mark.parametrize("operation", [
2517
+ 'add', 'subtract', 'multiply', 'floor_divide',
2518
+ 'conjugate', 'fmod', 'square', 'reciprocal',
2519
+ 'power', 'absolute', 'negative', 'positive',
2520
+ 'greater', 'greater_equal', 'less',
2521
+ 'less_equal', 'equal', 'not_equal', 'logical_and',
2522
+ 'logical_not', 'logical_or', 'bitwise_and', 'bitwise_or',
2523
+ 'bitwise_xor', 'invert', 'left_shift', 'right_shift',
2524
+ 'gcd', 'lcm'
2525
+ ]
2526
+ )
2527
+ @pytest.mark.parametrize("order", [
2528
+ ('b->', 'B->'),
2529
+ ('h->', 'H->'),
2530
+ ('i->', 'I->'),
2531
+ ('l->', 'L->'),
2532
+ ('q->', 'Q->'),
2533
+ ]
2534
+ )
2535
+ def test_ufunc_order(self, operation, order):
2536
+ # gh-18075
2537
+ # Ensure signed types before unsigned
2538
+ def get_idx(string, str_lst):
2539
+ for i, s in enumerate(str_lst):
2540
+ if string in s:
2541
+ return i
2542
+ raise ValueError(f"{string} not in list")
2543
+ types = getattr(np, operation).types
2544
+ assert get_idx(order[0], types) < get_idx(order[1], types), (
2545
+ f"Unexpected types order of ufunc in {operation}"
2546
+ f"for {order}. Possible fix: Use signed before unsigned"
2547
+ "in generate_umath.py")
2548
+
2549
+ def test_nonbool_logical(self):
2550
+ # gh-22845
2551
+ # create two arrays with bit patterns that do not overlap.
2552
+ # needs to be large enough to test both SIMD and scalar paths
2553
+ size = 100
2554
+ a = np.frombuffer(b'\x01' * size, dtype=np.bool)
2555
+ b = np.frombuffer(b'\x80' * size, dtype=np.bool)
2556
+ expected = np.ones(size, dtype=np.bool)
2557
+ assert_array_equal(np.logical_and(a, b), expected)
2558
+
2559
+ @pytest.mark.skipif(IS_PYPY, reason="PyPy issue 2742")
2560
+ def test_gh_23737(self):
2561
+ with pytest.raises(TypeError, match="not an acceptable base type"):
2562
+ class Y(np.flexible):
2563
+ pass
2564
+
2565
+ with pytest.raises(TypeError, match="not an acceptable base type"):
2566
+ class X(np.flexible, np.ma.core.MaskedArray):
2567
+ pass
2568
+
2569
+ def test_load_ufunc_pickle(self):
2570
+ # ufuncs are pickled with a semi-private path in
2571
+ # numpy.core._multiarray_umath and must be loadable without warning
2572
+ # despite np.core being deprecated.
2573
+ test_data = b'\x80\x04\x95(\x00\x00\x00\x00\x00\x00\x00\x8c\x1cnumpy.core._multiarray_umath\x94\x8c\x03add\x94\x93\x94.'
2574
+ result = pickle.loads(test_data, encoding='bytes')
2575
+ assert result is np.add
2576
+
2577
+ def test__array_namespace__(self):
2578
+ arr = np.arange(2)
2579
+
2580
+ xp = arr.__array_namespace__()
2581
+ assert xp is np
2582
+ xp = arr.__array_namespace__(api_version="2021.12")
2583
+ assert xp is np
2584
+ xp = arr.__array_namespace__(api_version="2022.12")
2585
+ assert xp is np
2586
+ xp = arr.__array_namespace__(api_version="2023.12")
2587
+ assert xp is np
2588
+ xp = arr.__array_namespace__(api_version="2024.12")
2589
+ assert xp is np
2590
+ xp = arr.__array_namespace__(api_version=None)
2591
+ assert xp is np
2592
+
2593
+ with pytest.raises(
2594
+ ValueError,
2595
+ match="Version \"2025.12\" of the Array API Standard "
2596
+ "is not supported."
2597
+ ):
2598
+ arr.__array_namespace__(api_version="2025.12")
2599
+
2600
+ with pytest.raises(
2601
+ ValueError,
2602
+ match="Only None and strings are allowed as the Array API version"
2603
+ ):
2604
+ arr.__array_namespace__(api_version=2024)
2605
+
2606
+ def test_isin_refcnt_bug(self):
2607
+ # gh-25295
2608
+ for _ in range(1000):
2609
+ np.isclose(np.int64(2), np.int64(2), atol=1e-15, rtol=1e-300)
2610
+
2611
+ def test_replace_regression(self):
2612
+ # gh-25513 segfault
2613
+ carr = np.char.chararray((2,), itemsize=25)
2614
+ test_strings = [b' 4.52173913043478315E+00',
2615
+ b' 4.95652173913043548E+00']
2616
+ carr[:] = test_strings
2617
+ out = carr.replace(b"E", b"D")
2618
+ expected = np.char.chararray((2,), itemsize=25)
2619
+ expected[:] = [s.replace(b"E", b"D") for s in test_strings]
2620
+ assert_array_equal(out, expected)
2621
+
2622
+ def test_logspace_base_does_not_determine_dtype(self):
2623
+ # gh-24957 and cupy/cupy/issues/7946
2624
+ start = np.array([0, 2], dtype=np.float16)
2625
+ stop = np.array([2, 0], dtype=np.float16)
2626
+ out = np.logspace(start, stop, num=5, axis=1, dtype=np.float32)
2627
+ expected = np.array([[1., 3.1621094, 10., 31.625, 100.],
2628
+ [100., 31.625, 10., 3.1621094, 1.]],
2629
+ dtype=np.float32)
2630
+ assert_almost_equal(out, expected)
2631
+ # Check test fails if the calculation is done in float64, as happened
2632
+ # before when a python float base incorrectly influenced the dtype.
2633
+ out2 = np.logspace(start, stop, num=5, axis=1, dtype=np.float32,
2634
+ base=np.array([10.0]))
2635
+ with pytest.raises(AssertionError, match="not almost equal"):
2636
+ assert_almost_equal(out2, expected)
2637
+
2638
+ def test_vectorize_fixed_width_string(self):
2639
+ arr = np.array(["SOme wOrd DŽ ß ᾛ ΣΣ ffi⁵Å Ç Ⅰ"]).astype(np.str_)
2640
+ f = str.casefold
2641
+ res = np.vectorize(f, otypes=[arr.dtype])(arr)
2642
+ assert res.dtype == "U30"
2643
+
2644
+ def test_repeated_square_consistency(self):
2645
+ # gh-26940
2646
+ buf = np.array([-5.171866611150749e-07 + 2.5618634555957426e-07j,
2647
+ 0, 0, 0, 0, 0])
2648
+ # Test buffer with regular and reverse strides
2649
+ for in_vec in [buf[:3], buf[:3][::-1]]:
2650
+ expected_res = np.square(in_vec)
2651
+ # Output vector immediately follows input vector
2652
+ # to reproduce off-by-one in nomemoverlap check.
2653
+ for res in [buf[3:], buf[3:][::-1]]:
2654
+ res = buf[3:]
2655
+ np.square(in_vec, out=res)
2656
+ assert_equal(res, expected_res)
2657
+
2658
+ def test_sort_unique_crash(self):
2659
+ # gh-27037
2660
+ for _ in range(4):
2661
+ vals = np.linspace(0, 1, num=128)
2662
+ data = np.broadcast_to(vals, (128, 128, 128))
2663
+ data = data.transpose(0, 2, 1).copy()
2664
+ np.unique(data)
2665
+
2666
+ def test_sort_overlap(self):
2667
+ # gh-27273
2668
+ size = 100
2669
+ inp = np.linspace(0, size, num=size, dtype=np.intc)
2670
+ out = np.sort(inp)
2671
+ assert_equal(inp, out)
2672
+
2673
+ def test_searchsorted_structured(self):
2674
+ # gh-28190
2675
+ x = np.array([(0, 1.)], dtype=[('time', '<i8'), ('value', '<f8')])
2676
+ y = np.array((0, 0.), dtype=[('time', '<i8'), ('value', '<f8')])
2677
+ x.searchsorted(y)