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,1692 @@
1
+ import functools
2
+ import inspect
3
+ import operator
4
+ import sys
5
+ import warnings
6
+ from itertools import product
7
+
8
+ import pytest
9
+
10
+ import numpy as np
11
+ from numpy._core._multiarray_tests import array_indexing
12
+ from numpy.exceptions import ComplexWarning, VisibleDeprecationWarning
13
+ from numpy.testing import (
14
+ HAS_REFCOUNT,
15
+ IS_PYPY,
16
+ assert_,
17
+ assert_array_equal,
18
+ assert_equal,
19
+ assert_raises,
20
+ assert_raises_regex,
21
+ )
22
+
23
+
24
+ class TestIndexing:
25
+ def test_index_no_floats(self):
26
+ a = np.array([[[5]]])
27
+
28
+ assert_raises(IndexError, lambda: a[0.0])
29
+ assert_raises(IndexError, lambda: a[0, 0.0])
30
+ assert_raises(IndexError, lambda: a[0.0, 0])
31
+ assert_raises(IndexError, lambda: a[0.0, :])
32
+ assert_raises(IndexError, lambda: a[:, 0.0])
33
+ assert_raises(IndexError, lambda: a[:, 0.0, :])
34
+ assert_raises(IndexError, lambda: a[0.0, :, :])
35
+ assert_raises(IndexError, lambda: a[0, 0, 0.0])
36
+ assert_raises(IndexError, lambda: a[0.0, 0, 0])
37
+ assert_raises(IndexError, lambda: a[0, 0.0, 0])
38
+ assert_raises(IndexError, lambda: a[-1.4])
39
+ assert_raises(IndexError, lambda: a[0, -1.4])
40
+ assert_raises(IndexError, lambda: a[-1.4, 0])
41
+ assert_raises(IndexError, lambda: a[-1.4, :])
42
+ assert_raises(IndexError, lambda: a[:, -1.4])
43
+ assert_raises(IndexError, lambda: a[:, -1.4, :])
44
+ assert_raises(IndexError, lambda: a[-1.4, :, :])
45
+ assert_raises(IndexError, lambda: a[0, 0, -1.4])
46
+ assert_raises(IndexError, lambda: a[-1.4, 0, 0])
47
+ assert_raises(IndexError, lambda: a[0, -1.4, 0])
48
+ assert_raises(IndexError, lambda: a[0.0:, 0.0])
49
+ assert_raises(IndexError, lambda: a[0.0:, 0.0, :])
50
+
51
+ def test_slicing_no_floats(self):
52
+ a = np.array([[5]])
53
+
54
+ # start as float.
55
+ assert_raises(TypeError, lambda: a[0.0:])
56
+ assert_raises(TypeError, lambda: a[0:, 0.0:2])
57
+ assert_raises(TypeError, lambda: a[0.0::2, :0])
58
+ assert_raises(TypeError, lambda: a[0.0:1:2, :])
59
+ assert_raises(TypeError, lambda: a[:, 0.0:])
60
+ # stop as float.
61
+ assert_raises(TypeError, lambda: a[:0.0])
62
+ assert_raises(TypeError, lambda: a[:0, 1:2.0])
63
+ assert_raises(TypeError, lambda: a[:0.0:2, :0])
64
+ assert_raises(TypeError, lambda: a[:0.0, :])
65
+ assert_raises(TypeError, lambda: a[:, 0:4.0:2])
66
+ # step as float.
67
+ assert_raises(TypeError, lambda: a[::1.0])
68
+ assert_raises(TypeError, lambda: a[0:, :2:2.0])
69
+ assert_raises(TypeError, lambda: a[1::4.0, :0])
70
+ assert_raises(TypeError, lambda: a[::5.0, :])
71
+ assert_raises(TypeError, lambda: a[:, 0:4:2.0])
72
+ # mixed.
73
+ assert_raises(TypeError, lambda: a[1.0:2:2.0])
74
+ assert_raises(TypeError, lambda: a[1.0::2.0])
75
+ assert_raises(TypeError, lambda: a[0:, :2.0:2.0])
76
+ assert_raises(TypeError, lambda: a[1.0:1:4.0, :0])
77
+ assert_raises(TypeError, lambda: a[1.0:5.0:5.0, :])
78
+ assert_raises(TypeError, lambda: a[:, 0.4:4.0:2.0])
79
+ # should still get the DeprecationWarning if step = 0.
80
+ assert_raises(TypeError, lambda: a[::0.0])
81
+
82
+ def test_index_no_array_to_index(self):
83
+ # No non-scalar arrays.
84
+ a = np.array([[[1]]])
85
+
86
+ assert_raises(TypeError, lambda: a[a:a:a])
87
+
88
+ def test_none_index(self):
89
+ # `None` index adds newaxis
90
+ a = np.array([1, 2, 3])
91
+ assert_equal(a[None], a[np.newaxis])
92
+ assert_equal(a[None].ndim, a.ndim + 1)
93
+
94
+ def test_empty_tuple_index(self):
95
+ # Empty tuple index creates a view
96
+ a = np.array([1, 2, 3])
97
+ assert_equal(a[()], a)
98
+ assert_(a[()].base is a)
99
+ a = np.array(0)
100
+ assert_(isinstance(a[()], np.int_))
101
+
102
+ def test_void_scalar_empty_tuple(self):
103
+ s = np.zeros((), dtype='V4')
104
+ assert_equal(s[()].dtype, s.dtype)
105
+ assert_equal(s[()], s)
106
+ assert_equal(type(s[...]), np.ndarray)
107
+
108
+ def test_same_kind_index_casting(self):
109
+ # Indexes should be cast with same-kind and not safe, even if that
110
+ # is somewhat unsafe. So test various different code paths.
111
+ index = np.arange(5)
112
+ u_index = index.astype(np.uintp)
113
+ arr = np.arange(10)
114
+
115
+ assert_array_equal(arr[index], arr[u_index])
116
+ arr[u_index] = np.arange(5)
117
+ assert_array_equal(arr, np.arange(10))
118
+
119
+ arr = np.arange(10).reshape(5, 2)
120
+ assert_array_equal(arr[index], arr[u_index])
121
+
122
+ arr[u_index] = np.arange(5)[:, None]
123
+ assert_array_equal(arr, np.arange(5)[:, None].repeat(2, axis=1))
124
+
125
+ arr = np.arange(25).reshape(5, 5)
126
+ assert_array_equal(arr[u_index, u_index], arr[index, index])
127
+
128
+ def test_empty_fancy_index(self):
129
+ # Empty list index creates an empty array
130
+ # with the same dtype (but with weird shape)
131
+ a = np.array([1, 2, 3])
132
+ assert_equal(a[[]], [])
133
+ assert_equal(a[[]].dtype, a.dtype)
134
+
135
+ b = np.array([], dtype=np.intp)
136
+ assert_equal(a[[]], [])
137
+ assert_equal(a[[]].dtype, a.dtype)
138
+
139
+ b = np.array([])
140
+ assert_raises(IndexError, a.__getitem__, b)
141
+
142
+ def test_gh_26542(self):
143
+ a = np.array([0, 1, 2])
144
+ idx = np.array([2, 1, 0])
145
+ a[idx] = a
146
+ expected = np.array([2, 1, 0])
147
+ assert_equal(a, expected)
148
+
149
+ def test_gh_26542_2d(self):
150
+ a = np.array([[0, 1, 2]])
151
+ idx_row = np.zeros(3, dtype=int)
152
+ idx_col = np.array([2, 1, 0])
153
+ a[idx_row, idx_col] = a
154
+ expected = np.array([[2, 1, 0]])
155
+ assert_equal(a, expected)
156
+
157
+ def test_gh_26542_index_overlap(self):
158
+ arr = np.arange(100)
159
+ expected_vals = np.copy(arr[:-10])
160
+ arr[10:] = arr[:-10]
161
+ actual_vals = arr[10:]
162
+ assert_equal(actual_vals, expected_vals)
163
+
164
+ def test_gh_26844(self):
165
+ expected = [0, 1, 3, 3, 3]
166
+ a = np.arange(5)
167
+ a[2:][a[:-2]] = 3
168
+ assert_equal(a, expected)
169
+
170
+ def test_gh_26844_segfault(self):
171
+ # check for absence of segfault for:
172
+ # https://github.com/numpy/numpy/pull/26958/files#r1854589178
173
+ a = np.arange(5)
174
+ expected = [0, 1, 3, 3, 3]
175
+ a[2:][None, a[:-2]] = 3
176
+ assert_equal(a, expected)
177
+
178
+ def test_ellipsis_index(self):
179
+ a = np.array([[1, 2, 3],
180
+ [4, 5, 6],
181
+ [7, 8, 9]])
182
+ assert_(a[...] is not a)
183
+ assert_equal(a[...], a)
184
+ # `a[...]` was `a` in numpy <1.9.
185
+ assert_(a[...].base is a)
186
+
187
+ # Slicing with ellipsis can skip an
188
+ # arbitrary number of dimensions
189
+ assert_equal(a[0, ...], a[0])
190
+ assert_equal(a[0, ...], a[0, :])
191
+ assert_equal(a[..., 0], a[:, 0])
192
+
193
+ # Slicing with ellipsis always results
194
+ # in an array, not a scalar
195
+ assert_equal(a[0, ..., 1], np.array(2))
196
+
197
+ # Assignment with `(Ellipsis,)` on 0-d arrays
198
+ b = np.array(1)
199
+ b[(Ellipsis,)] = 2
200
+ assert_equal(b, 2)
201
+
202
+ def test_single_int_index(self):
203
+ # Single integer index selects one row
204
+ a = np.array([[1, 2, 3],
205
+ [4, 5, 6],
206
+ [7, 8, 9]])
207
+
208
+ assert_equal(a[0], [1, 2, 3])
209
+ assert_equal(a[-1], [7, 8, 9])
210
+
211
+ # Index out of bounds produces IndexError
212
+ assert_raises(IndexError, a.__getitem__, 1 << 30)
213
+ # Index overflow produces IndexError
214
+ assert_raises(IndexError, a.__getitem__, 1 << 64)
215
+
216
+ def test_single_bool_index(self):
217
+ # Single boolean index
218
+ a = np.array([[1, 2, 3],
219
+ [4, 5, 6],
220
+ [7, 8, 9]])
221
+
222
+ assert_equal(a[np.array(True)], a[None])
223
+ assert_equal(a[np.array(False)], a[None][0:0])
224
+
225
+ def test_boolean_shape_mismatch(self):
226
+ arr = np.ones((5, 4, 3))
227
+
228
+ index = np.array([True])
229
+ assert_raises(IndexError, arr.__getitem__, index)
230
+
231
+ index = np.array([False] * 6)
232
+ assert_raises(IndexError, arr.__getitem__, index)
233
+
234
+ index = np.zeros((4, 4), dtype=bool)
235
+ assert_raises(IndexError, arr.__getitem__, index)
236
+
237
+ assert_raises(IndexError, arr.__getitem__, (slice(None), index))
238
+
239
+ def test_boolean_indexing_onedim(self):
240
+ # Indexing a 2-dimensional array with
241
+ # boolean array of length one
242
+ a = np.array([[0., 0., 0.]])
243
+ b = np.array([True], dtype=bool)
244
+ assert_equal(a[b], a)
245
+ # boolean assignment
246
+ a[b] = 1.
247
+ assert_equal(a, [[1., 1., 1.]])
248
+
249
+ def test_boolean_assignment_value_mismatch(self):
250
+ # A boolean assignment should fail when the shape of the values
251
+ # cannot be broadcast to the subscription. (see also gh-3458)
252
+ a = np.arange(4)
253
+
254
+ def f(a, v):
255
+ a[a > -1] = v
256
+
257
+ assert_raises(ValueError, f, a, [])
258
+ assert_raises(ValueError, f, a, [1, 2, 3])
259
+ assert_raises(ValueError, f, a[:1], [1, 2, 3])
260
+
261
+ def test_boolean_assignment_needs_api(self):
262
+ # See also gh-7666
263
+ # This caused a segfault on Python 2 due to the GIL not being
264
+ # held when the iterator does not need it, but the transfer function
265
+ # does
266
+ arr = np.zeros(1000)
267
+ indx = np.zeros(1000, dtype=bool)
268
+ indx[:100] = True
269
+ arr[indx] = np.ones(100, dtype=object)
270
+
271
+ expected = np.zeros(1000)
272
+ expected[:100] = 1
273
+ assert_array_equal(arr, expected)
274
+
275
+ def test_boolean_indexing_twodim(self):
276
+ # Indexing a 2-dimensional array with
277
+ # 2-dimensional boolean array
278
+ a = np.array([[1, 2, 3],
279
+ [4, 5, 6],
280
+ [7, 8, 9]])
281
+ b = np.array([[ True, False, True],
282
+ [False, True, False],
283
+ [ True, False, True]])
284
+ assert_equal(a[b], [1, 3, 5, 7, 9])
285
+ assert_equal(a[b[1]], [[4, 5, 6]])
286
+ assert_equal(a[b[0]], a[b[2]])
287
+
288
+ # boolean assignment
289
+ a[b] = 0
290
+ assert_equal(a, [[0, 2, 0],
291
+ [4, 0, 6],
292
+ [0, 8, 0]])
293
+
294
+ def test_boolean_indexing_list(self):
295
+ # Regression test for #13715. It's a use-after-free bug which the
296
+ # test won't directly catch, but it will show up in valgrind.
297
+ a = np.array([1, 2, 3])
298
+ b = [True, False, True]
299
+ # Two variants of the test because the first takes a fast path
300
+ assert_equal(a[b], [1, 3])
301
+ assert_equal(a[None, b], [[1, 3]])
302
+
303
+ def test_reverse_strides_and_subspace_bufferinit(self):
304
+ # This tests that the strides are not reversed for simple and
305
+ # subspace fancy indexing.
306
+ a = np.ones(5)
307
+ b = np.zeros(5, dtype=np.intp)[::-1]
308
+ c = np.arange(5)[::-1]
309
+
310
+ a[b] = c
311
+ # If the strides are not reversed, the 0 in the arange comes last.
312
+ assert_equal(a[0], 0)
313
+
314
+ # This also tests that the subspace buffer is initialized:
315
+ a = np.ones((5, 2))
316
+ c = np.arange(10).reshape(5, 2)[::-1]
317
+ a[b, :] = c
318
+ assert_equal(a[0], [0, 1])
319
+
320
+ def test_reversed_strides_result_allocation(self):
321
+ # Test a bug when calculating the output strides for a result array
322
+ # when the subspace size was 1 (and test other cases as well)
323
+ a = np.arange(10)[:, None]
324
+ i = np.arange(10)[::-1]
325
+ assert_array_equal(a[i], a[i.copy('C')])
326
+
327
+ a = np.arange(20).reshape(-1, 2)
328
+
329
+ def test_uncontiguous_subspace_assignment(self):
330
+ # During development there was a bug activating a skip logic
331
+ # based on ndim instead of size.
332
+ a = np.full((3, 4, 2), -1)
333
+ b = np.full((3, 4, 2), -1)
334
+
335
+ a[[0, 1]] = np.arange(2 * 4 * 2).reshape(2, 4, 2).T
336
+ b[[0, 1]] = np.arange(2 * 4 * 2).reshape(2, 4, 2).T.copy()
337
+
338
+ assert_equal(a, b)
339
+
340
+ def test_too_many_fancy_indices_special_case(self):
341
+ # Just documents behaviour, this is a small limitation.
342
+ a = np.ones((1,) * 64) # 64 is NPY_MAXDIMS
343
+ assert_raises(IndexError, a.__getitem__, (np.array([0]),) * 64)
344
+
345
+ def test_scalar_array_bool(self):
346
+ # NumPy bools can be used as boolean index (python ones as of yet not)
347
+ a = np.array(1)
348
+ assert_equal(a[np.bool(True)], a[np.array(True)])
349
+ assert_equal(a[np.bool(False)], a[np.array(False)])
350
+
351
+ # After deprecating bools as integers:
352
+ #a = np.array([0,1,2])
353
+ #assert_equal(a[True, :], a[None, :])
354
+ #assert_equal(a[:, True], a[:, None])
355
+ #
356
+ #assert_(not np.may_share_memory(a, a[True, :]))
357
+
358
+ def test_everything_returns_views(self):
359
+ # Before `...` would return a itself.
360
+ a = np.arange(5)
361
+
362
+ assert_(a is not a[()])
363
+ assert_(a is not a[...])
364
+ assert_(a is not a[:])
365
+
366
+ def test_broaderrors_indexing(self):
367
+ a = np.zeros((5, 5))
368
+ assert_raises(IndexError, a.__getitem__, ([0, 1], [0, 1, 2]))
369
+ assert_raises(IndexError, a.__setitem__, ([0, 1], [0, 1, 2]), 0)
370
+
371
+ def test_trivial_fancy_out_of_bounds(self):
372
+ a = np.zeros(5)
373
+ ind = np.ones(20, dtype=np.intp)
374
+ ind[-1] = 10
375
+ assert_raises(IndexError, a.__getitem__, ind)
376
+ assert_raises(IndexError, a.__setitem__, ind, 0)
377
+ ind = np.ones(20, dtype=np.intp)
378
+ ind[0] = 11
379
+ assert_raises(IndexError, a.__getitem__, ind)
380
+ assert_raises(IndexError, a.__setitem__, ind, 0)
381
+
382
+ def test_trivial_fancy_not_possible(self):
383
+ # Test that the fast path for trivial assignment is not incorrectly
384
+ # used when the index is not contiguous or 1D, see also gh-11467.
385
+ a = np.arange(6)
386
+ idx = np.arange(6, dtype=np.intp).reshape(2, 1, 3)[:, :, 0]
387
+ assert_array_equal(a[idx], idx)
388
+
389
+ # this case must not go into the fast path, note that idx is
390
+ # a non-contiguous none 1D array here.
391
+ a[idx] = -1
392
+ res = np.arange(6)
393
+ res[0] = -1
394
+ res[3] = -1
395
+ assert_array_equal(a, res)
396
+
397
+ def test_nonbaseclass_values(self):
398
+ class SubClass(np.ndarray):
399
+ def __array_finalize__(self, old):
400
+ # Have array finalize do funny things
401
+ self.fill(99)
402
+
403
+ a = np.zeros((5, 5))
404
+ s = a.copy().view(type=SubClass)
405
+ s.fill(1)
406
+
407
+ a[[0, 1, 2, 3, 4], :] = s
408
+ assert_((a == 1).all())
409
+
410
+ # Subspace is last, so transposing might want to finalize
411
+ a[:, [0, 1, 2, 3, 4]] = s
412
+ assert_((a == 1).all())
413
+
414
+ a.fill(0)
415
+ a[...] = s
416
+ assert_((a == 1).all())
417
+
418
+ def test_array_like_values(self):
419
+ # Similar to the above test, but use a memoryview instead
420
+ a = np.zeros((5, 5))
421
+ s = np.arange(25, dtype=np.float64).reshape(5, 5)
422
+
423
+ a[[0, 1, 2, 3, 4], :] = memoryview(s)
424
+ assert_array_equal(a, s)
425
+
426
+ a[:, [0, 1, 2, 3, 4]] = memoryview(s)
427
+ assert_array_equal(a, s)
428
+
429
+ a[...] = memoryview(s)
430
+ assert_array_equal(a, s)
431
+
432
+ @pytest.mark.parametrize("writeable", [True, False])
433
+ def test_subclass_writeable(self, writeable):
434
+ d = np.rec.array([('NGC1001', 11), ('NGC1002', 1.), ('NGC1003', 1.)],
435
+ dtype=[('target', 'S20'), ('V_mag', '>f4')])
436
+ d.flags.writeable = writeable
437
+ # Advanced indexing results are always writeable:
438
+ ind = np.array([False, True, True], dtype=bool)
439
+ assert d[ind].flags.writeable
440
+ ind = np.array([0, 1])
441
+ assert d[ind].flags.writeable
442
+ # Views should be writeable if the original array is:
443
+ assert d[...].flags.writeable == writeable
444
+ assert d[0].flags.writeable == writeable
445
+
446
+ def test_memory_order(self):
447
+ # This is not necessary to preserve. Memory layouts for
448
+ # more complex indices are not as simple.
449
+ a = np.arange(10)
450
+ b = np.arange(10).reshape(5, 2).T
451
+ assert_(a[b].flags.f_contiguous)
452
+
453
+ # Takes a different implementation branch:
454
+ a = a.reshape(-1, 1)
455
+ assert_(a[b, 0].flags.f_contiguous)
456
+
457
+ def test_scalar_return_type(self):
458
+ # Full scalar indices should return scalars and object
459
+ # arrays should not call PyArray_Return on their items
460
+ class Zero:
461
+ # The most basic valid indexing
462
+ def __index__(self):
463
+ return 0
464
+
465
+ z = Zero()
466
+
467
+ class ArrayLike:
468
+ # Simple array, should behave like the array
469
+ def __array__(self, dtype=None, copy=None):
470
+ return np.array(0)
471
+
472
+ a = np.zeros(())
473
+ assert_(isinstance(a[()], np.float64))
474
+ a = np.zeros(1)
475
+ assert_(isinstance(a[z], np.float64))
476
+ a = np.zeros((1, 1))
477
+ assert_(isinstance(a[z, np.array(0)], np.float64))
478
+ assert_(isinstance(a[z, ArrayLike()], np.float64))
479
+
480
+ # And object arrays do not call it too often:
481
+ b = np.array(0)
482
+ a = np.array(0, dtype=object)
483
+ a[()] = b
484
+ assert_(isinstance(a[()], np.ndarray))
485
+ a = np.array([b, None])
486
+ assert_(isinstance(a[z], np.ndarray))
487
+ a = np.array([[b, None]])
488
+ assert_(isinstance(a[z, np.array(0)], np.ndarray))
489
+ assert_(isinstance(a[z, ArrayLike()], np.ndarray))
490
+
491
+ def test_small_regressions(self):
492
+ # Reference count of intp for index checks
493
+ a = np.array([0])
494
+ if HAS_REFCOUNT:
495
+ refcount = sys.getrefcount(np.dtype(np.intp))
496
+ # item setting always checks indices in separate function:
497
+ a[np.array([0], dtype=np.intp)] = 1
498
+ a[np.array([0], dtype=np.uint8)] = 1
499
+ assert_raises(IndexError, a.__setitem__,
500
+ np.array([1], dtype=np.intp), 1)
501
+ assert_raises(IndexError, a.__setitem__,
502
+ np.array([1], dtype=np.uint8), 1)
503
+
504
+ if HAS_REFCOUNT:
505
+ assert_equal(sys.getrefcount(np.dtype(np.intp)), refcount)
506
+
507
+ def test_unaligned(self):
508
+ v = (np.zeros(64, dtype=np.int8) + ord('a'))[1:-7]
509
+ d = v.view(np.dtype("S8"))
510
+ # unaligned source
511
+ x = (np.zeros(16, dtype=np.int8) + ord('a'))[1:-7]
512
+ x = x.view(np.dtype("S8"))
513
+ x[...] = np.array("b" * 8, dtype="S")
514
+ b = np.arange(d.size)
515
+ # trivial
516
+ assert_equal(d[b], d)
517
+ d[b] = x
518
+ # nontrivial
519
+ # unaligned index array
520
+ b = np.zeros(d.size + 1).view(np.int8)[1:-(np.intp(0).itemsize - 1)]
521
+ b = b.view(np.intp)[:d.size]
522
+ b[...] = np.arange(d.size)
523
+ assert_equal(d[b.astype(np.int16)], d)
524
+ d[b.astype(np.int16)] = x
525
+ # boolean
526
+ d[b % 2 == 0]
527
+ d[b % 2 == 0] = x[::2]
528
+
529
+ def test_tuple_subclass(self):
530
+ arr = np.ones((5, 5))
531
+
532
+ # A tuple subclass should also be an nd-index
533
+ class TupleSubclass(tuple):
534
+ pass
535
+ index = ([1], [1])
536
+ index = TupleSubclass(index)
537
+ assert_(arr[index].shape == (1,))
538
+ # Unlike the non nd-index:
539
+ assert_(arr[index,].shape != (1,))
540
+
541
+ def test_broken_sequence_not_nd_index(self):
542
+ # See gh-5063:
543
+ # If we have an object which claims to be a sequence, but fails
544
+ # on item getting, this should not be converted to an nd-index (tuple)
545
+ # If this object happens to be a valid index otherwise, it should work
546
+ # This object here is very dubious and probably bad though:
547
+ class SequenceLike:
548
+ def __index__(self):
549
+ return 0
550
+
551
+ def __len__(self):
552
+ return 1
553
+
554
+ def __getitem__(self, item):
555
+ raise IndexError('Not possible')
556
+
557
+ arr = np.arange(10)
558
+ assert_array_equal(arr[SequenceLike()], arr[SequenceLike(),])
559
+
560
+ # also test that field indexing does not segfault
561
+ # for a similar reason, by indexing a structured array
562
+ arr = np.zeros((1,), dtype=[('f1', 'i8'), ('f2', 'i8')])
563
+ assert_array_equal(arr[SequenceLike()], arr[SequenceLike(),])
564
+
565
+ def test_indexing_array_weird_strides(self):
566
+ # See also gh-6221
567
+ # the shapes used here come from the issue and create the correct
568
+ # size for the iterator buffering size.
569
+ x = np.ones(10)
570
+ x2 = np.ones((10, 2))
571
+ ind = np.arange(10)[:, None, None, None]
572
+ ind = np.broadcast_to(ind, (10, 55, 4, 4))
573
+
574
+ # single advanced index case
575
+ assert_array_equal(x[ind], x[ind.copy()])
576
+ # higher dimensional advanced index
577
+ zind = np.zeros(4, dtype=np.intp)
578
+ assert_array_equal(x2[ind, zind], x2[ind.copy(), zind])
579
+
580
+ def test_indexing_array_negative_strides(self):
581
+ # From gh-8264,
582
+ # core dumps if negative strides are used in iteration
583
+ arro = np.zeros((4, 4))
584
+ arr = arro[::-1, ::-1]
585
+
586
+ slices = (slice(None), [0, 1, 2, 3])
587
+ arr[slices] = 10
588
+ assert_array_equal(arr, 10.)
589
+
590
+ def test_character_assignment(self):
591
+ # This is an example a function going through CopyObject which
592
+ # used to have an untested special path for scalars
593
+ # (the character special dtype case, should be deprecated probably)
594
+ arr = np.zeros((1, 5), dtype="c")
595
+ arr[0] = np.str_("asdfg") # must assign as a sequence
596
+ assert_array_equal(arr[0], np.array("asdfg", dtype="c"))
597
+ assert arr[0, 1] == b"s" # make sure not all were set to "a" for both
598
+
599
+ @pytest.mark.parametrize("index",
600
+ [True, False, np.array([0])])
601
+ @pytest.mark.parametrize("num", [64, 80])
602
+ @pytest.mark.parametrize("original_ndim", [1, 64])
603
+ def test_too_many_advanced_indices(self, index, num, original_ndim):
604
+ # These are limitations based on the number of arguments we can process.
605
+ # For `num=32` (and all boolean cases), the result is actually define;
606
+ # but the use of NpyIter (NPY_MAXARGS) limits it for technical reasons.
607
+ arr = np.ones((1,) * original_ndim)
608
+ with pytest.raises(IndexError):
609
+ arr[(index,) * num]
610
+ with pytest.raises(IndexError):
611
+ arr[(index,) * num] = 1.
612
+
613
+ def test_nontuple_ndindex(self):
614
+ a = np.arange(25).reshape((5, 5))
615
+ assert_equal(a[[0, 1]], np.array([a[0], a[1]]))
616
+ assert_equal(a[[0, 1], [0, 1]], np.array([0, 6]))
617
+ assert_raises(IndexError, a.__getitem__, [slice(None)])
618
+
619
+
620
+ class TestFieldIndexing:
621
+ def test_scalar_return_type(self):
622
+ # Field access on an array should return an array, even if it
623
+ # is 0-d.
624
+ a = np.zeros((), [('a', 'f8')])
625
+ assert_(isinstance(a['a'], np.ndarray))
626
+ assert_(isinstance(a[['a']], np.ndarray))
627
+
628
+
629
+ class TestBroadcastedAssignments:
630
+ def assign(self, a, ind, val):
631
+ a[ind] = val
632
+ return a
633
+
634
+ def test_prepending_ones(self):
635
+ a = np.zeros((3, 2))
636
+
637
+ a[...] = np.ones((1, 3, 2))
638
+ # Fancy with subspace with and without transpose
639
+ a[[0, 1, 2], :] = np.ones((1, 3, 2))
640
+ a[:, [0, 1]] = np.ones((1, 3, 2))
641
+ # Fancy without subspace (with broadcasting)
642
+ a[[[0], [1], [2]], [0, 1]] = np.ones((1, 3, 2))
643
+
644
+ def test_prepend_not_one(self):
645
+ assign = self.assign
646
+ s_ = np.s_
647
+ a = np.zeros(5)
648
+
649
+ # Too large and not only ones.
650
+ assert_raises(ValueError, assign, a, s_[...], np.ones((2, 1)))
651
+ assert_raises(ValueError, assign, a, s_[[1, 2, 3],], np.ones((2, 1)))
652
+ assert_raises(ValueError, assign, a, s_[[[1], [2]],], np.ones((2, 2, 1)))
653
+
654
+ def test_simple_broadcasting_errors(self):
655
+ assign = self.assign
656
+ s_ = np.s_
657
+ a = np.zeros((5, 1))
658
+
659
+ assert_raises(ValueError, assign, a, s_[...], np.zeros((5, 2)))
660
+ assert_raises(ValueError, assign, a, s_[...], np.zeros((5, 0)))
661
+ assert_raises(ValueError, assign, a, s_[:, [0]], np.zeros((5, 2)))
662
+ assert_raises(ValueError, assign, a, s_[:, [0]], np.zeros((5, 0)))
663
+ assert_raises(ValueError, assign, a, s_[[0], :], np.zeros((2, 1)))
664
+
665
+ @pytest.mark.parametrize("index", [
666
+ (..., [1, 2], slice(None)),
667
+ ([0, 1], ..., 0),
668
+ (..., [1, 2], [1, 2])])
669
+ def test_broadcast_error_reports_correct_shape(self, index):
670
+ values = np.zeros((100, 100)) # will never broadcast below
671
+
672
+ arr = np.zeros((3, 4, 5, 6, 7))
673
+ # We currently report without any spaces (could be changed)
674
+ shape_str = str(arr[index].shape).replace(" ", "")
675
+
676
+ with pytest.raises(ValueError) as e:
677
+ arr[index] = values
678
+
679
+ assert str(e.value).endswith(shape_str)
680
+
681
+ def test_index_is_larger(self):
682
+ # Simple case of fancy index broadcasting of the index.
683
+ a = np.zeros((5, 5))
684
+ a[[[0], [1], [2]], [0, 1, 2]] = [2, 3, 4]
685
+
686
+ assert_((a[:3, :3] == [2, 3, 4]).all())
687
+
688
+ def test_broadcast_subspace(self):
689
+ a = np.zeros((100, 100))
690
+ v = np.arange(100)[:, None]
691
+ b = np.arange(100)[::-1]
692
+ a[b] = v
693
+ assert_((a[::-1] == v).all())
694
+
695
+
696
+ class TestSubclasses:
697
+ def test_basic(self):
698
+ # Test that indexing in various ways produces SubClass instances,
699
+ # and that the base is set up correctly: the original subclass
700
+ # instance for views, and a new ndarray for advanced/boolean indexing
701
+ # where a copy was made (latter a regression test for gh-11983).
702
+ class SubClass(np.ndarray):
703
+ pass
704
+
705
+ a = np.arange(5)
706
+ s = a.view(SubClass)
707
+ s_slice = s[:3]
708
+ assert_(type(s_slice) is SubClass)
709
+ assert_(s_slice.base is s)
710
+ assert_array_equal(s_slice, a[:3])
711
+
712
+ s_fancy = s[[0, 1, 2]]
713
+ assert_(type(s_fancy) is SubClass)
714
+ assert_(s_fancy.base is not s)
715
+ assert_(type(s_fancy.base) is np.ndarray)
716
+ assert_array_equal(s_fancy, a[[0, 1, 2]])
717
+ assert_array_equal(s_fancy.base, a[[0, 1, 2]])
718
+
719
+ s_bool = s[s > 0]
720
+ assert_(type(s_bool) is SubClass)
721
+ assert_(s_bool.base is not s)
722
+ assert_(type(s_bool.base) is np.ndarray)
723
+ assert_array_equal(s_bool, a[a > 0])
724
+ assert_array_equal(s_bool.base, a[a > 0])
725
+
726
+ def test_fancy_on_read_only(self):
727
+ # Test that fancy indexing on read-only SubClass does not make a
728
+ # read-only copy (gh-14132)
729
+ class SubClass(np.ndarray):
730
+ pass
731
+
732
+ a = np.arange(5)
733
+ s = a.view(SubClass)
734
+ s.flags.writeable = False
735
+ s_fancy = s[[0, 1, 2]]
736
+ assert_(s_fancy.flags.writeable)
737
+
738
+ def test_finalize_gets_full_info(self):
739
+ # Array finalize should be called on the filled array.
740
+ class SubClass(np.ndarray):
741
+ def __array_finalize__(self, old):
742
+ self.finalize_status = np.array(self)
743
+ self.old = old
744
+
745
+ s = np.arange(10).view(SubClass)
746
+ new_s = s[:3]
747
+ assert_array_equal(new_s.finalize_status, new_s)
748
+ assert_array_equal(new_s.old, s)
749
+
750
+ new_s = s[[0, 1, 2, 3]]
751
+ assert_array_equal(new_s.finalize_status, new_s)
752
+ assert_array_equal(new_s.old, s)
753
+
754
+ new_s = s[s > 0]
755
+ assert_array_equal(new_s.finalize_status, new_s)
756
+ assert_array_equal(new_s.old, s)
757
+
758
+
759
+ class TestFancyIndexingCast:
760
+ def test_boolean_index_cast_assign(self):
761
+ # Setup the boolean index and float arrays.
762
+ shape = (8, 63)
763
+ bool_index = np.zeros(shape).astype(bool)
764
+ bool_index[0, 1] = True
765
+ zero_array = np.zeros(shape)
766
+
767
+ # Assigning float is fine.
768
+ zero_array[bool_index] = np.array([1])
769
+ assert_equal(zero_array[0, 1], 1)
770
+
771
+ # Fancy indexing works, although we get a cast warning.
772
+ pytest.warns(ComplexWarning,
773
+ zero_array.__setitem__, ([0], [1]), np.array([2 + 1j]))
774
+ assert_equal(zero_array[0, 1], 2) # No complex part
775
+
776
+ # Cast complex to float, throwing away the imaginary portion.
777
+ pytest.warns(ComplexWarning,
778
+ zero_array.__setitem__, bool_index, np.array([1j]))
779
+ assert_equal(zero_array[0, 1], 0)
780
+
781
+
782
+ class TestFancyIndexingEquivalence:
783
+ def test_object_assign(self):
784
+ # Check that the field and object special case using copyto is active.
785
+ # The right hand side cannot be converted to an array here.
786
+ a = np.arange(5, dtype=object)
787
+ b = a.copy()
788
+ a[:3] = [1, (1, 2), 3]
789
+ b[[0, 1, 2]] = [1, (1, 2), 3]
790
+ assert_array_equal(a, b)
791
+
792
+ # test same for subspace fancy indexing
793
+ b = np.arange(5, dtype=object)[None, :]
794
+ b[[0], :3] = [[1, (1, 2), 3]]
795
+ assert_array_equal(a, b[0])
796
+
797
+ # Check that swapping of axes works.
798
+ # There was a bug that made the later assignment throw a ValueError
799
+ # do to an incorrectly transposed temporary right hand side (gh-5714)
800
+ b = b.T
801
+ b[:3, [0]] = [[1], [(1, 2)], [3]]
802
+ assert_array_equal(a, b[:, 0])
803
+
804
+ # Another test for the memory order of the subspace
805
+ arr = np.ones((3, 4, 5), dtype=object)
806
+ # Equivalent slicing assignment for comparison
807
+ cmp_arr = arr.copy()
808
+ cmp_arr[:1, ...] = [[[1], [2], [3], [4]]]
809
+ arr[[0], ...] = [[[1], [2], [3], [4]]]
810
+ assert_array_equal(arr, cmp_arr)
811
+ arr = arr.copy('F')
812
+ arr[[0], ...] = [[[1], [2], [3], [4]]]
813
+ assert_array_equal(arr, cmp_arr)
814
+
815
+ def test_cast_equivalence(self):
816
+ # Yes, normal slicing uses unsafe casting.
817
+ a = np.arange(5)
818
+ b = a.copy()
819
+
820
+ a[:3] = np.array(['2', '-3', '-1'])
821
+ b[[0, 2, 1]] = np.array(['2', '-1', '-3'])
822
+ assert_array_equal(a, b)
823
+
824
+ # test the same for subspace fancy indexing
825
+ b = np.arange(5)[None, :]
826
+ b[[0], :3] = np.array([['2', '-3', '-1']])
827
+ assert_array_equal(a, b[0])
828
+
829
+
830
+ class TestMultiIndexingAutomated:
831
+ """
832
+ These tests use code to mimic the C-Code indexing for selection.
833
+
834
+ NOTE:
835
+
836
+ * This still lacks tests for complex item setting.
837
+ * If you change behavior of indexing, you might want to modify
838
+ these tests to try more combinations.
839
+ * Behavior was written to match numpy version 1.8. (though a
840
+ first version matched 1.7.)
841
+ * Only tuple indices are supported by the mimicking code.
842
+ (and tested as of writing this)
843
+ * Error types should match most of the time as long as there
844
+ is only one error. For multiple errors, what gets raised
845
+ will usually not be the same one. They are *not* tested.
846
+
847
+ Update 2016-11-30: It is probably not worth maintaining this test
848
+ indefinitely and it can be dropped if maintenance becomes a burden.
849
+
850
+ """
851
+
852
+ def _create_array(self):
853
+ return np.arange(np.prod([3, 1, 5, 6])).reshape(3, 1, 5, 6)
854
+
855
+ def _create_complex_indices(self):
856
+ return ['skip', Ellipsis,
857
+ 0,
858
+ # Boolean indices, up to 3-d for some special cases of eating up
859
+ # dimensions, also need to test all False
860
+ np.array([True, False, False]),
861
+ np.array([[True, False], [False, True]]),
862
+ np.array([[[False, False], [False, False]]]),
863
+ # Some slices:
864
+ slice(-5, 5, 2),
865
+ slice(1, 1, 100),
866
+ slice(4, -1, -2),
867
+ slice(None, None, -3),
868
+ # Some Fancy indexes:
869
+ np.empty((0, 1, 1), dtype=np.intp), # empty and can be broadcast
870
+ np.array([0, 1, -2]),
871
+ np.array([[2], [0], [1]]),
872
+ np.array([[0, -1], [0, 1]], dtype=np.dtype('intp').newbyteorder()),
873
+ np.array([2, -1], dtype=np.int8),
874
+ np.zeros([1] * 31, dtype=int), # trigger too large array.
875
+ np.array([0., 1.])] # invalid datatype
876
+
877
+ def _get_multi_index(self, arr, indices):
878
+ """Mimic multi dimensional indexing.
879
+
880
+ Parameters
881
+ ----------
882
+ arr : ndarray
883
+ Array to be indexed.
884
+ indices : tuple of index objects
885
+
886
+ Returns
887
+ -------
888
+ out : ndarray
889
+ An array equivalent to the indexing operation (but always a copy).
890
+ `arr[indices]` should be identical.
891
+ no_copy : bool
892
+ Whether the indexing operation requires a copy. If this is `True`,
893
+ `np.may_share_memory(arr, arr[indices])` should be `True` (with
894
+ some exceptions for scalars and possibly 0-d arrays).
895
+
896
+ Notes
897
+ -----
898
+ While the function may mostly match the errors of normal indexing this
899
+ is generally not the case.
900
+ """
901
+ in_indices = list(indices)
902
+ indices = []
903
+ # if False, this is a fancy or boolean index
904
+ no_copy = True
905
+ # number of fancy/scalar indexes that are not consecutive
906
+ num_fancy = 0
907
+ # number of dimensions indexed by a "fancy" index
908
+ fancy_dim = 0
909
+ # NOTE: This is a funny twist (and probably OK to change).
910
+ # The boolean array has illegal indexes, but this is
911
+ # allowed if the broadcast fancy-indices are 0-sized.
912
+ # This variable is to catch that case.
913
+ error_unless_broadcast_to_empty = False
914
+
915
+ # We need to handle Ellipsis and make arrays from indices, also
916
+ # check if this is fancy indexing (set no_copy).
917
+ ndim = 0
918
+ ellipsis_pos = None # define here mostly to replace all but first.
919
+ for i, indx in enumerate(in_indices):
920
+ if indx is None:
921
+ continue
922
+ if isinstance(indx, np.ndarray) and indx.dtype == bool:
923
+ no_copy = False
924
+ if indx.ndim == 0:
925
+ raise IndexError
926
+ # boolean indices can have higher dimensions
927
+ ndim += indx.ndim
928
+ fancy_dim += indx.ndim
929
+ continue
930
+ if indx is Ellipsis:
931
+ if ellipsis_pos is None:
932
+ ellipsis_pos = i
933
+ continue # do not increment ndim counter
934
+ raise IndexError
935
+ if isinstance(indx, slice):
936
+ ndim += 1
937
+ continue
938
+ if not isinstance(indx, np.ndarray):
939
+ # This could be open for changes in numpy.
940
+ # numpy should maybe raise an error if casting to intp
941
+ # is not safe. It rejects np.array([1., 2.]) but not
942
+ # [1., 2.] as index (same for ie. np.take).
943
+ # (Note the importance of empty lists if changing this here)
944
+ try:
945
+ indx = np.array(indx, dtype=np.intp)
946
+ except ValueError:
947
+ raise IndexError
948
+ in_indices[i] = indx
949
+ elif indx.dtype.kind not in 'bi':
950
+ raise IndexError('arrays used as indices must be of '
951
+ 'integer (or boolean) type')
952
+ if indx.ndim != 0:
953
+ no_copy = False
954
+ ndim += 1
955
+ fancy_dim += 1
956
+
957
+ if arr.ndim - ndim < 0:
958
+ # we can't take more dimensions then we have, not even for 0-d
959
+ # arrays. since a[()] makes sense, but not a[(),]. We will
960
+ # raise an error later on, unless a broadcasting error occurs
961
+ # first.
962
+ raise IndexError
963
+
964
+ if ndim == 0 and None not in in_indices:
965
+ # Well we have no indexes or one Ellipsis. This is legal.
966
+ return arr.copy(), no_copy
967
+
968
+ if ellipsis_pos is not None:
969
+ in_indices[ellipsis_pos:ellipsis_pos + 1] = ([slice(None, None)] *
970
+ (arr.ndim - ndim))
971
+
972
+ for ax, indx in enumerate(in_indices):
973
+ if isinstance(indx, slice):
974
+ # convert to an index array
975
+ indx = np.arange(*indx.indices(arr.shape[ax]))
976
+ indices.append(['s', indx])
977
+ continue
978
+ elif indx is None:
979
+ # this is like taking a slice with one element from a new axis:
980
+ indices.append(['n', np.array([0], dtype=np.intp)])
981
+ arr = arr.reshape(arr.shape[:ax] + (1,) + arr.shape[ax:])
982
+ continue
983
+ if isinstance(indx, np.ndarray) and indx.dtype == bool:
984
+ if indx.shape != arr.shape[ax:ax + indx.ndim]:
985
+ raise IndexError
986
+
987
+ try:
988
+ flat_indx = np.ravel_multi_index(np.nonzero(indx),
989
+ arr.shape[ax:ax + indx.ndim], mode='raise')
990
+ except Exception:
991
+ error_unless_broadcast_to_empty = True
992
+ # fill with 0s instead, and raise error later
993
+ flat_indx = np.array([0] * indx.sum(), dtype=np.intp)
994
+ # concatenate axis into a single one:
995
+ if indx.ndim != 0:
996
+ arr = arr.reshape(arr.shape[:ax]
997
+ + (np.prod(arr.shape[ax:ax + indx.ndim]),)
998
+ + arr.shape[ax + indx.ndim:])
999
+ indx = flat_indx
1000
+ else:
1001
+ # This could be changed, a 0-d boolean index can
1002
+ # make sense (even outside the 0-d indexed array case)
1003
+ # Note that originally this is could be interpreted as
1004
+ # integer in the full integer special case.
1005
+ raise IndexError
1006
+ # If the index is a singleton, the bounds check is done
1007
+ # before the broadcasting. This used to be different in <1.9
1008
+ elif indx.ndim == 0 and not (
1009
+ -arr.shape[ax] <= indx < arr.shape[ax]
1010
+ ):
1011
+ raise IndexError
1012
+ if indx.ndim == 0:
1013
+ # The index is a scalar. This used to be two fold, but if
1014
+ # fancy indexing was active, the check was done later,
1015
+ # possibly after broadcasting it away (1.7. or earlier).
1016
+ # Now it is always done.
1017
+ if indx >= arr.shape[ax] or indx < - arr.shape[ax]:
1018
+ raise IndexError
1019
+ if (len(indices) > 0 and
1020
+ indices[-1][0] == 'f' and
1021
+ ax != ellipsis_pos):
1022
+ # NOTE: There could still have been a 0-sized Ellipsis
1023
+ # between them. Checked that with ellipsis_pos.
1024
+ indices[-1].append(indx)
1025
+ else:
1026
+ # We have a fancy index that is not after an existing one.
1027
+ # NOTE: A 0-d array triggers this as well, while one may
1028
+ # expect it to not trigger it, since a scalar would not be
1029
+ # considered fancy indexing.
1030
+ num_fancy += 1
1031
+ indices.append(['f', indx])
1032
+
1033
+ if num_fancy > 1 and not no_copy:
1034
+ # We have to flush the fancy indexes left
1035
+ new_indices = indices[:]
1036
+ axes = list(range(arr.ndim))
1037
+ fancy_axes = []
1038
+ new_indices.insert(0, ['f'])
1039
+ ni = 0
1040
+ ai = 0
1041
+ for indx in indices:
1042
+ ni += 1
1043
+ if indx[0] == 'f':
1044
+ new_indices[0].extend(indx[1:])
1045
+ del new_indices[ni]
1046
+ ni -= 1
1047
+ for ax in range(ai, ai + len(indx[1:])):
1048
+ fancy_axes.append(ax)
1049
+ axes.remove(ax)
1050
+ ai += len(indx) - 1 # axis we are at
1051
+ indices = new_indices
1052
+ # and now we need to transpose arr:
1053
+ arr = arr.transpose(*(fancy_axes + axes))
1054
+
1055
+ # We only have one 'f' index now and arr is transposed accordingly.
1056
+ # Now handle newaxis by reshaping...
1057
+ ax = 0
1058
+ for indx in indices:
1059
+ if indx[0] == 'f':
1060
+ if len(indx) == 1:
1061
+ continue
1062
+ # First of all, reshape arr to combine fancy axes into one:
1063
+ orig_shape = arr.shape
1064
+ orig_slice = orig_shape[ax:ax + len(indx[1:])]
1065
+ arr = arr.reshape(arr.shape[:ax]
1066
+ + (np.prod(orig_slice).astype(int),)
1067
+ + arr.shape[ax + len(indx[1:]):])
1068
+
1069
+ # Check if broadcasting works
1070
+ res = np.broadcast(*indx[1:])
1071
+ # unfortunately the indices might be out of bounds. So check
1072
+ # that first, and use mode='wrap' then. However only if
1073
+ # there are any indices...
1074
+ if res.size != 0:
1075
+ if error_unless_broadcast_to_empty:
1076
+ raise IndexError
1077
+ for _indx, _size in zip(indx[1:], orig_slice):
1078
+ if _indx.size == 0:
1079
+ continue
1080
+ if np.any(_indx >= _size) or np.any(_indx < -_size):
1081
+ raise IndexError
1082
+ if len(indx[1:]) == len(orig_slice):
1083
+ if np.prod(orig_slice) == 0:
1084
+ # Work around for a crash or IndexError with 'wrap'
1085
+ # in some 0-sized cases.
1086
+ try:
1087
+ mi = np.ravel_multi_index(indx[1:], orig_slice,
1088
+ mode='raise')
1089
+ except Exception:
1090
+ # This happens with 0-sized orig_slice (sometimes?)
1091
+ # here it is a ValueError, but indexing gives a:
1092
+ raise IndexError('invalid index into 0-sized')
1093
+ else:
1094
+ mi = np.ravel_multi_index(indx[1:], orig_slice,
1095
+ mode='wrap')
1096
+ else:
1097
+ # Maybe never happens...
1098
+ raise ValueError
1099
+ arr = arr.take(mi.ravel(), axis=ax)
1100
+ try:
1101
+ arr = arr.reshape(arr.shape[:ax]
1102
+ + mi.shape
1103
+ + arr.shape[ax + 1:])
1104
+ except ValueError:
1105
+ # too many dimensions, probably
1106
+ raise IndexError
1107
+ ax += mi.ndim
1108
+ continue
1109
+
1110
+ # If we are here, we have a 1D array for take:
1111
+ arr = arr.take(indx[1], axis=ax)
1112
+ ax += 1
1113
+
1114
+ return arr, no_copy
1115
+
1116
+ def _check_multi_index(self, arr, index):
1117
+ """Check a multi index item getting and simple setting.
1118
+
1119
+ Parameters
1120
+ ----------
1121
+ arr : ndarray
1122
+ Array to be indexed, must be a reshaped arange.
1123
+ index : tuple of indexing objects
1124
+ Index being tested.
1125
+ """
1126
+ # Test item getting
1127
+ try:
1128
+ mimic_get, no_copy = self._get_multi_index(arr, index)
1129
+ except Exception as e:
1130
+ if HAS_REFCOUNT:
1131
+ prev_refcount = sys.getrefcount(arr)
1132
+ assert_raises(type(e), arr.__getitem__, index)
1133
+ assert_raises(type(e), arr.__setitem__, index, 0)
1134
+ if HAS_REFCOUNT:
1135
+ assert_equal(prev_refcount, sys.getrefcount(arr))
1136
+ return
1137
+
1138
+ self._compare_index_result(arr, index, mimic_get, no_copy)
1139
+
1140
+ def _check_single_index(self, arr, index):
1141
+ """Check a single index item getting and simple setting.
1142
+
1143
+ Parameters
1144
+ ----------
1145
+ arr : ndarray
1146
+ Array to be indexed, must be an arange.
1147
+ index : indexing object
1148
+ Index being tested. Must be a single index and not a tuple
1149
+ of indexing objects (see also `_check_multi_index`).
1150
+ """
1151
+ try:
1152
+ mimic_get, no_copy = self._get_multi_index(arr, (index,))
1153
+ except Exception as e:
1154
+ if HAS_REFCOUNT:
1155
+ prev_refcount = sys.getrefcount(arr)
1156
+ assert_raises(type(e), arr.__getitem__, index)
1157
+ assert_raises(type(e), arr.__setitem__, index, 0)
1158
+ if HAS_REFCOUNT:
1159
+ assert_equal(prev_refcount, sys.getrefcount(arr))
1160
+ return
1161
+
1162
+ self._compare_index_result(arr, index, mimic_get, no_copy)
1163
+
1164
+ def _compare_index_result(self, arr, index, mimic_get, no_copy):
1165
+ """Compare mimicked result to indexing result.
1166
+ """
1167
+ arr = arr.copy()
1168
+ if HAS_REFCOUNT:
1169
+ startcount = sys.getrefcount(arr)
1170
+ indexed_arr = arr[index]
1171
+ assert_array_equal(indexed_arr, mimic_get)
1172
+ # Check if we got a view, unless its a 0-sized or 0-d array.
1173
+ # (then its not a view, and that does not matter)
1174
+ if indexed_arr.size != 0 and indexed_arr.ndim != 0:
1175
+ assert_(np.may_share_memory(indexed_arr, arr) == no_copy)
1176
+ # Check reference count of the original array
1177
+ if HAS_REFCOUNT:
1178
+ if no_copy:
1179
+ # refcount increases by one:
1180
+ assert_equal(sys.getrefcount(arr), startcount + 1)
1181
+ else:
1182
+ assert_equal(sys.getrefcount(arr), startcount)
1183
+
1184
+ # Test non-broadcast setitem:
1185
+ b = arr.copy()
1186
+ b[index] = mimic_get + 1000
1187
+ if b.size == 0:
1188
+ return # nothing to compare here...
1189
+ if no_copy and indexed_arr.ndim != 0:
1190
+ # change indexed_arr in-place to manipulate original:
1191
+ indexed_arr += 1000
1192
+ assert_array_equal(arr, b)
1193
+ return
1194
+ # Use the fact that the array is originally an arange:
1195
+ arr.flat[indexed_arr.ravel()] += 1000
1196
+ assert_array_equal(arr, b)
1197
+
1198
+ def test_boolean(self):
1199
+ a = np.array(5)
1200
+ assert_equal(a[np.array(True)], 5)
1201
+ a[np.array(True)] = 1
1202
+ assert_equal(a, 1)
1203
+ # NOTE: This is different from normal broadcasting, as
1204
+ # arr[boolean_array] works like in a multi index. Which means
1205
+ # it is aligned to the left. This is probably correct for
1206
+ # consistency with arr[boolean_array,] also no broadcasting
1207
+ # is done at all
1208
+ a = self._create_array()
1209
+ self._check_multi_index(
1210
+ a, (np.zeros_like(a, dtype=bool),))
1211
+ self._check_multi_index(
1212
+ a, (np.zeros_like(a, dtype=bool)[..., 0],))
1213
+ self._check_multi_index(
1214
+ a, (np.zeros_like(a, dtype=bool)[None, ...],))
1215
+
1216
+ def test_multidim(self):
1217
+ # Automatically test combinations with complex indexes on 2nd (or 1st)
1218
+ # spot and the simple ones in one other spot.
1219
+ a = self._create_array()
1220
+ b = np.empty((3, 0, 5, 6))
1221
+ complex_indices = self._create_complex_indices()
1222
+ simple_indices = [Ellipsis, None, -1, [1], np.array([True]), 'skip']
1223
+ fill_indices = [slice(None, None), 0]
1224
+
1225
+ with warnings.catch_warnings():
1226
+ # This is so that np.array(True) is not accepted in a full integer
1227
+ # index, when running the file separately.
1228
+ warnings.filterwarnings('error', '', DeprecationWarning)
1229
+ warnings.filterwarnings('error', '', VisibleDeprecationWarning)
1230
+
1231
+ def isskip(idx):
1232
+ return isinstance(idx, str) and idx == "skip"
1233
+
1234
+ for simple_pos in [0, 2, 3]:
1235
+ tocheck = [fill_indices, complex_indices,
1236
+ fill_indices, fill_indices]
1237
+ tocheck[simple_pos] = simple_indices
1238
+ for index in product(*tocheck):
1239
+ index = tuple(i for i in index if not isskip(i))
1240
+ self._check_multi_index(a, index)
1241
+ self._check_multi_index(b, index)
1242
+
1243
+ # Check very simple item getting:
1244
+ self._check_multi_index(a, (0, 0, 0, 0))
1245
+ self._check_multi_index(b, (0, 0, 0, 0))
1246
+ # Also check (simple cases of) too many indices:
1247
+ assert_raises(IndexError, a.__getitem__, (0, 0, 0, 0, 0))
1248
+ assert_raises(IndexError, a.__setitem__, (0, 0, 0, 0, 0), 0)
1249
+ assert_raises(IndexError, a.__getitem__, (0, 0, [1], 0, 0))
1250
+ assert_raises(IndexError, a.__setitem__, (0, 0, [1], 0, 0), 0)
1251
+
1252
+ def test_1d(self):
1253
+ a = np.arange(10)
1254
+ complex_indices = self._create_complex_indices()
1255
+ for index in complex_indices:
1256
+ self._check_single_index(a, index)
1257
+
1258
+
1259
+ class TestFloatNonIntegerArgument:
1260
+ """
1261
+ These test that ``TypeError`` is raised when you try to use
1262
+ non-integers as arguments to for indexing and slicing e.g. ``a[0.0:5]``
1263
+ and ``a[0.5]``, or other functions like ``array.reshape(1., -1)``.
1264
+
1265
+ """
1266
+ def test_valid_indexing(self):
1267
+ # These should raise no errors.
1268
+ a = np.array([[[5]]])
1269
+
1270
+ a[np.array([0])]
1271
+ a[[0, 0]]
1272
+ a[:, [0, 0]]
1273
+ a[:, 0, :]
1274
+ a[:, :, :]
1275
+
1276
+ def test_valid_slicing(self):
1277
+ # These should raise no errors.
1278
+ a = np.array([[[5]]])
1279
+
1280
+ a[::]
1281
+ a[0:]
1282
+ a[:2]
1283
+ a[0:2]
1284
+ a[::2]
1285
+ a[1::2]
1286
+ a[:2:2]
1287
+ a[1:2:2]
1288
+
1289
+ def test_non_integer_argument_errors(self):
1290
+ a = np.array([[5]])
1291
+
1292
+ assert_raises(TypeError, np.reshape, a, (1., 1., -1))
1293
+ assert_raises(TypeError, np.reshape, a, (np.array(1.), -1))
1294
+ assert_raises(TypeError, np.take, a, [0], 1.)
1295
+ assert_raises(TypeError, np.take, a, [0], np.float64(1.))
1296
+
1297
+ def test_non_integer_sequence_multiplication(self):
1298
+ # NumPy scalar sequence multiply should not work with non-integers
1299
+ def mult(a, b):
1300
+ return a * b
1301
+
1302
+ assert_raises(TypeError, mult, [1], np.float64(3))
1303
+ # following should be OK
1304
+ mult([1], np.int_(3))
1305
+
1306
+ def test_reduce_axis_float_index(self):
1307
+ d = np.zeros((3, 3, 3))
1308
+ assert_raises(TypeError, np.min, d, 0.5)
1309
+ assert_raises(TypeError, np.min, d, (0.5, 1))
1310
+ assert_raises(TypeError, np.min, d, (1, 2.2))
1311
+ assert_raises(TypeError, np.min, d, (.2, 1.2))
1312
+
1313
+
1314
+ class TestBooleanIndexing:
1315
+ # Using a boolean as integer argument/indexing is an error.
1316
+ def test_bool_as_int_argument_errors(self):
1317
+ a = np.array([[[1]]])
1318
+
1319
+ assert_raises(TypeError, np.reshape, a, (True, -1))
1320
+ assert_raises(TypeError, np.reshape, a, (np.bool(True), -1))
1321
+ # Note that operator.index(np.array(True)) does not work, a boolean
1322
+ # array is thus also deprecated, but not with the same message:
1323
+ assert_raises(TypeError, operator.index, np.array(True))
1324
+ assert_raises(TypeError, operator.index, np.True_)
1325
+ assert_raises(TypeError, np.take, args=(a, [0], False))
1326
+
1327
+ def test_boolean_indexing_weirdness(self):
1328
+ # Weird boolean indexing things
1329
+ a = np.ones((2, 3, 4))
1330
+ assert a[False, True, ...].shape == (0, 2, 3, 4)
1331
+ assert a[True, [0, 1], True, True, [1], [[2]]].shape == (1, 2)
1332
+ assert_raises(IndexError, lambda: a[False, [0, 1], ...])
1333
+
1334
+ def test_boolean_indexing_fast_path(self):
1335
+ # These used to either give the wrong error, or incorrectly give no
1336
+ # error.
1337
+ a = np.ones((3, 3))
1338
+
1339
+ # This used to incorrectly work (and give an array of shape (0,))
1340
+ idx1 = np.array([[False] * 9])
1341
+ assert_raises_regex(IndexError,
1342
+ "boolean index did not match indexed array along axis 0; "
1343
+ "size of axis is 3 but size of corresponding boolean axis is 1",
1344
+ lambda: a[idx1])
1345
+
1346
+ # This used to incorrectly give a ValueError: operands could not be
1347
+ # broadcast together
1348
+ idx2 = np.array([[False] * 8 + [True]])
1349
+ assert_raises_regex(IndexError,
1350
+ "boolean index did not match indexed array along axis 0; "
1351
+ "size of axis is 3 but size of corresponding boolean axis is 1",
1352
+ lambda: a[idx2])
1353
+
1354
+ # This is the same as it used to be. The above two should work like this.
1355
+ idx3 = np.array([[False] * 10])
1356
+ assert_raises_regex(IndexError,
1357
+ "boolean index did not match indexed array along axis 0; "
1358
+ "size of axis is 3 but size of corresponding boolean axis is 1",
1359
+ lambda: a[idx3])
1360
+
1361
+ # This used to give ValueError: non-broadcastable operand
1362
+ a = np.ones((1, 1, 2))
1363
+ idx = np.array([[[True], [False]]])
1364
+ assert_raises_regex(IndexError,
1365
+ "boolean index did not match indexed array along axis 1; "
1366
+ "size of axis is 1 but size of corresponding boolean axis is 2",
1367
+ lambda: a[idx])
1368
+
1369
+
1370
+ class TestArrayToIndexDeprecation:
1371
+ """Creating an index from array not 0-D is an error.
1372
+
1373
+ """
1374
+ def test_array_to_index_error(self):
1375
+ # so no exception is expected. The raising is effectively tested above.
1376
+ a = np.array([[[1]]])
1377
+
1378
+ assert_raises(TypeError, operator.index, np.array([1]))
1379
+ assert_raises(TypeError, np.reshape, a, (a, -1))
1380
+ assert_raises(TypeError, np.take, a, [0], a)
1381
+
1382
+
1383
+ class TestNonIntegerArrayLike:
1384
+ """Tests that array_likes only valid if can safely cast to integer.
1385
+
1386
+ For instance, lists give IndexError when they cannot be safely cast to
1387
+ an integer.
1388
+
1389
+ """
1390
+ def test_basic(self):
1391
+ a = np.arange(10)
1392
+
1393
+ assert_raises(IndexError, a.__getitem__, [0.5, 1.5])
1394
+ assert_raises(IndexError, a.__getitem__, (['1', '2'],))
1395
+
1396
+ # The following is valid
1397
+ a.__getitem__([])
1398
+
1399
+
1400
+ class TestMultipleEllipsisError:
1401
+ """An index can only have a single ellipsis.
1402
+
1403
+ """
1404
+ def test_basic(self):
1405
+ a = np.arange(10)
1406
+ assert_raises(IndexError, lambda: a[..., ...])
1407
+ assert_raises(IndexError, a.__getitem__, ((Ellipsis,) * 2,))
1408
+ assert_raises(IndexError, a.__getitem__, ((Ellipsis,) * 3,))
1409
+
1410
+
1411
+ class TestCApiAccess:
1412
+ def test_getitem(self):
1413
+ subscript = functools.partial(array_indexing, 0)
1414
+
1415
+ # 0-d arrays don't work:
1416
+ assert_raises(IndexError, subscript, np.ones(()), 0)
1417
+ # Out of bound values:
1418
+ assert_raises(IndexError, subscript, np.ones(10), 11)
1419
+ assert_raises(IndexError, subscript, np.ones(10), -11)
1420
+ assert_raises(IndexError, subscript, np.ones((10, 10)), 11)
1421
+ assert_raises(IndexError, subscript, np.ones((10, 10)), -11)
1422
+
1423
+ a = np.arange(10)
1424
+ assert_array_equal(a[4], subscript(a, 4))
1425
+ a = a.reshape(5, 2)
1426
+ assert_array_equal(a[-4], subscript(a, -4))
1427
+
1428
+ def test_setitem(self):
1429
+ assign = functools.partial(array_indexing, 1)
1430
+
1431
+ # Deletion is impossible:
1432
+ assert_raises(ValueError, assign, np.ones(10), 0)
1433
+ # 0-d arrays don't work:
1434
+ assert_raises(IndexError, assign, np.ones(()), 0, 0)
1435
+ # Out of bound values:
1436
+ assert_raises(IndexError, assign, np.ones(10), 11, 0)
1437
+ assert_raises(IndexError, assign, np.ones(10), -11, 0)
1438
+ assert_raises(IndexError, assign, np.ones((10, 10)), 11, 0)
1439
+ assert_raises(IndexError, assign, np.ones((10, 10)), -11, 0)
1440
+
1441
+ a = np.arange(10)
1442
+ assign(a, 4, 10)
1443
+ assert_(a[4] == 10)
1444
+
1445
+ a = a.reshape(5, 2)
1446
+ assign(a, 4, 10)
1447
+ assert_array_equal(a[-1], [10, 10])
1448
+
1449
+
1450
+ class TestFlatiterIndexing:
1451
+ def test_flatiter_indexing_single_integer(self):
1452
+ a = np.arange(9).reshape((3, 3))
1453
+ assert_array_equal(a.flat[0], 0)
1454
+ assert_array_equal(a.flat[4], 4)
1455
+ assert_array_equal(a.flat[-1], 8)
1456
+
1457
+ with pytest.raises(IndexError, match="index 9 is out of bounds"):
1458
+ a.flat[9]
1459
+
1460
+ def test_flatiter_indexing_slice(self):
1461
+ a = np.arange(9).reshape((3, 3))
1462
+ assert_array_equal(a.flat[:], np.arange(9))
1463
+ assert_array_equal(a.flat[:5], np.arange(5))
1464
+ assert_array_equal(a.flat[5:10], np.arange(5, 9))
1465
+ assert_array_equal(a.flat[::2], np.arange(0, 9, 2))
1466
+ assert_array_equal(a.flat[::-1], np.arange(8, -1, -1))
1467
+ assert_array_equal(a.flat[10:5], np.array([]))
1468
+
1469
+ assert_array_equal(a.flat[()], np.arange(9))
1470
+ assert_array_equal(a.flat[...], np.arange(9))
1471
+
1472
+ def test_flatiter_indexing_boolean(self):
1473
+ a = np.arange(9).reshape((3, 3))
1474
+
1475
+ with pytest.warns(DeprecationWarning, match="0-dimensional boolean index"):
1476
+ assert_array_equal(a.flat[True], 0)
1477
+ with pytest.warns(DeprecationWarning, match="0-dimensional boolean index"):
1478
+ assert_array_equal(a.flat[False], np.array([]))
1479
+
1480
+ mask = np.zeros(len(a.flat), dtype=bool)
1481
+ mask[::2] = True
1482
+ assert_array_equal(a.flat[mask], np.arange(0, 9, 2))
1483
+
1484
+ wrong_mask = np.zeros(len(a.flat) + 1, dtype=bool)
1485
+ with pytest.raises(IndexError,
1486
+ match="boolean index did not match indexed flat iterator"):
1487
+ a.flat[wrong_mask]
1488
+
1489
+ def test_flatiter_indexing_fancy(self):
1490
+ a = np.arange(9).reshape((3, 3))
1491
+
1492
+ indices = np.array([1, 3, 5])
1493
+ assert_array_equal(a.flat[indices], indices)
1494
+
1495
+ assert_array_equal(a.flat[[-1, -2]], np.array([8, 7]))
1496
+
1497
+ indices_2d = np.array([[1, 2], [3, 4]])
1498
+ assert_array_equal(a.flat[indices_2d], indices_2d)
1499
+
1500
+ assert_array_equal(a.flat[[True, 1]], np.array([1, 1]))
1501
+
1502
+ assert_array_equal(a.flat[[]], np.array([], dtype=a.dtype))
1503
+
1504
+ with pytest.raises(IndexError,
1505
+ match="boolean indices for iterators are not supported"):
1506
+ a.flat[[True, True]]
1507
+
1508
+ a = np.arange(3)
1509
+ with pytest.raises(IndexError,
1510
+ match="boolean indices for iterators are not supported"):
1511
+ a.flat[[True, False, True]]
1512
+ assert_array_equal(a.flat[np.asarray([True, False, True])], np.array([0, 2]))
1513
+
1514
+ def test_flatiter_indexing_not_supported_newaxis_mutlidimensional_float(self):
1515
+ a = np.arange(9).reshape((3, 3))
1516
+ with pytest.raises(IndexError,
1517
+ match=r"only integers, slices \(`:`\), "
1518
+ r"ellipsis \(`\.\.\.`\) and "
1519
+ r"integer or boolean arrays are valid indices"):
1520
+ a.flat[None]
1521
+
1522
+ with pytest.raises(IndexError,
1523
+ match=r"too many indices for flat iterator: flat iterator "
1524
+ r"is 1-dimensional, but 2 were indexed"):
1525
+ a.flat[1, 2]
1526
+
1527
+ with pytest.warns(DeprecationWarning,
1528
+ match="Invalid non-array indices for iterator objects are "
1529
+ "deprecated"):
1530
+ assert_array_equal(a.flat[[1.0, 2.0]], np.array([1, 2]))
1531
+
1532
+ def test_flatiter_assign_single_integer(self):
1533
+ a = np.arange(9).reshape((3, 3))
1534
+
1535
+ a.flat[0] = 10
1536
+ assert_array_equal(a, np.array([[10, 1, 2], [3, 4, 5], [6, 7, 8]]))
1537
+
1538
+ a.flat[4] = 20
1539
+ assert_array_equal(a, np.array([[10, 1, 2], [3, 20, 5], [6, 7, 8]]))
1540
+
1541
+ a.flat[-1] = 30
1542
+ assert_array_equal(a, np.array([[10, 1, 2], [3, 20, 5], [6, 7, 30]]))
1543
+
1544
+ with pytest.raises(IndexError, match="index 9 is out of bounds"):
1545
+ a.flat[9] = 40
1546
+
1547
+ def test_flatiter_indexing_slice_assign(self):
1548
+ a = np.arange(9).reshape((3, 3))
1549
+ a.flat[:] = 10
1550
+ assert_array_equal(a, np.full((3, 3), 10))
1551
+
1552
+ a = np.arange(9).reshape((3, 3))
1553
+ a.flat[:5] = 20
1554
+ assert_array_equal(a, np.array([[20, 20, 20], [20, 20, 5], [6, 7, 8]]))
1555
+
1556
+ a = np.arange(9).reshape((3, 3))
1557
+ a.flat[5:10] = 30
1558
+ assert_array_equal(a, np.array([[0, 1, 2], [3, 4, 30], [30, 30, 30]]))
1559
+
1560
+ a = np.arange(9).reshape((3, 3))
1561
+ a.flat[::2] = 40
1562
+ assert_array_equal(a, np.array([[40, 1, 40], [3, 40, 5], [40, 7, 40]]))
1563
+
1564
+ a = np.arange(9).reshape((3, 3))
1565
+ a.flat[::-1] = 50
1566
+ assert_array_equal(a, np.full((3, 3), 50))
1567
+
1568
+ a = np.arange(9).reshape((3, 3))
1569
+ a.flat[10:5] = 60
1570
+ assert_array_equal(a, np.arange(9).reshape((3, 3)))
1571
+
1572
+ a = np.arange(9).reshape((3, 3))
1573
+ with pytest.raises(IndexError,
1574
+ match="Assigning to a flat iterator with a 0-D index"):
1575
+ a.flat[()] = 70
1576
+
1577
+ a = np.arange(9).reshape((3, 3))
1578
+ a.flat[...] = 80
1579
+ assert_array_equal(a, np.full((3, 3), 80))
1580
+
1581
+ def test_flatiter_indexing_boolean_assign(self):
1582
+ a = np.arange(9).reshape((3, 3))
1583
+ with pytest.warns(DeprecationWarning, match="0-dimensional boolean index"):
1584
+ a.flat[True] = 10
1585
+ assert_array_equal(a, np.array([[10, 1, 2], [3, 4, 5], [6, 7, 8]]))
1586
+
1587
+ a = np.arange(9).reshape((3, 3))
1588
+ with pytest.warns(DeprecationWarning, match="0-dimensional boolean index"):
1589
+ a.flat[False] = 20
1590
+ assert_array_equal(a, np.arange(9).reshape((3, 3)))
1591
+
1592
+ a = np.arange(9).reshape((3, 3))
1593
+ mask = np.zeros(len(a.flat), dtype=bool)
1594
+ mask[::2] = True
1595
+ a.flat[mask] = 30
1596
+ assert_array_equal(a, np.array([[30, 1, 30], [3, 30, 5], [30, 7, 30]]))
1597
+
1598
+ wrong_mask = np.zeros(len(a.flat) + 1, dtype=bool)
1599
+ with pytest.raises(IndexError,
1600
+ match="boolean index did not match indexed flat iterator"):
1601
+ a.flat[wrong_mask] = 40
1602
+
1603
+ def test_flatiter_indexing_fancy_assign(self):
1604
+ a = np.arange(9).reshape((3, 3))
1605
+ indices = np.array([1, 3, 5])
1606
+ a.flat[indices] = 10
1607
+ assert_array_equal(a, np.array([[0, 10, 2], [10, 4, 10], [6, 7, 8]]))
1608
+
1609
+ a.flat[[-1, -2]] = 20
1610
+ assert_array_equal(a, np.array([[0, 10, 2], [10, 4, 10], [6, 20, 20]]))
1611
+
1612
+ a = np.arange(9).reshape((3, 3))
1613
+ indices_2d = np.array([[1, 2], [3, 4]])
1614
+ a.flat[indices_2d] = 30
1615
+ assert_array_equal(a, np.array([[0, 30, 30], [30, 30, 5], [6, 7, 8]]))
1616
+
1617
+ a.flat[[True, 1]] = 40
1618
+ assert_array_equal(a, np.array([[0, 40, 30], [30, 30, 5], [6, 7, 8]]))
1619
+
1620
+ with pytest.raises(IndexError,
1621
+ match="boolean indices for iterators are not supported"):
1622
+ a.flat[[True, True]] = 50
1623
+
1624
+ a = np.arange(3)
1625
+ with pytest.raises(IndexError,
1626
+ match="boolean indices for iterators are not supported"):
1627
+ a.flat[[True, False, True]] = 20
1628
+ a.flat[np.asarray([True, False, True])] = 20
1629
+ assert_array_equal(a, np.array([20, 1, 20]))
1630
+
1631
+ def test_flatiter_indexing_fancy_int16_dtype(self):
1632
+ a = np.arange(9).reshape((3, 3))
1633
+ indices = np.array([1, 3, 5], dtype=np.int16)
1634
+ assert_array_equal(a.flat[indices], np.array([1, 3, 5]))
1635
+
1636
+ a.flat[indices] = 10
1637
+ assert_array_equal(a, np.array([[0, 10, 2], [10, 4, 10], [6, 7, 8]]))
1638
+
1639
+ def test_flatiter_indexing_not_supported_newaxis_mutlid_float_assign(self):
1640
+ a = np.arange(9).reshape((3, 3))
1641
+ with pytest.raises(IndexError,
1642
+ match=r"only integers, slices \(`:`\), "
1643
+ r"ellipsis \(`\.\.\.`\) and "
1644
+ r"integer or boolean arrays are valid indices"):
1645
+ a.flat[None] = 10
1646
+
1647
+ a.flat[[1, 2]] = 10
1648
+ assert_array_equal(a, np.array([[0, 10, 10], [3, 4, 5], [6, 7, 8]]))
1649
+
1650
+ with pytest.warns(DeprecationWarning,
1651
+ match="Invalid non-array indices for iterator objects are "
1652
+ "deprecated"):
1653
+ a.flat[[1.0, 2.0]] = 20
1654
+ assert_array_equal(a, np.array([[0, 20, 20], [3, 4, 5], [6, 7, 8]]))
1655
+
1656
+ def test_flat_index_on_flatiter(self):
1657
+ a = np.arange(9).reshape((3, 3))
1658
+ b = np.array([0, 5, 6])
1659
+ assert_equal(a.flat[b.flat], np.array([0, 5, 6]))
1660
+
1661
+ def test_empty_string_flat_index_on_flatiter(self):
1662
+ a = np.arange(9).reshape((3, 3))
1663
+ b = np.array([], dtype="S")
1664
+ # This is arguably incorrect, and should be removed (ideally with
1665
+ # deprecation). But it matches the array path and comes from not
1666
+ # distinguishing `arr[np.array([]).flat]` and `arr[[]]` and the latter
1667
+ # must pass.
1668
+ assert_equal(a.flat[b.flat], np.array([]))
1669
+
1670
+ def test_nonempty_string_flat_index_on_flatiter(self):
1671
+ a = np.arange(9).reshape((3, 3))
1672
+ b = np.array(["a"], dtype="S")
1673
+ with pytest.raises(IndexError,
1674
+ match=r"only integers, slices \(`:`\), ellipsis \(`\.\.\.`\) "
1675
+ r"and integer or boolean arrays are valid indices"):
1676
+ a.flat[b.flat]
1677
+
1678
+
1679
+ @pytest.mark.skipif(sys.flags.optimize == 2, reason="Python running -OO")
1680
+ @pytest.mark.xfail(IS_PYPY, reason="PyPy does not modify tp_doc")
1681
+ @pytest.mark.parametrize("methodname", ["__array__", "copy"])
1682
+ def test_flatiter_method_signatures(methodname: str):
1683
+ method = getattr(np.flatiter, methodname)
1684
+ assert callable(method)
1685
+
1686
+ try:
1687
+ sig = inspect.signature(method)
1688
+ except ValueError as e:
1689
+ pytest.fail(f"Could not get signature for np.flatiter.{methodname}: {e}")
1690
+
1691
+ assert "self" in sig.parameters
1692
+ assert sig.parameters["self"].kind is inspect.Parameter.POSITIONAL_ONLY