numpy 2.3.5__cp313-cp313-macosx_14_0_arm64.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.

Potentially problematic release.


This version of numpy might be problematic. Click here for more details.

Files changed (897) hide show
  1. numpy/__config__.py +170 -0
  2. numpy/__config__.pyi +102 -0
  3. numpy/__init__.cython-30.pxd +1241 -0
  4. numpy/__init__.pxd +1154 -0
  5. numpy/__init__.py +945 -0
  6. numpy/__init__.pyi +6147 -0
  7. numpy/_array_api_info.py +346 -0
  8. numpy/_array_api_info.pyi +207 -0
  9. numpy/_configtool.py +39 -0
  10. numpy/_configtool.pyi +1 -0
  11. numpy/_core/__init__.py +186 -0
  12. numpy/_core/__init__.pyi +2 -0
  13. numpy/_core/_add_newdocs.py +6967 -0
  14. numpy/_core/_add_newdocs.pyi +3 -0
  15. numpy/_core/_add_newdocs_scalars.py +390 -0
  16. numpy/_core/_add_newdocs_scalars.pyi +16 -0
  17. numpy/_core/_asarray.py +134 -0
  18. numpy/_core/_asarray.pyi +41 -0
  19. numpy/_core/_dtype.py +366 -0
  20. numpy/_core/_dtype.pyi +58 -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 +55 -0
  25. numpy/_core/_internal.py +958 -0
  26. numpy/_core/_internal.pyi +72 -0
  27. numpy/_core/_machar.py +355 -0
  28. numpy/_core/_machar.pyi +55 -0
  29. numpy/_core/_methods.py +255 -0
  30. numpy/_core/_methods.pyi +22 -0
  31. numpy/_core/_multiarray_tests.cpython-313-darwin.so +0 -0
  32. numpy/_core/_multiarray_umath.cpython-313-darwin.so +0 -0
  33. numpy/_core/_operand_flag_tests.cpython-313-darwin.so +0 -0
  34. numpy/_core/_rational_tests.cpython-313-darwin.so +0 -0
  35. numpy/_core/_simd.cpython-313-darwin.so +0 -0
  36. numpy/_core/_simd.pyi +25 -0
  37. numpy/_core/_string_helpers.py +100 -0
  38. numpy/_core/_string_helpers.pyi +12 -0
  39. numpy/_core/_struct_ufunc_tests.cpython-313-darwin.so +0 -0
  40. numpy/_core/_type_aliases.py +119 -0
  41. numpy/_core/_type_aliases.pyi +97 -0
  42. numpy/_core/_ufunc_config.py +491 -0
  43. numpy/_core/_ufunc_config.pyi +78 -0
  44. numpy/_core/_umath_tests.cpython-313-darwin.so +0 -0
  45. numpy/_core/arrayprint.py +1775 -0
  46. numpy/_core/arrayprint.pyi +238 -0
  47. numpy/_core/cversions.py +13 -0
  48. numpy/_core/defchararray.py +1427 -0
  49. numpy/_core/defchararray.pyi +1135 -0
  50. numpy/_core/einsumfunc.py +1498 -0
  51. numpy/_core/einsumfunc.pyi +184 -0
  52. numpy/_core/fromnumeric.py +4269 -0
  53. numpy/_core/fromnumeric.pyi +1750 -0
  54. numpy/_core/function_base.py +545 -0
  55. numpy/_core/function_base.pyi +278 -0
  56. numpy/_core/getlimits.py +748 -0
  57. numpy/_core/getlimits.pyi +3 -0
  58. numpy/_core/include/numpy/__multiarray_api.c +376 -0
  59. numpy/_core/include/numpy/__multiarray_api.h +1628 -0
  60. numpy/_core/include/numpy/__ufunc_api.c +54 -0
  61. numpy/_core/include/numpy/__ufunc_api.h +341 -0
  62. numpy/_core/include/numpy/_neighborhood_iterator_imp.h +90 -0
  63. numpy/_core/include/numpy/_numpyconfig.h +33 -0
  64. numpy/_core/include/numpy/_public_dtype_api_table.h +86 -0
  65. numpy/_core/include/numpy/arrayobject.h +7 -0
  66. numpy/_core/include/numpy/arrayscalars.h +196 -0
  67. numpy/_core/include/numpy/dtype_api.h +480 -0
  68. numpy/_core/include/numpy/halffloat.h +70 -0
  69. numpy/_core/include/numpy/ndarrayobject.h +304 -0
  70. numpy/_core/include/numpy/ndarraytypes.h +1950 -0
  71. numpy/_core/include/numpy/npy_2_compat.h +249 -0
  72. numpy/_core/include/numpy/npy_2_complexcompat.h +28 -0
  73. numpy/_core/include/numpy/npy_3kcompat.h +374 -0
  74. numpy/_core/include/numpy/npy_common.h +977 -0
  75. numpy/_core/include/numpy/npy_cpu.h +124 -0
  76. numpy/_core/include/numpy/npy_endian.h +78 -0
  77. numpy/_core/include/numpy/npy_math.h +602 -0
  78. numpy/_core/include/numpy/npy_no_deprecated_api.h +20 -0
  79. numpy/_core/include/numpy/npy_os.h +42 -0
  80. numpy/_core/include/numpy/numpyconfig.h +182 -0
  81. numpy/_core/include/numpy/random/LICENSE.txt +21 -0
  82. numpy/_core/include/numpy/random/bitgen.h +20 -0
  83. numpy/_core/include/numpy/random/distributions.h +209 -0
  84. numpy/_core/include/numpy/random/libdivide.h +2079 -0
  85. numpy/_core/include/numpy/ufuncobject.h +343 -0
  86. numpy/_core/include/numpy/utils.h +37 -0
  87. numpy/_core/lib/libnpymath.a +0 -0
  88. numpy/_core/lib/npy-pkg-config/mlib.ini +12 -0
  89. numpy/_core/lib/npy-pkg-config/npymath.ini +20 -0
  90. numpy/_core/lib/pkgconfig/numpy.pc +7 -0
  91. numpy/_core/memmap.py +363 -0
  92. numpy/_core/memmap.pyi +3 -0
  93. numpy/_core/multiarray.py +1762 -0
  94. numpy/_core/multiarray.pyi +1285 -0
  95. numpy/_core/numeric.py +2760 -0
  96. numpy/_core/numeric.pyi +882 -0
  97. numpy/_core/numerictypes.py +633 -0
  98. numpy/_core/numerictypes.pyi +197 -0
  99. numpy/_core/overrides.py +183 -0
  100. numpy/_core/overrides.pyi +48 -0
  101. numpy/_core/printoptions.py +32 -0
  102. numpy/_core/printoptions.pyi +28 -0
  103. numpy/_core/records.py +1089 -0
  104. numpy/_core/records.pyi +333 -0
  105. numpy/_core/shape_base.py +998 -0
  106. numpy/_core/shape_base.pyi +175 -0
  107. numpy/_core/strings.py +1829 -0
  108. numpy/_core/strings.pyi +511 -0
  109. numpy/_core/tests/_locales.py +72 -0
  110. numpy/_core/tests/_natype.py +205 -0
  111. numpy/_core/tests/data/astype_copy.pkl +0 -0
  112. numpy/_core/tests/data/generate_umath_validation_data.cpp +170 -0
  113. numpy/_core/tests/data/recarray_from_file.fits +0 -0
  114. numpy/_core/tests/data/umath-validation-set-README.txt +15 -0
  115. numpy/_core/tests/data/umath-validation-set-arccos.csv +1429 -0
  116. numpy/_core/tests/data/umath-validation-set-arccosh.csv +1429 -0
  117. numpy/_core/tests/data/umath-validation-set-arcsin.csv +1429 -0
  118. numpy/_core/tests/data/umath-validation-set-arcsinh.csv +1429 -0
  119. numpy/_core/tests/data/umath-validation-set-arctan.csv +1429 -0
  120. numpy/_core/tests/data/umath-validation-set-arctanh.csv +1429 -0
  121. numpy/_core/tests/data/umath-validation-set-cbrt.csv +1429 -0
  122. numpy/_core/tests/data/umath-validation-set-cos.csv +1375 -0
  123. numpy/_core/tests/data/umath-validation-set-cosh.csv +1429 -0
  124. numpy/_core/tests/data/umath-validation-set-exp.csv +412 -0
  125. numpy/_core/tests/data/umath-validation-set-exp2.csv +1429 -0
  126. numpy/_core/tests/data/umath-validation-set-expm1.csv +1429 -0
  127. numpy/_core/tests/data/umath-validation-set-log.csv +271 -0
  128. numpy/_core/tests/data/umath-validation-set-log10.csv +1629 -0
  129. numpy/_core/tests/data/umath-validation-set-log1p.csv +1429 -0
  130. numpy/_core/tests/data/umath-validation-set-log2.csv +1629 -0
  131. numpy/_core/tests/data/umath-validation-set-sin.csv +1370 -0
  132. numpy/_core/tests/data/umath-validation-set-sinh.csv +1429 -0
  133. numpy/_core/tests/data/umath-validation-set-tan.csv +1429 -0
  134. numpy/_core/tests/data/umath-validation-set-tanh.csv +1429 -0
  135. numpy/_core/tests/examples/cython/checks.pyx +373 -0
  136. numpy/_core/tests/examples/cython/meson.build +43 -0
  137. numpy/_core/tests/examples/cython/setup.py +39 -0
  138. numpy/_core/tests/examples/limited_api/limited_api1.c +17 -0
  139. numpy/_core/tests/examples/limited_api/limited_api2.pyx +11 -0
  140. numpy/_core/tests/examples/limited_api/limited_api_latest.c +19 -0
  141. numpy/_core/tests/examples/limited_api/meson.build +59 -0
  142. numpy/_core/tests/examples/limited_api/setup.py +24 -0
  143. numpy/_core/tests/test__exceptions.py +90 -0
  144. numpy/_core/tests/test_abc.py +54 -0
  145. numpy/_core/tests/test_api.py +654 -0
  146. numpy/_core/tests/test_argparse.py +92 -0
  147. numpy/_core/tests/test_array_api_info.py +113 -0
  148. numpy/_core/tests/test_array_coercion.py +911 -0
  149. numpy/_core/tests/test_array_interface.py +222 -0
  150. numpy/_core/tests/test_arraymethod.py +84 -0
  151. numpy/_core/tests/test_arrayobject.py +75 -0
  152. numpy/_core/tests/test_arrayprint.py +1328 -0
  153. numpy/_core/tests/test_casting_floatingpoint_errors.py +154 -0
  154. numpy/_core/tests/test_casting_unittests.py +817 -0
  155. numpy/_core/tests/test_conversion_utils.py +206 -0
  156. numpy/_core/tests/test_cpu_dispatcher.py +49 -0
  157. numpy/_core/tests/test_cpu_features.py +432 -0
  158. numpy/_core/tests/test_custom_dtypes.py +315 -0
  159. numpy/_core/tests/test_cython.py +351 -0
  160. numpy/_core/tests/test_datetime.py +2734 -0
  161. numpy/_core/tests/test_defchararray.py +825 -0
  162. numpy/_core/tests/test_deprecations.py +454 -0
  163. numpy/_core/tests/test_dlpack.py +190 -0
  164. numpy/_core/tests/test_dtype.py +1995 -0
  165. numpy/_core/tests/test_einsum.py +1317 -0
  166. numpy/_core/tests/test_errstate.py +131 -0
  167. numpy/_core/tests/test_extint128.py +217 -0
  168. numpy/_core/tests/test_function_base.py +503 -0
  169. numpy/_core/tests/test_getlimits.py +205 -0
  170. numpy/_core/tests/test_half.py +568 -0
  171. numpy/_core/tests/test_hashtable.py +35 -0
  172. numpy/_core/tests/test_indexerrors.py +125 -0
  173. numpy/_core/tests/test_indexing.py +1455 -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 +369 -0
  177. numpy/_core/tests/test_machar.py +30 -0
  178. numpy/_core/tests/test_mem_overlap.py +930 -0
  179. numpy/_core/tests/test_mem_policy.py +452 -0
  180. numpy/_core/tests/test_memmap.py +246 -0
  181. numpy/_core/tests/test_multiarray.py +10577 -0
  182. numpy/_core/tests/test_multithreading.py +292 -0
  183. numpy/_core/tests/test_nditer.py +3498 -0
  184. numpy/_core/tests/test_nep50_promotions.py +287 -0
  185. numpy/_core/tests/test_numeric.py +4247 -0
  186. numpy/_core/tests/test_numerictypes.py +651 -0
  187. numpy/_core/tests/test_overrides.py +791 -0
  188. numpy/_core/tests/test_print.py +200 -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 +2670 -0
  192. numpy/_core/tests/test_scalar_ctors.py +207 -0
  193. numpy/_core/tests/test_scalar_methods.py +246 -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 +1176 -0
  197. numpy/_core/tests/test_scalarprint.py +403 -0
  198. numpy/_core/tests/test_shape_base.py +891 -0
  199. numpy/_core/tests/test_simd.py +1341 -0
  200. numpy/_core/tests/test_simd_module.py +103 -0
  201. numpy/_core/tests/test_stringdtype.py +1814 -0
  202. numpy/_core/tests/test_strings.py +1499 -0
  203. numpy/_core/tests/test_ufunc.py +3313 -0
  204. numpy/_core/tests/test_umath.py +4928 -0
  205. numpy/_core/tests/test_umath_accuracy.py +124 -0
  206. numpy/_core/tests/test_umath_complex.py +626 -0
  207. numpy/_core/tests/test_unicode.py +368 -0
  208. numpy/_core/umath.py +60 -0
  209. numpy/_core/umath.pyi +197 -0
  210. numpy/_distributor_init.py +15 -0
  211. numpy/_distributor_init.pyi +1 -0
  212. numpy/_expired_attrs_2_0.py +79 -0
  213. numpy/_expired_attrs_2_0.pyi +62 -0
  214. numpy/_globals.py +96 -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 +13 -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 +148 -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 +40 -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 +941 -0
  239. numpy/_utils/__init__.py +95 -0
  240. numpy/_utils/__init__.pyi +30 -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 +71 -0
  245. numpy/_utils/_pep440.py +486 -0
  246. numpy/_utils/_pep440.pyi +121 -0
  247. numpy/char/__init__.py +2 -0
  248. numpy/char/__init__.pyi +111 -0
  249. numpy/conftest.py +258 -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 +33 -0
  275. numpy/ctypeslib/_ctypeslib.py +603 -0
  276. numpy/ctypeslib/_ctypeslib.pyi +245 -0
  277. numpy/doc/ufuncs.py +138 -0
  278. numpy/dtypes.py +41 -0
  279. numpy/dtypes.pyi +631 -0
  280. numpy/exceptions.py +247 -0
  281. numpy/exceptions.pyi +27 -0
  282. numpy/f2py/__init__.py +86 -0
  283. numpy/f2py/__init__.pyi +6 -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 +231 -0
  294. numpy/f2py/_backends/_meson.pyi +63 -0
  295. numpy/f2py/_backends/meson.build.template +55 -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 +29 -0
  300. numpy/f2py/auxfuncs.py +1004 -0
  301. numpy/f2py/auxfuncs.pyi +264 -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 +258 -0
  312. numpy/f2py/diagnose.py +149 -0
  313. numpy/f2py/diagnose.pyi +1 -0
  314. numpy/f2py/f2py2e.py +786 -0
  315. numpy/f2py/f2py2e.pyi +76 -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 +43 -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 +1516 -0
  326. numpy/f2py/symbolic.pyi +221 -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 +64 -0
  435. numpy/f2py/tests/test_f2cmap.py +17 -0
  436. numpy/f2py/tests/test_f2py2e.py +964 -0
  437. numpy/f2py/tests/test_isoc.py +56 -0
  438. numpy/f2py/tests/test_kind.py +53 -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 +495 -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 +215 -0
  460. numpy/fft/__init__.pyi +43 -0
  461. numpy/fft/_helper.py +235 -0
  462. numpy/fft/_helper.pyi +45 -0
  463. numpy/fft/_pocketfft.py +1693 -0
  464. numpy/fft/_pocketfft.pyi +138 -0
  465. numpy/fft/_pocketfft_umath.cpython-313-darwin.so +0 -0
  466. numpy/fft/helper.py +17 -0
  467. numpy/fft/helper.pyi +22 -0
  468. numpy/fft/tests/__init__.py +0 -0
  469. numpy/fft/tests/test_helper.py +167 -0
  470. numpy/fft/tests/test_pocketfft.py +589 -0
  471. numpy/lib/__init__.py +97 -0
  472. numpy/lib/__init__.pyi +44 -0
  473. numpy/lib/_array_utils_impl.py +62 -0
  474. numpy/lib/_array_utils_impl.pyi +26 -0
  475. numpy/lib/_arraypad_impl.py +890 -0
  476. numpy/lib/_arraypad_impl.pyi +89 -0
  477. numpy/lib/_arraysetops_impl.py +1260 -0
  478. numpy/lib/_arraysetops_impl.pyi +468 -0
  479. numpy/lib/_arrayterator_impl.py +224 -0
  480. numpy/lib/_arrayterator_impl.pyi +46 -0
  481. numpy/lib/_datasource.py +700 -0
  482. numpy/lib/_datasource.pyi +31 -0
  483. numpy/lib/_format_impl.py +1036 -0
  484. numpy/lib/_format_impl.pyi +26 -0
  485. numpy/lib/_function_base_impl.py +5844 -0
  486. numpy/lib/_function_base_impl.pyi +1164 -0
  487. numpy/lib/_histograms_impl.py +1085 -0
  488. numpy/lib/_histograms_impl.pyi +50 -0
  489. numpy/lib/_index_tricks_impl.py +1067 -0
  490. numpy/lib/_index_tricks_impl.pyi +208 -0
  491. numpy/lib/_iotools.py +900 -0
  492. numpy/lib/_iotools.pyi +114 -0
  493. numpy/lib/_nanfunctions_impl.py +2024 -0
  494. numpy/lib/_nanfunctions_impl.pyi +52 -0
  495. numpy/lib/_npyio_impl.py +2596 -0
  496. numpy/lib/_npyio_impl.pyi +301 -0
  497. numpy/lib/_polynomial_impl.py +1465 -0
  498. numpy/lib/_polynomial_impl.pyi +318 -0
  499. numpy/lib/_scimath_impl.py +642 -0
  500. numpy/lib/_scimath_impl.pyi +93 -0
  501. numpy/lib/_shape_base_impl.py +1301 -0
  502. numpy/lib/_shape_base_impl.pyi +235 -0
  503. numpy/lib/_stride_tricks_impl.py +549 -0
  504. numpy/lib/_stride_tricks_impl.pyi +74 -0
  505. numpy/lib/_twodim_base_impl.py +1201 -0
  506. numpy/lib/_twodim_base_impl.pyi +438 -0
  507. numpy/lib/_type_check_impl.py +699 -0
  508. numpy/lib/_type_check_impl.pyi +350 -0
  509. numpy/lib/_ufunclike_impl.py +207 -0
  510. numpy/lib/_ufunclike_impl.pyi +67 -0
  511. numpy/lib/_user_array_impl.py +299 -0
  512. numpy/lib/_user_array_impl.pyi +225 -0
  513. numpy/lib/_utils_impl.py +784 -0
  514. numpy/lib/_utils_impl.pyi +10 -0
  515. numpy/lib/_version.py +154 -0
  516. numpy/lib/_version.pyi +17 -0
  517. numpy/lib/array_utils.py +7 -0
  518. numpy/lib/array_utils.pyi +12 -0
  519. numpy/lib/format.py +24 -0
  520. numpy/lib/format.pyi +66 -0
  521. numpy/lib/introspect.py +95 -0
  522. numpy/lib/introspect.pyi +3 -0
  523. numpy/lib/mixins.py +180 -0
  524. numpy/lib/mixins.pyi +77 -0
  525. numpy/lib/npyio.py +1 -0
  526. numpy/lib/npyio.pyi +9 -0
  527. numpy/lib/recfunctions.py +1681 -0
  528. numpy/lib/recfunctions.pyi +435 -0
  529. numpy/lib/scimath.py +13 -0
  530. numpy/lib/scimath.pyi +30 -0
  531. numpy/lib/stride_tricks.py +1 -0
  532. numpy/lib/stride_tricks.pyi +6 -0
  533. numpy/lib/tests/__init__.py +0 -0
  534. numpy/lib/tests/data/py2-np0-objarr.npy +0 -0
  535. numpy/lib/tests/data/py2-objarr.npy +0 -0
  536. numpy/lib/tests/data/py2-objarr.npz +0 -0
  537. numpy/lib/tests/data/py3-objarr.npy +0 -0
  538. numpy/lib/tests/data/py3-objarr.npz +0 -0
  539. numpy/lib/tests/data/python3.npy +0 -0
  540. numpy/lib/tests/data/win64python2.npy +0 -0
  541. numpy/lib/tests/test__datasource.py +352 -0
  542. numpy/lib/tests/test__iotools.py +360 -0
  543. numpy/lib/tests/test__version.py +64 -0
  544. numpy/lib/tests/test_array_utils.py +32 -0
  545. numpy/lib/tests/test_arraypad.py +1415 -0
  546. numpy/lib/tests/test_arraysetops.py +1074 -0
  547. numpy/lib/tests/test_arrayterator.py +46 -0
  548. numpy/lib/tests/test_format.py +1054 -0
  549. numpy/lib/tests/test_function_base.py +4573 -0
  550. numpy/lib/tests/test_histograms.py +855 -0
  551. numpy/lib/tests/test_index_tricks.py +573 -0
  552. numpy/lib/tests/test_io.py +2848 -0
  553. numpy/lib/tests/test_loadtxt.py +1101 -0
  554. numpy/lib/tests/test_mixins.py +215 -0
  555. numpy/lib/tests/test_nanfunctions.py +1438 -0
  556. numpy/lib/tests/test_packbits.py +376 -0
  557. numpy/lib/tests/test_polynomial.py +320 -0
  558. numpy/lib/tests/test_recfunctions.py +1052 -0
  559. numpy/lib/tests/test_regression.py +231 -0
  560. numpy/lib/tests/test_shape_base.py +813 -0
  561. numpy/lib/tests/test_stride_tricks.py +656 -0
  562. numpy/lib/tests/test_twodim_base.py +559 -0
  563. numpy/lib/tests/test_type_check.py +473 -0
  564. numpy/lib/tests/test_ufunclike.py +97 -0
  565. numpy/lib/tests/test_utils.py +80 -0
  566. numpy/lib/user_array.py +1 -0
  567. numpy/lib/user_array.pyi +1 -0
  568. numpy/linalg/__init__.py +98 -0
  569. numpy/linalg/__init__.pyi +73 -0
  570. numpy/linalg/_linalg.py +3682 -0
  571. numpy/linalg/_linalg.pyi +475 -0
  572. numpy/linalg/_umath_linalg.cpython-313-darwin.so +0 -0
  573. numpy/linalg/_umath_linalg.pyi +61 -0
  574. numpy/linalg/lapack_lite.cpython-313-darwin.so +0 -0
  575. numpy/linalg/lapack_lite.pyi +141 -0
  576. numpy/linalg/linalg.py +17 -0
  577. numpy/linalg/linalg.pyi +69 -0
  578. numpy/linalg/tests/__init__.py +0 -0
  579. numpy/linalg/tests/test_deprecations.py +20 -0
  580. numpy/linalg/tests/test_linalg.py +2443 -0
  581. numpy/linalg/tests/test_regression.py +181 -0
  582. numpy/ma/API_CHANGES.txt +135 -0
  583. numpy/ma/LICENSE +24 -0
  584. numpy/ma/README.rst +236 -0
  585. numpy/ma/__init__.py +53 -0
  586. numpy/ma/__init__.pyi +458 -0
  587. numpy/ma/core.py +8933 -0
  588. numpy/ma/core.pyi +1462 -0
  589. numpy/ma/extras.py +2344 -0
  590. numpy/ma/extras.pyi +138 -0
  591. numpy/ma/mrecords.py +773 -0
  592. numpy/ma/mrecords.pyi +96 -0
  593. numpy/ma/tests/__init__.py +0 -0
  594. numpy/ma/tests/test_arrayobject.py +40 -0
  595. numpy/ma/tests/test_core.py +5886 -0
  596. numpy/ma/tests/test_deprecations.py +87 -0
  597. numpy/ma/tests/test_extras.py +1998 -0
  598. numpy/ma/tests/test_mrecords.py +497 -0
  599. numpy/ma/tests/test_old_ma.py +942 -0
  600. numpy/ma/tests/test_regression.py +100 -0
  601. numpy/ma/tests/test_subclassing.py +469 -0
  602. numpy/ma/testutils.py +294 -0
  603. numpy/matlib.py +380 -0
  604. numpy/matlib.pyi +582 -0
  605. numpy/matrixlib/__init__.py +12 -0
  606. numpy/matrixlib/__init__.pyi +5 -0
  607. numpy/matrixlib/defmatrix.py +1119 -0
  608. numpy/matrixlib/defmatrix.pyi +17 -0
  609. numpy/matrixlib/tests/__init__.py +0 -0
  610. numpy/matrixlib/tests/test_defmatrix.py +455 -0
  611. numpy/matrixlib/tests/test_interaction.py +360 -0
  612. numpy/matrixlib/tests/test_masked_matrix.py +240 -0
  613. numpy/matrixlib/tests/test_matrix_linalg.py +105 -0
  614. numpy/matrixlib/tests/test_multiarray.py +17 -0
  615. numpy/matrixlib/tests/test_numeric.py +18 -0
  616. numpy/matrixlib/tests/test_regression.py +31 -0
  617. numpy/polynomial/__init__.py +187 -0
  618. numpy/polynomial/__init__.pyi +25 -0
  619. numpy/polynomial/_polybase.py +1191 -0
  620. numpy/polynomial/_polybase.pyi +285 -0
  621. numpy/polynomial/_polytypes.pyi +892 -0
  622. numpy/polynomial/chebyshev.py +2003 -0
  623. numpy/polynomial/chebyshev.pyi +181 -0
  624. numpy/polynomial/hermite.py +1740 -0
  625. numpy/polynomial/hermite.pyi +107 -0
  626. numpy/polynomial/hermite_e.py +1642 -0
  627. numpy/polynomial/hermite_e.pyi +107 -0
  628. numpy/polynomial/laguerre.py +1675 -0
  629. numpy/polynomial/laguerre.pyi +100 -0
  630. numpy/polynomial/legendre.py +1605 -0
  631. numpy/polynomial/legendre.pyi +100 -0
  632. numpy/polynomial/polynomial.py +1616 -0
  633. numpy/polynomial/polynomial.pyi +89 -0
  634. numpy/polynomial/polyutils.py +759 -0
  635. numpy/polynomial/polyutils.pyi +423 -0
  636. numpy/polynomial/tests/__init__.py +0 -0
  637. numpy/polynomial/tests/test_chebyshev.py +623 -0
  638. numpy/polynomial/tests/test_classes.py +618 -0
  639. numpy/polynomial/tests/test_hermite.py +558 -0
  640. numpy/polynomial/tests/test_hermite_e.py +559 -0
  641. numpy/polynomial/tests/test_laguerre.py +540 -0
  642. numpy/polynomial/tests/test_legendre.py +571 -0
  643. numpy/polynomial/tests/test_polynomial.py +669 -0
  644. numpy/polynomial/tests/test_polyutils.py +128 -0
  645. numpy/polynomial/tests/test_printing.py +555 -0
  646. numpy/polynomial/tests/test_symbol.py +217 -0
  647. numpy/py.typed +0 -0
  648. numpy/random/LICENSE.md +71 -0
  649. numpy/random/__init__.pxd +14 -0
  650. numpy/random/__init__.py +213 -0
  651. numpy/random/__init__.pyi +124 -0
  652. numpy/random/_bounded_integers.cpython-313-darwin.so +0 -0
  653. numpy/random/_bounded_integers.pxd +29 -0
  654. numpy/random/_bounded_integers.pyi +1 -0
  655. numpy/random/_common.cpython-313-darwin.so +0 -0
  656. numpy/random/_common.pxd +107 -0
  657. numpy/random/_common.pyi +16 -0
  658. numpy/random/_examples/cffi/extending.py +44 -0
  659. numpy/random/_examples/cffi/parse.py +53 -0
  660. numpy/random/_examples/cython/extending.pyx +77 -0
  661. numpy/random/_examples/cython/extending_distributions.pyx +118 -0
  662. numpy/random/_examples/cython/meson.build +53 -0
  663. numpy/random/_examples/numba/extending.py +86 -0
  664. numpy/random/_examples/numba/extending_distributions.py +67 -0
  665. numpy/random/_generator.cpython-313-darwin.so +0 -0
  666. numpy/random/_generator.pyi +861 -0
  667. numpy/random/_mt19937.cpython-313-darwin.so +0 -0
  668. numpy/random/_mt19937.pyi +25 -0
  669. numpy/random/_pcg64.cpython-313-darwin.so +0 -0
  670. numpy/random/_pcg64.pyi +44 -0
  671. numpy/random/_philox.cpython-313-darwin.so +0 -0
  672. numpy/random/_philox.pyi +39 -0
  673. numpy/random/_pickle.py +88 -0
  674. numpy/random/_pickle.pyi +43 -0
  675. numpy/random/_sfc64.cpython-313-darwin.so +0 -0
  676. numpy/random/_sfc64.pyi +28 -0
  677. numpy/random/bit_generator.cpython-313-darwin.so +0 -0
  678. numpy/random/bit_generator.pxd +35 -0
  679. numpy/random/bit_generator.pyi +124 -0
  680. numpy/random/c_distributions.pxd +119 -0
  681. numpy/random/lib/libnpyrandom.a +0 -0
  682. numpy/random/mtrand.cpython-313-darwin.so +0 -0
  683. numpy/random/mtrand.pyi +703 -0
  684. numpy/random/tests/__init__.py +0 -0
  685. numpy/random/tests/data/__init__.py +0 -0
  686. numpy/random/tests/data/generator_pcg64_np121.pkl.gz +0 -0
  687. numpy/random/tests/data/generator_pcg64_np126.pkl.gz +0 -0
  688. numpy/random/tests/data/mt19937-testset-1.csv +1001 -0
  689. numpy/random/tests/data/mt19937-testset-2.csv +1001 -0
  690. numpy/random/tests/data/pcg64-testset-1.csv +1001 -0
  691. numpy/random/tests/data/pcg64-testset-2.csv +1001 -0
  692. numpy/random/tests/data/pcg64dxsm-testset-1.csv +1001 -0
  693. numpy/random/tests/data/pcg64dxsm-testset-2.csv +1001 -0
  694. numpy/random/tests/data/philox-testset-1.csv +1001 -0
  695. numpy/random/tests/data/philox-testset-2.csv +1001 -0
  696. numpy/random/tests/data/sfc64-testset-1.csv +1001 -0
  697. numpy/random/tests/data/sfc64-testset-2.csv +1001 -0
  698. numpy/random/tests/data/sfc64_np126.pkl.gz +0 -0
  699. numpy/random/tests/test_direct.py +592 -0
  700. numpy/random/tests/test_extending.py +127 -0
  701. numpy/random/tests/test_generator_mt19937.py +2809 -0
  702. numpy/random/tests/test_generator_mt19937_regressions.py +207 -0
  703. numpy/random/tests/test_random.py +1757 -0
  704. numpy/random/tests/test_randomstate.py +2130 -0
  705. numpy/random/tests/test_randomstate_regression.py +217 -0
  706. numpy/random/tests/test_regression.py +152 -0
  707. numpy/random/tests/test_seed_sequence.py +79 -0
  708. numpy/random/tests/test_smoke.py +819 -0
  709. numpy/rec/__init__.py +2 -0
  710. numpy/rec/__init__.pyi +23 -0
  711. numpy/strings/__init__.py +2 -0
  712. numpy/strings/__init__.pyi +97 -0
  713. numpy/testing/__init__.py +22 -0
  714. numpy/testing/__init__.pyi +102 -0
  715. numpy/testing/_private/__init__.py +0 -0
  716. numpy/testing/_private/__init__.pyi +0 -0
  717. numpy/testing/_private/extbuild.py +250 -0
  718. numpy/testing/_private/extbuild.pyi +25 -0
  719. numpy/testing/_private/utils.py +2752 -0
  720. numpy/testing/_private/utils.pyi +499 -0
  721. numpy/testing/overrides.py +84 -0
  722. numpy/testing/overrides.pyi +11 -0
  723. numpy/testing/print_coercion_tables.py +207 -0
  724. numpy/testing/print_coercion_tables.pyi +27 -0
  725. numpy/testing/tests/__init__.py +0 -0
  726. numpy/testing/tests/test_utils.py +1917 -0
  727. numpy/tests/__init__.py +0 -0
  728. numpy/tests/test__all__.py +10 -0
  729. numpy/tests/test_configtool.py +48 -0
  730. numpy/tests/test_ctypeslib.py +377 -0
  731. numpy/tests/test_lazyloading.py +38 -0
  732. numpy/tests/test_matlib.py +59 -0
  733. numpy/tests/test_numpy_config.py +46 -0
  734. numpy/tests/test_numpy_version.py +54 -0
  735. numpy/tests/test_public_api.py +806 -0
  736. numpy/tests/test_reloading.py +74 -0
  737. numpy/tests/test_scripts.py +49 -0
  738. numpy/tests/test_warnings.py +78 -0
  739. numpy/typing/__init__.py +201 -0
  740. numpy/typing/mypy_plugin.py +195 -0
  741. numpy/typing/tests/__init__.py +0 -0
  742. numpy/typing/tests/data/fail/arithmetic.pyi +126 -0
  743. numpy/typing/tests/data/fail/array_constructors.pyi +34 -0
  744. numpy/typing/tests/data/fail/array_like.pyi +15 -0
  745. numpy/typing/tests/data/fail/array_pad.pyi +6 -0
  746. numpy/typing/tests/data/fail/arrayprint.pyi +16 -0
  747. numpy/typing/tests/data/fail/arrayterator.pyi +14 -0
  748. numpy/typing/tests/data/fail/bitwise_ops.pyi +17 -0
  749. numpy/typing/tests/data/fail/char.pyi +65 -0
  750. numpy/typing/tests/data/fail/chararray.pyi +62 -0
  751. numpy/typing/tests/data/fail/comparisons.pyi +27 -0
  752. numpy/typing/tests/data/fail/constants.pyi +3 -0
  753. numpy/typing/tests/data/fail/datasource.pyi +15 -0
  754. numpy/typing/tests/data/fail/dtype.pyi +17 -0
  755. numpy/typing/tests/data/fail/einsumfunc.pyi +12 -0
  756. numpy/typing/tests/data/fail/flatiter.pyi +20 -0
  757. numpy/typing/tests/data/fail/fromnumeric.pyi +148 -0
  758. numpy/typing/tests/data/fail/histograms.pyi +12 -0
  759. numpy/typing/tests/data/fail/index_tricks.pyi +14 -0
  760. numpy/typing/tests/data/fail/lib_function_base.pyi +62 -0
  761. numpy/typing/tests/data/fail/lib_polynomial.pyi +29 -0
  762. numpy/typing/tests/data/fail/lib_utils.pyi +3 -0
  763. numpy/typing/tests/data/fail/lib_version.pyi +6 -0
  764. numpy/typing/tests/data/fail/linalg.pyi +48 -0
  765. numpy/typing/tests/data/fail/ma.pyi +143 -0
  766. numpy/typing/tests/data/fail/memmap.pyi +5 -0
  767. numpy/typing/tests/data/fail/modules.pyi +17 -0
  768. numpy/typing/tests/data/fail/multiarray.pyi +52 -0
  769. numpy/typing/tests/data/fail/ndarray.pyi +11 -0
  770. numpy/typing/tests/data/fail/ndarray_misc.pyi +36 -0
  771. numpy/typing/tests/data/fail/nditer.pyi +8 -0
  772. numpy/typing/tests/data/fail/nested_sequence.pyi +16 -0
  773. numpy/typing/tests/data/fail/npyio.pyi +24 -0
  774. numpy/typing/tests/data/fail/numerictypes.pyi +5 -0
  775. numpy/typing/tests/data/fail/random.pyi +62 -0
  776. numpy/typing/tests/data/fail/rec.pyi +17 -0
  777. numpy/typing/tests/data/fail/scalars.pyi +87 -0
  778. numpy/typing/tests/data/fail/shape.pyi +6 -0
  779. numpy/typing/tests/data/fail/shape_base.pyi +8 -0
  780. numpy/typing/tests/data/fail/stride_tricks.pyi +9 -0
  781. numpy/typing/tests/data/fail/strings.pyi +52 -0
  782. numpy/typing/tests/data/fail/testing.pyi +28 -0
  783. numpy/typing/tests/data/fail/twodim_base.pyi +32 -0
  784. numpy/typing/tests/data/fail/type_check.pyi +13 -0
  785. numpy/typing/tests/data/fail/ufunc_config.pyi +21 -0
  786. numpy/typing/tests/data/fail/ufunclike.pyi +21 -0
  787. numpy/typing/tests/data/fail/ufuncs.pyi +17 -0
  788. numpy/typing/tests/data/fail/warnings_and_errors.pyi +5 -0
  789. numpy/typing/tests/data/misc/extended_precision.pyi +9 -0
  790. numpy/typing/tests/data/mypy.ini +9 -0
  791. numpy/typing/tests/data/pass/arithmetic.py +612 -0
  792. numpy/typing/tests/data/pass/array_constructors.py +137 -0
  793. numpy/typing/tests/data/pass/array_like.py +43 -0
  794. numpy/typing/tests/data/pass/arrayprint.py +37 -0
  795. numpy/typing/tests/data/pass/arrayterator.py +27 -0
  796. numpy/typing/tests/data/pass/bitwise_ops.py +131 -0
  797. numpy/typing/tests/data/pass/comparisons.py +315 -0
  798. numpy/typing/tests/data/pass/dtype.py +57 -0
  799. numpy/typing/tests/data/pass/einsumfunc.py +36 -0
  800. numpy/typing/tests/data/pass/flatiter.py +19 -0
  801. numpy/typing/tests/data/pass/fromnumeric.py +272 -0
  802. numpy/typing/tests/data/pass/index_tricks.py +60 -0
  803. numpy/typing/tests/data/pass/lib_user_array.py +22 -0
  804. numpy/typing/tests/data/pass/lib_utils.py +19 -0
  805. numpy/typing/tests/data/pass/lib_version.py +18 -0
  806. numpy/typing/tests/data/pass/literal.py +51 -0
  807. numpy/typing/tests/data/pass/ma.py +174 -0
  808. numpy/typing/tests/data/pass/mod.py +149 -0
  809. numpy/typing/tests/data/pass/modules.py +45 -0
  810. numpy/typing/tests/data/pass/multiarray.py +76 -0
  811. numpy/typing/tests/data/pass/ndarray_conversion.py +87 -0
  812. numpy/typing/tests/data/pass/ndarray_misc.py +203 -0
  813. numpy/typing/tests/data/pass/ndarray_shape_manipulation.py +47 -0
  814. numpy/typing/tests/data/pass/nditer.py +4 -0
  815. numpy/typing/tests/data/pass/numeric.py +95 -0
  816. numpy/typing/tests/data/pass/numerictypes.py +17 -0
  817. numpy/typing/tests/data/pass/random.py +1497 -0
  818. numpy/typing/tests/data/pass/recfunctions.py +161 -0
  819. numpy/typing/tests/data/pass/scalars.py +248 -0
  820. numpy/typing/tests/data/pass/shape.py +19 -0
  821. numpy/typing/tests/data/pass/simple.py +168 -0
  822. numpy/typing/tests/data/pass/simple_py3.py +6 -0
  823. numpy/typing/tests/data/pass/ufunc_config.py +64 -0
  824. numpy/typing/tests/data/pass/ufunclike.py +47 -0
  825. numpy/typing/tests/data/pass/ufuncs.py +16 -0
  826. numpy/typing/tests/data/pass/warnings_and_errors.py +6 -0
  827. numpy/typing/tests/data/reveal/arithmetic.pyi +720 -0
  828. numpy/typing/tests/data/reveal/array_api_info.pyi +70 -0
  829. numpy/typing/tests/data/reveal/array_constructors.pyi +249 -0
  830. numpy/typing/tests/data/reveal/arraypad.pyi +22 -0
  831. numpy/typing/tests/data/reveal/arrayprint.pyi +25 -0
  832. numpy/typing/tests/data/reveal/arraysetops.pyi +74 -0
  833. numpy/typing/tests/data/reveal/arrayterator.pyi +27 -0
  834. numpy/typing/tests/data/reveal/bitwise_ops.pyi +167 -0
  835. numpy/typing/tests/data/reveal/char.pyi +224 -0
  836. numpy/typing/tests/data/reveal/chararray.pyi +137 -0
  837. numpy/typing/tests/data/reveal/comparisons.pyi +264 -0
  838. numpy/typing/tests/data/reveal/constants.pyi +14 -0
  839. numpy/typing/tests/data/reveal/ctypeslib.pyi +81 -0
  840. numpy/typing/tests/data/reveal/datasource.pyi +23 -0
  841. numpy/typing/tests/data/reveal/dtype.pyi +136 -0
  842. numpy/typing/tests/data/reveal/einsumfunc.pyi +39 -0
  843. numpy/typing/tests/data/reveal/emath.pyi +54 -0
  844. numpy/typing/tests/data/reveal/fft.pyi +37 -0
  845. numpy/typing/tests/data/reveal/flatiter.pyi +47 -0
  846. numpy/typing/tests/data/reveal/fromnumeric.pyi +347 -0
  847. numpy/typing/tests/data/reveal/getlimits.pyi +51 -0
  848. numpy/typing/tests/data/reveal/histograms.pyi +25 -0
  849. numpy/typing/tests/data/reveal/index_tricks.pyi +70 -0
  850. numpy/typing/tests/data/reveal/lib_function_base.pyi +213 -0
  851. numpy/typing/tests/data/reveal/lib_polynomial.pyi +144 -0
  852. numpy/typing/tests/data/reveal/lib_utils.pyi +17 -0
  853. numpy/typing/tests/data/reveal/lib_version.pyi +20 -0
  854. numpy/typing/tests/data/reveal/linalg.pyi +132 -0
  855. numpy/typing/tests/data/reveal/ma.pyi +369 -0
  856. numpy/typing/tests/data/reveal/matrix.pyi +73 -0
  857. numpy/typing/tests/data/reveal/memmap.pyi +19 -0
  858. numpy/typing/tests/data/reveal/mod.pyi +179 -0
  859. numpy/typing/tests/data/reveal/modules.pyi +51 -0
  860. numpy/typing/tests/data/reveal/multiarray.pyi +194 -0
  861. numpy/typing/tests/data/reveal/nbit_base_example.pyi +21 -0
  862. numpy/typing/tests/data/reveal/ndarray_assignability.pyi +77 -0
  863. numpy/typing/tests/data/reveal/ndarray_conversion.pyi +85 -0
  864. numpy/typing/tests/data/reveal/ndarray_misc.pyi +247 -0
  865. numpy/typing/tests/data/reveal/ndarray_shape_manipulation.pyi +39 -0
  866. numpy/typing/tests/data/reveal/nditer.pyi +49 -0
  867. numpy/typing/tests/data/reveal/nested_sequence.pyi +25 -0
  868. numpy/typing/tests/data/reveal/npyio.pyi +83 -0
  869. numpy/typing/tests/data/reveal/numeric.pyi +134 -0
  870. numpy/typing/tests/data/reveal/numerictypes.pyi +16 -0
  871. numpy/typing/tests/data/reveal/polynomial_polybase.pyi +220 -0
  872. numpy/typing/tests/data/reveal/polynomial_polyutils.pyi +219 -0
  873. numpy/typing/tests/data/reveal/polynomial_series.pyi +138 -0
  874. numpy/typing/tests/data/reveal/random.pyi +1546 -0
  875. numpy/typing/tests/data/reveal/rec.pyi +171 -0
  876. numpy/typing/tests/data/reveal/scalars.pyi +191 -0
  877. numpy/typing/tests/data/reveal/shape.pyi +13 -0
  878. numpy/typing/tests/data/reveal/shape_base.pyi +52 -0
  879. numpy/typing/tests/data/reveal/stride_tricks.pyi +27 -0
  880. numpy/typing/tests/data/reveal/strings.pyi +196 -0
  881. numpy/typing/tests/data/reveal/testing.pyi +198 -0
  882. numpy/typing/tests/data/reveal/twodim_base.pyi +145 -0
  883. numpy/typing/tests/data/reveal/type_check.pyi +67 -0
  884. numpy/typing/tests/data/reveal/ufunc_config.pyi +30 -0
  885. numpy/typing/tests/data/reveal/ufunclike.pyi +31 -0
  886. numpy/typing/tests/data/reveal/ufuncs.pyi +123 -0
  887. numpy/typing/tests/data/reveal/warnings_and_errors.pyi +11 -0
  888. numpy/typing/tests/test_isfile.py +32 -0
  889. numpy/typing/tests/test_runtime.py +102 -0
  890. numpy/typing/tests/test_typing.py +205 -0
  891. numpy/version.py +11 -0
  892. numpy/version.pyi +18 -0
  893. numpy-2.3.5.dist-info/LICENSE.txt +971 -0
  894. numpy-2.3.5.dist-info/METADATA +1093 -0
  895. numpy-2.3.5.dist-info/RECORD +897 -0
  896. numpy-2.3.5.dist-info/WHEEL +6 -0
  897. numpy-2.3.5.dist-info/entry_points.txt +13 -0
numpy/f2py/symbolic.py ADDED
@@ -0,0 +1,1516 @@
1
+ """Fortran/C symbolic expressions
2
+
3
+ References:
4
+ - J3/21-007: Draft Fortran 202x. https://j3-fortran.org/doc/year/21/21-007.pdf
5
+
6
+ Copyright 1999 -- 2011 Pearu Peterson all rights reserved.
7
+ Copyright 2011 -- present NumPy Developers.
8
+ Permission to use, modify, and distribute this software is given under the
9
+ terms of the NumPy License.
10
+
11
+ NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
12
+ """
13
+
14
+ # To analyze Fortran expressions to solve dimensions specifications,
15
+ # for instances, we implement a minimal symbolic engine for parsing
16
+ # expressions into a tree of expression instances. As a first
17
+ # instance, we care only about arithmetic expressions involving
18
+ # integers and operations like addition (+), subtraction (-),
19
+ # multiplication (*), division (Fortran / is Python //, Fortran // is
20
+ # concatenate), and exponentiation (**). In addition, .pyf files may
21
+ # contain C expressions that support here is implemented as well.
22
+ #
23
+ # TODO: support logical constants (Op.BOOLEAN)
24
+ # TODO: support logical operators (.AND., ...)
25
+ # TODO: support defined operators (.MYOP., ...)
26
+ #
27
+ __all__ = ['Expr']
28
+
29
+
30
+ import re
31
+ import warnings
32
+ from enum import Enum
33
+ from math import gcd
34
+
35
+
36
+ class Language(Enum):
37
+ """
38
+ Used as Expr.tostring language argument.
39
+ """
40
+ Python = 0
41
+ Fortran = 1
42
+ C = 2
43
+
44
+
45
+ class Op(Enum):
46
+ """
47
+ Used as Expr op attribute.
48
+ """
49
+ INTEGER = 10
50
+ REAL = 12
51
+ COMPLEX = 15
52
+ STRING = 20
53
+ ARRAY = 30
54
+ SYMBOL = 40
55
+ TERNARY = 100
56
+ APPLY = 200
57
+ INDEXING = 210
58
+ CONCAT = 220
59
+ RELATIONAL = 300
60
+ TERMS = 1000
61
+ FACTORS = 2000
62
+ REF = 3000
63
+ DEREF = 3001
64
+
65
+
66
+ class RelOp(Enum):
67
+ """
68
+ Used in Op.RELATIONAL expression to specify the function part.
69
+ """
70
+ EQ = 1
71
+ NE = 2
72
+ LT = 3
73
+ LE = 4
74
+ GT = 5
75
+ GE = 6
76
+
77
+ @classmethod
78
+ def fromstring(cls, s, language=Language.C):
79
+ if language is Language.Fortran:
80
+ return {'.eq.': RelOp.EQ, '.ne.': RelOp.NE,
81
+ '.lt.': RelOp.LT, '.le.': RelOp.LE,
82
+ '.gt.': RelOp.GT, '.ge.': RelOp.GE}[s.lower()]
83
+ return {'==': RelOp.EQ, '!=': RelOp.NE, '<': RelOp.LT,
84
+ '<=': RelOp.LE, '>': RelOp.GT, '>=': RelOp.GE}[s]
85
+
86
+ def tostring(self, language=Language.C):
87
+ if language is Language.Fortran:
88
+ return {RelOp.EQ: '.eq.', RelOp.NE: '.ne.',
89
+ RelOp.LT: '.lt.', RelOp.LE: '.le.',
90
+ RelOp.GT: '.gt.', RelOp.GE: '.ge.'}[self]
91
+ return {RelOp.EQ: '==', RelOp.NE: '!=',
92
+ RelOp.LT: '<', RelOp.LE: '<=',
93
+ RelOp.GT: '>', RelOp.GE: '>='}[self]
94
+
95
+
96
+ class ArithOp(Enum):
97
+ """
98
+ Used in Op.APPLY expression to specify the function part.
99
+ """
100
+ POS = 1
101
+ NEG = 2
102
+ ADD = 3
103
+ SUB = 4
104
+ MUL = 5
105
+ DIV = 6
106
+ POW = 7
107
+
108
+
109
+ class OpError(Exception):
110
+ pass
111
+
112
+
113
+ class Precedence(Enum):
114
+ """
115
+ Used as Expr.tostring precedence argument.
116
+ """
117
+ ATOM = 0
118
+ POWER = 1
119
+ UNARY = 2
120
+ PRODUCT = 3
121
+ SUM = 4
122
+ LT = 6
123
+ EQ = 7
124
+ LAND = 11
125
+ LOR = 12
126
+ TERNARY = 13
127
+ ASSIGN = 14
128
+ TUPLE = 15
129
+ NONE = 100
130
+
131
+
132
+ integer_types = (int,)
133
+ number_types = (int, float)
134
+
135
+
136
+ def _pairs_add(d, k, v):
137
+ # Internal utility method for updating terms and factors data.
138
+ c = d.get(k)
139
+ if c is None:
140
+ d[k] = v
141
+ else:
142
+ c = c + v
143
+ if c:
144
+ d[k] = c
145
+ else:
146
+ del d[k]
147
+
148
+
149
+ class ExprWarning(UserWarning):
150
+ pass
151
+
152
+
153
+ def ewarn(message):
154
+ warnings.warn(message, ExprWarning, stacklevel=2)
155
+
156
+
157
+ class Expr:
158
+ """Represents a Fortran expression as a op-data pair.
159
+
160
+ Expr instances are hashable and sortable.
161
+ """
162
+
163
+ @staticmethod
164
+ def parse(s, language=Language.C):
165
+ """Parse a Fortran expression to a Expr.
166
+ """
167
+ return fromstring(s, language=language)
168
+
169
+ def __init__(self, op, data):
170
+ assert isinstance(op, Op)
171
+
172
+ # sanity checks
173
+ if op is Op.INTEGER:
174
+ # data is a 2-tuple of numeric object and a kind value
175
+ # (default is 4)
176
+ assert isinstance(data, tuple) and len(data) == 2
177
+ assert isinstance(data[0], int)
178
+ assert isinstance(data[1], (int, str)), data
179
+ elif op is Op.REAL:
180
+ # data is a 2-tuple of numeric object and a kind value
181
+ # (default is 4)
182
+ assert isinstance(data, tuple) and len(data) == 2
183
+ assert isinstance(data[0], float)
184
+ assert isinstance(data[1], (int, str)), data
185
+ elif op is Op.COMPLEX:
186
+ # data is a 2-tuple of constant expressions
187
+ assert isinstance(data, tuple) and len(data) == 2
188
+ elif op is Op.STRING:
189
+ # data is a 2-tuple of quoted string and a kind value
190
+ # (default is 1)
191
+ assert isinstance(data, tuple) and len(data) == 2
192
+ assert (isinstance(data[0], str)
193
+ and data[0][::len(data[0]) - 1] in ('""', "''", '@@'))
194
+ assert isinstance(data[1], (int, str)), data
195
+ elif op is Op.SYMBOL:
196
+ # data is any hashable object
197
+ assert hash(data) is not None
198
+ elif op in (Op.ARRAY, Op.CONCAT):
199
+ # data is a tuple of expressions
200
+ assert isinstance(data, tuple)
201
+ assert all(isinstance(item, Expr) for item in data), data
202
+ elif op in (Op.TERMS, Op.FACTORS):
203
+ # data is {<term|base>:<coeff|exponent>} where dict values
204
+ # are nonzero Python integers
205
+ assert isinstance(data, dict)
206
+ elif op is Op.APPLY:
207
+ # data is (<function>, <operands>, <kwoperands>) where
208
+ # operands are Expr instances
209
+ assert isinstance(data, tuple) and len(data) == 3
210
+ # function is any hashable object
211
+ assert hash(data[0]) is not None
212
+ assert isinstance(data[1], tuple)
213
+ assert isinstance(data[2], dict)
214
+ elif op is Op.INDEXING:
215
+ # data is (<object>, <indices>)
216
+ assert isinstance(data, tuple) and len(data) == 2
217
+ # function is any hashable object
218
+ assert hash(data[0]) is not None
219
+ elif op is Op.TERNARY:
220
+ # data is (<cond>, <expr1>, <expr2>)
221
+ assert isinstance(data, tuple) and len(data) == 3
222
+ elif op in (Op.REF, Op.DEREF):
223
+ # data is Expr instance
224
+ assert isinstance(data, Expr)
225
+ elif op is Op.RELATIONAL:
226
+ # data is (<relop>, <left>, <right>)
227
+ assert isinstance(data, tuple) and len(data) == 3
228
+ else:
229
+ raise NotImplementedError(
230
+ f'unknown op or missing sanity check: {op}')
231
+
232
+ self.op = op
233
+ self.data = data
234
+
235
+ def __eq__(self, other):
236
+ return (isinstance(other, Expr)
237
+ and self.op is other.op
238
+ and self.data == other.data)
239
+
240
+ def __hash__(self):
241
+ if self.op in (Op.TERMS, Op.FACTORS):
242
+ data = tuple(sorted(self.data.items()))
243
+ elif self.op is Op.APPLY:
244
+ data = self.data[:2] + tuple(sorted(self.data[2].items()))
245
+ else:
246
+ data = self.data
247
+ return hash((self.op, data))
248
+
249
+ def __lt__(self, other):
250
+ if isinstance(other, Expr):
251
+ if self.op is not other.op:
252
+ return self.op.value < other.op.value
253
+ if self.op in (Op.TERMS, Op.FACTORS):
254
+ return (tuple(sorted(self.data.items()))
255
+ < tuple(sorted(other.data.items())))
256
+ if self.op is Op.APPLY:
257
+ if self.data[:2] != other.data[:2]:
258
+ return self.data[:2] < other.data[:2]
259
+ return tuple(sorted(self.data[2].items())) < tuple(
260
+ sorted(other.data[2].items()))
261
+ return self.data < other.data
262
+ return NotImplemented
263
+
264
+ def __le__(self, other): return self == other or self < other
265
+
266
+ def __gt__(self, other): return not (self <= other)
267
+
268
+ def __ge__(self, other): return not (self < other)
269
+
270
+ def __repr__(self):
271
+ return f'{type(self).__name__}({self.op}, {self.data!r})'
272
+
273
+ def __str__(self):
274
+ return self.tostring()
275
+
276
+ def tostring(self, parent_precedence=Precedence.NONE,
277
+ language=Language.Fortran):
278
+ """Return a string representation of Expr.
279
+ """
280
+ if self.op in (Op.INTEGER, Op.REAL):
281
+ precedence = (Precedence.SUM if self.data[0] < 0
282
+ else Precedence.ATOM)
283
+ r = str(self.data[0]) + (f'_{self.data[1]}'
284
+ if self.data[1] != 4 else '')
285
+ elif self.op is Op.COMPLEX:
286
+ r = ', '.join(item.tostring(Precedence.TUPLE, language=language)
287
+ for item in self.data)
288
+ r = '(' + r + ')'
289
+ precedence = Precedence.ATOM
290
+ elif self.op is Op.SYMBOL:
291
+ precedence = Precedence.ATOM
292
+ r = str(self.data)
293
+ elif self.op is Op.STRING:
294
+ r = self.data[0]
295
+ if self.data[1] != 1:
296
+ r = self.data[1] + '_' + r
297
+ precedence = Precedence.ATOM
298
+ elif self.op is Op.ARRAY:
299
+ r = ', '.join(item.tostring(Precedence.TUPLE, language=language)
300
+ for item in self.data)
301
+ r = '[' + r + ']'
302
+ precedence = Precedence.ATOM
303
+ elif self.op is Op.TERMS:
304
+ terms = []
305
+ for term, coeff in sorted(self.data.items()):
306
+ if coeff < 0:
307
+ op = ' - '
308
+ coeff = -coeff
309
+ else:
310
+ op = ' + '
311
+ if coeff == 1:
312
+ term = term.tostring(Precedence.SUM, language=language)
313
+ elif term == as_number(1):
314
+ term = str(coeff)
315
+ else:
316
+ term = f'{coeff} * ' + term.tostring(
317
+ Precedence.PRODUCT, language=language)
318
+ if terms:
319
+ terms.append(op)
320
+ elif op == ' - ':
321
+ terms.append('-')
322
+ terms.append(term)
323
+ r = ''.join(terms) or '0'
324
+ precedence = Precedence.SUM if terms else Precedence.ATOM
325
+ elif self.op is Op.FACTORS:
326
+ factors = []
327
+ tail = []
328
+ for base, exp in sorted(self.data.items()):
329
+ op = ' * '
330
+ if exp == 1:
331
+ factor = base.tostring(Precedence.PRODUCT,
332
+ language=language)
333
+ elif language is Language.C:
334
+ if exp in range(2, 10):
335
+ factor = base.tostring(Precedence.PRODUCT,
336
+ language=language)
337
+ factor = ' * '.join([factor] * exp)
338
+ elif exp in range(-10, 0):
339
+ factor = base.tostring(Precedence.PRODUCT,
340
+ language=language)
341
+ tail += [factor] * -exp
342
+ continue
343
+ else:
344
+ factor = base.tostring(Precedence.TUPLE,
345
+ language=language)
346
+ factor = f'pow({factor}, {exp})'
347
+ else:
348
+ factor = base.tostring(Precedence.POWER,
349
+ language=language) + f' ** {exp}'
350
+ if factors:
351
+ factors.append(op)
352
+ factors.append(factor)
353
+ if tail:
354
+ if not factors:
355
+ factors += ['1']
356
+ factors += ['/', '(', ' * '.join(tail), ')']
357
+ r = ''.join(factors) or '1'
358
+ precedence = Precedence.PRODUCT if factors else Precedence.ATOM
359
+ elif self.op is Op.APPLY:
360
+ name, args, kwargs = self.data
361
+ if name is ArithOp.DIV and language is Language.C:
362
+ numer, denom = [arg.tostring(Precedence.PRODUCT,
363
+ language=language)
364
+ for arg in args]
365
+ r = f'{numer} / {denom}'
366
+ precedence = Precedence.PRODUCT
367
+ else:
368
+ args = [arg.tostring(Precedence.TUPLE, language=language)
369
+ for arg in args]
370
+ args += [k + '=' + v.tostring(Precedence.NONE)
371
+ for k, v in kwargs.items()]
372
+ r = f'{name}({", ".join(args)})'
373
+ precedence = Precedence.ATOM
374
+ elif self.op is Op.INDEXING:
375
+ name = self.data[0]
376
+ args = [arg.tostring(Precedence.TUPLE, language=language)
377
+ for arg in self.data[1:]]
378
+ r = f'{name}[{", ".join(args)}]'
379
+ precedence = Precedence.ATOM
380
+ elif self.op is Op.CONCAT:
381
+ args = [arg.tostring(Precedence.PRODUCT, language=language)
382
+ for arg in self.data]
383
+ r = " // ".join(args)
384
+ precedence = Precedence.PRODUCT
385
+ elif self.op is Op.TERNARY:
386
+ cond, expr1, expr2 = [a.tostring(Precedence.TUPLE,
387
+ language=language)
388
+ for a in self.data]
389
+ if language is Language.C:
390
+ r = f'({cond}?{expr1}:{expr2})'
391
+ elif language is Language.Python:
392
+ r = f'({expr1} if {cond} else {expr2})'
393
+ elif language is Language.Fortran:
394
+ r = f'merge({expr1}, {expr2}, {cond})'
395
+ else:
396
+ raise NotImplementedError(
397
+ f'tostring for {self.op} and {language}')
398
+ precedence = Precedence.ATOM
399
+ elif self.op is Op.REF:
400
+ r = '&' + self.data.tostring(Precedence.UNARY, language=language)
401
+ precedence = Precedence.UNARY
402
+ elif self.op is Op.DEREF:
403
+ r = '*' + self.data.tostring(Precedence.UNARY, language=language)
404
+ precedence = Precedence.UNARY
405
+ elif self.op is Op.RELATIONAL:
406
+ rop, left, right = self.data
407
+ precedence = (Precedence.EQ if rop in (RelOp.EQ, RelOp.NE)
408
+ else Precedence.LT)
409
+ left = left.tostring(precedence, language=language)
410
+ right = right.tostring(precedence, language=language)
411
+ rop = rop.tostring(language=language)
412
+ r = f'{left} {rop} {right}'
413
+ else:
414
+ raise NotImplementedError(f'tostring for op {self.op}')
415
+ if parent_precedence.value < precedence.value:
416
+ # If parent precedence is higher than operand precedence,
417
+ # operand will be enclosed in parenthesis.
418
+ return '(' + r + ')'
419
+ return r
420
+
421
+ def __pos__(self):
422
+ return self
423
+
424
+ def __neg__(self):
425
+ return self * -1
426
+
427
+ def __add__(self, other):
428
+ other = as_expr(other)
429
+ if isinstance(other, Expr):
430
+ if self.op is other.op:
431
+ if self.op in (Op.INTEGER, Op.REAL):
432
+ return as_number(
433
+ self.data[0] + other.data[0],
434
+ max(self.data[1], other.data[1]))
435
+ if self.op is Op.COMPLEX:
436
+ r1, i1 = self.data
437
+ r2, i2 = other.data
438
+ return as_complex(r1 + r2, i1 + i2)
439
+ if self.op is Op.TERMS:
440
+ r = Expr(self.op, dict(self.data))
441
+ for k, v in other.data.items():
442
+ _pairs_add(r.data, k, v)
443
+ return normalize(r)
444
+ if self.op is Op.COMPLEX and other.op in (Op.INTEGER, Op.REAL):
445
+ return self + as_complex(other)
446
+ elif self.op in (Op.INTEGER, Op.REAL) and other.op is Op.COMPLEX:
447
+ return as_complex(self) + other
448
+ elif self.op is Op.REAL and other.op is Op.INTEGER:
449
+ return self + as_real(other, kind=self.data[1])
450
+ elif self.op is Op.INTEGER and other.op is Op.REAL:
451
+ return as_real(self, kind=other.data[1]) + other
452
+ return as_terms(self) + as_terms(other)
453
+ return NotImplemented
454
+
455
+ def __radd__(self, other):
456
+ if isinstance(other, number_types):
457
+ return as_number(other) + self
458
+ return NotImplemented
459
+
460
+ def __sub__(self, other):
461
+ return self + (-other)
462
+
463
+ def __rsub__(self, other):
464
+ if isinstance(other, number_types):
465
+ return as_number(other) - self
466
+ return NotImplemented
467
+
468
+ def __mul__(self, other):
469
+ other = as_expr(other)
470
+ if isinstance(other, Expr):
471
+ if self.op is other.op:
472
+ if self.op in (Op.INTEGER, Op.REAL):
473
+ return as_number(self.data[0] * other.data[0],
474
+ max(self.data[1], other.data[1]))
475
+ elif self.op is Op.COMPLEX:
476
+ r1, i1 = self.data
477
+ r2, i2 = other.data
478
+ return as_complex(r1 * r2 - i1 * i2, r1 * i2 + r2 * i1)
479
+
480
+ if self.op is Op.FACTORS:
481
+ r = Expr(self.op, dict(self.data))
482
+ for k, v in other.data.items():
483
+ _pairs_add(r.data, k, v)
484
+ return normalize(r)
485
+ elif self.op is Op.TERMS:
486
+ r = Expr(self.op, {})
487
+ for t1, c1 in self.data.items():
488
+ for t2, c2 in other.data.items():
489
+ _pairs_add(r.data, t1 * t2, c1 * c2)
490
+ return normalize(r)
491
+
492
+ if self.op is Op.COMPLEX and other.op in (Op.INTEGER, Op.REAL):
493
+ return self * as_complex(other)
494
+ elif other.op is Op.COMPLEX and self.op in (Op.INTEGER, Op.REAL):
495
+ return as_complex(self) * other
496
+ elif self.op is Op.REAL and other.op is Op.INTEGER:
497
+ return self * as_real(other, kind=self.data[1])
498
+ elif self.op is Op.INTEGER and other.op is Op.REAL:
499
+ return as_real(self, kind=other.data[1]) * other
500
+
501
+ if self.op is Op.TERMS:
502
+ return self * as_terms(other)
503
+ elif other.op is Op.TERMS:
504
+ return as_terms(self) * other
505
+
506
+ return as_factors(self) * as_factors(other)
507
+ return NotImplemented
508
+
509
+ def __rmul__(self, other):
510
+ if isinstance(other, number_types):
511
+ return as_number(other) * self
512
+ return NotImplemented
513
+
514
+ def __pow__(self, other):
515
+ other = as_expr(other)
516
+ if isinstance(other, Expr):
517
+ if other.op is Op.INTEGER:
518
+ exponent = other.data[0]
519
+ # TODO: other kind not used
520
+ if exponent == 0:
521
+ return as_number(1)
522
+ if exponent == 1:
523
+ return self
524
+ if exponent > 0:
525
+ if self.op is Op.FACTORS:
526
+ r = Expr(self.op, {})
527
+ for k, v in self.data.items():
528
+ r.data[k] = v * exponent
529
+ return normalize(r)
530
+ return self * (self ** (exponent - 1))
531
+ elif exponent != -1:
532
+ return (self ** (-exponent)) ** -1
533
+ return Expr(Op.FACTORS, {self: exponent})
534
+ return as_apply(ArithOp.POW, self, other)
535
+ return NotImplemented
536
+
537
+ def __truediv__(self, other):
538
+ other = as_expr(other)
539
+ if isinstance(other, Expr):
540
+ # Fortran / is different from Python /:
541
+ # - `/` is a truncate operation for integer operands
542
+ return normalize(as_apply(ArithOp.DIV, self, other))
543
+ return NotImplemented
544
+
545
+ def __rtruediv__(self, other):
546
+ other = as_expr(other)
547
+ if isinstance(other, Expr):
548
+ return other / self
549
+ return NotImplemented
550
+
551
+ def __floordiv__(self, other):
552
+ other = as_expr(other)
553
+ if isinstance(other, Expr):
554
+ # Fortran // is different from Python //:
555
+ # - `//` is a concatenate operation for string operands
556
+ return normalize(Expr(Op.CONCAT, (self, other)))
557
+ return NotImplemented
558
+
559
+ def __rfloordiv__(self, other):
560
+ other = as_expr(other)
561
+ if isinstance(other, Expr):
562
+ return other // self
563
+ return NotImplemented
564
+
565
+ def __call__(self, *args, **kwargs):
566
+ # In Fortran, parenthesis () are use for both function call as
567
+ # well as indexing operations.
568
+ #
569
+ # TODO: implement a method for deciding when __call__ should
570
+ # return an INDEXING expression.
571
+ return as_apply(self, *map(as_expr, args),
572
+ **{k: as_expr(v) for k, v in kwargs.items()})
573
+
574
+ def __getitem__(self, index):
575
+ # Provided to support C indexing operations that .pyf files
576
+ # may contain.
577
+ index = as_expr(index)
578
+ if not isinstance(index, tuple):
579
+ index = index,
580
+ if len(index) > 1:
581
+ ewarn(f'C-index should be a single expression but got `{index}`')
582
+ return Expr(Op.INDEXING, (self,) + index)
583
+
584
+ def substitute(self, symbols_map):
585
+ """Recursively substitute symbols with values in symbols map.
586
+
587
+ Symbols map is a dictionary of symbol-expression pairs.
588
+ """
589
+ if self.op is Op.SYMBOL:
590
+ value = symbols_map.get(self)
591
+ if value is None:
592
+ return self
593
+ m = re.match(r'\A(@__f2py_PARENTHESIS_(\w+)_\d+@)\Z', self.data)
594
+ if m:
595
+ # complement to fromstring method
596
+ items, paren = m.groups()
597
+ if paren in ['ROUNDDIV', 'SQUARE']:
598
+ return as_array(value)
599
+ assert paren == 'ROUND', (paren, value)
600
+ return value
601
+ if self.op in (Op.INTEGER, Op.REAL, Op.STRING):
602
+ return self
603
+ if self.op in (Op.ARRAY, Op.COMPLEX):
604
+ return Expr(self.op, tuple(item.substitute(symbols_map)
605
+ for item in self.data))
606
+ if self.op is Op.CONCAT:
607
+ return normalize(Expr(self.op, tuple(item.substitute(symbols_map)
608
+ for item in self.data)))
609
+ if self.op is Op.TERMS:
610
+ r = None
611
+ for term, coeff in self.data.items():
612
+ if r is None:
613
+ r = term.substitute(symbols_map) * coeff
614
+ else:
615
+ r += term.substitute(symbols_map) * coeff
616
+ if r is None:
617
+ ewarn('substitute: empty TERMS expression interpreted as'
618
+ ' int-literal 0')
619
+ return as_number(0)
620
+ return r
621
+ if self.op is Op.FACTORS:
622
+ r = None
623
+ for base, exponent in self.data.items():
624
+ if r is None:
625
+ r = base.substitute(symbols_map) ** exponent
626
+ else:
627
+ r *= base.substitute(symbols_map) ** exponent
628
+ if r is None:
629
+ ewarn('substitute: empty FACTORS expression interpreted'
630
+ ' as int-literal 1')
631
+ return as_number(1)
632
+ return r
633
+ if self.op is Op.APPLY:
634
+ target, args, kwargs = self.data
635
+ if isinstance(target, Expr):
636
+ target = target.substitute(symbols_map)
637
+ args = tuple(a.substitute(symbols_map) for a in args)
638
+ kwargs = {k: v.substitute(symbols_map)
639
+ for k, v in kwargs.items()}
640
+ return normalize(Expr(self.op, (target, args, kwargs)))
641
+ if self.op is Op.INDEXING:
642
+ func = self.data[0]
643
+ if isinstance(func, Expr):
644
+ func = func.substitute(symbols_map)
645
+ args = tuple(a.substitute(symbols_map) for a in self.data[1:])
646
+ return normalize(Expr(self.op, (func,) + args))
647
+ if self.op is Op.TERNARY:
648
+ operands = tuple(a.substitute(symbols_map) for a in self.data)
649
+ return normalize(Expr(self.op, operands))
650
+ if self.op in (Op.REF, Op.DEREF):
651
+ return normalize(Expr(self.op, self.data.substitute(symbols_map)))
652
+ if self.op is Op.RELATIONAL:
653
+ rop, left, right = self.data
654
+ left = left.substitute(symbols_map)
655
+ right = right.substitute(symbols_map)
656
+ return normalize(Expr(self.op, (rop, left, right)))
657
+ raise NotImplementedError(f'substitute method for {self.op}: {self!r}')
658
+
659
+ def traverse(self, visit, *args, **kwargs):
660
+ """Traverse expression tree with visit function.
661
+
662
+ The visit function is applied to an expression with given args
663
+ and kwargs.
664
+
665
+ Traverse call returns an expression returned by visit when not
666
+ None, otherwise return a new normalized expression with
667
+ traverse-visit sub-expressions.
668
+ """
669
+ result = visit(self, *args, **kwargs)
670
+ if result is not None:
671
+ return result
672
+
673
+ if self.op in (Op.INTEGER, Op.REAL, Op.STRING, Op.SYMBOL):
674
+ return self
675
+ elif self.op in (Op.COMPLEX, Op.ARRAY, Op.CONCAT, Op.TERNARY):
676
+ return normalize(Expr(self.op, tuple(
677
+ item.traverse(visit, *args, **kwargs)
678
+ for item in self.data)))
679
+ elif self.op in (Op.TERMS, Op.FACTORS):
680
+ data = {}
681
+ for k, v in self.data.items():
682
+ k = k.traverse(visit, *args, **kwargs)
683
+ v = (v.traverse(visit, *args, **kwargs)
684
+ if isinstance(v, Expr) else v)
685
+ if k in data:
686
+ v = data[k] + v
687
+ data[k] = v
688
+ return normalize(Expr(self.op, data))
689
+ elif self.op is Op.APPLY:
690
+ obj = self.data[0]
691
+ func = (obj.traverse(visit, *args, **kwargs)
692
+ if isinstance(obj, Expr) else obj)
693
+ operands = tuple(operand.traverse(visit, *args, **kwargs)
694
+ for operand in self.data[1])
695
+ kwoperands = {k: v.traverse(visit, *args, **kwargs)
696
+ for k, v in self.data[2].items()}
697
+ return normalize(Expr(self.op, (func, operands, kwoperands)))
698
+ elif self.op is Op.INDEXING:
699
+ obj = self.data[0]
700
+ obj = (obj.traverse(visit, *args, **kwargs)
701
+ if isinstance(obj, Expr) else obj)
702
+ indices = tuple(index.traverse(visit, *args, **kwargs)
703
+ for index in self.data[1:])
704
+ return normalize(Expr(self.op, (obj,) + indices))
705
+ elif self.op in (Op.REF, Op.DEREF):
706
+ return normalize(Expr(self.op,
707
+ self.data.traverse(visit, *args, **kwargs)))
708
+ elif self.op is Op.RELATIONAL:
709
+ rop, left, right = self.data
710
+ left = left.traverse(visit, *args, **kwargs)
711
+ right = right.traverse(visit, *args, **kwargs)
712
+ return normalize(Expr(self.op, (rop, left, right)))
713
+ raise NotImplementedError(f'traverse method for {self.op}')
714
+
715
+ def contains(self, other):
716
+ """Check if self contains other.
717
+ """
718
+ found = []
719
+
720
+ def visit(expr, found=found):
721
+ if found:
722
+ return expr
723
+ elif expr == other:
724
+ found.append(1)
725
+ return expr
726
+
727
+ self.traverse(visit)
728
+
729
+ return len(found) != 0
730
+
731
+ def symbols(self):
732
+ """Return a set of symbols contained in self.
733
+ """
734
+ found = set()
735
+
736
+ def visit(expr, found=found):
737
+ if expr.op is Op.SYMBOL:
738
+ found.add(expr)
739
+
740
+ self.traverse(visit)
741
+
742
+ return found
743
+
744
+ def polynomial_atoms(self):
745
+ """Return a set of expressions used as atoms in polynomial self.
746
+ """
747
+ found = set()
748
+
749
+ def visit(expr, found=found):
750
+ if expr.op is Op.FACTORS:
751
+ for b in expr.data:
752
+ b.traverse(visit)
753
+ return expr
754
+ if expr.op in (Op.TERMS, Op.COMPLEX):
755
+ return
756
+ if expr.op is Op.APPLY and isinstance(expr.data[0], ArithOp):
757
+ if expr.data[0] is ArithOp.POW:
758
+ expr.data[1][0].traverse(visit)
759
+ return expr
760
+ return
761
+ if expr.op in (Op.INTEGER, Op.REAL):
762
+ return expr
763
+
764
+ found.add(expr)
765
+
766
+ if expr.op in (Op.INDEXING, Op.APPLY):
767
+ return expr
768
+
769
+ self.traverse(visit)
770
+
771
+ return found
772
+
773
+ def linear_solve(self, symbol):
774
+ """Return a, b such that a * symbol + b == self.
775
+
776
+ If self is not linear with respect to symbol, raise RuntimeError.
777
+ """
778
+ b = self.substitute({symbol: as_number(0)})
779
+ ax = self - b
780
+ a = ax.substitute({symbol: as_number(1)})
781
+
782
+ zero, _ = as_numer_denom(a * symbol - ax)
783
+
784
+ if zero != as_number(0):
785
+ raise RuntimeError(f'not a {symbol}-linear equation:'
786
+ f' {a} * {symbol} + {b} == {self}')
787
+ return a, b
788
+
789
+
790
+ def normalize(obj):
791
+ """Normalize Expr and apply basic evaluation methods.
792
+ """
793
+ if not isinstance(obj, Expr):
794
+ return obj
795
+
796
+ if obj.op is Op.TERMS:
797
+ d = {}
798
+ for t, c in obj.data.items():
799
+ if c == 0:
800
+ continue
801
+ if t.op is Op.COMPLEX and c != 1:
802
+ t = t * c
803
+ c = 1
804
+ if t.op is Op.TERMS:
805
+ for t1, c1 in t.data.items():
806
+ _pairs_add(d, t1, c1 * c)
807
+ else:
808
+ _pairs_add(d, t, c)
809
+ if len(d) == 0:
810
+ # TODO: determine correct kind
811
+ return as_number(0)
812
+ elif len(d) == 1:
813
+ (t, c), = d.items()
814
+ if c == 1:
815
+ return t
816
+ return Expr(Op.TERMS, d)
817
+
818
+ if obj.op is Op.FACTORS:
819
+ coeff = 1
820
+ d = {}
821
+ for b, e in obj.data.items():
822
+ if e == 0:
823
+ continue
824
+ if b.op is Op.TERMS and isinstance(e, integer_types) and e > 1:
825
+ # expand integer powers of sums
826
+ b = b * (b ** (e - 1))
827
+ e = 1
828
+
829
+ if b.op in (Op.INTEGER, Op.REAL):
830
+ if e == 1:
831
+ coeff *= b.data[0]
832
+ elif e > 0:
833
+ coeff *= b.data[0] ** e
834
+ else:
835
+ _pairs_add(d, b, e)
836
+ elif b.op is Op.FACTORS:
837
+ if e > 0 and isinstance(e, integer_types):
838
+ for b1, e1 in b.data.items():
839
+ _pairs_add(d, b1, e1 * e)
840
+ else:
841
+ _pairs_add(d, b, e)
842
+ else:
843
+ _pairs_add(d, b, e)
844
+ if len(d) == 0 or coeff == 0:
845
+ # TODO: determine correct kind
846
+ assert isinstance(coeff, number_types)
847
+ return as_number(coeff)
848
+ elif len(d) == 1:
849
+ (b, e), = d.items()
850
+ if e == 1:
851
+ t = b
852
+ else:
853
+ t = Expr(Op.FACTORS, d)
854
+ if coeff == 1:
855
+ return t
856
+ return Expr(Op.TERMS, {t: coeff})
857
+ elif coeff == 1:
858
+ return Expr(Op.FACTORS, d)
859
+ else:
860
+ return Expr(Op.TERMS, {Expr(Op.FACTORS, d): coeff})
861
+
862
+ if obj.op is Op.APPLY and obj.data[0] is ArithOp.DIV:
863
+ dividend, divisor = obj.data[1]
864
+ t1, c1 = as_term_coeff(dividend)
865
+ t2, c2 = as_term_coeff(divisor)
866
+ if isinstance(c1, integer_types) and isinstance(c2, integer_types):
867
+ g = gcd(c1, c2)
868
+ c1, c2 = c1 // g, c2 // g
869
+ else:
870
+ c1, c2 = c1 / c2, 1
871
+
872
+ if t1.op is Op.APPLY and t1.data[0] is ArithOp.DIV:
873
+ numer = t1.data[1][0] * c1
874
+ denom = t1.data[1][1] * t2 * c2
875
+ return as_apply(ArithOp.DIV, numer, denom)
876
+
877
+ if t2.op is Op.APPLY and t2.data[0] is ArithOp.DIV:
878
+ numer = t2.data[1][1] * t1 * c1
879
+ denom = t2.data[1][0] * c2
880
+ return as_apply(ArithOp.DIV, numer, denom)
881
+
882
+ d = dict(as_factors(t1).data)
883
+ for b, e in as_factors(t2).data.items():
884
+ _pairs_add(d, b, -e)
885
+ numer, denom = {}, {}
886
+ for b, e in d.items():
887
+ if e > 0:
888
+ numer[b] = e
889
+ else:
890
+ denom[b] = -e
891
+ numer = normalize(Expr(Op.FACTORS, numer)) * c1
892
+ denom = normalize(Expr(Op.FACTORS, denom)) * c2
893
+
894
+ if denom.op in (Op.INTEGER, Op.REAL) and denom.data[0] == 1:
895
+ # TODO: denom kind not used
896
+ return numer
897
+ return as_apply(ArithOp.DIV, numer, denom)
898
+
899
+ if obj.op is Op.CONCAT:
900
+ lst = [obj.data[0]]
901
+ for s in obj.data[1:]:
902
+ last = lst[-1]
903
+ if (
904
+ last.op is Op.STRING
905
+ and s.op is Op.STRING
906
+ and last.data[0][0] in '"\''
907
+ and s.data[0][0] == last.data[0][-1]
908
+ ):
909
+ new_last = as_string(last.data[0][:-1] + s.data[0][1:],
910
+ max(last.data[1], s.data[1]))
911
+ lst[-1] = new_last
912
+ else:
913
+ lst.append(s)
914
+ if len(lst) == 1:
915
+ return lst[0]
916
+ return Expr(Op.CONCAT, tuple(lst))
917
+
918
+ if obj.op is Op.TERNARY:
919
+ cond, expr1, expr2 = map(normalize, obj.data)
920
+ if cond.op is Op.INTEGER:
921
+ return expr1 if cond.data[0] else expr2
922
+ return Expr(Op.TERNARY, (cond, expr1, expr2))
923
+
924
+ return obj
925
+
926
+
927
+ def as_expr(obj):
928
+ """Convert non-Expr objects to Expr objects.
929
+ """
930
+ if isinstance(obj, complex):
931
+ return as_complex(obj.real, obj.imag)
932
+ if isinstance(obj, number_types):
933
+ return as_number(obj)
934
+ if isinstance(obj, str):
935
+ # STRING expression holds string with boundary quotes, hence
936
+ # applying repr:
937
+ return as_string(repr(obj))
938
+ if isinstance(obj, tuple):
939
+ return tuple(map(as_expr, obj))
940
+ return obj
941
+
942
+
943
+ def as_symbol(obj):
944
+ """Return object as SYMBOL expression (variable or unparsed expression).
945
+ """
946
+ return Expr(Op.SYMBOL, obj)
947
+
948
+
949
+ def as_number(obj, kind=4):
950
+ """Return object as INTEGER or REAL constant.
951
+ """
952
+ if isinstance(obj, int):
953
+ return Expr(Op.INTEGER, (obj, kind))
954
+ if isinstance(obj, float):
955
+ return Expr(Op.REAL, (obj, kind))
956
+ if isinstance(obj, Expr):
957
+ if obj.op in (Op.INTEGER, Op.REAL):
958
+ return obj
959
+ raise OpError(f'cannot convert {obj} to INTEGER or REAL constant')
960
+
961
+
962
+ def as_integer(obj, kind=4):
963
+ """Return object as INTEGER constant.
964
+ """
965
+ if isinstance(obj, int):
966
+ return Expr(Op.INTEGER, (obj, kind))
967
+ if isinstance(obj, Expr):
968
+ if obj.op is Op.INTEGER:
969
+ return obj
970
+ raise OpError(f'cannot convert {obj} to INTEGER constant')
971
+
972
+
973
+ def as_real(obj, kind=4):
974
+ """Return object as REAL constant.
975
+ """
976
+ if isinstance(obj, int):
977
+ return Expr(Op.REAL, (float(obj), kind))
978
+ if isinstance(obj, float):
979
+ return Expr(Op.REAL, (obj, kind))
980
+ if isinstance(obj, Expr):
981
+ if obj.op is Op.REAL:
982
+ return obj
983
+ elif obj.op is Op.INTEGER:
984
+ return Expr(Op.REAL, (float(obj.data[0]), kind))
985
+ raise OpError(f'cannot convert {obj} to REAL constant')
986
+
987
+
988
+ def as_string(obj, kind=1):
989
+ """Return object as STRING expression (string literal constant).
990
+ """
991
+ return Expr(Op.STRING, (obj, kind))
992
+
993
+
994
+ def as_array(obj):
995
+ """Return object as ARRAY expression (array constant).
996
+ """
997
+ if isinstance(obj, Expr):
998
+ obj = obj,
999
+ return Expr(Op.ARRAY, obj)
1000
+
1001
+
1002
+ def as_complex(real, imag=0):
1003
+ """Return object as COMPLEX expression (complex literal constant).
1004
+ """
1005
+ return Expr(Op.COMPLEX, (as_expr(real), as_expr(imag)))
1006
+
1007
+
1008
+ def as_apply(func, *args, **kwargs):
1009
+ """Return object as APPLY expression (function call, constructor, etc.)
1010
+ """
1011
+ return Expr(Op.APPLY,
1012
+ (func, tuple(map(as_expr, args)),
1013
+ {k: as_expr(v) for k, v in kwargs.items()}))
1014
+
1015
+
1016
+ def as_ternary(cond, expr1, expr2):
1017
+ """Return object as TERNARY expression (cond?expr1:expr2).
1018
+ """
1019
+ return Expr(Op.TERNARY, (cond, expr1, expr2))
1020
+
1021
+
1022
+ def as_ref(expr):
1023
+ """Return object as referencing expression.
1024
+ """
1025
+ return Expr(Op.REF, expr)
1026
+
1027
+
1028
+ def as_deref(expr):
1029
+ """Return object as dereferencing expression.
1030
+ """
1031
+ return Expr(Op.DEREF, expr)
1032
+
1033
+
1034
+ def as_eq(left, right):
1035
+ return Expr(Op.RELATIONAL, (RelOp.EQ, left, right))
1036
+
1037
+
1038
+ def as_ne(left, right):
1039
+ return Expr(Op.RELATIONAL, (RelOp.NE, left, right))
1040
+
1041
+
1042
+ def as_lt(left, right):
1043
+ return Expr(Op.RELATIONAL, (RelOp.LT, left, right))
1044
+
1045
+
1046
+ def as_le(left, right):
1047
+ return Expr(Op.RELATIONAL, (RelOp.LE, left, right))
1048
+
1049
+
1050
+ def as_gt(left, right):
1051
+ return Expr(Op.RELATIONAL, (RelOp.GT, left, right))
1052
+
1053
+
1054
+ def as_ge(left, right):
1055
+ return Expr(Op.RELATIONAL, (RelOp.GE, left, right))
1056
+
1057
+
1058
+ def as_terms(obj):
1059
+ """Return expression as TERMS expression.
1060
+ """
1061
+ if isinstance(obj, Expr):
1062
+ obj = normalize(obj)
1063
+ if obj.op is Op.TERMS:
1064
+ return obj
1065
+ if obj.op is Op.INTEGER:
1066
+ return Expr(Op.TERMS, {as_integer(1, obj.data[1]): obj.data[0]})
1067
+ if obj.op is Op.REAL:
1068
+ return Expr(Op.TERMS, {as_real(1, obj.data[1]): obj.data[0]})
1069
+ return Expr(Op.TERMS, {obj: 1})
1070
+ raise OpError(f'cannot convert {type(obj)} to terms Expr')
1071
+
1072
+
1073
+ def as_factors(obj):
1074
+ """Return expression as FACTORS expression.
1075
+ """
1076
+ if isinstance(obj, Expr):
1077
+ obj = normalize(obj)
1078
+ if obj.op is Op.FACTORS:
1079
+ return obj
1080
+ if obj.op is Op.TERMS:
1081
+ if len(obj.data) == 1:
1082
+ (term, coeff), = obj.data.items()
1083
+ if coeff == 1:
1084
+ return Expr(Op.FACTORS, {term: 1})
1085
+ return Expr(Op.FACTORS, {term: 1, Expr.number(coeff): 1})
1086
+ if (obj.op is Op.APPLY
1087
+ and obj.data[0] is ArithOp.DIV
1088
+ and not obj.data[2]):
1089
+ return Expr(Op.FACTORS, {obj.data[1][0]: 1, obj.data[1][1]: -1})
1090
+ return Expr(Op.FACTORS, {obj: 1})
1091
+ raise OpError(f'cannot convert {type(obj)} to terms Expr')
1092
+
1093
+
1094
+ def as_term_coeff(obj):
1095
+ """Return expression as term-coefficient pair.
1096
+ """
1097
+ if isinstance(obj, Expr):
1098
+ obj = normalize(obj)
1099
+ if obj.op is Op.INTEGER:
1100
+ return as_integer(1, obj.data[1]), obj.data[0]
1101
+ if obj.op is Op.REAL:
1102
+ return as_real(1, obj.data[1]), obj.data[0]
1103
+ if obj.op is Op.TERMS:
1104
+ if len(obj.data) == 1:
1105
+ (term, coeff), = obj.data.items()
1106
+ return term, coeff
1107
+ # TODO: find common divisor of coefficients
1108
+ if obj.op is Op.APPLY and obj.data[0] is ArithOp.DIV:
1109
+ t, c = as_term_coeff(obj.data[1][0])
1110
+ return as_apply(ArithOp.DIV, t, obj.data[1][1]), c
1111
+ return obj, 1
1112
+ raise OpError(f'cannot convert {type(obj)} to term and coeff')
1113
+
1114
+
1115
+ def as_numer_denom(obj):
1116
+ """Return expression as numer-denom pair.
1117
+ """
1118
+ if isinstance(obj, Expr):
1119
+ obj = normalize(obj)
1120
+ if obj.op in (Op.INTEGER, Op.REAL, Op.COMPLEX, Op.SYMBOL,
1121
+ Op.INDEXING, Op.TERNARY):
1122
+ return obj, as_number(1)
1123
+ elif obj.op is Op.APPLY:
1124
+ if obj.data[0] is ArithOp.DIV and not obj.data[2]:
1125
+ numers, denoms = map(as_numer_denom, obj.data[1])
1126
+ return numers[0] * denoms[1], numers[1] * denoms[0]
1127
+ return obj, as_number(1)
1128
+ elif obj.op is Op.TERMS:
1129
+ numers, denoms = [], []
1130
+ for term, coeff in obj.data.items():
1131
+ n, d = as_numer_denom(term)
1132
+ n = n * coeff
1133
+ numers.append(n)
1134
+ denoms.append(d)
1135
+ numer, denom = as_number(0), as_number(1)
1136
+ for i in range(len(numers)):
1137
+ n = numers[i]
1138
+ for j in range(len(numers)):
1139
+ if i != j:
1140
+ n *= denoms[j]
1141
+ numer += n
1142
+ denom *= denoms[i]
1143
+ if denom.op in (Op.INTEGER, Op.REAL) and denom.data[0] < 0:
1144
+ numer, denom = -numer, -denom
1145
+ return numer, denom
1146
+ elif obj.op is Op.FACTORS:
1147
+ numer, denom = as_number(1), as_number(1)
1148
+ for b, e in obj.data.items():
1149
+ bnumer, bdenom = as_numer_denom(b)
1150
+ if e > 0:
1151
+ numer *= bnumer ** e
1152
+ denom *= bdenom ** e
1153
+ elif e < 0:
1154
+ numer *= bdenom ** (-e)
1155
+ denom *= bnumer ** (-e)
1156
+ return numer, denom
1157
+ raise OpError(f'cannot convert {type(obj)} to numer and denom')
1158
+
1159
+
1160
+ def _counter():
1161
+ # Used internally to generate unique dummy symbols
1162
+ counter = 0
1163
+ while True:
1164
+ counter += 1
1165
+ yield counter
1166
+
1167
+
1168
+ COUNTER = _counter()
1169
+
1170
+
1171
+ def eliminate_quotes(s):
1172
+ """Replace quoted substrings of input string.
1173
+
1174
+ Return a new string and a mapping of replacements.
1175
+ """
1176
+ d = {}
1177
+
1178
+ def repl(m):
1179
+ kind, value = m.groups()[:2]
1180
+ if kind:
1181
+ # remove trailing underscore
1182
+ kind = kind[:-1]
1183
+ p = {"'": "SINGLE", '"': "DOUBLE"}[value[0]]
1184
+ k = f'{kind}@__f2py_QUOTES_{p}_{COUNTER.__next__()}@'
1185
+ d[k] = value
1186
+ return k
1187
+
1188
+ new_s = re.sub(r'({kind}_|)({single_quoted}|{double_quoted})'.format(
1189
+ kind=r'\w[\w\d_]*',
1190
+ single_quoted=r"('([^'\\]|(\\.))*')",
1191
+ double_quoted=r'("([^"\\]|(\\.))*")'),
1192
+ repl, s)
1193
+
1194
+ assert '"' not in new_s
1195
+ assert "'" not in new_s
1196
+
1197
+ return new_s, d
1198
+
1199
+
1200
+ def insert_quotes(s, d):
1201
+ """Inverse of eliminate_quotes.
1202
+ """
1203
+ for k, v in d.items():
1204
+ kind = k[:k.find('@')]
1205
+ if kind:
1206
+ kind += '_'
1207
+ s = s.replace(k, kind + v)
1208
+ return s
1209
+
1210
+
1211
+ def replace_parenthesis(s):
1212
+ """Replace substrings of input that are enclosed in parenthesis.
1213
+
1214
+ Return a new string and a mapping of replacements.
1215
+ """
1216
+ # Find a parenthesis pair that appears first.
1217
+
1218
+ # Fortran deliminator are `(`, `)`, `[`, `]`, `(/', '/)`, `/`.
1219
+ # We don't handle `/` deliminator because it is not a part of an
1220
+ # expression.
1221
+ left, right = None, None
1222
+ mn_i = len(s)
1223
+ for left_, right_ in (('(/', '/)'),
1224
+ '()',
1225
+ '{}', # to support C literal structs
1226
+ '[]'):
1227
+ i = s.find(left_)
1228
+ if i == -1:
1229
+ continue
1230
+ if i < mn_i:
1231
+ mn_i = i
1232
+ left, right = left_, right_
1233
+
1234
+ if left is None:
1235
+ return s, {}
1236
+
1237
+ i = mn_i
1238
+ j = s.find(right, i)
1239
+
1240
+ while s.count(left, i + 1, j) != s.count(right, i + 1, j):
1241
+ j = s.find(right, j + 1)
1242
+ if j == -1:
1243
+ raise ValueError(f'Mismatch of {left + right} parenthesis in {s!r}')
1244
+
1245
+ p = {'(': 'ROUND', '[': 'SQUARE', '{': 'CURLY', '(/': 'ROUNDDIV'}[left]
1246
+
1247
+ k = f'@__f2py_PARENTHESIS_{p}_{COUNTER.__next__()}@'
1248
+ v = s[i + len(left):j]
1249
+ r, d = replace_parenthesis(s[j + len(right):])
1250
+ d[k] = v
1251
+ return s[:i] + k + r, d
1252
+
1253
+
1254
+ def _get_parenthesis_kind(s):
1255
+ assert s.startswith('@__f2py_PARENTHESIS_'), s
1256
+ return s.split('_')[4]
1257
+
1258
+
1259
+ def unreplace_parenthesis(s, d):
1260
+ """Inverse of replace_parenthesis.
1261
+ """
1262
+ for k, v in d.items():
1263
+ p = _get_parenthesis_kind(k)
1264
+ left = {'ROUND': '(', 'SQUARE': '[', 'CURLY': '{', 'ROUNDDIV': '(/'}[p]
1265
+ right = {'ROUND': ')', 'SQUARE': ']', 'CURLY': '}', 'ROUNDDIV': '/)'}[p]
1266
+ s = s.replace(k, left + v + right)
1267
+ return s
1268
+
1269
+
1270
+ def fromstring(s, language=Language.C):
1271
+ """Create an expression from a string.
1272
+
1273
+ This is a "lazy" parser, that is, only arithmetic operations are
1274
+ resolved, non-arithmetic operations are treated as symbols.
1275
+ """
1276
+ r = _FromStringWorker(language=language).parse(s)
1277
+ if isinstance(r, Expr):
1278
+ return r
1279
+ raise ValueError(f'failed to parse `{s}` to Expr instance: got `{r}`')
1280
+
1281
+
1282
+ class _Pair:
1283
+ # Internal class to represent a pair of expressions
1284
+
1285
+ def __init__(self, left, right):
1286
+ self.left = left
1287
+ self.right = right
1288
+
1289
+ def substitute(self, symbols_map):
1290
+ left, right = self.left, self.right
1291
+ if isinstance(left, Expr):
1292
+ left = left.substitute(symbols_map)
1293
+ if isinstance(right, Expr):
1294
+ right = right.substitute(symbols_map)
1295
+ return _Pair(left, right)
1296
+
1297
+ def __repr__(self):
1298
+ return f'{type(self).__name__}({self.left}, {self.right})'
1299
+
1300
+
1301
+ class _FromStringWorker:
1302
+
1303
+ def __init__(self, language=Language.C):
1304
+ self.original = None
1305
+ self.quotes_map = None
1306
+ self.language = language
1307
+
1308
+ def finalize_string(self, s):
1309
+ return insert_quotes(s, self.quotes_map)
1310
+
1311
+ def parse(self, inp):
1312
+ self.original = inp
1313
+ unquoted, self.quotes_map = eliminate_quotes(inp)
1314
+ return self.process(unquoted)
1315
+
1316
+ def process(self, s, context='expr'):
1317
+ """Parse string within the given context.
1318
+
1319
+ The context may define the result in case of ambiguous
1320
+ expressions. For instance, consider expressions `f(x, y)` and
1321
+ `(x, y) + (a, b)` where `f` is a function and pair `(x, y)`
1322
+ denotes complex number. Specifying context as "args" or
1323
+ "expr", the subexpression `(x, y)` will be parse to an
1324
+ argument list or to a complex number, respectively.
1325
+ """
1326
+ if isinstance(s, (list, tuple)):
1327
+ return type(s)(self.process(s_, context) for s_ in s)
1328
+
1329
+ assert isinstance(s, str), (type(s), s)
1330
+
1331
+ # replace subexpressions in parenthesis with f2py @-names
1332
+ r, raw_symbols_map = replace_parenthesis(s)
1333
+ r = r.strip()
1334
+
1335
+ def restore(r):
1336
+ # restores subexpressions marked with f2py @-names
1337
+ if isinstance(r, (list, tuple)):
1338
+ return type(r)(map(restore, r))
1339
+ return unreplace_parenthesis(r, raw_symbols_map)
1340
+
1341
+ # comma-separated tuple
1342
+ if ',' in r:
1343
+ operands = restore(r.split(','))
1344
+ if context == 'args':
1345
+ return tuple(self.process(operands))
1346
+ if context == 'expr':
1347
+ if len(operands) == 2:
1348
+ # complex number literal
1349
+ return as_complex(*self.process(operands))
1350
+ raise NotImplementedError(
1351
+ f'parsing comma-separated list (context={context}): {r}')
1352
+
1353
+ # ternary operation
1354
+ m = re.match(r'\A([^?]+)[?]([^:]+)[:](.+)\Z', r)
1355
+ if m:
1356
+ assert context == 'expr', context
1357
+ oper, expr1, expr2 = restore(m.groups())
1358
+ oper = self.process(oper)
1359
+ expr1 = self.process(expr1)
1360
+ expr2 = self.process(expr2)
1361
+ return as_ternary(oper, expr1, expr2)
1362
+
1363
+ # relational expression
1364
+ if self.language is Language.Fortran:
1365
+ m = re.match(
1366
+ r'\A(.+)\s*[.](eq|ne|lt|le|gt|ge)[.]\s*(.+)\Z', r, re.I)
1367
+ else:
1368
+ m = re.match(
1369
+ r'\A(.+)\s*([=][=]|[!][=]|[<][=]|[<]|[>][=]|[>])\s*(.+)\Z', r)
1370
+ if m:
1371
+ left, rop, right = m.groups()
1372
+ if self.language is Language.Fortran:
1373
+ rop = '.' + rop + '.'
1374
+ left, right = self.process(restore((left, right)))
1375
+ rop = RelOp.fromstring(rop, language=self.language)
1376
+ return Expr(Op.RELATIONAL, (rop, left, right))
1377
+
1378
+ # keyword argument
1379
+ m = re.match(r'\A(\w[\w\d_]*)\s*[=](.*)\Z', r)
1380
+ if m:
1381
+ keyname, value = m.groups()
1382
+ value = restore(value)
1383
+ return _Pair(keyname, self.process(value))
1384
+
1385
+ # addition/subtraction operations
1386
+ operands = re.split(r'((?<!\d[edED])[+-])', r)
1387
+ if len(operands) > 1:
1388
+ result = self.process(restore(operands[0] or '0'))
1389
+ for op, operand in zip(operands[1::2], operands[2::2]):
1390
+ operand = self.process(restore(operand))
1391
+ op = op.strip()
1392
+ if op == '+':
1393
+ result += operand
1394
+ else:
1395
+ assert op == '-'
1396
+ result -= operand
1397
+ return result
1398
+
1399
+ # string concatenate operation
1400
+ if self.language is Language.Fortran and '//' in r:
1401
+ operands = restore(r.split('//'))
1402
+ return Expr(Op.CONCAT,
1403
+ tuple(self.process(operands)))
1404
+
1405
+ # multiplication/division operations
1406
+ operands = re.split(r'(?<=[@\w\d_])\s*([*]|/)',
1407
+ (r if self.language is Language.C
1408
+ else r.replace('**', '@__f2py_DOUBLE_STAR@')))
1409
+ if len(operands) > 1:
1410
+ operands = restore(operands)
1411
+ if self.language is not Language.C:
1412
+ operands = [operand.replace('@__f2py_DOUBLE_STAR@', '**')
1413
+ for operand in operands]
1414
+ # Expression is an arithmetic product
1415
+ result = self.process(operands[0])
1416
+ for op, operand in zip(operands[1::2], operands[2::2]):
1417
+ operand = self.process(operand)
1418
+ op = op.strip()
1419
+ if op == '*':
1420
+ result *= operand
1421
+ else:
1422
+ assert op == '/'
1423
+ result /= operand
1424
+ return result
1425
+
1426
+ # referencing/dereferencing
1427
+ if r.startswith(('*', '&')):
1428
+ op = {'*': Op.DEREF, '&': Op.REF}[r[0]]
1429
+ operand = self.process(restore(r[1:]))
1430
+ return Expr(op, operand)
1431
+
1432
+ # exponentiation operations
1433
+ if self.language is not Language.C and '**' in r:
1434
+ operands = list(reversed(restore(r.split('**'))))
1435
+ result = self.process(operands[0])
1436
+ for operand in operands[1:]:
1437
+ operand = self.process(operand)
1438
+ result = operand ** result
1439
+ return result
1440
+
1441
+ # int-literal-constant
1442
+ m = re.match(r'\A({digit_string})({kind}|)\Z'.format(
1443
+ digit_string=r'\d+',
1444
+ kind=r'_(\d+|\w[\w\d_]*)'), r)
1445
+ if m:
1446
+ value, _, kind = m.groups()
1447
+ if kind and kind.isdigit():
1448
+ kind = int(kind)
1449
+ return as_integer(int(value), kind or 4)
1450
+
1451
+ # real-literal-constant
1452
+ m = re.match(r'\A({significant}({exponent}|)|\d+{exponent})({kind}|)\Z'
1453
+ .format(
1454
+ significant=r'[.]\d+|\d+[.]\d*',
1455
+ exponent=r'[edED][+-]?\d+',
1456
+ kind=r'_(\d+|\w[\w\d_]*)'), r)
1457
+ if m:
1458
+ value, _, _, kind = m.groups()
1459
+ if kind and kind.isdigit():
1460
+ kind = int(kind)
1461
+ value = value.lower()
1462
+ if 'd' in value:
1463
+ return as_real(float(value.replace('d', 'e')), kind or 8)
1464
+ return as_real(float(value), kind or 4)
1465
+
1466
+ # string-literal-constant with kind parameter specification
1467
+ if r in self.quotes_map:
1468
+ kind = r[:r.find('@')]
1469
+ return as_string(self.quotes_map[r], kind or 1)
1470
+
1471
+ # array constructor or literal complex constant or
1472
+ # parenthesized expression
1473
+ if r in raw_symbols_map:
1474
+ paren = _get_parenthesis_kind(r)
1475
+ items = self.process(restore(raw_symbols_map[r]),
1476
+ 'expr' if paren == 'ROUND' else 'args')
1477
+ if paren == 'ROUND':
1478
+ if isinstance(items, Expr):
1479
+ return items
1480
+ if paren in ['ROUNDDIV', 'SQUARE']:
1481
+ # Expression is a array constructor
1482
+ if isinstance(items, Expr):
1483
+ items = (items,)
1484
+ return as_array(items)
1485
+
1486
+ # function call/indexing
1487
+ m = re.match(r'\A(.+)\s*(@__f2py_PARENTHESIS_(ROUND|SQUARE)_\d+@)\Z',
1488
+ r)
1489
+ if m:
1490
+ target, args, paren = m.groups()
1491
+ target = self.process(restore(target))
1492
+ args = self.process(restore(args)[1:-1], 'args')
1493
+ if not isinstance(args, tuple):
1494
+ args = args,
1495
+ if paren == 'ROUND':
1496
+ kwargs = {a.left: a.right for a in args
1497
+ if isinstance(a, _Pair)}
1498
+ args = tuple(a for a in args if not isinstance(a, _Pair))
1499
+ # Warning: this could also be Fortran indexing operation..
1500
+ return as_apply(target, *args, **kwargs)
1501
+ else:
1502
+ # Expression is a C/Python indexing operation
1503
+ # (e.g. used in .pyf files)
1504
+ assert paren == 'SQUARE'
1505
+ return target[args]
1506
+
1507
+ # Fortran standard conforming identifier
1508
+ m = re.match(r'\A\w[\w\d_]*\Z', r)
1509
+ if m:
1510
+ return as_symbol(r)
1511
+
1512
+ # fall-back to symbol
1513
+ r = self.finalize_string(restore(r))
1514
+ ewarn(
1515
+ f'fromstring: treating {r!r} as symbol (original={self.original})')
1516
+ return as_symbol(r)