scipy 1.16.2__cp314-cp314t-win_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.
Files changed (1530) hide show
  1. scipy/__config__.py +161 -0
  2. scipy/__init__.py +150 -0
  3. scipy/_cyutility.cp314t-win_arm64.lib +0 -0
  4. scipy/_cyutility.cp314t-win_arm64.pyd +0 -0
  5. scipy/_distributor_init.py +18 -0
  6. scipy/_lib/__init__.py +14 -0
  7. scipy/_lib/_array_api.py +931 -0
  8. scipy/_lib/_array_api_compat_vendor.py +9 -0
  9. scipy/_lib/_array_api_no_0d.py +103 -0
  10. scipy/_lib/_bunch.py +229 -0
  11. scipy/_lib/_ccallback.py +251 -0
  12. scipy/_lib/_ccallback_c.cp314t-win_arm64.lib +0 -0
  13. scipy/_lib/_ccallback_c.cp314t-win_arm64.pyd +0 -0
  14. scipy/_lib/_disjoint_set.py +254 -0
  15. scipy/_lib/_docscrape.py +761 -0
  16. scipy/_lib/_elementwise_iterative_method.py +346 -0
  17. scipy/_lib/_fpumode.cp314t-win_arm64.lib +0 -0
  18. scipy/_lib/_fpumode.cp314t-win_arm64.pyd +0 -0
  19. scipy/_lib/_gcutils.py +105 -0
  20. scipy/_lib/_pep440.py +487 -0
  21. scipy/_lib/_sparse.py +41 -0
  22. scipy/_lib/_test_ccallback.cp314t-win_arm64.lib +0 -0
  23. scipy/_lib/_test_ccallback.cp314t-win_arm64.pyd +0 -0
  24. scipy/_lib/_test_deprecation_call.cp314t-win_arm64.lib +0 -0
  25. scipy/_lib/_test_deprecation_call.cp314t-win_arm64.pyd +0 -0
  26. scipy/_lib/_test_deprecation_def.cp314t-win_arm64.lib +0 -0
  27. scipy/_lib/_test_deprecation_def.cp314t-win_arm64.pyd +0 -0
  28. scipy/_lib/_testutils.py +373 -0
  29. scipy/_lib/_threadsafety.py +58 -0
  30. scipy/_lib/_tmpdirs.py +86 -0
  31. scipy/_lib/_uarray/LICENSE +29 -0
  32. scipy/_lib/_uarray/__init__.py +116 -0
  33. scipy/_lib/_uarray/_backend.py +707 -0
  34. scipy/_lib/_uarray/_uarray.cp314t-win_arm64.lib +0 -0
  35. scipy/_lib/_uarray/_uarray.cp314t-win_arm64.pyd +0 -0
  36. scipy/_lib/_util.py +1283 -0
  37. scipy/_lib/array_api_compat/__init__.py +22 -0
  38. scipy/_lib/array_api_compat/_internal.py +59 -0
  39. scipy/_lib/array_api_compat/common/__init__.py +1 -0
  40. scipy/_lib/array_api_compat/common/_aliases.py +727 -0
  41. scipy/_lib/array_api_compat/common/_fft.py +213 -0
  42. scipy/_lib/array_api_compat/common/_helpers.py +1058 -0
  43. scipy/_lib/array_api_compat/common/_linalg.py +232 -0
  44. scipy/_lib/array_api_compat/common/_typing.py +192 -0
  45. scipy/_lib/array_api_compat/cupy/__init__.py +13 -0
  46. scipy/_lib/array_api_compat/cupy/_aliases.py +156 -0
  47. scipy/_lib/array_api_compat/cupy/_info.py +336 -0
  48. scipy/_lib/array_api_compat/cupy/_typing.py +31 -0
  49. scipy/_lib/array_api_compat/cupy/fft.py +36 -0
  50. scipy/_lib/array_api_compat/cupy/linalg.py +49 -0
  51. scipy/_lib/array_api_compat/dask/__init__.py +0 -0
  52. scipy/_lib/array_api_compat/dask/array/__init__.py +12 -0
  53. scipy/_lib/array_api_compat/dask/array/_aliases.py +376 -0
  54. scipy/_lib/array_api_compat/dask/array/_info.py +416 -0
  55. scipy/_lib/array_api_compat/dask/array/fft.py +21 -0
  56. scipy/_lib/array_api_compat/dask/array/linalg.py +72 -0
  57. scipy/_lib/array_api_compat/numpy/__init__.py +28 -0
  58. scipy/_lib/array_api_compat/numpy/_aliases.py +190 -0
  59. scipy/_lib/array_api_compat/numpy/_info.py +366 -0
  60. scipy/_lib/array_api_compat/numpy/_typing.py +30 -0
  61. scipy/_lib/array_api_compat/numpy/fft.py +35 -0
  62. scipy/_lib/array_api_compat/numpy/linalg.py +143 -0
  63. scipy/_lib/array_api_compat/torch/__init__.py +22 -0
  64. scipy/_lib/array_api_compat/torch/_aliases.py +855 -0
  65. scipy/_lib/array_api_compat/torch/_info.py +369 -0
  66. scipy/_lib/array_api_compat/torch/_typing.py +3 -0
  67. scipy/_lib/array_api_compat/torch/fft.py +85 -0
  68. scipy/_lib/array_api_compat/torch/linalg.py +121 -0
  69. scipy/_lib/array_api_extra/__init__.py +38 -0
  70. scipy/_lib/array_api_extra/_delegation.py +171 -0
  71. scipy/_lib/array_api_extra/_lib/__init__.py +1 -0
  72. scipy/_lib/array_api_extra/_lib/_at.py +463 -0
  73. scipy/_lib/array_api_extra/_lib/_backends.py +46 -0
  74. scipy/_lib/array_api_extra/_lib/_funcs.py +937 -0
  75. scipy/_lib/array_api_extra/_lib/_lazy.py +357 -0
  76. scipy/_lib/array_api_extra/_lib/_testing.py +278 -0
  77. scipy/_lib/array_api_extra/_lib/_utils/__init__.py +1 -0
  78. scipy/_lib/array_api_extra/_lib/_utils/_compat.py +74 -0
  79. scipy/_lib/array_api_extra/_lib/_utils/_compat.pyi +45 -0
  80. scipy/_lib/array_api_extra/_lib/_utils/_helpers.py +559 -0
  81. scipy/_lib/array_api_extra/_lib/_utils/_typing.py +10 -0
  82. scipy/_lib/array_api_extra/_lib/_utils/_typing.pyi +105 -0
  83. scipy/_lib/array_api_extra/testing.py +359 -0
  84. scipy/_lib/cobyqa/__init__.py +20 -0
  85. scipy/_lib/cobyqa/framework.py +1240 -0
  86. scipy/_lib/cobyqa/main.py +1506 -0
  87. scipy/_lib/cobyqa/models.py +1529 -0
  88. scipy/_lib/cobyqa/problem.py +1296 -0
  89. scipy/_lib/cobyqa/settings.py +132 -0
  90. scipy/_lib/cobyqa/subsolvers/__init__.py +14 -0
  91. scipy/_lib/cobyqa/subsolvers/geometry.py +387 -0
  92. scipy/_lib/cobyqa/subsolvers/optim.py +1203 -0
  93. scipy/_lib/cobyqa/utils/__init__.py +18 -0
  94. scipy/_lib/cobyqa/utils/exceptions.py +22 -0
  95. scipy/_lib/cobyqa/utils/math.py +77 -0
  96. scipy/_lib/cobyqa/utils/versions.py +67 -0
  97. scipy/_lib/decorator.py +399 -0
  98. scipy/_lib/deprecation.py +274 -0
  99. scipy/_lib/doccer.py +366 -0
  100. scipy/_lib/messagestream.cp314t-win_arm64.lib +0 -0
  101. scipy/_lib/messagestream.cp314t-win_arm64.pyd +0 -0
  102. scipy/_lib/pyprima/__init__.py +212 -0
  103. scipy/_lib/pyprima/cobyla/__init__.py +0 -0
  104. scipy/_lib/pyprima/cobyla/cobyla.py +559 -0
  105. scipy/_lib/pyprima/cobyla/cobylb.py +714 -0
  106. scipy/_lib/pyprima/cobyla/geometry.py +226 -0
  107. scipy/_lib/pyprima/cobyla/initialize.py +215 -0
  108. scipy/_lib/pyprima/cobyla/trustregion.py +492 -0
  109. scipy/_lib/pyprima/cobyla/update.py +289 -0
  110. scipy/_lib/pyprima/common/__init__.py +0 -0
  111. scipy/_lib/pyprima/common/_bounds.py +34 -0
  112. scipy/_lib/pyprima/common/_linear_constraints.py +46 -0
  113. scipy/_lib/pyprima/common/_nonlinear_constraints.py +54 -0
  114. scipy/_lib/pyprima/common/_project.py +173 -0
  115. scipy/_lib/pyprima/common/checkbreak.py +93 -0
  116. scipy/_lib/pyprima/common/consts.py +47 -0
  117. scipy/_lib/pyprima/common/evaluate.py +99 -0
  118. scipy/_lib/pyprima/common/history.py +38 -0
  119. scipy/_lib/pyprima/common/infos.py +30 -0
  120. scipy/_lib/pyprima/common/linalg.py +435 -0
  121. scipy/_lib/pyprima/common/message.py +290 -0
  122. scipy/_lib/pyprima/common/powalg.py +131 -0
  123. scipy/_lib/pyprima/common/preproc.py +277 -0
  124. scipy/_lib/pyprima/common/present.py +5 -0
  125. scipy/_lib/pyprima/common/ratio.py +54 -0
  126. scipy/_lib/pyprima/common/redrho.py +47 -0
  127. scipy/_lib/pyprima/common/selectx.py +296 -0
  128. scipy/_lib/tests/__init__.py +0 -0
  129. scipy/_lib/tests/test__gcutils.py +110 -0
  130. scipy/_lib/tests/test__pep440.py +67 -0
  131. scipy/_lib/tests/test__testutils.py +32 -0
  132. scipy/_lib/tests/test__threadsafety.py +51 -0
  133. scipy/_lib/tests/test__util.py +641 -0
  134. scipy/_lib/tests/test_array_api.py +322 -0
  135. scipy/_lib/tests/test_bunch.py +169 -0
  136. scipy/_lib/tests/test_ccallback.py +196 -0
  137. scipy/_lib/tests/test_config.py +45 -0
  138. scipy/_lib/tests/test_deprecation.py +10 -0
  139. scipy/_lib/tests/test_doccer.py +143 -0
  140. scipy/_lib/tests/test_import_cycles.py +18 -0
  141. scipy/_lib/tests/test_public_api.py +482 -0
  142. scipy/_lib/tests/test_scipy_version.py +28 -0
  143. scipy/_lib/tests/test_tmpdirs.py +48 -0
  144. scipy/_lib/tests/test_warnings.py +137 -0
  145. scipy/_lib/uarray.py +31 -0
  146. scipy/cluster/__init__.py +31 -0
  147. scipy/cluster/_hierarchy.cp314t-win_arm64.lib +0 -0
  148. scipy/cluster/_hierarchy.cp314t-win_arm64.pyd +0 -0
  149. scipy/cluster/_optimal_leaf_ordering.cp314t-win_arm64.lib +0 -0
  150. scipy/cluster/_optimal_leaf_ordering.cp314t-win_arm64.pyd +0 -0
  151. scipy/cluster/_vq.cp314t-win_arm64.lib +0 -0
  152. scipy/cluster/_vq.cp314t-win_arm64.pyd +0 -0
  153. scipy/cluster/hierarchy.py +4348 -0
  154. scipy/cluster/tests/__init__.py +0 -0
  155. scipy/cluster/tests/hierarchy_test_data.py +145 -0
  156. scipy/cluster/tests/test_disjoint_set.py +202 -0
  157. scipy/cluster/tests/test_hierarchy.py +1238 -0
  158. scipy/cluster/tests/test_vq.py +434 -0
  159. scipy/cluster/vq.py +832 -0
  160. scipy/conftest.py +683 -0
  161. scipy/constants/__init__.py +358 -0
  162. scipy/constants/_codata.py +2266 -0
  163. scipy/constants/_constants.py +369 -0
  164. scipy/constants/codata.py +21 -0
  165. scipy/constants/constants.py +53 -0
  166. scipy/constants/tests/__init__.py +0 -0
  167. scipy/constants/tests/test_codata.py +78 -0
  168. scipy/constants/tests/test_constants.py +83 -0
  169. scipy/datasets/__init__.py +90 -0
  170. scipy/datasets/_download_all.py +71 -0
  171. scipy/datasets/_fetchers.py +225 -0
  172. scipy/datasets/_registry.py +26 -0
  173. scipy/datasets/_utils.py +81 -0
  174. scipy/datasets/tests/__init__.py +0 -0
  175. scipy/datasets/tests/test_data.py +128 -0
  176. scipy/differentiate/__init__.py +27 -0
  177. scipy/differentiate/_differentiate.py +1129 -0
  178. scipy/differentiate/tests/__init__.py +0 -0
  179. scipy/differentiate/tests/test_differentiate.py +694 -0
  180. scipy/fft/__init__.py +114 -0
  181. scipy/fft/_backend.py +196 -0
  182. scipy/fft/_basic.py +1650 -0
  183. scipy/fft/_basic_backend.py +197 -0
  184. scipy/fft/_debug_backends.py +22 -0
  185. scipy/fft/_fftlog.py +223 -0
  186. scipy/fft/_fftlog_backend.py +200 -0
  187. scipy/fft/_helper.py +348 -0
  188. scipy/fft/_pocketfft/LICENSE.md +25 -0
  189. scipy/fft/_pocketfft/__init__.py +9 -0
  190. scipy/fft/_pocketfft/basic.py +251 -0
  191. scipy/fft/_pocketfft/helper.py +249 -0
  192. scipy/fft/_pocketfft/pypocketfft.cp314t-win_arm64.lib +0 -0
  193. scipy/fft/_pocketfft/pypocketfft.cp314t-win_arm64.pyd +0 -0
  194. scipy/fft/_pocketfft/realtransforms.py +109 -0
  195. scipy/fft/_pocketfft/tests/__init__.py +0 -0
  196. scipy/fft/_pocketfft/tests/test_basic.py +1011 -0
  197. scipy/fft/_pocketfft/tests/test_real_transforms.py +505 -0
  198. scipy/fft/_realtransforms.py +706 -0
  199. scipy/fft/_realtransforms_backend.py +63 -0
  200. scipy/fft/tests/__init__.py +0 -0
  201. scipy/fft/tests/mock_backend.py +96 -0
  202. scipy/fft/tests/test_backend.py +98 -0
  203. scipy/fft/tests/test_basic.py +504 -0
  204. scipy/fft/tests/test_fftlog.py +215 -0
  205. scipy/fft/tests/test_helper.py +558 -0
  206. scipy/fft/tests/test_multithreading.py +84 -0
  207. scipy/fft/tests/test_real_transforms.py +247 -0
  208. scipy/fftpack/__init__.py +103 -0
  209. scipy/fftpack/_basic.py +428 -0
  210. scipy/fftpack/_helper.py +115 -0
  211. scipy/fftpack/_pseudo_diffs.py +554 -0
  212. scipy/fftpack/_realtransforms.py +598 -0
  213. scipy/fftpack/basic.py +20 -0
  214. scipy/fftpack/convolve.cp314t-win_arm64.lib +0 -0
  215. scipy/fftpack/convolve.cp314t-win_arm64.pyd +0 -0
  216. scipy/fftpack/helper.py +19 -0
  217. scipy/fftpack/pseudo_diffs.py +22 -0
  218. scipy/fftpack/realtransforms.py +19 -0
  219. scipy/fftpack/tests/__init__.py +0 -0
  220. scipy/fftpack/tests/fftw_double_ref.npz +0 -0
  221. scipy/fftpack/tests/fftw_longdouble_ref.npz +0 -0
  222. scipy/fftpack/tests/fftw_single_ref.npz +0 -0
  223. scipy/fftpack/tests/test.npz +0 -0
  224. scipy/fftpack/tests/test_basic.py +877 -0
  225. scipy/fftpack/tests/test_helper.py +54 -0
  226. scipy/fftpack/tests/test_import.py +33 -0
  227. scipy/fftpack/tests/test_pseudo_diffs.py +388 -0
  228. scipy/fftpack/tests/test_real_transforms.py +836 -0
  229. scipy/integrate/__init__.py +122 -0
  230. scipy/integrate/_bvp.py +1160 -0
  231. scipy/integrate/_cubature.py +729 -0
  232. scipy/integrate/_dop.cp314t-win_arm64.lib +0 -0
  233. scipy/integrate/_dop.cp314t-win_arm64.pyd +0 -0
  234. scipy/integrate/_ivp/__init__.py +8 -0
  235. scipy/integrate/_ivp/base.py +290 -0
  236. scipy/integrate/_ivp/bdf.py +478 -0
  237. scipy/integrate/_ivp/common.py +451 -0
  238. scipy/integrate/_ivp/dop853_coefficients.py +193 -0
  239. scipy/integrate/_ivp/ivp.py +755 -0
  240. scipy/integrate/_ivp/lsoda.py +224 -0
  241. scipy/integrate/_ivp/radau.py +572 -0
  242. scipy/integrate/_ivp/rk.py +601 -0
  243. scipy/integrate/_ivp/tests/__init__.py +0 -0
  244. scipy/integrate/_ivp/tests/test_ivp.py +1287 -0
  245. scipy/integrate/_ivp/tests/test_rk.py +37 -0
  246. scipy/integrate/_lebedev.py +5450 -0
  247. scipy/integrate/_lsoda.cp314t-win_arm64.lib +0 -0
  248. scipy/integrate/_lsoda.cp314t-win_arm64.pyd +0 -0
  249. scipy/integrate/_ode.py +1395 -0
  250. scipy/integrate/_odepack.cp314t-win_arm64.lib +0 -0
  251. scipy/integrate/_odepack.cp314t-win_arm64.pyd +0 -0
  252. scipy/integrate/_odepack_py.py +273 -0
  253. scipy/integrate/_quad_vec.py +674 -0
  254. scipy/integrate/_quadpack.cp314t-win_arm64.lib +0 -0
  255. scipy/integrate/_quadpack.cp314t-win_arm64.pyd +0 -0
  256. scipy/integrate/_quadpack_py.py +1283 -0
  257. scipy/integrate/_quadrature.py +1336 -0
  258. scipy/integrate/_rules/__init__.py +12 -0
  259. scipy/integrate/_rules/_base.py +518 -0
  260. scipy/integrate/_rules/_gauss_kronrod.py +202 -0
  261. scipy/integrate/_rules/_gauss_legendre.py +62 -0
  262. scipy/integrate/_rules/_genz_malik.py +210 -0
  263. scipy/integrate/_tanhsinh.py +1385 -0
  264. scipy/integrate/_test_multivariate.cp314t-win_arm64.lib +0 -0
  265. scipy/integrate/_test_multivariate.cp314t-win_arm64.pyd +0 -0
  266. scipy/integrate/_test_odeint_banded.cp314t-win_arm64.lib +0 -0
  267. scipy/integrate/_test_odeint_banded.cp314t-win_arm64.pyd +0 -0
  268. scipy/integrate/_vode.cp314t-win_arm64.lib +0 -0
  269. scipy/integrate/_vode.cp314t-win_arm64.pyd +0 -0
  270. scipy/integrate/dop.py +15 -0
  271. scipy/integrate/lsoda.py +15 -0
  272. scipy/integrate/odepack.py +17 -0
  273. scipy/integrate/quadpack.py +23 -0
  274. scipy/integrate/tests/__init__.py +0 -0
  275. scipy/integrate/tests/test__quad_vec.py +211 -0
  276. scipy/integrate/tests/test_banded_ode_solvers.py +305 -0
  277. scipy/integrate/tests/test_bvp.py +714 -0
  278. scipy/integrate/tests/test_cubature.py +1375 -0
  279. scipy/integrate/tests/test_integrate.py +840 -0
  280. scipy/integrate/tests/test_odeint_jac.py +74 -0
  281. scipy/integrate/tests/test_quadpack.py +680 -0
  282. scipy/integrate/tests/test_quadrature.py +730 -0
  283. scipy/integrate/tests/test_tanhsinh.py +1171 -0
  284. scipy/integrate/vode.py +15 -0
  285. scipy/interpolate/__init__.py +228 -0
  286. scipy/interpolate/_bary_rational.py +715 -0
  287. scipy/interpolate/_bsplines.py +2469 -0
  288. scipy/interpolate/_cubic.py +973 -0
  289. scipy/interpolate/_dfitpack.cp314t-win_arm64.lib +0 -0
  290. scipy/interpolate/_dfitpack.cp314t-win_arm64.pyd +0 -0
  291. scipy/interpolate/_dierckx.cp314t-win_arm64.lib +0 -0
  292. scipy/interpolate/_dierckx.cp314t-win_arm64.pyd +0 -0
  293. scipy/interpolate/_fitpack.cp314t-win_arm64.lib +0 -0
  294. scipy/interpolate/_fitpack.cp314t-win_arm64.pyd +0 -0
  295. scipy/interpolate/_fitpack2.py +2397 -0
  296. scipy/interpolate/_fitpack_impl.py +811 -0
  297. scipy/interpolate/_fitpack_py.py +898 -0
  298. scipy/interpolate/_fitpack_repro.py +996 -0
  299. scipy/interpolate/_interpnd.cp314t-win_arm64.lib +0 -0
  300. scipy/interpolate/_interpnd.cp314t-win_arm64.pyd +0 -0
  301. scipy/interpolate/_interpolate.py +2266 -0
  302. scipy/interpolate/_ndbspline.py +415 -0
  303. scipy/interpolate/_ndgriddata.py +329 -0
  304. scipy/interpolate/_pade.py +67 -0
  305. scipy/interpolate/_polyint.py +1025 -0
  306. scipy/interpolate/_ppoly.cp314t-win_arm64.lib +0 -0
  307. scipy/interpolate/_ppoly.cp314t-win_arm64.pyd +0 -0
  308. scipy/interpolate/_rbf.py +290 -0
  309. scipy/interpolate/_rbfinterp.py +550 -0
  310. scipy/interpolate/_rbfinterp_pythran.cp314t-win_arm64.lib +0 -0
  311. scipy/interpolate/_rbfinterp_pythran.cp314t-win_arm64.pyd +0 -0
  312. scipy/interpolate/_rgi.py +764 -0
  313. scipy/interpolate/_rgi_cython.cp314t-win_arm64.lib +0 -0
  314. scipy/interpolate/_rgi_cython.cp314t-win_arm64.pyd +0 -0
  315. scipy/interpolate/dfitpack.py +24 -0
  316. scipy/interpolate/fitpack.py +31 -0
  317. scipy/interpolate/fitpack2.py +29 -0
  318. scipy/interpolate/interpnd.py +24 -0
  319. scipy/interpolate/interpolate.py +30 -0
  320. scipy/interpolate/ndgriddata.py +23 -0
  321. scipy/interpolate/polyint.py +24 -0
  322. scipy/interpolate/rbf.py +18 -0
  323. scipy/interpolate/tests/__init__.py +0 -0
  324. scipy/interpolate/tests/data/bug-1310.npz +0 -0
  325. scipy/interpolate/tests/data/estimate_gradients_hang.npy +0 -0
  326. scipy/interpolate/tests/data/gcvspl.npz +0 -0
  327. scipy/interpolate/tests/test_bary_rational.py +368 -0
  328. scipy/interpolate/tests/test_bsplines.py +3754 -0
  329. scipy/interpolate/tests/test_fitpack.py +519 -0
  330. scipy/interpolate/tests/test_fitpack2.py +1431 -0
  331. scipy/interpolate/tests/test_gil.py +64 -0
  332. scipy/interpolate/tests/test_interpnd.py +452 -0
  333. scipy/interpolate/tests/test_interpolate.py +2630 -0
  334. scipy/interpolate/tests/test_ndgriddata.py +308 -0
  335. scipy/interpolate/tests/test_pade.py +107 -0
  336. scipy/interpolate/tests/test_polyint.py +972 -0
  337. scipy/interpolate/tests/test_rbf.py +246 -0
  338. scipy/interpolate/tests/test_rbfinterp.py +534 -0
  339. scipy/interpolate/tests/test_rgi.py +1151 -0
  340. scipy/io/__init__.py +116 -0
  341. scipy/io/_fast_matrix_market/__init__.py +600 -0
  342. scipy/io/_fast_matrix_market/_fmm_core.cp314t-win_arm64.lib +0 -0
  343. scipy/io/_fast_matrix_market/_fmm_core.cp314t-win_arm64.pyd +0 -0
  344. scipy/io/_fortran.py +354 -0
  345. scipy/io/_harwell_boeing/__init__.py +7 -0
  346. scipy/io/_harwell_boeing/_fortran_format_parser.py +316 -0
  347. scipy/io/_harwell_boeing/hb.py +571 -0
  348. scipy/io/_harwell_boeing/tests/__init__.py +0 -0
  349. scipy/io/_harwell_boeing/tests/test_fortran_format.py +74 -0
  350. scipy/io/_harwell_boeing/tests/test_hb.py +70 -0
  351. scipy/io/_idl.py +917 -0
  352. scipy/io/_mmio.py +968 -0
  353. scipy/io/_netcdf.py +1104 -0
  354. scipy/io/_test_fortran.cp314t-win_arm64.lib +0 -0
  355. scipy/io/_test_fortran.cp314t-win_arm64.pyd +0 -0
  356. scipy/io/arff/__init__.py +28 -0
  357. scipy/io/arff/_arffread.py +873 -0
  358. scipy/io/arff/arffread.py +19 -0
  359. scipy/io/arff/tests/__init__.py +0 -0
  360. scipy/io/arff/tests/data/iris.arff +225 -0
  361. scipy/io/arff/tests/data/missing.arff +8 -0
  362. scipy/io/arff/tests/data/nodata.arff +11 -0
  363. scipy/io/arff/tests/data/quoted_nominal.arff +13 -0
  364. scipy/io/arff/tests/data/quoted_nominal_spaces.arff +13 -0
  365. scipy/io/arff/tests/data/test1.arff +10 -0
  366. scipy/io/arff/tests/data/test10.arff +8 -0
  367. scipy/io/arff/tests/data/test11.arff +11 -0
  368. scipy/io/arff/tests/data/test2.arff +15 -0
  369. scipy/io/arff/tests/data/test3.arff +6 -0
  370. scipy/io/arff/tests/data/test4.arff +11 -0
  371. scipy/io/arff/tests/data/test5.arff +26 -0
  372. scipy/io/arff/tests/data/test6.arff +12 -0
  373. scipy/io/arff/tests/data/test7.arff +15 -0
  374. scipy/io/arff/tests/data/test8.arff +12 -0
  375. scipy/io/arff/tests/data/test9.arff +14 -0
  376. scipy/io/arff/tests/test_arffread.py +421 -0
  377. scipy/io/harwell_boeing.py +17 -0
  378. scipy/io/idl.py +17 -0
  379. scipy/io/matlab/__init__.py +66 -0
  380. scipy/io/matlab/_byteordercodes.py +75 -0
  381. scipy/io/matlab/_mio.py +375 -0
  382. scipy/io/matlab/_mio4.py +632 -0
  383. scipy/io/matlab/_mio5.py +901 -0
  384. scipy/io/matlab/_mio5_params.py +281 -0
  385. scipy/io/matlab/_mio5_utils.cp314t-win_arm64.lib +0 -0
  386. scipy/io/matlab/_mio5_utils.cp314t-win_arm64.pyd +0 -0
  387. scipy/io/matlab/_mio_utils.cp314t-win_arm64.lib +0 -0
  388. scipy/io/matlab/_mio_utils.cp314t-win_arm64.pyd +0 -0
  389. scipy/io/matlab/_miobase.py +435 -0
  390. scipy/io/matlab/_streams.cp314t-win_arm64.lib +0 -0
  391. scipy/io/matlab/_streams.cp314t-win_arm64.pyd +0 -0
  392. scipy/io/matlab/byteordercodes.py +17 -0
  393. scipy/io/matlab/mio.py +16 -0
  394. scipy/io/matlab/mio4.py +17 -0
  395. scipy/io/matlab/mio5.py +19 -0
  396. scipy/io/matlab/mio5_params.py +18 -0
  397. scipy/io/matlab/mio5_utils.py +17 -0
  398. scipy/io/matlab/mio_utils.py +17 -0
  399. scipy/io/matlab/miobase.py +16 -0
  400. scipy/io/matlab/streams.py +16 -0
  401. scipy/io/matlab/tests/__init__.py +0 -0
  402. scipy/io/matlab/tests/data/bad_miuint32.mat +0 -0
  403. scipy/io/matlab/tests/data/bad_miutf8_array_name.mat +0 -0
  404. scipy/io/matlab/tests/data/big_endian.mat +0 -0
  405. scipy/io/matlab/tests/data/broken_utf8.mat +0 -0
  406. scipy/io/matlab/tests/data/corrupted_zlib_checksum.mat +0 -0
  407. scipy/io/matlab/tests/data/corrupted_zlib_data.mat +0 -0
  408. scipy/io/matlab/tests/data/debigged_m4.mat +0 -0
  409. scipy/io/matlab/tests/data/japanese_utf8.txt +5 -0
  410. scipy/io/matlab/tests/data/little_endian.mat +0 -0
  411. scipy/io/matlab/tests/data/logical_sparse.mat +0 -0
  412. scipy/io/matlab/tests/data/malformed1.mat +0 -0
  413. scipy/io/matlab/tests/data/miuint32_for_miint32.mat +0 -0
  414. scipy/io/matlab/tests/data/miutf8_array_name.mat +0 -0
  415. scipy/io/matlab/tests/data/nasty_duplicate_fieldnames.mat +0 -0
  416. scipy/io/matlab/tests/data/one_by_zero_char.mat +0 -0
  417. scipy/io/matlab/tests/data/parabola.mat +0 -0
  418. scipy/io/matlab/tests/data/single_empty_string.mat +0 -0
  419. scipy/io/matlab/tests/data/some_functions.mat +0 -0
  420. scipy/io/matlab/tests/data/sqr.mat +0 -0
  421. scipy/io/matlab/tests/data/test3dmatrix_6.1_SOL2.mat +0 -0
  422. scipy/io/matlab/tests/data/test3dmatrix_6.5.1_GLNX86.mat +0 -0
  423. scipy/io/matlab/tests/data/test3dmatrix_7.1_GLNX86.mat +0 -0
  424. scipy/io/matlab/tests/data/test3dmatrix_7.4_GLNX86.mat +0 -0
  425. scipy/io/matlab/tests/data/test_empty_struct.mat +0 -0
  426. scipy/io/matlab/tests/data/test_mat4_le_floats.mat +0 -0
  427. scipy/io/matlab/tests/data/test_skip_variable.mat +0 -0
  428. scipy/io/matlab/tests/data/testbool_8_WIN64.mat +0 -0
  429. scipy/io/matlab/tests/data/testcell_6.1_SOL2.mat +0 -0
  430. scipy/io/matlab/tests/data/testcell_6.5.1_GLNX86.mat +0 -0
  431. scipy/io/matlab/tests/data/testcell_7.1_GLNX86.mat +0 -0
  432. scipy/io/matlab/tests/data/testcell_7.4_GLNX86.mat +0 -0
  433. scipy/io/matlab/tests/data/testcellnest_6.1_SOL2.mat +0 -0
  434. scipy/io/matlab/tests/data/testcellnest_6.5.1_GLNX86.mat +0 -0
  435. scipy/io/matlab/tests/data/testcellnest_7.1_GLNX86.mat +0 -0
  436. scipy/io/matlab/tests/data/testcellnest_7.4_GLNX86.mat +0 -0
  437. scipy/io/matlab/tests/data/testcomplex_4.2c_SOL2.mat +0 -0
  438. scipy/io/matlab/tests/data/testcomplex_6.1_SOL2.mat +0 -0
  439. scipy/io/matlab/tests/data/testcomplex_6.5.1_GLNX86.mat +0 -0
  440. scipy/io/matlab/tests/data/testcomplex_7.1_GLNX86.mat +0 -0
  441. scipy/io/matlab/tests/data/testcomplex_7.4_GLNX86.mat +0 -0
  442. scipy/io/matlab/tests/data/testdouble_4.2c_SOL2.mat +0 -0
  443. scipy/io/matlab/tests/data/testdouble_6.1_SOL2.mat +0 -0
  444. scipy/io/matlab/tests/data/testdouble_6.5.1_GLNX86.mat +0 -0
  445. scipy/io/matlab/tests/data/testdouble_7.1_GLNX86.mat +0 -0
  446. scipy/io/matlab/tests/data/testdouble_7.4_GLNX86.mat +0 -0
  447. scipy/io/matlab/tests/data/testemptycell_5.3_SOL2.mat +0 -0
  448. scipy/io/matlab/tests/data/testemptycell_6.5.1_GLNX86.mat +0 -0
  449. scipy/io/matlab/tests/data/testemptycell_7.1_GLNX86.mat +0 -0
  450. scipy/io/matlab/tests/data/testemptycell_7.4_GLNX86.mat +0 -0
  451. scipy/io/matlab/tests/data/testfunc_7.4_GLNX86.mat +0 -0
  452. scipy/io/matlab/tests/data/testhdf5_7.4_GLNX86.mat +0 -0
  453. scipy/io/matlab/tests/data/testmatrix_4.2c_SOL2.mat +0 -0
  454. scipy/io/matlab/tests/data/testmatrix_6.1_SOL2.mat +0 -0
  455. scipy/io/matlab/tests/data/testmatrix_6.5.1_GLNX86.mat +0 -0
  456. scipy/io/matlab/tests/data/testmatrix_7.1_GLNX86.mat +0 -0
  457. scipy/io/matlab/tests/data/testmatrix_7.4_GLNX86.mat +0 -0
  458. scipy/io/matlab/tests/data/testminus_4.2c_SOL2.mat +0 -0
  459. scipy/io/matlab/tests/data/testminus_6.1_SOL2.mat +0 -0
  460. scipy/io/matlab/tests/data/testminus_6.5.1_GLNX86.mat +0 -0
  461. scipy/io/matlab/tests/data/testminus_7.1_GLNX86.mat +0 -0
  462. scipy/io/matlab/tests/data/testminus_7.4_GLNX86.mat +0 -0
  463. scipy/io/matlab/tests/data/testmulti_4.2c_SOL2.mat +0 -0
  464. scipy/io/matlab/tests/data/testmulti_7.1_GLNX86.mat +0 -0
  465. scipy/io/matlab/tests/data/testmulti_7.4_GLNX86.mat +0 -0
  466. scipy/io/matlab/tests/data/testobject_6.1_SOL2.mat +0 -0
  467. scipy/io/matlab/tests/data/testobject_6.5.1_GLNX86.mat +0 -0
  468. scipy/io/matlab/tests/data/testobject_7.1_GLNX86.mat +0 -0
  469. scipy/io/matlab/tests/data/testobject_7.4_GLNX86.mat +0 -0
  470. scipy/io/matlab/tests/data/testonechar_4.2c_SOL2.mat +0 -0
  471. scipy/io/matlab/tests/data/testonechar_6.1_SOL2.mat +0 -0
  472. scipy/io/matlab/tests/data/testonechar_6.5.1_GLNX86.mat +0 -0
  473. scipy/io/matlab/tests/data/testonechar_7.1_GLNX86.mat +0 -0
  474. scipy/io/matlab/tests/data/testonechar_7.4_GLNX86.mat +0 -0
  475. scipy/io/matlab/tests/data/testscalarcell_7.4_GLNX86.mat +0 -0
  476. scipy/io/matlab/tests/data/testsimplecell.mat +0 -0
  477. scipy/io/matlab/tests/data/testsparse_4.2c_SOL2.mat +0 -0
  478. scipy/io/matlab/tests/data/testsparse_6.1_SOL2.mat +0 -0
  479. scipy/io/matlab/tests/data/testsparse_6.5.1_GLNX86.mat +0 -0
  480. scipy/io/matlab/tests/data/testsparse_7.1_GLNX86.mat +0 -0
  481. scipy/io/matlab/tests/data/testsparse_7.4_GLNX86.mat +0 -0
  482. scipy/io/matlab/tests/data/testsparsecomplex_4.2c_SOL2.mat +0 -0
  483. scipy/io/matlab/tests/data/testsparsecomplex_6.1_SOL2.mat +0 -0
  484. scipy/io/matlab/tests/data/testsparsecomplex_6.5.1_GLNX86.mat +0 -0
  485. scipy/io/matlab/tests/data/testsparsecomplex_7.1_GLNX86.mat +0 -0
  486. scipy/io/matlab/tests/data/testsparsecomplex_7.4_GLNX86.mat +0 -0
  487. scipy/io/matlab/tests/data/testsparsefloat_7.4_GLNX86.mat +0 -0
  488. scipy/io/matlab/tests/data/teststring_4.2c_SOL2.mat +0 -0
  489. scipy/io/matlab/tests/data/teststring_6.1_SOL2.mat +0 -0
  490. scipy/io/matlab/tests/data/teststring_6.5.1_GLNX86.mat +0 -0
  491. scipy/io/matlab/tests/data/teststring_7.1_GLNX86.mat +0 -0
  492. scipy/io/matlab/tests/data/teststring_7.4_GLNX86.mat +0 -0
  493. scipy/io/matlab/tests/data/teststringarray_4.2c_SOL2.mat +0 -0
  494. scipy/io/matlab/tests/data/teststringarray_6.1_SOL2.mat +0 -0
  495. scipy/io/matlab/tests/data/teststringarray_6.5.1_GLNX86.mat +0 -0
  496. scipy/io/matlab/tests/data/teststringarray_7.1_GLNX86.mat +0 -0
  497. scipy/io/matlab/tests/data/teststringarray_7.4_GLNX86.mat +0 -0
  498. scipy/io/matlab/tests/data/teststruct_6.1_SOL2.mat +0 -0
  499. scipy/io/matlab/tests/data/teststruct_6.5.1_GLNX86.mat +0 -0
  500. scipy/io/matlab/tests/data/teststruct_7.1_GLNX86.mat +0 -0
  501. scipy/io/matlab/tests/data/teststruct_7.4_GLNX86.mat +0 -0
  502. scipy/io/matlab/tests/data/teststructarr_6.1_SOL2.mat +0 -0
  503. scipy/io/matlab/tests/data/teststructarr_6.5.1_GLNX86.mat +0 -0
  504. scipy/io/matlab/tests/data/teststructarr_7.1_GLNX86.mat +0 -0
  505. scipy/io/matlab/tests/data/teststructarr_7.4_GLNX86.mat +0 -0
  506. scipy/io/matlab/tests/data/teststructnest_6.1_SOL2.mat +0 -0
  507. scipy/io/matlab/tests/data/teststructnest_6.5.1_GLNX86.mat +0 -0
  508. scipy/io/matlab/tests/data/teststructnest_7.1_GLNX86.mat +0 -0
  509. scipy/io/matlab/tests/data/teststructnest_7.4_GLNX86.mat +0 -0
  510. scipy/io/matlab/tests/data/testunicode_7.1_GLNX86.mat +0 -0
  511. scipy/io/matlab/tests/data/testunicode_7.4_GLNX86.mat +0 -0
  512. scipy/io/matlab/tests/data/testvec_4_GLNX86.mat +0 -0
  513. scipy/io/matlab/tests/test_byteordercodes.py +29 -0
  514. scipy/io/matlab/tests/test_mio.py +1399 -0
  515. scipy/io/matlab/tests/test_mio5_utils.py +179 -0
  516. scipy/io/matlab/tests/test_mio_funcs.py +51 -0
  517. scipy/io/matlab/tests/test_mio_utils.py +45 -0
  518. scipy/io/matlab/tests/test_miobase.py +32 -0
  519. scipy/io/matlab/tests/test_pathological.py +33 -0
  520. scipy/io/matlab/tests/test_streams.py +241 -0
  521. scipy/io/mmio.py +17 -0
  522. scipy/io/netcdf.py +17 -0
  523. scipy/io/tests/__init__.py +0 -0
  524. scipy/io/tests/data/Transparent Busy.ani +0 -0
  525. scipy/io/tests/data/array_float32_1d.sav +0 -0
  526. scipy/io/tests/data/array_float32_2d.sav +0 -0
  527. scipy/io/tests/data/array_float32_3d.sav +0 -0
  528. scipy/io/tests/data/array_float32_4d.sav +0 -0
  529. scipy/io/tests/data/array_float32_5d.sav +0 -0
  530. scipy/io/tests/data/array_float32_6d.sav +0 -0
  531. scipy/io/tests/data/array_float32_7d.sav +0 -0
  532. scipy/io/tests/data/array_float32_8d.sav +0 -0
  533. scipy/io/tests/data/array_float32_pointer_1d.sav +0 -0
  534. scipy/io/tests/data/array_float32_pointer_2d.sav +0 -0
  535. scipy/io/tests/data/array_float32_pointer_3d.sav +0 -0
  536. scipy/io/tests/data/array_float32_pointer_4d.sav +0 -0
  537. scipy/io/tests/data/array_float32_pointer_5d.sav +0 -0
  538. scipy/io/tests/data/array_float32_pointer_6d.sav +0 -0
  539. scipy/io/tests/data/array_float32_pointer_7d.sav +0 -0
  540. scipy/io/tests/data/array_float32_pointer_8d.sav +0 -0
  541. scipy/io/tests/data/example_1.nc +0 -0
  542. scipy/io/tests/data/example_2.nc +0 -0
  543. scipy/io/tests/data/example_3_maskedvals.nc +0 -0
  544. scipy/io/tests/data/fortran-3x3d-2i.dat +0 -0
  545. scipy/io/tests/data/fortran-mixed.dat +0 -0
  546. scipy/io/tests/data/fortran-sf8-11x1x10.dat +0 -0
  547. scipy/io/tests/data/fortran-sf8-15x10x22.dat +0 -0
  548. scipy/io/tests/data/fortran-sf8-1x1x1.dat +0 -0
  549. scipy/io/tests/data/fortran-sf8-1x1x5.dat +0 -0
  550. scipy/io/tests/data/fortran-sf8-1x1x7.dat +0 -0
  551. scipy/io/tests/data/fortran-sf8-1x3x5.dat +0 -0
  552. scipy/io/tests/data/fortran-si4-11x1x10.dat +0 -0
  553. scipy/io/tests/data/fortran-si4-15x10x22.dat +0 -0
  554. scipy/io/tests/data/fortran-si4-1x1x1.dat +0 -0
  555. scipy/io/tests/data/fortran-si4-1x1x5.dat +0 -0
  556. scipy/io/tests/data/fortran-si4-1x1x7.dat +0 -0
  557. scipy/io/tests/data/fortran-si4-1x3x5.dat +0 -0
  558. scipy/io/tests/data/invalid_pointer.sav +0 -0
  559. scipy/io/tests/data/null_pointer.sav +0 -0
  560. scipy/io/tests/data/scalar_byte.sav +0 -0
  561. scipy/io/tests/data/scalar_byte_descr.sav +0 -0
  562. scipy/io/tests/data/scalar_complex32.sav +0 -0
  563. scipy/io/tests/data/scalar_complex64.sav +0 -0
  564. scipy/io/tests/data/scalar_float32.sav +0 -0
  565. scipy/io/tests/data/scalar_float64.sav +0 -0
  566. scipy/io/tests/data/scalar_heap_pointer.sav +0 -0
  567. scipy/io/tests/data/scalar_int16.sav +0 -0
  568. scipy/io/tests/data/scalar_int32.sav +0 -0
  569. scipy/io/tests/data/scalar_int64.sav +0 -0
  570. scipy/io/tests/data/scalar_string.sav +0 -0
  571. scipy/io/tests/data/scalar_uint16.sav +0 -0
  572. scipy/io/tests/data/scalar_uint32.sav +0 -0
  573. scipy/io/tests/data/scalar_uint64.sav +0 -0
  574. scipy/io/tests/data/struct_arrays.sav +0 -0
  575. scipy/io/tests/data/struct_arrays_byte_idl80.sav +0 -0
  576. scipy/io/tests/data/struct_arrays_replicated.sav +0 -0
  577. scipy/io/tests/data/struct_arrays_replicated_3d.sav +0 -0
  578. scipy/io/tests/data/struct_inherit.sav +0 -0
  579. scipy/io/tests/data/struct_pointer_arrays.sav +0 -0
  580. scipy/io/tests/data/struct_pointer_arrays_replicated.sav +0 -0
  581. scipy/io/tests/data/struct_pointer_arrays_replicated_3d.sav +0 -0
  582. scipy/io/tests/data/struct_pointers.sav +0 -0
  583. scipy/io/tests/data/struct_pointers_replicated.sav +0 -0
  584. scipy/io/tests/data/struct_pointers_replicated_3d.sav +0 -0
  585. scipy/io/tests/data/struct_scalars.sav +0 -0
  586. scipy/io/tests/data/struct_scalars_replicated.sav +0 -0
  587. scipy/io/tests/data/struct_scalars_replicated_3d.sav +0 -0
  588. scipy/io/tests/data/test-1234Hz-le-1ch-10S-20bit-extra.wav +0 -0
  589. scipy/io/tests/data/test-44100Hz-2ch-32bit-float-be.wav +0 -0
  590. scipy/io/tests/data/test-44100Hz-2ch-32bit-float-le.wav +0 -0
  591. scipy/io/tests/data/test-44100Hz-be-1ch-4bytes.wav +0 -0
  592. scipy/io/tests/data/test-44100Hz-le-1ch-4bytes-early-eof-no-data.wav +0 -0
  593. scipy/io/tests/data/test-44100Hz-le-1ch-4bytes-early-eof.wav +0 -0
  594. scipy/io/tests/data/test-44100Hz-le-1ch-4bytes-incomplete-chunk.wav +0 -0
  595. scipy/io/tests/data/test-44100Hz-le-1ch-4bytes-rf64.wav +0 -0
  596. scipy/io/tests/data/test-44100Hz-le-1ch-4bytes.wav +0 -0
  597. scipy/io/tests/data/test-48000Hz-2ch-64bit-float-le-wavex.wav +0 -0
  598. scipy/io/tests/data/test-8000Hz-be-3ch-5S-24bit.wav +0 -0
  599. scipy/io/tests/data/test-8000Hz-le-1ch-1byte-ulaw.wav +0 -0
  600. scipy/io/tests/data/test-8000Hz-le-2ch-1byteu.wav +0 -0
  601. scipy/io/tests/data/test-8000Hz-le-3ch-5S-24bit-inconsistent.wav +0 -0
  602. scipy/io/tests/data/test-8000Hz-le-3ch-5S-24bit-rf64.wav +0 -0
  603. scipy/io/tests/data/test-8000Hz-le-3ch-5S-24bit.wav +0 -0
  604. scipy/io/tests/data/test-8000Hz-le-3ch-5S-36bit.wav +0 -0
  605. scipy/io/tests/data/test-8000Hz-le-3ch-5S-45bit.wav +0 -0
  606. scipy/io/tests/data/test-8000Hz-le-3ch-5S-53bit.wav +0 -0
  607. scipy/io/tests/data/test-8000Hz-le-3ch-5S-64bit.wav +0 -0
  608. scipy/io/tests/data/test-8000Hz-le-4ch-9S-12bit.wav +0 -0
  609. scipy/io/tests/data/test-8000Hz-le-5ch-9S-5bit.wav +0 -0
  610. scipy/io/tests/data/various_compressed.sav +0 -0
  611. scipy/io/tests/test_fortran.py +264 -0
  612. scipy/io/tests/test_idl.py +483 -0
  613. scipy/io/tests/test_mmio.py +831 -0
  614. scipy/io/tests/test_netcdf.py +550 -0
  615. scipy/io/tests/test_paths.py +93 -0
  616. scipy/io/tests/test_wavfile.py +501 -0
  617. scipy/io/wavfile.py +938 -0
  618. scipy/linalg/__init__.pxd +1 -0
  619. scipy/linalg/__init__.py +236 -0
  620. scipy/linalg/_basic.py +2146 -0
  621. scipy/linalg/_blas_subroutines.h +164 -0
  622. scipy/linalg/_cythonized_array_utils.cp314t-win_arm64.lib +0 -0
  623. scipy/linalg/_cythonized_array_utils.cp314t-win_arm64.pyd +0 -0
  624. scipy/linalg/_cythonized_array_utils.pxd +40 -0
  625. scipy/linalg/_cythonized_array_utils.pyi +16 -0
  626. scipy/linalg/_decomp.py +1645 -0
  627. scipy/linalg/_decomp_cholesky.py +413 -0
  628. scipy/linalg/_decomp_cossin.py +236 -0
  629. scipy/linalg/_decomp_interpolative.cp314t-win_arm64.lib +0 -0
  630. scipy/linalg/_decomp_interpolative.cp314t-win_arm64.pyd +0 -0
  631. scipy/linalg/_decomp_ldl.py +356 -0
  632. scipy/linalg/_decomp_lu.py +401 -0
  633. scipy/linalg/_decomp_lu_cython.cp314t-win_arm64.lib +0 -0
  634. scipy/linalg/_decomp_lu_cython.cp314t-win_arm64.pyd +0 -0
  635. scipy/linalg/_decomp_lu_cython.pyi +6 -0
  636. scipy/linalg/_decomp_polar.py +113 -0
  637. scipy/linalg/_decomp_qr.py +494 -0
  638. scipy/linalg/_decomp_qz.py +452 -0
  639. scipy/linalg/_decomp_schur.py +336 -0
  640. scipy/linalg/_decomp_svd.py +545 -0
  641. scipy/linalg/_decomp_update.cp314t-win_arm64.lib +0 -0
  642. scipy/linalg/_decomp_update.cp314t-win_arm64.pyd +0 -0
  643. scipy/linalg/_expm_frechet.py +417 -0
  644. scipy/linalg/_fblas.cp314t-win_arm64.lib +0 -0
  645. scipy/linalg/_fblas.cp314t-win_arm64.pyd +0 -0
  646. scipy/linalg/_flapack.cp314t-win_arm64.lib +0 -0
  647. scipy/linalg/_flapack.cp314t-win_arm64.pyd +0 -0
  648. scipy/linalg/_lapack_subroutines.h +1521 -0
  649. scipy/linalg/_linalg_pythran.cp314t-win_arm64.lib +0 -0
  650. scipy/linalg/_linalg_pythran.cp314t-win_arm64.pyd +0 -0
  651. scipy/linalg/_matfuncs.py +1050 -0
  652. scipy/linalg/_matfuncs_expm.cp314t-win_arm64.lib +0 -0
  653. scipy/linalg/_matfuncs_expm.cp314t-win_arm64.pyd +0 -0
  654. scipy/linalg/_matfuncs_expm.pyi +6 -0
  655. scipy/linalg/_matfuncs_inv_ssq.py +886 -0
  656. scipy/linalg/_matfuncs_schur_sqrtm.cp314t-win_arm64.lib +0 -0
  657. scipy/linalg/_matfuncs_schur_sqrtm.cp314t-win_arm64.pyd +0 -0
  658. scipy/linalg/_matfuncs_sqrtm.py +107 -0
  659. scipy/linalg/_matfuncs_sqrtm_triu.cp314t-win_arm64.lib +0 -0
  660. scipy/linalg/_matfuncs_sqrtm_triu.cp314t-win_arm64.pyd +0 -0
  661. scipy/linalg/_misc.py +191 -0
  662. scipy/linalg/_procrustes.py +113 -0
  663. scipy/linalg/_sketches.py +189 -0
  664. scipy/linalg/_solve_toeplitz.cp314t-win_arm64.lib +0 -0
  665. scipy/linalg/_solve_toeplitz.cp314t-win_arm64.pyd +0 -0
  666. scipy/linalg/_solvers.py +862 -0
  667. scipy/linalg/_special_matrices.py +1322 -0
  668. scipy/linalg/_testutils.py +65 -0
  669. scipy/linalg/basic.py +23 -0
  670. scipy/linalg/blas.py +495 -0
  671. scipy/linalg/cython_blas.cp314t-win_arm64.lib +0 -0
  672. scipy/linalg/cython_blas.cp314t-win_arm64.pyd +0 -0
  673. scipy/linalg/cython_blas.pxd +169 -0
  674. scipy/linalg/cython_blas.pyx +1432 -0
  675. scipy/linalg/cython_lapack.cp314t-win_arm64.lib +0 -0
  676. scipy/linalg/cython_lapack.cp314t-win_arm64.pyd +0 -0
  677. scipy/linalg/cython_lapack.pxd +1528 -0
  678. scipy/linalg/cython_lapack.pyx +12045 -0
  679. scipy/linalg/decomp.py +23 -0
  680. scipy/linalg/decomp_cholesky.py +21 -0
  681. scipy/linalg/decomp_lu.py +21 -0
  682. scipy/linalg/decomp_qr.py +20 -0
  683. scipy/linalg/decomp_schur.py +21 -0
  684. scipy/linalg/decomp_svd.py +21 -0
  685. scipy/linalg/interpolative.py +989 -0
  686. scipy/linalg/lapack.py +1081 -0
  687. scipy/linalg/matfuncs.py +23 -0
  688. scipy/linalg/misc.py +21 -0
  689. scipy/linalg/special_matrices.py +22 -0
  690. scipy/linalg/tests/__init__.py +0 -0
  691. scipy/linalg/tests/_cython_examples/extending.pyx +23 -0
  692. scipy/linalg/tests/_cython_examples/meson.build +34 -0
  693. scipy/linalg/tests/data/carex_15_data.npz +0 -0
  694. scipy/linalg/tests/data/carex_18_data.npz +0 -0
  695. scipy/linalg/tests/data/carex_19_data.npz +0 -0
  696. scipy/linalg/tests/data/carex_20_data.npz +0 -0
  697. scipy/linalg/tests/data/carex_6_data.npz +0 -0
  698. scipy/linalg/tests/data/gendare_20170120_data.npz +0 -0
  699. scipy/linalg/tests/test_basic.py +2074 -0
  700. scipy/linalg/tests/test_batch.py +588 -0
  701. scipy/linalg/tests/test_blas.py +1127 -0
  702. scipy/linalg/tests/test_cython_blas.py +118 -0
  703. scipy/linalg/tests/test_cython_lapack.py +22 -0
  704. scipy/linalg/tests/test_cythonized_array_utils.py +130 -0
  705. scipy/linalg/tests/test_decomp.py +3189 -0
  706. scipy/linalg/tests/test_decomp_cholesky.py +268 -0
  707. scipy/linalg/tests/test_decomp_cossin.py +314 -0
  708. scipy/linalg/tests/test_decomp_ldl.py +137 -0
  709. scipy/linalg/tests/test_decomp_lu.py +308 -0
  710. scipy/linalg/tests/test_decomp_polar.py +110 -0
  711. scipy/linalg/tests/test_decomp_update.py +1701 -0
  712. scipy/linalg/tests/test_extending.py +46 -0
  713. scipy/linalg/tests/test_fblas.py +607 -0
  714. scipy/linalg/tests/test_interpolative.py +232 -0
  715. scipy/linalg/tests/test_lapack.py +3620 -0
  716. scipy/linalg/tests/test_matfuncs.py +1125 -0
  717. scipy/linalg/tests/test_matmul_toeplitz.py +136 -0
  718. scipy/linalg/tests/test_procrustes.py +214 -0
  719. scipy/linalg/tests/test_sketches.py +118 -0
  720. scipy/linalg/tests/test_solve_toeplitz.py +150 -0
  721. scipy/linalg/tests/test_solvers.py +844 -0
  722. scipy/linalg/tests/test_special_matrices.py +636 -0
  723. scipy/misc/__init__.py +6 -0
  724. scipy/misc/common.py +6 -0
  725. scipy/misc/doccer.py +6 -0
  726. scipy/ndimage/__init__.py +174 -0
  727. scipy/ndimage/_ctest.cp314t-win_arm64.lib +0 -0
  728. scipy/ndimage/_ctest.cp314t-win_arm64.pyd +0 -0
  729. scipy/ndimage/_cytest.cp314t-win_arm64.lib +0 -0
  730. scipy/ndimage/_cytest.cp314t-win_arm64.pyd +0 -0
  731. scipy/ndimage/_delegators.py +303 -0
  732. scipy/ndimage/_filters.py +2422 -0
  733. scipy/ndimage/_fourier.py +306 -0
  734. scipy/ndimage/_interpolation.py +1033 -0
  735. scipy/ndimage/_measurements.py +1689 -0
  736. scipy/ndimage/_morphology.py +2634 -0
  737. scipy/ndimage/_nd_image.cp314t-win_arm64.lib +0 -0
  738. scipy/ndimage/_nd_image.cp314t-win_arm64.pyd +0 -0
  739. scipy/ndimage/_ndimage_api.py +16 -0
  740. scipy/ndimage/_ni_docstrings.py +214 -0
  741. scipy/ndimage/_ni_label.cp314t-win_arm64.lib +0 -0
  742. scipy/ndimage/_ni_label.cp314t-win_arm64.pyd +0 -0
  743. scipy/ndimage/_ni_support.py +139 -0
  744. scipy/ndimage/_rank_filter_1d.cp314t-win_arm64.lib +0 -0
  745. scipy/ndimage/_rank_filter_1d.cp314t-win_arm64.pyd +0 -0
  746. scipy/ndimage/_support_alternative_backends.py +84 -0
  747. scipy/ndimage/filters.py +27 -0
  748. scipy/ndimage/fourier.py +21 -0
  749. scipy/ndimage/interpolation.py +22 -0
  750. scipy/ndimage/measurements.py +24 -0
  751. scipy/ndimage/morphology.py +27 -0
  752. scipy/ndimage/tests/__init__.py +12 -0
  753. scipy/ndimage/tests/data/label_inputs.txt +21 -0
  754. scipy/ndimage/tests/data/label_results.txt +294 -0
  755. scipy/ndimage/tests/data/label_strels.txt +42 -0
  756. scipy/ndimage/tests/dots.png +0 -0
  757. scipy/ndimage/tests/test_c_api.py +102 -0
  758. scipy/ndimage/tests/test_datatypes.py +67 -0
  759. scipy/ndimage/tests/test_filters.py +3083 -0
  760. scipy/ndimage/tests/test_fourier.py +187 -0
  761. scipy/ndimage/tests/test_interpolation.py +1491 -0
  762. scipy/ndimage/tests/test_measurements.py +1592 -0
  763. scipy/ndimage/tests/test_morphology.py +2950 -0
  764. scipy/ndimage/tests/test_ni_support.py +78 -0
  765. scipy/ndimage/tests/test_splines.py +70 -0
  766. scipy/odr/__init__.py +131 -0
  767. scipy/odr/__odrpack.cp314t-win_arm64.lib +0 -0
  768. scipy/odr/__odrpack.cp314t-win_arm64.pyd +0 -0
  769. scipy/odr/_add_newdocs.py +34 -0
  770. scipy/odr/_models.py +315 -0
  771. scipy/odr/_odrpack.py +1154 -0
  772. scipy/odr/models.py +20 -0
  773. scipy/odr/odrpack.py +21 -0
  774. scipy/odr/tests/__init__.py +0 -0
  775. scipy/odr/tests/test_odr.py +607 -0
  776. scipy/optimize/__init__.pxd +1 -0
  777. scipy/optimize/__init__.py +460 -0
  778. scipy/optimize/_basinhopping.py +741 -0
  779. scipy/optimize/_bglu_dense.cp314t-win_arm64.lib +0 -0
  780. scipy/optimize/_bglu_dense.cp314t-win_arm64.pyd +0 -0
  781. scipy/optimize/_bracket.py +706 -0
  782. scipy/optimize/_chandrupatla.py +551 -0
  783. scipy/optimize/_cobyla_py.py +297 -0
  784. scipy/optimize/_cobyqa_py.py +72 -0
  785. scipy/optimize/_constraints.py +598 -0
  786. scipy/optimize/_dcsrch.py +728 -0
  787. scipy/optimize/_differentiable_functions.py +835 -0
  788. scipy/optimize/_differentialevolution.py +1970 -0
  789. scipy/optimize/_direct.cp314t-win_arm64.lib +0 -0
  790. scipy/optimize/_direct.cp314t-win_arm64.pyd +0 -0
  791. scipy/optimize/_direct_py.py +280 -0
  792. scipy/optimize/_dual_annealing.py +732 -0
  793. scipy/optimize/_elementwise.py +798 -0
  794. scipy/optimize/_group_columns.cp314t-win_arm64.lib +0 -0
  795. scipy/optimize/_group_columns.cp314t-win_arm64.pyd +0 -0
  796. scipy/optimize/_hessian_update_strategy.py +479 -0
  797. scipy/optimize/_highspy/__init__.py +0 -0
  798. scipy/optimize/_highspy/_core.cp314t-win_arm64.lib +0 -0
  799. scipy/optimize/_highspy/_core.cp314t-win_arm64.pyd +0 -0
  800. scipy/optimize/_highspy/_highs_options.cp314t-win_arm64.lib +0 -0
  801. scipy/optimize/_highspy/_highs_options.cp314t-win_arm64.pyd +0 -0
  802. scipy/optimize/_highspy/_highs_wrapper.py +338 -0
  803. scipy/optimize/_isotonic.py +157 -0
  804. scipy/optimize/_lbfgsb.cp314t-win_arm64.lib +0 -0
  805. scipy/optimize/_lbfgsb.cp314t-win_arm64.pyd +0 -0
  806. scipy/optimize/_lbfgsb_py.py +634 -0
  807. scipy/optimize/_linesearch.py +896 -0
  808. scipy/optimize/_linprog.py +733 -0
  809. scipy/optimize/_linprog_doc.py +1434 -0
  810. scipy/optimize/_linprog_highs.py +422 -0
  811. scipy/optimize/_linprog_ip.py +1141 -0
  812. scipy/optimize/_linprog_rs.py +572 -0
  813. scipy/optimize/_linprog_simplex.py +663 -0
  814. scipy/optimize/_linprog_util.py +1521 -0
  815. scipy/optimize/_lsap.cp314t-win_arm64.lib +0 -0
  816. scipy/optimize/_lsap.cp314t-win_arm64.pyd +0 -0
  817. scipy/optimize/_lsq/__init__.py +5 -0
  818. scipy/optimize/_lsq/bvls.py +183 -0
  819. scipy/optimize/_lsq/common.py +731 -0
  820. scipy/optimize/_lsq/dogbox.py +345 -0
  821. scipy/optimize/_lsq/givens_elimination.cp314t-win_arm64.lib +0 -0
  822. scipy/optimize/_lsq/givens_elimination.cp314t-win_arm64.pyd +0 -0
  823. scipy/optimize/_lsq/least_squares.py +1044 -0
  824. scipy/optimize/_lsq/lsq_linear.py +361 -0
  825. scipy/optimize/_lsq/trf.py +587 -0
  826. scipy/optimize/_lsq/trf_linear.py +249 -0
  827. scipy/optimize/_milp.py +394 -0
  828. scipy/optimize/_minimize.py +1199 -0
  829. scipy/optimize/_minpack.cp314t-win_arm64.lib +0 -0
  830. scipy/optimize/_minpack.cp314t-win_arm64.pyd +0 -0
  831. scipy/optimize/_minpack_py.py +1178 -0
  832. scipy/optimize/_moduleTNC.cp314t-win_arm64.lib +0 -0
  833. scipy/optimize/_moduleTNC.cp314t-win_arm64.pyd +0 -0
  834. scipy/optimize/_nnls.py +96 -0
  835. scipy/optimize/_nonlin.py +1634 -0
  836. scipy/optimize/_numdiff.py +963 -0
  837. scipy/optimize/_optimize.py +4169 -0
  838. scipy/optimize/_pava_pybind.cp314t-win_arm64.lib +0 -0
  839. scipy/optimize/_pava_pybind.cp314t-win_arm64.pyd +0 -0
  840. scipy/optimize/_qap.py +760 -0
  841. scipy/optimize/_remove_redundancy.py +522 -0
  842. scipy/optimize/_root.py +732 -0
  843. scipy/optimize/_root_scalar.py +538 -0
  844. scipy/optimize/_shgo.py +1606 -0
  845. scipy/optimize/_shgo_lib/__init__.py +0 -0
  846. scipy/optimize/_shgo_lib/_complex.py +1225 -0
  847. scipy/optimize/_shgo_lib/_vertex.py +460 -0
  848. scipy/optimize/_slsqp_py.py +603 -0
  849. scipy/optimize/_slsqplib.cp314t-win_arm64.lib +0 -0
  850. scipy/optimize/_slsqplib.cp314t-win_arm64.pyd +0 -0
  851. scipy/optimize/_spectral.py +260 -0
  852. scipy/optimize/_tnc.py +438 -0
  853. scipy/optimize/_trlib/__init__.py +12 -0
  854. scipy/optimize/_trlib/_trlib.cp314t-win_arm64.lib +0 -0
  855. scipy/optimize/_trlib/_trlib.cp314t-win_arm64.pyd +0 -0
  856. scipy/optimize/_trustregion.py +318 -0
  857. scipy/optimize/_trustregion_constr/__init__.py +6 -0
  858. scipy/optimize/_trustregion_constr/canonical_constraint.py +390 -0
  859. scipy/optimize/_trustregion_constr/equality_constrained_sqp.py +231 -0
  860. scipy/optimize/_trustregion_constr/minimize_trustregion_constr.py +584 -0
  861. scipy/optimize/_trustregion_constr/projections.py +411 -0
  862. scipy/optimize/_trustregion_constr/qp_subproblem.py +637 -0
  863. scipy/optimize/_trustregion_constr/report.py +49 -0
  864. scipy/optimize/_trustregion_constr/tests/__init__.py +0 -0
  865. scipy/optimize/_trustregion_constr/tests/test_canonical_constraint.py +296 -0
  866. scipy/optimize/_trustregion_constr/tests/test_nested_minimize.py +39 -0
  867. scipy/optimize/_trustregion_constr/tests/test_projections.py +214 -0
  868. scipy/optimize/_trustregion_constr/tests/test_qp_subproblem.py +645 -0
  869. scipy/optimize/_trustregion_constr/tests/test_report.py +34 -0
  870. scipy/optimize/_trustregion_constr/tr_interior_point.py +361 -0
  871. scipy/optimize/_trustregion_dogleg.py +122 -0
  872. scipy/optimize/_trustregion_exact.py +437 -0
  873. scipy/optimize/_trustregion_krylov.py +65 -0
  874. scipy/optimize/_trustregion_ncg.py +126 -0
  875. scipy/optimize/_tstutils.py +972 -0
  876. scipy/optimize/_zeros.cp314t-win_arm64.lib +0 -0
  877. scipy/optimize/_zeros.cp314t-win_arm64.pyd +0 -0
  878. scipy/optimize/_zeros_py.py +1475 -0
  879. scipy/optimize/cobyla.py +19 -0
  880. scipy/optimize/cython_optimize/__init__.py +133 -0
  881. scipy/optimize/cython_optimize/_zeros.cp314t-win_arm64.lib +0 -0
  882. scipy/optimize/cython_optimize/_zeros.cp314t-win_arm64.pyd +0 -0
  883. scipy/optimize/cython_optimize/_zeros.pxd +33 -0
  884. scipy/optimize/cython_optimize/c_zeros.pxd +26 -0
  885. scipy/optimize/cython_optimize.pxd +11 -0
  886. scipy/optimize/elementwise.py +38 -0
  887. scipy/optimize/lbfgsb.py +23 -0
  888. scipy/optimize/linesearch.py +18 -0
  889. scipy/optimize/minpack.py +27 -0
  890. scipy/optimize/minpack2.py +17 -0
  891. scipy/optimize/moduleTNC.py +19 -0
  892. scipy/optimize/nonlin.py +29 -0
  893. scipy/optimize/optimize.py +40 -0
  894. scipy/optimize/slsqp.py +22 -0
  895. scipy/optimize/tests/__init__.py +0 -0
  896. scipy/optimize/tests/_cython_examples/extending.pyx +43 -0
  897. scipy/optimize/tests/_cython_examples/meson.build +32 -0
  898. scipy/optimize/tests/test__basinhopping.py +535 -0
  899. scipy/optimize/tests/test__differential_evolution.py +1703 -0
  900. scipy/optimize/tests/test__dual_annealing.py +416 -0
  901. scipy/optimize/tests/test__linprog_clean_inputs.py +312 -0
  902. scipy/optimize/tests/test__numdiff.py +885 -0
  903. scipy/optimize/tests/test__remove_redundancy.py +228 -0
  904. scipy/optimize/tests/test__root.py +124 -0
  905. scipy/optimize/tests/test__shgo.py +1164 -0
  906. scipy/optimize/tests/test__spectral.py +226 -0
  907. scipy/optimize/tests/test_bracket.py +896 -0
  908. scipy/optimize/tests/test_chandrupatla.py +982 -0
  909. scipy/optimize/tests/test_cobyla.py +195 -0
  910. scipy/optimize/tests/test_cobyqa.py +252 -0
  911. scipy/optimize/tests/test_constraint_conversion.py +286 -0
  912. scipy/optimize/tests/test_constraints.py +255 -0
  913. scipy/optimize/tests/test_cython_optimize.py +92 -0
  914. scipy/optimize/tests/test_differentiable_functions.py +1025 -0
  915. scipy/optimize/tests/test_direct.py +321 -0
  916. scipy/optimize/tests/test_extending.py +28 -0
  917. scipy/optimize/tests/test_hessian_update_strategy.py +300 -0
  918. scipy/optimize/tests/test_isotonic_regression.py +167 -0
  919. scipy/optimize/tests/test_lbfgsb_hessinv.py +65 -0
  920. scipy/optimize/tests/test_lbfgsb_setulb.py +122 -0
  921. scipy/optimize/tests/test_least_squares.py +986 -0
  922. scipy/optimize/tests/test_linear_assignment.py +116 -0
  923. scipy/optimize/tests/test_linesearch.py +328 -0
  924. scipy/optimize/tests/test_linprog.py +2577 -0
  925. scipy/optimize/tests/test_lsq_common.py +297 -0
  926. scipy/optimize/tests/test_lsq_linear.py +287 -0
  927. scipy/optimize/tests/test_milp.py +459 -0
  928. scipy/optimize/tests/test_minimize_constrained.py +845 -0
  929. scipy/optimize/tests/test_minpack.py +1194 -0
  930. scipy/optimize/tests/test_nnls.py +469 -0
  931. scipy/optimize/tests/test_nonlin.py +572 -0
  932. scipy/optimize/tests/test_optimize.py +3344 -0
  933. scipy/optimize/tests/test_quadratic_assignment.py +455 -0
  934. scipy/optimize/tests/test_regression.py +40 -0
  935. scipy/optimize/tests/test_slsqp.py +645 -0
  936. scipy/optimize/tests/test_tnc.py +345 -0
  937. scipy/optimize/tests/test_trustregion.py +110 -0
  938. scipy/optimize/tests/test_trustregion_exact.py +351 -0
  939. scipy/optimize/tests/test_trustregion_krylov.py +170 -0
  940. scipy/optimize/tests/test_zeros.py +998 -0
  941. scipy/optimize/tnc.py +22 -0
  942. scipy/optimize/zeros.py +26 -0
  943. scipy/signal/__init__.py +316 -0
  944. scipy/signal/_arraytools.py +264 -0
  945. scipy/signal/_czt.py +575 -0
  946. scipy/signal/_delegators.py +568 -0
  947. scipy/signal/_filter_design.py +5893 -0
  948. scipy/signal/_fir_filter_design.py +1458 -0
  949. scipy/signal/_lti_conversion.py +534 -0
  950. scipy/signal/_ltisys.py +3546 -0
  951. scipy/signal/_max_len_seq.py +139 -0
  952. scipy/signal/_max_len_seq_inner.cp314t-win_arm64.lib +0 -0
  953. scipy/signal/_max_len_seq_inner.cp314t-win_arm64.pyd +0 -0
  954. scipy/signal/_peak_finding.py +1310 -0
  955. scipy/signal/_peak_finding_utils.cp314t-win_arm64.lib +0 -0
  956. scipy/signal/_peak_finding_utils.cp314t-win_arm64.pyd +0 -0
  957. scipy/signal/_polyutils.py +172 -0
  958. scipy/signal/_savitzky_golay.py +357 -0
  959. scipy/signal/_short_time_fft.py +2228 -0
  960. scipy/signal/_signal_api.py +30 -0
  961. scipy/signal/_signaltools.py +5309 -0
  962. scipy/signal/_sigtools.cp314t-win_arm64.lib +0 -0
  963. scipy/signal/_sigtools.cp314t-win_arm64.pyd +0 -0
  964. scipy/signal/_sosfilt.cp314t-win_arm64.lib +0 -0
  965. scipy/signal/_sosfilt.cp314t-win_arm64.pyd +0 -0
  966. scipy/signal/_spectral_py.py +2471 -0
  967. scipy/signal/_spline.cp314t-win_arm64.lib +0 -0
  968. scipy/signal/_spline.cp314t-win_arm64.pyd +0 -0
  969. scipy/signal/_spline.pyi +34 -0
  970. scipy/signal/_spline_filters.py +848 -0
  971. scipy/signal/_support_alternative_backends.py +73 -0
  972. scipy/signal/_upfirdn.py +219 -0
  973. scipy/signal/_upfirdn_apply.cp314t-win_arm64.lib +0 -0
  974. scipy/signal/_upfirdn_apply.cp314t-win_arm64.pyd +0 -0
  975. scipy/signal/_waveforms.py +687 -0
  976. scipy/signal/_wavelets.py +29 -0
  977. scipy/signal/bsplines.py +21 -0
  978. scipy/signal/filter_design.py +28 -0
  979. scipy/signal/fir_filter_design.py +21 -0
  980. scipy/signal/lti_conversion.py +20 -0
  981. scipy/signal/ltisys.py +25 -0
  982. scipy/signal/signaltools.py +27 -0
  983. scipy/signal/spectral.py +21 -0
  984. scipy/signal/spline.py +18 -0
  985. scipy/signal/tests/__init__.py +0 -0
  986. scipy/signal/tests/_scipy_spectral_test_shim.py +311 -0
  987. scipy/signal/tests/mpsig.py +122 -0
  988. scipy/signal/tests/test_array_tools.py +111 -0
  989. scipy/signal/tests/test_bsplines.py +365 -0
  990. scipy/signal/tests/test_cont2discrete.py +424 -0
  991. scipy/signal/tests/test_czt.py +221 -0
  992. scipy/signal/tests/test_dltisys.py +599 -0
  993. scipy/signal/tests/test_filter_design.py +4744 -0
  994. scipy/signal/tests/test_fir_filter_design.py +851 -0
  995. scipy/signal/tests/test_ltisys.py +1225 -0
  996. scipy/signal/tests/test_max_len_seq.py +71 -0
  997. scipy/signal/tests/test_peak_finding.py +915 -0
  998. scipy/signal/tests/test_result_type.py +51 -0
  999. scipy/signal/tests/test_savitzky_golay.py +363 -0
  1000. scipy/signal/tests/test_short_time_fft.py +1107 -0
  1001. scipy/signal/tests/test_signaltools.py +4735 -0
  1002. scipy/signal/tests/test_spectral.py +2141 -0
  1003. scipy/signal/tests/test_splines.py +427 -0
  1004. scipy/signal/tests/test_upfirdn.py +322 -0
  1005. scipy/signal/tests/test_waveforms.py +400 -0
  1006. scipy/signal/tests/test_wavelets.py +59 -0
  1007. scipy/signal/tests/test_windows.py +987 -0
  1008. scipy/signal/waveforms.py +20 -0
  1009. scipy/signal/wavelets.py +17 -0
  1010. scipy/signal/windows/__init__.py +52 -0
  1011. scipy/signal/windows/_windows.py +2513 -0
  1012. scipy/signal/windows/windows.py +23 -0
  1013. scipy/sparse/__init__.py +350 -0
  1014. scipy/sparse/_base.py +1613 -0
  1015. scipy/sparse/_bsr.py +880 -0
  1016. scipy/sparse/_compressed.py +1328 -0
  1017. scipy/sparse/_construct.py +1454 -0
  1018. scipy/sparse/_coo.py +1581 -0
  1019. scipy/sparse/_csc.py +367 -0
  1020. scipy/sparse/_csparsetools.cp314t-win_arm64.lib +0 -0
  1021. scipy/sparse/_csparsetools.cp314t-win_arm64.pyd +0 -0
  1022. scipy/sparse/_csr.py +558 -0
  1023. scipy/sparse/_data.py +569 -0
  1024. scipy/sparse/_dia.py +677 -0
  1025. scipy/sparse/_dok.py +669 -0
  1026. scipy/sparse/_extract.py +178 -0
  1027. scipy/sparse/_index.py +444 -0
  1028. scipy/sparse/_lil.py +632 -0
  1029. scipy/sparse/_matrix.py +169 -0
  1030. scipy/sparse/_matrix_io.py +167 -0
  1031. scipy/sparse/_sparsetools.cp314t-win_arm64.lib +0 -0
  1032. scipy/sparse/_sparsetools.cp314t-win_arm64.pyd +0 -0
  1033. scipy/sparse/_spfuncs.py +76 -0
  1034. scipy/sparse/_sputils.py +632 -0
  1035. scipy/sparse/base.py +24 -0
  1036. scipy/sparse/bsr.py +22 -0
  1037. scipy/sparse/compressed.py +20 -0
  1038. scipy/sparse/construct.py +38 -0
  1039. scipy/sparse/coo.py +23 -0
  1040. scipy/sparse/csc.py +22 -0
  1041. scipy/sparse/csgraph/__init__.py +210 -0
  1042. scipy/sparse/csgraph/_flow.cp314t-win_arm64.lib +0 -0
  1043. scipy/sparse/csgraph/_flow.cp314t-win_arm64.pyd +0 -0
  1044. scipy/sparse/csgraph/_laplacian.py +563 -0
  1045. scipy/sparse/csgraph/_matching.cp314t-win_arm64.lib +0 -0
  1046. scipy/sparse/csgraph/_matching.cp314t-win_arm64.pyd +0 -0
  1047. scipy/sparse/csgraph/_min_spanning_tree.cp314t-win_arm64.lib +0 -0
  1048. scipy/sparse/csgraph/_min_spanning_tree.cp314t-win_arm64.pyd +0 -0
  1049. scipy/sparse/csgraph/_reordering.cp314t-win_arm64.lib +0 -0
  1050. scipy/sparse/csgraph/_reordering.cp314t-win_arm64.pyd +0 -0
  1051. scipy/sparse/csgraph/_shortest_path.cp314t-win_arm64.lib +0 -0
  1052. scipy/sparse/csgraph/_shortest_path.cp314t-win_arm64.pyd +0 -0
  1053. scipy/sparse/csgraph/_tools.cp314t-win_arm64.lib +0 -0
  1054. scipy/sparse/csgraph/_tools.cp314t-win_arm64.pyd +0 -0
  1055. scipy/sparse/csgraph/_traversal.cp314t-win_arm64.lib +0 -0
  1056. scipy/sparse/csgraph/_traversal.cp314t-win_arm64.pyd +0 -0
  1057. scipy/sparse/csgraph/_validation.py +66 -0
  1058. scipy/sparse/csgraph/tests/__init__.py +0 -0
  1059. scipy/sparse/csgraph/tests/test_connected_components.py +119 -0
  1060. scipy/sparse/csgraph/tests/test_conversions.py +61 -0
  1061. scipy/sparse/csgraph/tests/test_flow.py +209 -0
  1062. scipy/sparse/csgraph/tests/test_graph_laplacian.py +368 -0
  1063. scipy/sparse/csgraph/tests/test_matching.py +307 -0
  1064. scipy/sparse/csgraph/tests/test_pydata_sparse.py +197 -0
  1065. scipy/sparse/csgraph/tests/test_reordering.py +70 -0
  1066. scipy/sparse/csgraph/tests/test_shortest_path.py +540 -0
  1067. scipy/sparse/csgraph/tests/test_spanning_tree.py +66 -0
  1068. scipy/sparse/csgraph/tests/test_traversal.py +148 -0
  1069. scipy/sparse/csr.py +22 -0
  1070. scipy/sparse/data.py +18 -0
  1071. scipy/sparse/dia.py +22 -0
  1072. scipy/sparse/dok.py +22 -0
  1073. scipy/sparse/extract.py +23 -0
  1074. scipy/sparse/lil.py +22 -0
  1075. scipy/sparse/linalg/__init__.py +148 -0
  1076. scipy/sparse/linalg/_dsolve/__init__.py +71 -0
  1077. scipy/sparse/linalg/_dsolve/_add_newdocs.py +147 -0
  1078. scipy/sparse/linalg/_dsolve/_superlu.cp314t-win_arm64.lib +0 -0
  1079. scipy/sparse/linalg/_dsolve/_superlu.cp314t-win_arm64.pyd +0 -0
  1080. scipy/sparse/linalg/_dsolve/linsolve.py +882 -0
  1081. scipy/sparse/linalg/_dsolve/tests/__init__.py +0 -0
  1082. scipy/sparse/linalg/_dsolve/tests/test_linsolve.py +928 -0
  1083. scipy/sparse/linalg/_eigen/__init__.py +22 -0
  1084. scipy/sparse/linalg/_eigen/_svds.py +540 -0
  1085. scipy/sparse/linalg/_eigen/_svds_doc.py +382 -0
  1086. scipy/sparse/linalg/_eigen/arpack/COPYING +45 -0
  1087. scipy/sparse/linalg/_eigen/arpack/__init__.py +20 -0
  1088. scipy/sparse/linalg/_eigen/arpack/_arpack.cp314t-win_arm64.lib +0 -0
  1089. scipy/sparse/linalg/_eigen/arpack/_arpack.cp314t-win_arm64.pyd +0 -0
  1090. scipy/sparse/linalg/_eigen/arpack/arpack.py +1706 -0
  1091. scipy/sparse/linalg/_eigen/arpack/tests/__init__.py +0 -0
  1092. scipy/sparse/linalg/_eigen/arpack/tests/test_arpack.py +717 -0
  1093. scipy/sparse/linalg/_eigen/lobpcg/__init__.py +16 -0
  1094. scipy/sparse/linalg/_eigen/lobpcg/lobpcg.py +1110 -0
  1095. scipy/sparse/linalg/_eigen/lobpcg/tests/__init__.py +0 -0
  1096. scipy/sparse/linalg/_eigen/lobpcg/tests/test_lobpcg.py +725 -0
  1097. scipy/sparse/linalg/_eigen/tests/__init__.py +0 -0
  1098. scipy/sparse/linalg/_eigen/tests/test_svds.py +886 -0
  1099. scipy/sparse/linalg/_expm_multiply.py +816 -0
  1100. scipy/sparse/linalg/_interface.py +920 -0
  1101. scipy/sparse/linalg/_isolve/__init__.py +20 -0
  1102. scipy/sparse/linalg/_isolve/_gcrotmk.py +503 -0
  1103. scipy/sparse/linalg/_isolve/iterative.py +1051 -0
  1104. scipy/sparse/linalg/_isolve/lgmres.py +230 -0
  1105. scipy/sparse/linalg/_isolve/lsmr.py +486 -0
  1106. scipy/sparse/linalg/_isolve/lsqr.py +589 -0
  1107. scipy/sparse/linalg/_isolve/minres.py +372 -0
  1108. scipy/sparse/linalg/_isolve/tests/__init__.py +0 -0
  1109. scipy/sparse/linalg/_isolve/tests/test_gcrotmk.py +183 -0
  1110. scipy/sparse/linalg/_isolve/tests/test_iterative.py +809 -0
  1111. scipy/sparse/linalg/_isolve/tests/test_lgmres.py +225 -0
  1112. scipy/sparse/linalg/_isolve/tests/test_lsmr.py +185 -0
  1113. scipy/sparse/linalg/_isolve/tests/test_lsqr.py +120 -0
  1114. scipy/sparse/linalg/_isolve/tests/test_minres.py +97 -0
  1115. scipy/sparse/linalg/_isolve/tests/test_utils.py +9 -0
  1116. scipy/sparse/linalg/_isolve/tfqmr.py +179 -0
  1117. scipy/sparse/linalg/_isolve/utils.py +121 -0
  1118. scipy/sparse/linalg/_matfuncs.py +940 -0
  1119. scipy/sparse/linalg/_norm.py +195 -0
  1120. scipy/sparse/linalg/_onenormest.py +467 -0
  1121. scipy/sparse/linalg/_propack/_cpropack.cp314t-win_arm64.lib +0 -0
  1122. scipy/sparse/linalg/_propack/_cpropack.cp314t-win_arm64.pyd +0 -0
  1123. scipy/sparse/linalg/_propack/_dpropack.cp314t-win_arm64.lib +0 -0
  1124. scipy/sparse/linalg/_propack/_dpropack.cp314t-win_arm64.pyd +0 -0
  1125. scipy/sparse/linalg/_propack/_spropack.cp314t-win_arm64.lib +0 -0
  1126. scipy/sparse/linalg/_propack/_spropack.cp314t-win_arm64.pyd +0 -0
  1127. scipy/sparse/linalg/_propack/_zpropack.cp314t-win_arm64.lib +0 -0
  1128. scipy/sparse/linalg/_propack/_zpropack.cp314t-win_arm64.pyd +0 -0
  1129. scipy/sparse/linalg/_special_sparse_arrays.py +949 -0
  1130. scipy/sparse/linalg/_svdp.py +309 -0
  1131. scipy/sparse/linalg/dsolve.py +22 -0
  1132. scipy/sparse/linalg/eigen.py +21 -0
  1133. scipy/sparse/linalg/interface.py +20 -0
  1134. scipy/sparse/linalg/isolve.py +22 -0
  1135. scipy/sparse/linalg/matfuncs.py +18 -0
  1136. scipy/sparse/linalg/tests/__init__.py +0 -0
  1137. scipy/sparse/linalg/tests/propack_test_data.npz +0 -0
  1138. scipy/sparse/linalg/tests/test_expm_multiply.py +367 -0
  1139. scipy/sparse/linalg/tests/test_interface.py +561 -0
  1140. scipy/sparse/linalg/tests/test_matfuncs.py +592 -0
  1141. scipy/sparse/linalg/tests/test_norm.py +154 -0
  1142. scipy/sparse/linalg/tests/test_onenormest.py +252 -0
  1143. scipy/sparse/linalg/tests/test_propack.py +165 -0
  1144. scipy/sparse/linalg/tests/test_pydata_sparse.py +272 -0
  1145. scipy/sparse/linalg/tests/test_special_sparse_arrays.py +337 -0
  1146. scipy/sparse/sparsetools.py +17 -0
  1147. scipy/sparse/spfuncs.py +17 -0
  1148. scipy/sparse/sputils.py +17 -0
  1149. scipy/sparse/tests/__init__.py +0 -0
  1150. scipy/sparse/tests/data/csc_py2.npz +0 -0
  1151. scipy/sparse/tests/data/csc_py3.npz +0 -0
  1152. scipy/sparse/tests/test_arithmetic1d.py +341 -0
  1153. scipy/sparse/tests/test_array_api.py +561 -0
  1154. scipy/sparse/tests/test_base.py +5870 -0
  1155. scipy/sparse/tests/test_common1d.py +447 -0
  1156. scipy/sparse/tests/test_construct.py +872 -0
  1157. scipy/sparse/tests/test_coo.py +1119 -0
  1158. scipy/sparse/tests/test_csc.py +98 -0
  1159. scipy/sparse/tests/test_csr.py +214 -0
  1160. scipy/sparse/tests/test_dok.py +209 -0
  1161. scipy/sparse/tests/test_extract.py +51 -0
  1162. scipy/sparse/tests/test_indexing1d.py +603 -0
  1163. scipy/sparse/tests/test_matrix_io.py +109 -0
  1164. scipy/sparse/tests/test_minmax1d.py +128 -0
  1165. scipy/sparse/tests/test_sparsetools.py +344 -0
  1166. scipy/sparse/tests/test_spfuncs.py +97 -0
  1167. scipy/sparse/tests/test_sputils.py +424 -0
  1168. scipy/spatial/__init__.py +129 -0
  1169. scipy/spatial/_ckdtree.cp314t-win_arm64.lib +0 -0
  1170. scipy/spatial/_ckdtree.cp314t-win_arm64.pyd +0 -0
  1171. scipy/spatial/_distance_pybind.cp314t-win_arm64.lib +0 -0
  1172. scipy/spatial/_distance_pybind.cp314t-win_arm64.pyd +0 -0
  1173. scipy/spatial/_distance_wrap.cp314t-win_arm64.lib +0 -0
  1174. scipy/spatial/_distance_wrap.cp314t-win_arm64.pyd +0 -0
  1175. scipy/spatial/_geometric_slerp.py +238 -0
  1176. scipy/spatial/_hausdorff.cp314t-win_arm64.lib +0 -0
  1177. scipy/spatial/_hausdorff.cp314t-win_arm64.pyd +0 -0
  1178. scipy/spatial/_kdtree.py +920 -0
  1179. scipy/spatial/_plotutils.py +274 -0
  1180. scipy/spatial/_procrustes.py +132 -0
  1181. scipy/spatial/_qhull.cp314t-win_arm64.lib +0 -0
  1182. scipy/spatial/_qhull.cp314t-win_arm64.pyd +0 -0
  1183. scipy/spatial/_qhull.pyi +213 -0
  1184. scipy/spatial/_spherical_voronoi.py +341 -0
  1185. scipy/spatial/_voronoi.cp314t-win_arm64.lib +0 -0
  1186. scipy/spatial/_voronoi.cp314t-win_arm64.pyd +0 -0
  1187. scipy/spatial/_voronoi.pyi +4 -0
  1188. scipy/spatial/ckdtree.py +18 -0
  1189. scipy/spatial/distance.py +3147 -0
  1190. scipy/spatial/distance.pyi +210 -0
  1191. scipy/spatial/kdtree.py +25 -0
  1192. scipy/spatial/qhull.py +25 -0
  1193. scipy/spatial/qhull_src/COPYING_QHULL.txt +39 -0
  1194. scipy/spatial/tests/__init__.py +0 -0
  1195. scipy/spatial/tests/data/cdist-X1.txt +10 -0
  1196. scipy/spatial/tests/data/cdist-X2.txt +20 -0
  1197. scipy/spatial/tests/data/degenerate_pointset.npz +0 -0
  1198. scipy/spatial/tests/data/iris.txt +150 -0
  1199. scipy/spatial/tests/data/pdist-boolean-inp.txt +20 -0
  1200. scipy/spatial/tests/data/pdist-chebyshev-ml-iris.txt +1 -0
  1201. scipy/spatial/tests/data/pdist-chebyshev-ml.txt +1 -0
  1202. scipy/spatial/tests/data/pdist-cityblock-ml-iris.txt +1 -0
  1203. scipy/spatial/tests/data/pdist-cityblock-ml.txt +1 -0
  1204. scipy/spatial/tests/data/pdist-correlation-ml-iris.txt +1 -0
  1205. scipy/spatial/tests/data/pdist-correlation-ml.txt +1 -0
  1206. scipy/spatial/tests/data/pdist-cosine-ml-iris.txt +1 -0
  1207. scipy/spatial/tests/data/pdist-cosine-ml.txt +1 -0
  1208. scipy/spatial/tests/data/pdist-double-inp.txt +20 -0
  1209. scipy/spatial/tests/data/pdist-euclidean-ml-iris.txt +1 -0
  1210. scipy/spatial/tests/data/pdist-euclidean-ml.txt +1 -0
  1211. scipy/spatial/tests/data/pdist-hamming-ml.txt +1 -0
  1212. scipy/spatial/tests/data/pdist-jaccard-ml.txt +1 -0
  1213. scipy/spatial/tests/data/pdist-jensenshannon-ml-iris.txt +1 -0
  1214. scipy/spatial/tests/data/pdist-jensenshannon-ml.txt +1 -0
  1215. scipy/spatial/tests/data/pdist-minkowski-3.2-ml-iris.txt +1 -0
  1216. scipy/spatial/tests/data/pdist-minkowski-3.2-ml.txt +1 -0
  1217. scipy/spatial/tests/data/pdist-minkowski-5.8-ml-iris.txt +1 -0
  1218. scipy/spatial/tests/data/pdist-seuclidean-ml-iris.txt +1 -0
  1219. scipy/spatial/tests/data/pdist-seuclidean-ml.txt +1 -0
  1220. scipy/spatial/tests/data/pdist-spearman-ml.txt +1 -0
  1221. scipy/spatial/tests/data/random-bool-data.txt +100 -0
  1222. scipy/spatial/tests/data/random-double-data.txt +100 -0
  1223. scipy/spatial/tests/data/random-int-data.txt +100 -0
  1224. scipy/spatial/tests/data/random-uint-data.txt +100 -0
  1225. scipy/spatial/tests/data/selfdual-4d-polytope.txt +27 -0
  1226. scipy/spatial/tests/test__plotutils.py +91 -0
  1227. scipy/spatial/tests/test__procrustes.py +116 -0
  1228. scipy/spatial/tests/test_distance.py +2389 -0
  1229. scipy/spatial/tests/test_hausdorff.py +199 -0
  1230. scipy/spatial/tests/test_kdtree.py +1536 -0
  1231. scipy/spatial/tests/test_qhull.py +1313 -0
  1232. scipy/spatial/tests/test_slerp.py +417 -0
  1233. scipy/spatial/tests/test_spherical_voronoi.py +358 -0
  1234. scipy/spatial/transform/__init__.py +31 -0
  1235. scipy/spatial/transform/_rigid_transform.cp314t-win_arm64.lib +0 -0
  1236. scipy/spatial/transform/_rigid_transform.cp314t-win_arm64.pyd +0 -0
  1237. scipy/spatial/transform/_rotation.cp314t-win_arm64.lib +0 -0
  1238. scipy/spatial/transform/_rotation.cp314t-win_arm64.pyd +0 -0
  1239. scipy/spatial/transform/_rotation_groups.py +140 -0
  1240. scipy/spatial/transform/_rotation_spline.py +460 -0
  1241. scipy/spatial/transform/rotation.py +21 -0
  1242. scipy/spatial/transform/tests/__init__.py +0 -0
  1243. scipy/spatial/transform/tests/test_rigid_transform.py +1221 -0
  1244. scipy/spatial/transform/tests/test_rotation.py +2569 -0
  1245. scipy/spatial/transform/tests/test_rotation_groups.py +169 -0
  1246. scipy/spatial/transform/tests/test_rotation_spline.py +183 -0
  1247. scipy/special/__init__.pxd +1 -0
  1248. scipy/special/__init__.py +841 -0
  1249. scipy/special/_add_newdocs.py +9961 -0
  1250. scipy/special/_basic.py +3576 -0
  1251. scipy/special/_comb.cp314t-win_arm64.lib +0 -0
  1252. scipy/special/_comb.cp314t-win_arm64.pyd +0 -0
  1253. scipy/special/_ellip_harm.py +214 -0
  1254. scipy/special/_ellip_harm_2.cp314t-win_arm64.lib +0 -0
  1255. scipy/special/_ellip_harm_2.cp314t-win_arm64.pyd +0 -0
  1256. scipy/special/_gufuncs.cp314t-win_arm64.lib +0 -0
  1257. scipy/special/_gufuncs.cp314t-win_arm64.pyd +0 -0
  1258. scipy/special/_input_validation.py +17 -0
  1259. scipy/special/_lambertw.py +149 -0
  1260. scipy/special/_logsumexp.py +426 -0
  1261. scipy/special/_mptestutils.py +453 -0
  1262. scipy/special/_multiufuncs.py +610 -0
  1263. scipy/special/_orthogonal.py +2592 -0
  1264. scipy/special/_orthogonal.pyi +330 -0
  1265. scipy/special/_precompute/__init__.py +0 -0
  1266. scipy/special/_precompute/cosine_cdf.py +17 -0
  1267. scipy/special/_precompute/expn_asy.py +54 -0
  1268. scipy/special/_precompute/gammainc_asy.py +116 -0
  1269. scipy/special/_precompute/gammainc_data.py +124 -0
  1270. scipy/special/_precompute/hyp2f1_data.py +484 -0
  1271. scipy/special/_precompute/lambertw.py +68 -0
  1272. scipy/special/_precompute/loggamma.py +43 -0
  1273. scipy/special/_precompute/struve_convergence.py +131 -0
  1274. scipy/special/_precompute/utils.py +38 -0
  1275. scipy/special/_precompute/wright_bessel.py +342 -0
  1276. scipy/special/_precompute/wright_bessel_data.py +152 -0
  1277. scipy/special/_precompute/wrightomega.py +41 -0
  1278. scipy/special/_precompute/zetac.py +27 -0
  1279. scipy/special/_sf_error.py +15 -0
  1280. scipy/special/_specfun.cp314t-win_arm64.lib +0 -0
  1281. scipy/special/_specfun.cp314t-win_arm64.pyd +0 -0
  1282. scipy/special/_special_ufuncs.cp314t-win_arm64.lib +0 -0
  1283. scipy/special/_special_ufuncs.cp314t-win_arm64.pyd +0 -0
  1284. scipy/special/_spfun_stats.py +106 -0
  1285. scipy/special/_spherical_bessel.py +397 -0
  1286. scipy/special/_support_alternative_backends.py +295 -0
  1287. scipy/special/_test_internal.cp314t-win_arm64.lib +0 -0
  1288. scipy/special/_test_internal.cp314t-win_arm64.pyd +0 -0
  1289. scipy/special/_test_internal.pyi +9 -0
  1290. scipy/special/_testutils.py +321 -0
  1291. scipy/special/_ufuncs.cp314t-win_arm64.lib +0 -0
  1292. scipy/special/_ufuncs.cp314t-win_arm64.pyd +0 -0
  1293. scipy/special/_ufuncs.pyi +522 -0
  1294. scipy/special/_ufuncs.pyx +13173 -0
  1295. scipy/special/_ufuncs_cxx.cp314t-win_arm64.lib +0 -0
  1296. scipy/special/_ufuncs_cxx.cp314t-win_arm64.pyd +0 -0
  1297. scipy/special/_ufuncs_cxx.pxd +142 -0
  1298. scipy/special/_ufuncs_cxx.pyx +427 -0
  1299. scipy/special/_ufuncs_cxx_defs.h +147 -0
  1300. scipy/special/_ufuncs_defs.h +57 -0
  1301. scipy/special/add_newdocs.py +15 -0
  1302. scipy/special/basic.py +87 -0
  1303. scipy/special/cython_special.cp314t-win_arm64.lib +0 -0
  1304. scipy/special/cython_special.cp314t-win_arm64.pyd +0 -0
  1305. scipy/special/cython_special.pxd +259 -0
  1306. scipy/special/cython_special.pyi +3 -0
  1307. scipy/special/orthogonal.py +45 -0
  1308. scipy/special/sf_error.py +20 -0
  1309. scipy/special/specfun.py +24 -0
  1310. scipy/special/spfun_stats.py +17 -0
  1311. scipy/special/tests/__init__.py +0 -0
  1312. scipy/special/tests/_cython_examples/extending.pyx +12 -0
  1313. scipy/special/tests/_cython_examples/meson.build +34 -0
  1314. scipy/special/tests/data/__init__.py +0 -0
  1315. scipy/special/tests/data/boost.npz +0 -0
  1316. scipy/special/tests/data/gsl.npz +0 -0
  1317. scipy/special/tests/data/local.npz +0 -0
  1318. scipy/special/tests/test_basic.py +4815 -0
  1319. scipy/special/tests/test_bdtr.py +112 -0
  1320. scipy/special/tests/test_boost_ufuncs.py +64 -0
  1321. scipy/special/tests/test_boxcox.py +125 -0
  1322. scipy/special/tests/test_cdflib.py +712 -0
  1323. scipy/special/tests/test_cdft_asymptotic.py +49 -0
  1324. scipy/special/tests/test_cephes_intp_cast.py +29 -0
  1325. scipy/special/tests/test_cosine_distr.py +83 -0
  1326. scipy/special/tests/test_cython_special.py +363 -0
  1327. scipy/special/tests/test_data.py +719 -0
  1328. scipy/special/tests/test_dd.py +42 -0
  1329. scipy/special/tests/test_digamma.py +45 -0
  1330. scipy/special/tests/test_ellip_harm.py +278 -0
  1331. scipy/special/tests/test_erfinv.py +89 -0
  1332. scipy/special/tests/test_exponential_integrals.py +118 -0
  1333. scipy/special/tests/test_extending.py +28 -0
  1334. scipy/special/tests/test_faddeeva.py +85 -0
  1335. scipy/special/tests/test_gamma.py +12 -0
  1336. scipy/special/tests/test_gammainc.py +152 -0
  1337. scipy/special/tests/test_hyp2f1.py +2566 -0
  1338. scipy/special/tests/test_hypergeometric.py +234 -0
  1339. scipy/special/tests/test_iv_ratio.py +249 -0
  1340. scipy/special/tests/test_kolmogorov.py +491 -0
  1341. scipy/special/tests/test_lambertw.py +109 -0
  1342. scipy/special/tests/test_legendre.py +1518 -0
  1343. scipy/special/tests/test_log1mexp.py +85 -0
  1344. scipy/special/tests/test_loggamma.py +70 -0
  1345. scipy/special/tests/test_logit.py +162 -0
  1346. scipy/special/tests/test_logsumexp.py +469 -0
  1347. scipy/special/tests/test_mpmath.py +2293 -0
  1348. scipy/special/tests/test_nan_inputs.py +65 -0
  1349. scipy/special/tests/test_ndtr.py +77 -0
  1350. scipy/special/tests/test_ndtri_exp.py +94 -0
  1351. scipy/special/tests/test_orthogonal.py +821 -0
  1352. scipy/special/tests/test_orthogonal_eval.py +275 -0
  1353. scipy/special/tests/test_owens_t.py +53 -0
  1354. scipy/special/tests/test_pcf.py +24 -0
  1355. scipy/special/tests/test_pdtr.py +48 -0
  1356. scipy/special/tests/test_powm1.py +65 -0
  1357. scipy/special/tests/test_precompute_expn_asy.py +24 -0
  1358. scipy/special/tests/test_precompute_gammainc.py +108 -0
  1359. scipy/special/tests/test_precompute_utils.py +36 -0
  1360. scipy/special/tests/test_round.py +18 -0
  1361. scipy/special/tests/test_sf_error.py +146 -0
  1362. scipy/special/tests/test_sici.py +36 -0
  1363. scipy/special/tests/test_specfun.py +48 -0
  1364. scipy/special/tests/test_spence.py +32 -0
  1365. scipy/special/tests/test_spfun_stats.py +61 -0
  1366. scipy/special/tests/test_sph_harm.py +85 -0
  1367. scipy/special/tests/test_spherical_bessel.py +400 -0
  1368. scipy/special/tests/test_support_alternative_backends.py +248 -0
  1369. scipy/special/tests/test_trig.py +72 -0
  1370. scipy/special/tests/test_ufunc_signatures.py +46 -0
  1371. scipy/special/tests/test_wright_bessel.py +205 -0
  1372. scipy/special/tests/test_wrightomega.py +117 -0
  1373. scipy/special/tests/test_zeta.py +301 -0
  1374. scipy/stats/__init__.py +670 -0
  1375. scipy/stats/_ansari_swilk_statistics.cp314t-win_arm64.lib +0 -0
  1376. scipy/stats/_ansari_swilk_statistics.cp314t-win_arm64.pyd +0 -0
  1377. scipy/stats/_axis_nan_policy.py +692 -0
  1378. scipy/stats/_biasedurn.cp314t-win_arm64.lib +0 -0
  1379. scipy/stats/_biasedurn.cp314t-win_arm64.pyd +0 -0
  1380. scipy/stats/_biasedurn.pxd +27 -0
  1381. scipy/stats/_binned_statistic.py +795 -0
  1382. scipy/stats/_binomtest.py +375 -0
  1383. scipy/stats/_bws_test.py +177 -0
  1384. scipy/stats/_censored_data.py +459 -0
  1385. scipy/stats/_common.py +5 -0
  1386. scipy/stats/_constants.py +42 -0
  1387. scipy/stats/_continued_fraction.py +387 -0
  1388. scipy/stats/_continuous_distns.py +12486 -0
  1389. scipy/stats/_correlation.py +210 -0
  1390. scipy/stats/_covariance.py +636 -0
  1391. scipy/stats/_crosstab.py +204 -0
  1392. scipy/stats/_discrete_distns.py +2098 -0
  1393. scipy/stats/_distn_infrastructure.py +4201 -0
  1394. scipy/stats/_distr_params.py +299 -0
  1395. scipy/stats/_distribution_infrastructure.py +5750 -0
  1396. scipy/stats/_entropy.py +428 -0
  1397. scipy/stats/_finite_differences.py +145 -0
  1398. scipy/stats/_fit.py +1351 -0
  1399. scipy/stats/_hypotests.py +2060 -0
  1400. scipy/stats/_kde.py +732 -0
  1401. scipy/stats/_ksstats.py +600 -0
  1402. scipy/stats/_levy_stable/__init__.py +1231 -0
  1403. scipy/stats/_levy_stable/levyst.cp314t-win_arm64.lib +0 -0
  1404. scipy/stats/_levy_stable/levyst.cp314t-win_arm64.pyd +0 -0
  1405. scipy/stats/_mannwhitneyu.py +492 -0
  1406. scipy/stats/_mgc.py +550 -0
  1407. scipy/stats/_morestats.py +4626 -0
  1408. scipy/stats/_mstats_basic.py +3658 -0
  1409. scipy/stats/_mstats_extras.py +521 -0
  1410. scipy/stats/_multicomp.py +449 -0
  1411. scipy/stats/_multivariate.py +7281 -0
  1412. scipy/stats/_new_distributions.py +452 -0
  1413. scipy/stats/_odds_ratio.py +466 -0
  1414. scipy/stats/_page_trend_test.py +486 -0
  1415. scipy/stats/_probability_distribution.py +1964 -0
  1416. scipy/stats/_qmc.py +2956 -0
  1417. scipy/stats/_qmc_cy.cp314t-win_arm64.lib +0 -0
  1418. scipy/stats/_qmc_cy.cp314t-win_arm64.pyd +0 -0
  1419. scipy/stats/_qmc_cy.pyi +54 -0
  1420. scipy/stats/_qmvnt.py +454 -0
  1421. scipy/stats/_qmvnt_cy.cp314t-win_arm64.lib +0 -0
  1422. scipy/stats/_qmvnt_cy.cp314t-win_arm64.pyd +0 -0
  1423. scipy/stats/_quantile.py +335 -0
  1424. scipy/stats/_rcont/__init__.py +4 -0
  1425. scipy/stats/_rcont/rcont.cp314t-win_arm64.lib +0 -0
  1426. scipy/stats/_rcont/rcont.cp314t-win_arm64.pyd +0 -0
  1427. scipy/stats/_relative_risk.py +263 -0
  1428. scipy/stats/_resampling.py +2352 -0
  1429. scipy/stats/_result_classes.py +40 -0
  1430. scipy/stats/_sampling.py +1314 -0
  1431. scipy/stats/_sensitivity_analysis.py +713 -0
  1432. scipy/stats/_sobol.cp314t-win_arm64.lib +0 -0
  1433. scipy/stats/_sobol.cp314t-win_arm64.pyd +0 -0
  1434. scipy/stats/_sobol.pyi +54 -0
  1435. scipy/stats/_sobol_direction_numbers.npz +0 -0
  1436. scipy/stats/_stats.cp314t-win_arm64.lib +0 -0
  1437. scipy/stats/_stats.cp314t-win_arm64.pyd +0 -0
  1438. scipy/stats/_stats.pxd +10 -0
  1439. scipy/stats/_stats_mstats_common.py +322 -0
  1440. scipy/stats/_stats_py.py +11089 -0
  1441. scipy/stats/_stats_pythran.cp314t-win_arm64.lib +0 -0
  1442. scipy/stats/_stats_pythran.cp314t-win_arm64.pyd +0 -0
  1443. scipy/stats/_survival.py +683 -0
  1444. scipy/stats/_tukeylambda_stats.py +199 -0
  1445. scipy/stats/_unuran/__init__.py +0 -0
  1446. scipy/stats/_unuran/unuran_wrapper.cp314t-win_arm64.lib +0 -0
  1447. scipy/stats/_unuran/unuran_wrapper.cp314t-win_arm64.pyd +0 -0
  1448. scipy/stats/_unuran/unuran_wrapper.pyi +179 -0
  1449. scipy/stats/_variation.py +126 -0
  1450. scipy/stats/_warnings_errors.py +38 -0
  1451. scipy/stats/_wilcoxon.py +265 -0
  1452. scipy/stats/biasedurn.py +16 -0
  1453. scipy/stats/contingency.py +521 -0
  1454. scipy/stats/distributions.py +24 -0
  1455. scipy/stats/kde.py +18 -0
  1456. scipy/stats/morestats.py +27 -0
  1457. scipy/stats/mstats.py +140 -0
  1458. scipy/stats/mstats_basic.py +42 -0
  1459. scipy/stats/mstats_extras.py +25 -0
  1460. scipy/stats/mvn.py +17 -0
  1461. scipy/stats/qmc.py +236 -0
  1462. scipy/stats/sampling.py +73 -0
  1463. scipy/stats/stats.py +41 -0
  1464. scipy/stats/tests/__init__.py +0 -0
  1465. scipy/stats/tests/common_tests.py +356 -0
  1466. scipy/stats/tests/data/_mvt.py +171 -0
  1467. scipy/stats/tests/data/fisher_exact_results_from_r.py +607 -0
  1468. scipy/stats/tests/data/jf_skew_t_gamlss_pdf_data.npy +0 -0
  1469. scipy/stats/tests/data/levy_stable/stable-Z1-cdf-sample-data.npy +0 -0
  1470. scipy/stats/tests/data/levy_stable/stable-Z1-pdf-sample-data.npy +0 -0
  1471. scipy/stats/tests/data/levy_stable/stable-loc-scale-sample-data.npy +0 -0
  1472. scipy/stats/tests/data/nist_anova/AtmWtAg.dat +108 -0
  1473. scipy/stats/tests/data/nist_anova/SiRstv.dat +85 -0
  1474. scipy/stats/tests/data/nist_anova/SmLs01.dat +249 -0
  1475. scipy/stats/tests/data/nist_anova/SmLs02.dat +1869 -0
  1476. scipy/stats/tests/data/nist_anova/SmLs03.dat +18069 -0
  1477. scipy/stats/tests/data/nist_anova/SmLs04.dat +249 -0
  1478. scipy/stats/tests/data/nist_anova/SmLs05.dat +1869 -0
  1479. scipy/stats/tests/data/nist_anova/SmLs06.dat +18069 -0
  1480. scipy/stats/tests/data/nist_anova/SmLs07.dat +249 -0
  1481. scipy/stats/tests/data/nist_anova/SmLs08.dat +1869 -0
  1482. scipy/stats/tests/data/nist_anova/SmLs09.dat +18069 -0
  1483. scipy/stats/tests/data/nist_linregress/Norris.dat +97 -0
  1484. scipy/stats/tests/data/rel_breitwigner_pdf_sample_data_ROOT.npy +0 -0
  1485. scipy/stats/tests/data/studentized_range_mpmath_ref.json +1499 -0
  1486. scipy/stats/tests/test_axis_nan_policy.py +1388 -0
  1487. scipy/stats/tests/test_binned_statistic.py +568 -0
  1488. scipy/stats/tests/test_censored_data.py +152 -0
  1489. scipy/stats/tests/test_contingency.py +294 -0
  1490. scipy/stats/tests/test_continued_fraction.py +173 -0
  1491. scipy/stats/tests/test_continuous.py +2198 -0
  1492. scipy/stats/tests/test_continuous_basic.py +1053 -0
  1493. scipy/stats/tests/test_continuous_fit_censored.py +683 -0
  1494. scipy/stats/tests/test_correlation.py +80 -0
  1495. scipy/stats/tests/test_crosstab.py +115 -0
  1496. scipy/stats/tests/test_discrete_basic.py +580 -0
  1497. scipy/stats/tests/test_discrete_distns.py +700 -0
  1498. scipy/stats/tests/test_distributions.py +10413 -0
  1499. scipy/stats/tests/test_entropy.py +322 -0
  1500. scipy/stats/tests/test_fast_gen_inversion.py +435 -0
  1501. scipy/stats/tests/test_fit.py +1090 -0
  1502. scipy/stats/tests/test_hypotests.py +1991 -0
  1503. scipy/stats/tests/test_kdeoth.py +676 -0
  1504. scipy/stats/tests/test_marray.py +289 -0
  1505. scipy/stats/tests/test_mgc.py +217 -0
  1506. scipy/stats/tests/test_morestats.py +3259 -0
  1507. scipy/stats/tests/test_mstats_basic.py +2071 -0
  1508. scipy/stats/tests/test_mstats_extras.py +172 -0
  1509. scipy/stats/tests/test_multicomp.py +405 -0
  1510. scipy/stats/tests/test_multivariate.py +4381 -0
  1511. scipy/stats/tests/test_odds_ratio.py +148 -0
  1512. scipy/stats/tests/test_qmc.py +1492 -0
  1513. scipy/stats/tests/test_quantile.py +199 -0
  1514. scipy/stats/tests/test_rank.py +345 -0
  1515. scipy/stats/tests/test_relative_risk.py +95 -0
  1516. scipy/stats/tests/test_resampling.py +2000 -0
  1517. scipy/stats/tests/test_sampling.py +1450 -0
  1518. scipy/stats/tests/test_sensitivity_analysis.py +310 -0
  1519. scipy/stats/tests/test_stats.py +9707 -0
  1520. scipy/stats/tests/test_survival.py +466 -0
  1521. scipy/stats/tests/test_tukeylambda_stats.py +85 -0
  1522. scipy/stats/tests/test_variation.py +216 -0
  1523. scipy/version.py +12 -0
  1524. scipy-1.16.2.dist-info/DELVEWHEEL +2 -0
  1525. scipy-1.16.2.dist-info/LICENSE.txt +912 -0
  1526. scipy-1.16.2.dist-info/METADATA +1061 -0
  1527. scipy-1.16.2.dist-info/RECORD +1530 -0
  1528. scipy-1.16.2.dist-info/WHEEL +4 -0
  1529. scipy.libs/msvcp140-5f1c5dd31916990d94181e07bc3afb32.dll +0 -0
  1530. scipy.libs/scipy_openblas-f3ac85b1f412f7e86514c923dc4058d1.dll +0 -0
@@ -0,0 +1,1385 @@
1
+ # mypy: disable-error-code="attr-defined"
2
+ import math
3
+ import numpy as np
4
+ from scipy import special
5
+ import scipy._lib._elementwise_iterative_method as eim
6
+ from scipy._lib._util import _RichResult
7
+ from scipy._lib._array_api import (array_namespace, xp_copy, xp_ravel,
8
+ xp_promote)
9
+
10
+
11
+ __all__ = ['nsum']
12
+
13
+
14
+ # todo:
15
+ # figure out warning situation
16
+ # address https://github.com/scipy/scipy/pull/18650#discussion_r1233032521
17
+ # without `minweight`, we are also suppressing infinities within the interval.
18
+ # Is that OK? If so, we can probably get rid of `status=3`.
19
+ # Add heuristic to stop when improvement is too slow / antithrashing
20
+ # support singularities? interval subdivision? this feature will be added
21
+ # eventually, but do we adjust the interface now?
22
+ # When doing log-integration, should the tolerances control the error of the
23
+ # log-integral or the error of the integral? The trouble is that `log`
24
+ # inherently looses some precision so it may not be possible to refine
25
+ # the integral further. Example: 7th moment of stats.f(15, 20)
26
+ # respect function evaluation limit?
27
+ # make public?
28
+
29
+
30
+ def tanhsinh(f, a, b, *, args=(), log=False, maxlevel=None, minlevel=2,
31
+ atol=None, rtol=None, preserve_shape=False, callback=None):
32
+ """Evaluate a convergent integral numerically using tanh-sinh quadrature.
33
+
34
+ In practice, tanh-sinh quadrature achieves quadratic convergence for
35
+ many integrands: the number of accurate *digits* scales roughly linearly
36
+ with the number of function evaluations [1]_.
37
+
38
+ Either or both of the limits of integration may be infinite, and
39
+ singularities at the endpoints are acceptable. Divergent integrals and
40
+ integrands with non-finite derivatives or singularities within an interval
41
+ are out of scope, but the latter may be evaluated be calling `tanhsinh` on
42
+ each sub-interval separately.
43
+
44
+ Parameters
45
+ ----------
46
+ f : callable
47
+ The function to be integrated. The signature must be::
48
+
49
+ f(xi: ndarray, *argsi) -> ndarray
50
+
51
+ where each element of ``xi`` is a finite real number and ``argsi`` is a tuple,
52
+ which may contain an arbitrary number of arrays that are broadcastable
53
+ with ``xi``. `f` must be an elementwise function: see documentation of parameter
54
+ `preserve_shape` for details. It must not mutate the array ``xi`` or the arrays
55
+ in ``argsi``.
56
+ If ``f`` returns a value with complex dtype when evaluated at
57
+ either endpoint, subsequent arguments ``x`` will have complex dtype
58
+ (but zero imaginary part).
59
+ a, b : float array_like
60
+ Real lower and upper limits of integration. Must be broadcastable with one
61
+ another and with arrays in `args`. Elements may be infinite.
62
+ args : tuple of array_like, optional
63
+ Additional positional array arguments to be passed to `f`. Arrays
64
+ must be broadcastable with one another and the arrays of `a` and `b`.
65
+ If the callable for which the root is desired requires arguments that are
66
+ not broadcastable with `x`, wrap that callable with `f` such that `f`
67
+ accepts only `x` and broadcastable ``*args``.
68
+ log : bool, default: False
69
+ Setting to True indicates that `f` returns the log of the integrand
70
+ and that `atol` and `rtol` are expressed as the logs of the absolute
71
+ and relative errors. In this case, the result object will contain the
72
+ log of the integral and error. This is useful for integrands for which
73
+ numerical underflow or overflow would lead to inaccuracies.
74
+ When ``log=True``, the integrand (the exponential of `f`) must be real,
75
+ but it may be negative, in which case the log of the integrand is a
76
+ complex number with an imaginary part that is an odd multiple of π.
77
+ maxlevel : int, default: 10
78
+ The maximum refinement level of the algorithm.
79
+
80
+ At the zeroth level, `f` is called once, performing 16 function
81
+ evaluations. At each subsequent level, `f` is called once more,
82
+ approximately doubling the number of function evaluations that have
83
+ been performed. Accordingly, for many integrands, each successive level
84
+ will double the number of accurate digits in the result (up to the
85
+ limits of floating point precision).
86
+
87
+ The algorithm will terminate after completing level `maxlevel` or after
88
+ another termination condition is satisfied, whichever comes first.
89
+ minlevel : int, default: 2
90
+ The level at which to begin iteration (default: 2). This does not
91
+ change the total number of function evaluations or the abscissae at
92
+ which the function is evaluated; it changes only the *number of times*
93
+ `f` is called. If ``minlevel=k``, then the integrand is evaluated at
94
+ all abscissae from levels ``0`` through ``k`` in a single call.
95
+ Note that if `minlevel` exceeds `maxlevel`, the provided `minlevel` is
96
+ ignored, and `minlevel` is set equal to `maxlevel`.
97
+ atol, rtol : float, optional
98
+ Absolute termination tolerance (default: 0) and relative termination
99
+ tolerance (default: ``eps**0.75``, where ``eps`` is the precision of
100
+ the result dtype), respectively. Must be non-negative and finite if
101
+ `log` is False, and must be expressed as the log of a non-negative and
102
+ finite number if `log` is True. Iteration will stop when
103
+ ``res.error < atol`` or ``res.error < res.integral * rtol``.
104
+ preserve_shape : bool, default: False
105
+ In the following, "arguments of `f`" refers to the array ``xi`` and
106
+ any arrays within ``argsi``. Let ``shape`` be the broadcasted shape
107
+ of `a`, `b`, and all elements of `args` (which is conceptually
108
+ distinct from ``xi` and ``argsi`` passed into `f`).
109
+
110
+ - When ``preserve_shape=False`` (default), `f` must accept arguments
111
+ of *any* broadcastable shapes.
112
+
113
+ - When ``preserve_shape=True``, `f` must accept arguments of shape
114
+ ``shape`` *or* ``shape + (n,)``, where ``(n,)`` is the number of
115
+ abscissae at which the function is being evaluated.
116
+
117
+ In either case, for each scalar element ``xi[j]`` within ``xi``, the array
118
+ returned by `f` must include the scalar ``f(xi[j])`` at the same index.
119
+ Consequently, the shape of the output is always the shape of the input
120
+ ``xi``.
121
+
122
+ See Examples.
123
+
124
+ callback : callable, optional
125
+ An optional user-supplied function to be called before the first
126
+ iteration and after each iteration.
127
+ Called as ``callback(res)``, where ``res`` is a ``_RichResult``
128
+ similar to that returned by `tanhsinh` (but containing the
129
+ current iterate's values of all variables). If `callback` raises a
130
+ ``StopIteration``, the algorithm will terminate immediately and
131
+ `tanhsinh` will return a result object. `callback` must not mutate
132
+ `res` or its attributes.
133
+
134
+ Returns
135
+ -------
136
+ res : _RichResult
137
+ An object similar to an instance of `scipy.optimize.OptimizeResult` with the
138
+ following attributes. (The descriptions are written as though the values will
139
+ be scalars; however, if `f` returns an array, the outputs will be
140
+ arrays of the same shape.)
141
+
142
+ success : bool array
143
+ ``True`` when the algorithm terminated successfully (status ``0``).
144
+ ``False`` otherwise.
145
+ status : int array
146
+ An integer representing the exit status of the algorithm.
147
+
148
+ ``0`` : The algorithm converged to the specified tolerances.
149
+ ``-1`` : (unused)
150
+ ``-2`` : The maximum number of iterations was reached.
151
+ ``-3`` : A non-finite value was encountered.
152
+ ``-4`` : Iteration was terminated by `callback`.
153
+ ``1`` : The algorithm is proceeding normally (in `callback` only).
154
+
155
+ integral : float array
156
+ An estimate of the integral.
157
+ error : float array
158
+ An estimate of the error. Only available if level two or higher
159
+ has been completed; otherwise NaN.
160
+ maxlevel : int array
161
+ The maximum refinement level used.
162
+ nfev : int array
163
+ The number of points at which `f` was evaluated.
164
+
165
+ See Also
166
+ --------
167
+ quad
168
+
169
+ Notes
170
+ -----
171
+ Implements the algorithm as described in [1]_ with minor adaptations for
172
+ finite-precision arithmetic, including some described by [2]_ and [3]_. The
173
+ tanh-sinh scheme was originally introduced in [4]_.
174
+
175
+ Two error estimation schemes are described in [1]_ Section 5: one attempts to
176
+ detect and exploit quadratic convergence; the other simply compares the integral
177
+ estimates at successive levels. While neither is theoretically rigorous or
178
+ conservative, both work well in practice. Our error estimate uses the minimum of
179
+ these two schemes with a lower bound of ``eps * res.integral``.
180
+
181
+ Due to floating-point error in the abscissae, the function may be evaluated
182
+ at the endpoints of the interval during iterations, but the values returned by
183
+ the function at the endpoints will be ignored.
184
+
185
+ References
186
+ ----------
187
+ .. [1] Bailey, David H., Karthik Jeyabalan, and Xiaoye S. Li. "A comparison of
188
+ three high-precision quadrature schemes." Experimental Mathematics 14.3
189
+ (2005): 317-329.
190
+ .. [2] Vanherck, Joren, Bart Sorée, and Wim Magnus. "Tanh-sinh quadrature for
191
+ single and multiple integration using floating-point arithmetic."
192
+ arXiv preprint arXiv:2007.15057 (2020).
193
+ .. [3] van Engelen, Robert A. "Improving the Double Exponential Quadrature
194
+ Tanh-Sinh, Sinh-Sinh and Exp-Sinh Formulas."
195
+ https://www.genivia.com/files/qthsh.pdf
196
+ .. [4] Takahasi, Hidetosi, and Masatake Mori. "Double exponential formulas for
197
+ numerical integration." Publications of the Research Institute for
198
+ Mathematical Sciences 9.3 (1974): 721-741.
199
+
200
+ Examples
201
+ --------
202
+ Evaluate the Gaussian integral:
203
+
204
+ >>> import numpy as np
205
+ >>> from scipy.integrate import tanhsinh
206
+ >>> def f(x):
207
+ ... return np.exp(-x**2)
208
+ >>> res = tanhsinh(f, -np.inf, np.inf)
209
+ >>> res.integral # true value is np.sqrt(np.pi), 1.7724538509055159
210
+ 1.7724538509055159
211
+ >>> res.error # actual error is 0
212
+ 4.0007963937534104e-16
213
+
214
+ The value of the Gaussian function (bell curve) is nearly zero for
215
+ arguments sufficiently far from zero, so the value of the integral
216
+ over a finite interval is nearly the same.
217
+
218
+ >>> tanhsinh(f, -20, 20).integral
219
+ 1.772453850905518
220
+
221
+ However, with unfavorable integration limits, the integration scheme
222
+ may not be able to find the important region.
223
+
224
+ >>> tanhsinh(f, -np.inf, 1000).integral
225
+ 4.500490856616431
226
+
227
+ In such cases, or when there are singularities within the interval,
228
+ break the integral into parts with endpoints at the important points.
229
+
230
+ >>> tanhsinh(f, -np.inf, 0).integral + tanhsinh(f, 0, 1000).integral
231
+ 1.772453850905404
232
+
233
+ For integration involving very large or very small magnitudes, use
234
+ log-integration. (For illustrative purposes, the following example shows a
235
+ case in which both regular and log-integration work, but for more extreme
236
+ limits of integration, log-integration would avoid the underflow
237
+ experienced when evaluating the integral normally.)
238
+
239
+ >>> res = tanhsinh(f, 20, 30, rtol=1e-10)
240
+ >>> res.integral, res.error
241
+ (4.7819613911309014e-176, 4.670364401645202e-187)
242
+ >>> def log_f(x):
243
+ ... return -x**2
244
+ >>> res = tanhsinh(log_f, 20, 30, log=True, rtol=np.log(1e-10))
245
+ >>> np.exp(res.integral), np.exp(res.error)
246
+ (4.7819613911306924e-176, 4.670364401645093e-187)
247
+
248
+ The limits of integration and elements of `args` may be broadcastable
249
+ arrays, and integration is performed elementwise.
250
+
251
+ >>> from scipy import stats
252
+ >>> dist = stats.gausshyper(13.8, 3.12, 2.51, 5.18)
253
+ >>> a, b = dist.support()
254
+ >>> x = np.linspace(a, b, 100)
255
+ >>> res = tanhsinh(dist.pdf, a, x)
256
+ >>> ref = dist.cdf(x)
257
+ >>> np.allclose(res.integral, ref)
258
+ True
259
+
260
+ By default, `preserve_shape` is False, and therefore the callable
261
+ `f` may be called with arrays of any broadcastable shapes.
262
+ For example:
263
+
264
+ >>> shapes = []
265
+ >>> def f(x, c):
266
+ ... shape = np.broadcast_shapes(x.shape, c.shape)
267
+ ... shapes.append(shape)
268
+ ... return np.sin(c*x)
269
+ >>>
270
+ >>> c = [1, 10, 30, 100]
271
+ >>> res = tanhsinh(f, 0, 1, args=(c,), minlevel=1)
272
+ >>> shapes
273
+ [(4,), (4, 34), (4, 32), (3, 64), (2, 128), (1, 256)]
274
+
275
+ To understand where these shapes are coming from - and to better
276
+ understand how `tanhsinh` computes accurate results - note that
277
+ higher values of ``c`` correspond with higher frequency sinusoids.
278
+ The higher frequency sinusoids make the integrand more complicated,
279
+ so more function evaluations are required to achieve the target
280
+ accuracy:
281
+
282
+ >>> res.nfev
283
+ array([ 67, 131, 259, 515], dtype=int32)
284
+
285
+ The initial ``shape``, ``(4,)``, corresponds with evaluating the
286
+ integrand at a single abscissa and all four frequencies; this is used
287
+ for input validation and to determine the size and dtype of the arrays
288
+ that store results. The next shape corresponds with evaluating the
289
+ integrand at an initial grid of abscissae and all four frequencies.
290
+ Successive calls to the function double the total number of abscissae at
291
+ which the function has been evaluated. However, in later function
292
+ evaluations, the integrand is evaluated at fewer frequencies because
293
+ the corresponding integral has already converged to the required
294
+ tolerance. This saves function evaluations to improve performance, but
295
+ it requires the function to accept arguments of any shape.
296
+
297
+ "Vector-valued" integrands, such as those written for use with
298
+ `scipy.integrate.quad_vec`, are unlikely to satisfy this requirement.
299
+ For example, consider
300
+
301
+ >>> def f(x):
302
+ ... return [x, np.sin(10*x), np.cos(30*x), x*np.sin(100*x)**2]
303
+
304
+ This integrand is not compatible with `tanhsinh` as written; for instance,
305
+ the shape of the output will not be the same as the shape of ``x``. Such a
306
+ function *could* be converted to a compatible form with the introduction of
307
+ additional parameters, but this would be inconvenient. In such cases,
308
+ a simpler solution would be to use `preserve_shape`.
309
+
310
+ >>> shapes = []
311
+ >>> def f(x):
312
+ ... shapes.append(x.shape)
313
+ ... x0, x1, x2, x3 = x
314
+ ... return [x0, np.sin(10*x1), np.cos(30*x2), x3*np.sin(100*x3)]
315
+ >>>
316
+ >>> a = np.zeros(4)
317
+ >>> res = tanhsinh(f, a, 1, preserve_shape=True)
318
+ >>> shapes
319
+ [(4,), (4, 66), (4, 64), (4, 128), (4, 256)]
320
+
321
+ Here, the broadcasted shape of `a` and `b` is ``(4,)``. With
322
+ ``preserve_shape=True``, the function may be called with argument
323
+ ``x`` of shape ``(4,)`` or ``(4, n)``, and this is what we observe.
324
+
325
+ """
326
+ maxfun = None # unused right now
327
+ (f, a, b, log, maxfun, maxlevel, minlevel,
328
+ atol, rtol, args, preserve_shape, callback, xp) = _tanhsinh_iv(
329
+ f, a, b, log, maxfun, maxlevel, minlevel, atol,
330
+ rtol, args, preserve_shape, callback)
331
+
332
+ # Initialization
333
+ # `eim._initialize` does several important jobs, including
334
+ # ensuring that limits, each of the `args`, and the output of `f`
335
+ # broadcast correctly and are of consistent types. To save a function
336
+ # evaluation, I pass the midpoint of the integration interval. This comes
337
+ # at a cost of some gymnastics to ensure that the midpoint has the right
338
+ # shape and dtype. Did you know that 0d and >0d arrays follow different
339
+ # type promotion rules?
340
+ with np.errstate(over='ignore', invalid='ignore', divide='ignore'):
341
+ c = xp.reshape((xp_ravel(a) + xp_ravel(b))/2, a.shape)
342
+ inf_a, inf_b = xp.isinf(a), xp.isinf(b)
343
+ c[inf_a] = b[inf_a] - 1. # takes care of infinite a
344
+ c[inf_b] = a[inf_b] + 1. # takes care of infinite b
345
+ c[inf_a & inf_b] = 0. # takes care of infinite a and b
346
+ temp = eim._initialize(f, (c,), args, complex_ok=True,
347
+ preserve_shape=preserve_shape, xp=xp)
348
+ f, xs, fs, args, shape, dtype, xp = temp
349
+ a = xp_ravel(xp.astype(xp.broadcast_to(a, shape), dtype))
350
+ b = xp_ravel(xp.astype(xp.broadcast_to(b, shape), dtype))
351
+
352
+ # Transform improper integrals
353
+ a, b, a0, negative, abinf, ainf, binf = _transform_integrals(a, b, xp)
354
+
355
+ # Define variables we'll need
356
+ nit, nfev = 0, 1 # one function evaluation performed above
357
+ zero = -xp.inf if log else 0
358
+ pi = xp.asarray(xp.pi, dtype=dtype)[()]
359
+ maxiter = maxlevel - minlevel + 1
360
+ eps = xp.finfo(dtype).eps
361
+ if rtol is None:
362
+ rtol = 0.75*math.log(eps) if log else eps**0.75
363
+
364
+ Sn = xp_ravel(xp.full(shape, zero, dtype=dtype)) # latest integral estimate
365
+ Sn[xp.isnan(a) | xp.isnan(b) | xp.isnan(fs[0])] = xp.nan
366
+ Sk = xp.reshape(xp.empty_like(Sn), (-1, 1))[:, 0:0] # all integral estimates
367
+ aerr = xp_ravel(xp.full(shape, xp.nan, dtype=dtype)) # absolute error
368
+ status = xp_ravel(xp.full(shape, eim._EINPROGRESS, dtype=xp.int32))
369
+ h0 = _get_base_step(dtype, xp)
370
+ h0 = xp.real(h0) # base step
371
+
372
+ # For term `d4` of error estimate ([1] Section 5), we need to keep the
373
+ # most extreme abscissae and corresponding `fj`s, `wj`s in Euler-Maclaurin
374
+ # sum. Here, we initialize these variables.
375
+ xr0 = xp_ravel(xp.full(shape, -xp.inf, dtype=dtype))
376
+ fr0 = xp_ravel(xp.full(shape, xp.nan, dtype=dtype))
377
+ wr0 = xp_ravel(xp.zeros(shape, dtype=dtype))
378
+ xl0 = xp_ravel(xp.full(shape, xp.inf, dtype=dtype))
379
+ fl0 = xp_ravel(xp.full(shape, xp.nan, dtype=dtype))
380
+ wl0 = xp_ravel(xp.zeros(shape, dtype=dtype))
381
+ d4 = xp_ravel(xp.zeros(shape, dtype=dtype))
382
+
383
+ work = _RichResult(
384
+ Sn=Sn, Sk=Sk, aerr=aerr, h=h0, log=log, dtype=dtype, pi=pi, eps=eps,
385
+ a=xp.reshape(a, (-1, 1)), b=xp.reshape(b, (-1, 1)), # integration limits
386
+ n=minlevel, nit=nit, nfev=nfev, status=status, # iter/eval counts
387
+ xr0=xr0, fr0=fr0, wr0=wr0, xl0=xl0, fl0=fl0, wl0=wl0, d4=d4, # err est
388
+ ainf=ainf, binf=binf, abinf=abinf, a0=xp.reshape(a0, (-1, 1)), # transforms
389
+ # Store the xjc/wj pair cache in an object so they can't get compressed
390
+ # Using RichResult to allow dot notation, but a dictionary would suffice
391
+ pair_cache=_RichResult(xjc=None, wj=None, indices=[0], h0=None)) # pair cache
392
+
393
+ # Constant scalars don't need to be put in `work` unless they need to be
394
+ # passed outside `tanhsinh`. Examples: atol, rtol, h0, minlevel.
395
+
396
+ # Correspondence between terms in the `work` object and the result
397
+ res_work_pairs = [('status', 'status'), ('integral', 'Sn'),
398
+ ('error', 'aerr'), ('nit', 'nit'), ('nfev', 'nfev')]
399
+
400
+ def pre_func_eval(work):
401
+ # Determine abscissae at which to evaluate `f`
402
+ work.h = h0 / 2**work.n
403
+ xjc, wj = _get_pairs(work.n, h0, dtype=work.dtype,
404
+ inclusive=(work.n == minlevel), xp=xp, work=work)
405
+ work.xj, work.wj = _transform_to_limits(xjc, wj, work.a, work.b, xp)
406
+
407
+ # Perform abscissae substitutions for infinite limits of integration
408
+ xj = xp_copy(work.xj)
409
+ xj[work.abinf] = xj[work.abinf] / (1 - xp.real(xj[work.abinf])**2)
410
+ xj[work.binf] = 1/xj[work.binf] - 1 + work.a0[work.binf]
411
+ xj[work.ainf] *= -1
412
+ return xj
413
+
414
+ def post_func_eval(x, fj, work):
415
+ # Weight integrand as required by substitutions for infinite limits
416
+ if work.log:
417
+ fj[work.abinf] += (xp.log(1 + work.xj[work.abinf]**2)
418
+ - 2*xp.log(1 - work.xj[work.abinf]**2))
419
+ fj[work.binf] -= 2 * xp.log(work.xj[work.binf])
420
+ else:
421
+ fj[work.abinf] *= ((1 + work.xj[work.abinf]**2) /
422
+ (1 - work.xj[work.abinf]**2)**2)
423
+ fj[work.binf] *= work.xj[work.binf]**-2.
424
+
425
+ # Estimate integral with Euler-Maclaurin Sum
426
+ fjwj, Sn = _euler_maclaurin_sum(fj, work, xp)
427
+ if work.Sk.shape[-1]:
428
+ Snm1 = work.Sk[:, -1]
429
+ Sn = (special.logsumexp(xp.stack([Snm1 - math.log(2), Sn]), axis=0) if log
430
+ else Snm1 / 2 + Sn)
431
+
432
+ work.fjwj = fjwj
433
+ work.Sn = Sn
434
+
435
+ def check_termination(work):
436
+ """Terminate due to convergence or encountering non-finite values"""
437
+ stop = xp.zeros(work.Sn.shape, dtype=bool)
438
+
439
+ # Terminate before first iteration if integration limits are equal
440
+ if work.nit == 0:
441
+ i = xp_ravel(work.a == work.b) # ravel singleton dimension
442
+ zero = xp.asarray(-xp.inf if log else 0.)
443
+ zero = xp.full(work.Sn.shape, zero, dtype=Sn.dtype)
444
+ zero[xp.isnan(Sn)] = xp.nan
445
+ work.Sn[i] = zero[i]
446
+ work.aerr[i] = zero[i]
447
+ work.status[i] = eim._ECONVERGED
448
+ stop[i] = True
449
+ else:
450
+ # Terminate if convergence criterion is met
451
+ rerr, aerr = _estimate_error(work, xp)
452
+ i = (rerr < rtol) | (aerr < atol)
453
+ work.aerr = xp.reshape(xp.astype(aerr, work.dtype), work.Sn.shape)
454
+ work.status[i] = eim._ECONVERGED
455
+ stop[i] = True
456
+
457
+ # Terminate if integral estimate becomes invalid
458
+ if log:
459
+ Sn_real = xp.real(work.Sn)
460
+ Sn_pos_inf = xp.isinf(Sn_real) & (Sn_real > 0)
461
+ i = (Sn_pos_inf | xp.isnan(work.Sn)) & ~stop
462
+ else:
463
+ i = ~xp.isfinite(work.Sn) & ~stop
464
+ work.status[i] = eim._EVALUEERR
465
+ stop[i] = True
466
+
467
+ return stop
468
+
469
+ def post_termination_check(work):
470
+ work.n += 1
471
+ work.Sk = xp.concat((work.Sk, work.Sn[:, xp.newaxis]), axis=-1)
472
+ return
473
+
474
+ def customize_result(res, shape):
475
+ # If the integration limits were such that b < a, we reversed them
476
+ # to perform the calculation, and the final result needs to be negated.
477
+ if log and xp.any(negative):
478
+ res['integral'] = res['integral'] + negative * xp.pi * 1.0j
479
+ else:
480
+ res['integral'][negative] *= -1
481
+
482
+ # For this algorithm, it seems more appropriate to report the maximum
483
+ # level rather than the number of iterations in which it was performed.
484
+ res['maxlevel'] = minlevel + res['nit'] - 1
485
+ res['maxlevel'][res['nit'] == 0] = -1
486
+ del res['nit']
487
+ return shape
488
+
489
+ # Suppress all warnings initially, since there are many places in the code
490
+ # for which this is expected behavior.
491
+ with np.errstate(over='ignore', invalid='ignore', divide='ignore'):
492
+ res = eim._loop(work, callback, shape, maxiter, f, args, dtype, pre_func_eval,
493
+ post_func_eval, check_termination, post_termination_check,
494
+ customize_result, res_work_pairs, xp, preserve_shape)
495
+ return res
496
+
497
+
498
+ def _get_base_step(dtype, xp):
499
+ # Compute the base step length for the provided dtype. Theoretically, the
500
+ # Euler-Maclaurin sum is infinite, but it gets cut off when either the
501
+ # weights underflow or the abscissae cannot be distinguished from the
502
+ # limits of integration. The latter happens to occur first for float32 and
503
+ # float64, and it occurs when `xjc` (the abscissa complement)
504
+ # in `_compute_pair` underflows. We can solve for the argument `tmax` at
505
+ # which it will underflow using [2] Eq. 13.
506
+ fmin = 4*xp.finfo(dtype).smallest_normal # stay a little away from the limit
507
+ tmax = math.asinh(math.log(2/fmin - 1) / xp.pi)
508
+
509
+ # Based on this, we can choose a base step size `h` for level 0.
510
+ # The number of function evaluations will be `2 + m*2^(k+1)`, where `k` is
511
+ # the level and `m` is an integer we get to choose. I choose
512
+ # m = _N_BASE_STEPS = `8` somewhat arbitrarily, but a rationale is that a
513
+ # power of 2 makes floating point arithmetic more predictable. It also
514
+ # results in a base step size close to `1`, which is what [1] uses (and I
515
+ # used here until I found [2] and these ideas settled).
516
+ h0 = tmax / _N_BASE_STEPS
517
+ return xp.asarray(h0, dtype=dtype)[()]
518
+
519
+
520
+ _N_BASE_STEPS = 8
521
+
522
+
523
+ def _compute_pair(k, h0, xp):
524
+ # Compute the abscissa-weight pairs for each level k. See [1] page 9.
525
+
526
+ # For now, we compute and store in 64-bit precision. If higher-precision
527
+ # data types become better supported, it would be good to compute these
528
+ # using the highest precision available. Or, once there is an Array API-
529
+ # compatible arbitrary precision array, we can compute at the required
530
+ # precision.
531
+
532
+ # "....each level k of abscissa-weight pairs uses h = 2 **-k"
533
+ # We adapt to floating point arithmetic using ideas of [2].
534
+ h = h0 / 2**k
535
+ max = _N_BASE_STEPS * 2**k
536
+
537
+ # For iterations after the first, "....the integrand function needs to be
538
+ # evaluated only at the odd-indexed abscissas at each level."
539
+ j = xp.arange(max+1) if k == 0 else xp.arange(1, max+1, 2)
540
+ jh = j * h
541
+
542
+ # "In this case... the weights wj = u1/cosh(u2)^2, where..."
543
+ pi_2 = xp.pi / 2
544
+ u1 = pi_2*xp.cosh(jh)
545
+ u2 = pi_2*xp.sinh(jh)
546
+ # Denominators get big here. Overflow then underflow doesn't need warning.
547
+ # with np.errstate(under='ignore', over='ignore'):
548
+ wj = u1 / xp.cosh(u2)**2
549
+ # "We actually store 1-xj = 1/(...)."
550
+ xjc = 1 / (xp.exp(u2) * xp.cosh(u2)) # complement of xj = xp.tanh(u2)
551
+
552
+ # When level k == 0, the zeroth xj corresponds with xj = 0. To simplify
553
+ # code, the function will be evaluated there twice; each gets half weight.
554
+ wj[0] = wj[0] / 2 if k == 0 else wj[0]
555
+
556
+ return xjc, wj # store at full precision
557
+
558
+
559
+ def _pair_cache(k, h0, xp, work):
560
+ # Cache the abscissa-weight pairs up to a specified level.
561
+ # Abscissae and weights of consecutive levels are concatenated.
562
+ # `index` records the indices that correspond with each level:
563
+ # `xjc[index[k]:index[k+1]` extracts the level `k` abscissae.
564
+ if not isinstance(h0, type(work.pair_cache.h0)) or h0 != work.pair_cache.h0:
565
+ work.pair_cache.xjc = xp.empty(0)
566
+ work.pair_cache.wj = xp.empty(0)
567
+ work.pair_cache.indices = [0]
568
+
569
+ xjcs = [work.pair_cache.xjc]
570
+ wjs = [work.pair_cache.wj]
571
+
572
+ for i in range(len(work.pair_cache.indices)-1, k + 1):
573
+ xjc, wj = _compute_pair(i, h0, xp)
574
+ xjcs.append(xjc)
575
+ wjs.append(wj)
576
+ work.pair_cache.indices.append(work.pair_cache.indices[-1] + xjc.shape[0])
577
+
578
+ work.pair_cache.xjc = xp.concat(xjcs)
579
+ work.pair_cache.wj = xp.concat(wjs)
580
+ work.pair_cache.h0 = h0
581
+
582
+
583
+ def _get_pairs(k, h0, inclusive, dtype, xp, work):
584
+ # Retrieve the specified abscissa-weight pairs from the cache
585
+ # If `inclusive`, return all up to and including the specified level
586
+ if (len(work.pair_cache.indices) <= k+2
587
+ or not isinstance (h0, type(work.pair_cache.h0))
588
+ or h0 != work.pair_cache.h0):
589
+ _pair_cache(k, h0, xp, work)
590
+
591
+ xjc = work.pair_cache.xjc
592
+ wj = work.pair_cache.wj
593
+ indices = work.pair_cache.indices
594
+
595
+ start = 0 if inclusive else indices[k]
596
+ end = indices[k+1]
597
+
598
+ return xp.astype(xjc[start:end], dtype), xp.astype(wj[start:end], dtype)
599
+
600
+
601
+ def _transform_to_limits(xjc, wj, a, b, xp):
602
+ # Transform integral according to user-specified limits. This is just
603
+ # math that follows from the fact that the standard limits are (-1, 1).
604
+ # Note: If we had stored xj instead of xjc, we would have
605
+ # xj = alpha * xj + beta, where beta = (a + b)/2
606
+ alpha = (b - a) / 2
607
+ xj = xp.concat((-alpha * xjc + b, alpha * xjc + a), axis=-1)
608
+ wj = wj*alpha # arguments get broadcasted, so we can't use *=
609
+ wj = xp.concat((wj, wj), axis=-1)
610
+
611
+ # Points at the boundaries can be generated due to finite precision
612
+ # arithmetic, but these function values aren't supposed to be included in
613
+ # the Euler-Maclaurin sum. Ideally we wouldn't evaluate the function at
614
+ # these points; however, we can't easily filter out points since this
615
+ # function is vectorized. Instead, zero the weights.
616
+ # Note: values may have complex dtype, but have zero imaginary part
617
+ xj_real, a_real, b_real = xp.real(xj), xp.real(a), xp.real(b)
618
+ invalid = (xj_real <= a_real) | (xj_real >= b_real)
619
+ wj[invalid] = 0
620
+ return xj, wj
621
+
622
+
623
+ def _euler_maclaurin_sum(fj, work, xp):
624
+ # Perform the Euler-Maclaurin Sum, [1] Section 4
625
+
626
+ # The error estimate needs to know the magnitude of the last term
627
+ # omitted from the Euler-Maclaurin sum. This is a bit involved because
628
+ # it may have been computed at a previous level. I sure hope it's worth
629
+ # all the trouble.
630
+ xr0, fr0, wr0 = work.xr0, work.fr0, work.wr0
631
+ xl0, fl0, wl0 = work.xl0, work.fl0, work.wl0
632
+
633
+ # It is much more convenient to work with the transposes of our work
634
+ # variables here.
635
+ xj, fj, wj = work.xj.T, fj.T, work.wj.T
636
+ n_x, n_active = xj.shape # number of abscissae, number of active elements
637
+
638
+ # We'll work with the left and right sides separately
639
+ xr, xl = xp_copy(xp.reshape(xj, (2, n_x // 2, n_active))) # this gets modified
640
+ fr, fl = xp.reshape(fj, (2, n_x // 2, n_active))
641
+ wr, wl = xp.reshape(wj, (2, n_x // 2, n_active))
642
+
643
+ invalid_r = ~xp.isfinite(fr) | (wr == 0)
644
+ invalid_l = ~xp.isfinite(fl) | (wl == 0)
645
+
646
+ # integer index of the maximum abscissa at this level
647
+ xr[invalid_r] = -xp.inf
648
+ ir = xp.argmax(xp.real(xr), axis=0, keepdims=True)
649
+ # abscissa, function value, and weight at this index
650
+ ### Not Array API Compatible... yet ###
651
+ xr_max = xp.take_along_axis(xr, ir, axis=0)[0]
652
+ fr_max = xp.take_along_axis(fr, ir, axis=0)[0]
653
+ wr_max = xp.take_along_axis(wr, ir, axis=0)[0]
654
+ # boolean indices at which maximum abscissa at this level exceeds
655
+ # the incumbent maximum abscissa (from all previous levels)
656
+ # note: abscissa may have complex dtype, but will have zero imaginary part
657
+ j = xp.real(xr_max) > xp.real(xr0)
658
+ # Update record of the incumbent abscissa, function value, and weight
659
+ xr0[j] = xr_max[j]
660
+ fr0[j] = fr_max[j]
661
+ wr0[j] = wr_max[j]
662
+
663
+ # integer index of the minimum abscissa at this level
664
+ xl[invalid_l] = xp.inf
665
+ il = xp.argmin(xp.real(xl), axis=0, keepdims=True)
666
+ # abscissa, function value, and weight at this index
667
+ xl_min = xp.take_along_axis(xl, il, axis=0)[0]
668
+ fl_min = xp.take_along_axis(fl, il, axis=0)[0]
669
+ wl_min = xp.take_along_axis(wl, il, axis=0)[0]
670
+ # boolean indices at which minimum abscissa at this level is less than
671
+ # the incumbent minimum abscissa (from all previous levels)
672
+ # note: abscissa may have complex dtype, but will have zero imaginary part
673
+ j = xp.real(xl_min) < xp.real(xl0)
674
+ # Update record of the incumbent abscissa, function value, and weight
675
+ xl0[j] = xl_min[j]
676
+ fl0[j] = fl_min[j]
677
+ wl0[j] = wl_min[j]
678
+ fj = fj.T
679
+
680
+ # Compute the error estimate `d4` - the magnitude of the leftmost or
681
+ # rightmost term, whichever is greater.
682
+ flwl0 = fl0 + xp.log(wl0) if work.log else fl0 * wl0 # leftmost term
683
+ frwr0 = fr0 + xp.log(wr0) if work.log else fr0 * wr0 # rightmost term
684
+ magnitude = xp.real if work.log else xp.abs
685
+ work.d4 = xp.maximum(magnitude(flwl0), magnitude(frwr0))
686
+
687
+ # There are two approaches to dealing with function values that are
688
+ # numerically infinite due to approaching a singularity - zero them, or
689
+ # replace them with the function value at the nearest non-infinite point.
690
+ # [3] pg. 22 suggests the latter, so let's do that given that we have the
691
+ # information.
692
+ fr0b = xp.broadcast_to(fr0[xp.newaxis, :], fr.shape)
693
+ fl0b = xp.broadcast_to(fl0[xp.newaxis, :], fl.shape)
694
+ fr[invalid_r] = fr0b[invalid_r]
695
+ fl[invalid_l] = fl0b[invalid_l]
696
+
697
+ # When wj is zero, log emits a warning
698
+ # with np.errstate(divide='ignore'):
699
+ fjwj = fj + xp.log(work.wj) if work.log else fj * work.wj
700
+
701
+ # update integral estimate
702
+ Sn = (special.logsumexp(fjwj + xp.log(work.h), axis=-1) if work.log
703
+ else xp.sum(fjwj, axis=-1) * work.h)
704
+
705
+ work.xr0, work.fr0, work.wr0 = xr0, fr0, wr0
706
+ work.xl0, work.fl0, work.wl0 = xl0, fl0, wl0
707
+
708
+ return fjwj, Sn
709
+
710
+
711
+ def _estimate_error(work, xp):
712
+ # Estimate the error according to [1] Section 5
713
+
714
+ if work.n == 0 or work.nit == 0:
715
+ # The paper says to use "one" as the error before it can be calculated.
716
+ # NaN seems to be more appropriate.
717
+ nan = xp.full_like(work.Sn, xp.nan)
718
+ return nan, nan
719
+
720
+ indices = work.pair_cache.indices
721
+
722
+ n_active = work.Sn.shape[0] # number of active elements
723
+ axis_kwargs = dict(axis=-1, keepdims=True)
724
+
725
+ # With a jump start (starting at level higher than 0), we haven't
726
+ # explicitly calculated the integral estimate at lower levels. But we have
727
+ # all the function value-weight products, so we can compute the
728
+ # lower-level estimates.
729
+ if work.Sk.shape[-1] == 0:
730
+ h = 2 * work.h # step size at this level
731
+ n_x = indices[work.n] # number of abscissa up to this level
732
+ # The right and left fjwj terms from all levels are concatenated along
733
+ # the last axis. Get out only the terms up to this level.
734
+ fjwj_rl = xp.reshape(work.fjwj, (n_active, 2, -1))
735
+ fjwj = xp.reshape(fjwj_rl[:, :, :n_x], (n_active, 2*n_x))
736
+ # Compute the Euler-Maclaurin sum at this level
737
+ Snm1 = (special.logsumexp(fjwj, **axis_kwargs) + xp.log(h) if work.log
738
+ else xp.sum(fjwj, **axis_kwargs) * h)
739
+ work.Sk = xp.concat((Snm1, work.Sk), axis=-1)
740
+
741
+ if work.n == 1:
742
+ nan = xp.full_like(work.Sn, xp.nan)
743
+ return nan, nan
744
+
745
+ # The paper says not to calculate the error for n<=2, but it's not clear
746
+ # about whether it starts at level 0 or level 1. We start at level 0, so
747
+ # why not compute the error beginning in level 2?
748
+ if work.Sk.shape[-1] < 2:
749
+ h = 4 * work.h # step size at this level
750
+ n_x = indices[work.n-1] # number of abscissa up to this level
751
+ # The right and left fjwj terms from all levels are concatenated along
752
+ # the last axis. Get out only the terms up to this level.
753
+ fjwj_rl = xp.reshape(work.fjwj, (work.Sn.shape[0], 2, -1))
754
+ fjwj = xp.reshape(fjwj_rl[..., :n_x], (n_active, 2*n_x))
755
+ # Compute the Euler-Maclaurin sum at this level
756
+ Snm2 = (special.logsumexp(fjwj, **axis_kwargs) + xp.log(h) if work.log
757
+ else xp.sum(fjwj, **axis_kwargs) * h)
758
+ work.Sk = xp.concat((Snm2, work.Sk), axis=-1)
759
+
760
+ Snm2 = work.Sk[..., -2]
761
+ Snm1 = work.Sk[..., -1]
762
+
763
+ e1 = xp.asarray(work.eps)[()]
764
+
765
+ if work.log:
766
+ log_e1 = xp.log(e1)
767
+ # Currently, only real integrals are supported in log-scale. All
768
+ # complex values have imaginary part in increments of pi*j, which just
769
+ # carries sign information of the original integral, so use of
770
+ # `xp.real` here is equivalent to absolute value in real scale.
771
+ d1 = xp.real(special.logsumexp(xp.stack([work.Sn, Snm1 + work.pi*1j]), axis=0))
772
+ d2 = xp.real(special.logsumexp(xp.stack([work.Sn, Snm2 + work.pi*1j]), axis=0))
773
+ d3 = log_e1 + xp.max(xp.real(work.fjwj), axis=-1)
774
+ d4 = work.d4
775
+ d5 = log_e1 + xp.real(work.Sn)
776
+ temp = xp.where(d1 > -xp.inf, d1 ** 2 / d2, -xp.inf)
777
+ ds = xp.stack([temp, 2 * d1, d3, d4])
778
+ aerr = xp.clip(xp.max(ds, axis=0), d5, d1)
779
+ rerr = aerr - xp.real(work.Sn)
780
+ else:
781
+ # Note: explicit computation of log10 of each of these is unnecessary.
782
+ d1 = xp.abs(work.Sn - Snm1)
783
+ d2 = xp.abs(work.Sn - Snm2)
784
+ d3 = e1 * xp.max(xp.abs(work.fjwj), axis=-1)
785
+ d4 = work.d4
786
+ d5 = e1 * xp.abs(work.Sn)
787
+ temp = xp.where(d1 > 0, d1**(xp.log(d1)/xp.log(d2)), 0)
788
+ ds = xp.stack([temp, d1**2, d3, d4])
789
+ aerr = xp.clip(xp.max(ds, axis=0), d5, d1)
790
+ rerr = aerr/xp.abs(work.Sn)
791
+
792
+ return rerr, aerr
793
+
794
+
795
+ def _transform_integrals(a, b, xp):
796
+ # Transform integrals to a form with finite a <= b
797
+ # For b == a (even infinite), we ensure that the limits remain equal
798
+ # For b < a, we reverse the limits and will multiply the final result by -1
799
+ # For infinite limit on the right, we use the substitution x = 1/t - 1 + a
800
+ # For infinite limit on the left, we substitute x = -x and treat as above
801
+ # For infinite limits, we substitute x = t / (1-t**2)
802
+ ab_same = (a == b)
803
+ a[ab_same], b[ab_same] = 1, 1
804
+
805
+ # `a, b` may have complex dtype but have zero imaginary part
806
+ negative = xp.real(b) < xp.real(a)
807
+ a[negative], b[negative] = b[negative], a[negative]
808
+
809
+ abinf = xp.isinf(a) & xp.isinf(b)
810
+ a[abinf], b[abinf] = -1, 1
811
+
812
+ ainf = xp.isinf(a)
813
+ a[ainf], b[ainf] = -b[ainf], -a[ainf]
814
+
815
+ binf = xp.isinf(b)
816
+ a0 = xp_copy(a)
817
+ a[binf], b[binf] = 0, 1
818
+
819
+ return a, b, a0, negative, abinf, ainf, binf
820
+
821
+
822
+ def _tanhsinh_iv(f, a, b, log, maxfun, maxlevel, minlevel,
823
+ atol, rtol, args, preserve_shape, callback):
824
+ # Input validation and standardization
825
+
826
+ xp = array_namespace(a, b)
827
+ a, b = xp_promote(a, b, broadcast=True, force_floating=True, xp=xp)
828
+
829
+ message = '`f` must be callable.'
830
+ if not callable(f):
831
+ raise ValueError(message)
832
+
833
+ message = 'All elements of `a` and `b` must be real numbers.'
834
+ if (xp.isdtype(a.dtype, 'complex floating')
835
+ or xp.isdtype(b.dtype, 'complex floating')):
836
+ raise ValueError(message)
837
+
838
+ message = '`log` must be True or False.'
839
+ if log not in {True, False}:
840
+ raise ValueError(message)
841
+ log = bool(log)
842
+
843
+ if atol is None:
844
+ atol = -xp.inf if log else 0
845
+
846
+ rtol_temp = rtol if rtol is not None else 0.
847
+
848
+ # using NumPy for convenience here; these are just floats, not arrays
849
+ params = np.asarray([atol, rtol_temp, 0.])
850
+ message = "`atol` and `rtol` must be real numbers."
851
+ if not np.issubdtype(params.dtype, np.floating):
852
+ raise ValueError(message)
853
+
854
+ if log:
855
+ message = '`atol` and `rtol` may not be positive infinity.'
856
+ if np.any(np.isposinf(params)):
857
+ raise ValueError(message)
858
+ else:
859
+ message = '`atol` and `rtol` must be non-negative and finite.'
860
+ if np.any(params < 0) or np.any(np.isinf(params)):
861
+ raise ValueError(message)
862
+ atol = params[0]
863
+ rtol = rtol if rtol is None else params[1]
864
+
865
+ BIGINT = float(2**62)
866
+ if maxfun is None and maxlevel is None:
867
+ maxlevel = 10
868
+
869
+ maxfun = BIGINT if maxfun is None else maxfun
870
+ maxlevel = BIGINT if maxlevel is None else maxlevel
871
+
872
+ message = '`maxfun`, `maxlevel`, and `minlevel` must be integers.'
873
+ params = np.asarray([maxfun, maxlevel, minlevel])
874
+ if not (np.issubdtype(params.dtype, np.number)
875
+ and np.all(np.isreal(params))
876
+ and np.all(params.astype(np.int64) == params)):
877
+ raise ValueError(message)
878
+ message = '`maxfun`, `maxlevel`, and `minlevel` must be non-negative.'
879
+ if np.any(params < 0):
880
+ raise ValueError(message)
881
+ maxfun, maxlevel, minlevel = params.astype(np.int64)
882
+ minlevel = min(minlevel, maxlevel)
883
+
884
+ if not np.iterable(args):
885
+ args = (args,)
886
+ args = (xp.asarray(arg) for arg in args)
887
+
888
+ message = '`preserve_shape` must be True or False.'
889
+ if preserve_shape not in {True, False}:
890
+ raise ValueError(message)
891
+
892
+ if callback is not None and not callable(callback):
893
+ raise ValueError('`callback` must be callable.')
894
+
895
+ return (f, a, b, log, maxfun, maxlevel, minlevel,
896
+ atol, rtol, args, preserve_shape, callback, xp)
897
+
898
+
899
+ def _nsum_iv(f, a, b, step, args, log, maxterms, tolerances):
900
+ # Input validation and standardization
901
+
902
+ xp = array_namespace(a, b, step)
903
+ a, b, step = xp_promote(a, b, step, broadcast=True, force_floating=True, xp=xp)
904
+
905
+ message = '`f` must be callable.'
906
+ if not callable(f):
907
+ raise ValueError(message)
908
+
909
+ message = 'All elements of `a`, `b`, and `step` must be real numbers.'
910
+ if not xp.isdtype(a.dtype, ('integral', 'real floating')):
911
+ raise ValueError(message)
912
+
913
+ valid_b = b >= a # NaNs will be False
914
+ valid_step = xp.isfinite(step) & (step > 0)
915
+ valid_abstep = valid_b & valid_step
916
+
917
+ message = '`log` must be True or False.'
918
+ if log not in {True, False}:
919
+ raise ValueError(message)
920
+
921
+ tolerances = {} if tolerances is None else tolerances
922
+
923
+ atol = tolerances.get('atol', None)
924
+ if atol is None:
925
+ atol = -xp.inf if log else 0
926
+
927
+ rtol = tolerances.get('rtol', None)
928
+ rtol_temp = rtol if rtol is not None else 0.
929
+
930
+ # using NumPy for convenience here; these are just floats, not arrays
931
+ params = np.asarray([atol, rtol_temp, 0.])
932
+ message = "`atol` and `rtol` must be real numbers."
933
+ if not np.issubdtype(params.dtype, np.floating):
934
+ raise ValueError(message)
935
+
936
+ if log:
937
+ message = '`atol`, `rtol` may not be positive infinity or NaN.'
938
+ if np.any(np.isposinf(params) | np.isnan(params)):
939
+ raise ValueError(message)
940
+ else:
941
+ message = '`atol`, and `rtol` must be non-negative and finite.'
942
+ if np.any((params < 0) | (~np.isfinite(params))):
943
+ raise ValueError(message)
944
+ atol = params[0]
945
+ rtol = rtol if rtol is None else params[1]
946
+
947
+ maxterms_int = int(maxterms)
948
+ if maxterms_int != maxterms or maxterms < 0:
949
+ message = "`maxterms` must be a non-negative integer."
950
+ raise ValueError(message)
951
+
952
+ if not np.iterable(args):
953
+ args = (args,)
954
+
955
+ return f, a, b, step, valid_abstep, args, log, maxterms_int, atol, rtol, xp
956
+
957
+
958
+ def nsum(f, a, b, *, step=1, args=(), log=False, maxterms=int(2**20), tolerances=None):
959
+ r"""Evaluate a convergent finite or infinite series.
960
+
961
+ For finite `a` and `b`, this evaluates::
962
+
963
+ f(a + np.arange(n)*step).sum()
964
+
965
+ where ``n = int((b - a) / step) + 1``, where `f` is smooth, positive, and
966
+ unimodal. The number of terms in the sum may be very large or infinite,
967
+ in which case a partial sum is evaluated directly and the remainder is
968
+ approximated using integration.
969
+
970
+ Parameters
971
+ ----------
972
+ f : callable
973
+ The function that evaluates terms to be summed. The signature must be::
974
+
975
+ f(x: ndarray, *args) -> ndarray
976
+
977
+ where each element of ``x`` is a finite real and ``args`` is a tuple,
978
+ which may contain an arbitrary number of arrays that are broadcastable
979
+ with ``x``.
980
+
981
+ `f` must be an elementwise function: each element ``f(x)[i]``
982
+ must equal ``f(x[i])`` for all indices ``i``. It must not mutate the
983
+ array ``x`` or the arrays in ``args``, and it must return NaN where
984
+ the argument is NaN.
985
+
986
+ `f` must represent a smooth, positive, unimodal function of `x` defined at
987
+ *all reals* between `a` and `b`.
988
+ a, b : float array_like
989
+ Real lower and upper limits of summed terms. Must be broadcastable.
990
+ Each element of `a` must be less than the corresponding element in `b`.
991
+ step : float array_like
992
+ Finite, positive, real step between summed terms. Must be broadcastable
993
+ with `a` and `b`. Note that the number of terms included in the sum will
994
+ be ``floor((b - a) / step)`` + 1; adjust `b` accordingly to ensure
995
+ that ``f(b)`` is included if intended.
996
+ args : tuple of array_like, optional
997
+ Additional positional arguments to be passed to `f`. Must be arrays
998
+ broadcastable with `a`, `b`, and `step`. If the callable to be summed
999
+ requires arguments that are not broadcastable with `a`, `b`, and `step`,
1000
+ wrap that callable with `f` such that `f` accepts only `x` and
1001
+ broadcastable ``*args``. See Examples.
1002
+ log : bool, default: False
1003
+ Setting to True indicates that `f` returns the log of the terms
1004
+ and that `atol` and `rtol` are expressed as the logs of the absolute
1005
+ and relative errors. In this case, the result object will contain the
1006
+ log of the sum and error. This is useful for summands for which
1007
+ numerical underflow or overflow would lead to inaccuracies.
1008
+ maxterms : int, default: 2**20
1009
+ The maximum number of terms to evaluate for direct summation.
1010
+ Additional function evaluations may be performed for input
1011
+ validation and integral evaluation.
1012
+ atol, rtol : float, optional
1013
+ Absolute termination tolerance (default: 0) and relative termination
1014
+ tolerance (default: ``eps**0.5``, where ``eps`` is the precision of
1015
+ the result dtype), respectively. Must be non-negative
1016
+ and finite if `log` is False, and must be expressed as the log of a
1017
+ non-negative and finite number if `log` is True.
1018
+
1019
+ Returns
1020
+ -------
1021
+ res : _RichResult
1022
+ An object similar to an instance of `scipy.optimize.OptimizeResult` with the
1023
+ following attributes. (The descriptions are written as though the values will
1024
+ be scalars; however, if `f` returns an array, the outputs will be
1025
+ arrays of the same shape.)
1026
+
1027
+ success : bool
1028
+ ``True`` when the algorithm terminated successfully (status ``0``);
1029
+ ``False`` otherwise.
1030
+ status : int array
1031
+ An integer representing the exit status of the algorithm.
1032
+
1033
+ - ``0`` : The algorithm converged to the specified tolerances.
1034
+ - ``-1`` : Element(s) of `a`, `b`, or `step` are invalid
1035
+ - ``-2`` : Numerical integration reached its iteration limit;
1036
+ the sum may be divergent.
1037
+ - ``-3`` : A non-finite value was encountered.
1038
+ - ``-4`` : The magnitude of the last term of the partial sum exceeds
1039
+ the tolerances, so the error estimate exceeds the tolerances.
1040
+ Consider increasing `maxterms` or loosening `tolerances`.
1041
+ Alternatively, the callable may not be unimodal, or the limits of
1042
+ summation may be too far from the function maximum. Consider
1043
+ increasing `maxterms` or breaking the sum into pieces.
1044
+
1045
+ sum : float array
1046
+ An estimate of the sum.
1047
+ error : float array
1048
+ An estimate of the absolute error, assuming all terms are non-negative,
1049
+ the function is computed exactly, and direct summation is accurate to
1050
+ the precision of the result dtype.
1051
+ nfev : int array
1052
+ The number of points at which `f` was evaluated.
1053
+
1054
+ See Also
1055
+ --------
1056
+ mpmath.nsum
1057
+
1058
+ Notes
1059
+ -----
1060
+ The method implemented for infinite summation is related to the integral
1061
+ test for convergence of an infinite series: assuming `step` size 1 for
1062
+ simplicity of exposition, the sum of a monotone decreasing function is bounded by
1063
+
1064
+ .. math::
1065
+
1066
+ \int_u^\infty f(x) dx \leq \sum_{k=u}^\infty f(k) \leq \int_u^\infty f(x) dx + f(u)
1067
+
1068
+ Let :math:`a` represent `a`, :math:`n` represent `maxterms`, :math:`\epsilon_a`
1069
+ represent `atol`, and :math:`\epsilon_r` represent `rtol`.
1070
+ The implementation first evaluates the integral :math:`S_l=\int_a^\infty f(x) dx`
1071
+ as a lower bound of the infinite sum. Then, it seeks a value :math:`c > a` such
1072
+ that :math:`f(c) < \epsilon_a + S_l \epsilon_r`, if it exists; otherwise,
1073
+ let :math:`c = a + n`. Then the infinite sum is approximated as
1074
+
1075
+ .. math::
1076
+
1077
+ \sum_{k=a}^{c-1} f(k) + \int_c^\infty f(x) dx + f(c)/2
1078
+
1079
+ and the reported error is :math:`f(c)/2` plus the error estimate of
1080
+ numerical integration. Note that the integral approximations may require
1081
+ evaluation of the function at points besides those that appear in the sum,
1082
+ so `f` must be a continuous and monotonically decreasing function defined
1083
+ for all reals within the integration interval. However, due to the nature
1084
+ of the integral approximation, the shape of the function between points
1085
+ that appear in the sum has little effect. If there is not a natural
1086
+ extension of the function to all reals, consider using linear interpolation,
1087
+ which is easy to evaluate and preserves monotonicity.
1088
+
1089
+ The approach described above is generalized for non-unit
1090
+ `step` and finite `b` that is too large for direct evaluation of the sum,
1091
+ i.e. ``b - a + 1 > maxterms``. It is further generalized to unimodal
1092
+ functions by directly summing terms surrounding the maximum.
1093
+ This strategy may fail:
1094
+
1095
+ - If the left limit is finite and the maximum is far from it.
1096
+ - If the right limit is finite and the maximum is far from it.
1097
+ - If both limits are finite and the maximum is far from the origin.
1098
+
1099
+ In these cases, accuracy may be poor, and `nsum` may return status code ``4``.
1100
+
1101
+ Although the callable `f` must be non-negative and unimodal,
1102
+ `nsum` can be used to evaluate more general forms of series. For instance, to
1103
+ evaluate an alternating series, pass a callable that returns the difference
1104
+ between pairs of adjacent terms, and adjust `step` accordingly. See Examples.
1105
+
1106
+ References
1107
+ ----------
1108
+ .. [1] Wikipedia. "Integral test for convergence."
1109
+ https://en.wikipedia.org/wiki/Integral_test_for_convergence
1110
+
1111
+ Examples
1112
+ --------
1113
+ Compute the infinite sum of the reciprocals of squared integers.
1114
+
1115
+ >>> import numpy as np
1116
+ >>> from scipy.integrate import nsum
1117
+ >>> res = nsum(lambda k: 1/k**2, 1, np.inf)
1118
+ >>> ref = np.pi**2/6 # true value
1119
+ >>> res.error # estimated error
1120
+ np.float64(7.448762306416137e-09)
1121
+ >>> (res.sum - ref)/ref # true error
1122
+ np.float64(-1.839871898894426e-13)
1123
+ >>> res.nfev # number of points at which callable was evaluated
1124
+ np.int32(8561)
1125
+
1126
+ Compute the infinite sums of the reciprocals of integers raised to powers ``p``,
1127
+ where ``p`` is an array.
1128
+
1129
+ >>> from scipy import special
1130
+ >>> p = np.arange(3, 10)
1131
+ >>> res = nsum(lambda k, p: 1/k**p, 1, np.inf, maxterms=1e3, args=(p,))
1132
+ >>> ref = special.zeta(p, 1)
1133
+ >>> np.allclose(res.sum, ref)
1134
+ True
1135
+
1136
+ Evaluate the alternating harmonic series.
1137
+
1138
+ >>> res = nsum(lambda x: 1/x - 1/(x+1), 1, np.inf, step=2)
1139
+ >>> res.sum, res.sum - np.log(2) # result, difference vs analytical sum
1140
+ (np.float64(0.6931471805598691), np.float64(-7.616129948928574e-14))
1141
+
1142
+ """ # noqa: E501
1143
+ # Potential future work:
1144
+ # - improve error estimate of `_direct` sum
1145
+ # - add other methods for convergence acceleration (Richardson, epsilon)
1146
+ # - support negative monotone increasing functions?
1147
+ # - b < a / negative step?
1148
+ # - complex-valued function?
1149
+ # - check for violations of monotonicity?
1150
+
1151
+ # Function-specific input validation / standardization
1152
+ tmp = _nsum_iv(f, a, b, step, args, log, maxterms, tolerances)
1153
+ f, a, b, step, valid_abstep, args, log, maxterms, atol, rtol, xp = tmp
1154
+
1155
+ # Additional elementwise algorithm input validation / standardization
1156
+ tmp = eim._initialize(f, (a,), args, complex_ok=False, xp=xp)
1157
+ f, xs, fs, args, shape, dtype, xp = tmp
1158
+
1159
+ # Finish preparing `a`, `b`, and `step` arrays
1160
+ a = xs[0]
1161
+ b = xp.astype(xp_ravel(xp.broadcast_to(b, shape)), dtype)
1162
+ step = xp.astype(xp_ravel(xp.broadcast_to(step, shape)), dtype)
1163
+ valid_abstep = xp_ravel(xp.broadcast_to(valid_abstep, shape))
1164
+ nterms = xp.floor((b - a) / step)
1165
+ finite_terms = xp.isfinite(nterms)
1166
+ b[finite_terms] = a[finite_terms] + nterms[finite_terms]*step[finite_terms]
1167
+
1168
+ # Define constants
1169
+ eps = xp.finfo(dtype).eps
1170
+ zero = xp.asarray(-xp.inf if log else 0, dtype=dtype)[()]
1171
+ if rtol is None:
1172
+ rtol = 0.5*math.log(eps) if log else eps**0.5
1173
+ constants = (dtype, log, eps, zero, rtol, atol, maxterms)
1174
+
1175
+ # Prepare result arrays
1176
+ S = xp.empty_like(a)
1177
+ E = xp.empty_like(a)
1178
+ status = xp.zeros(len(a), dtype=xp.int32)
1179
+ nfev = xp.ones(len(a), dtype=xp.int32) # one function evaluation above
1180
+
1181
+ # Branch for direct sum evaluation / integral approximation / invalid input
1182
+ i0 = ~valid_abstep # invalid
1183
+ i0b = b < a # zero
1184
+ i1 = (nterms + 1 <= maxterms) & ~i0 # direct sum evaluation
1185
+ i2 = xp.isfinite(a) & ~i1 & ~i0 # infinite sum to the right
1186
+ i3 = xp.isfinite(b) & ~i2 & ~i1 & ~i0 # infinite sum to the left
1187
+ i4 = ~i3 & ~i2 & ~i1 & ~i0 # infinite sum on both sides
1188
+
1189
+ if xp.any(i0):
1190
+ S[i0], E[i0] = xp.nan, xp.nan
1191
+ status[i0] = -1
1192
+
1193
+ S[i0b], E[i0b] = zero, zero
1194
+ status[i0b] = 0
1195
+
1196
+ if xp.any(i1):
1197
+ args_direct = [arg[i1] for arg in args]
1198
+ tmp = _direct(f, a[i1], b[i1], step[i1], args_direct, constants, xp)
1199
+ S[i1], E[i1] = tmp[:-1]
1200
+ nfev[i1] += tmp[-1]
1201
+ status[i1] = -3 * xp.asarray(~xp.isfinite(S[i1]), dtype=xp.int32)
1202
+
1203
+ if xp.any(i2):
1204
+ args_indirect = [arg[i2] for arg in args]
1205
+ tmp = _integral_bound(f, a[i2], b[i2], step[i2],
1206
+ args_indirect, constants, xp)
1207
+ S[i2], E[i2], status[i2] = tmp[:-1]
1208
+ nfev[i2] += tmp[-1]
1209
+
1210
+ if xp.any(i3):
1211
+ args_indirect = [arg[i3] for arg in args]
1212
+ def _f(x, *args): return f(-x, *args)
1213
+ tmp = _integral_bound(_f, -b[i3], -a[i3], step[i3],
1214
+ args_indirect, constants, xp)
1215
+ S[i3], E[i3], status[i3] = tmp[:-1]
1216
+ nfev[i3] += tmp[-1]
1217
+
1218
+ if xp.any(i4):
1219
+ args_indirect = [arg[i4] for arg in args]
1220
+
1221
+ # There are two obvious high-level strategies:
1222
+ # - Do two separate half-infinite sums (e.g. from -inf to 0 and 1 to inf)
1223
+ # - Make a callable that returns f(x) + f(-x) and do a single half-infinite sum
1224
+ # I thought the latter would have about half the overhead, so I went that way.
1225
+ # Then there are two ways of ensuring that f(0) doesn't get counted twice.
1226
+ # - Evaluate the sum from 1 to inf and add f(0)
1227
+ # - Evaluate the sum from 0 to inf and subtract f(0)
1228
+ # - Evaluate the sum from 0 to inf, but apply a weight of 0.5 when `x = 0`
1229
+ # The last option has more overhead, but is simpler to implement correctly
1230
+ # (especially getting the status message right)
1231
+ if log:
1232
+ def _f(x, *args):
1233
+ log_factor = xp.where(x==0, math.log(0.5), 0)
1234
+ out = xp.stack([f(x, *args), f(-x, *args)], axis=0)
1235
+ return special.logsumexp(out, axis=0) + log_factor
1236
+
1237
+ else:
1238
+ def _f(x, *args):
1239
+ factor = xp.where(x==0, 0.5, 1)
1240
+ return (f(x, *args) + f(-x, *args)) * factor
1241
+
1242
+ zero = xp.zeros_like(a[i4])
1243
+ tmp = _integral_bound(_f, zero, b[i4], step[i4], args_indirect, constants, xp)
1244
+ S[i4], E[i4], status[i4] = tmp[:-1]
1245
+ nfev[i4] += 2*tmp[-1]
1246
+
1247
+ # Return results
1248
+ S, E = S.reshape(shape)[()], E.reshape(shape)[()]
1249
+ status, nfev = status.reshape(shape)[()], nfev.reshape(shape)[()]
1250
+ return _RichResult(sum=S, error=E, status=status, success=status == 0,
1251
+ nfev=nfev)
1252
+
1253
+
1254
+ def _direct(f, a, b, step, args, constants, xp, inclusive=True):
1255
+ # Directly evaluate the sum.
1256
+
1257
+ # When used in the context of distributions, `args` would contain the
1258
+ # distribution parameters. We have broadcasted for simplicity, but we could
1259
+ # reduce function evaluations when distribution parameters are the same but
1260
+ # sum limits differ. Roughly:
1261
+ # - compute the function at all points between min(a) and max(b),
1262
+ # - compute the cumulative sum,
1263
+ # - take the difference between elements of the cumulative sum
1264
+ # corresponding with b and a.
1265
+ # This is left to future enhancement
1266
+
1267
+ dtype, log, eps, zero, _, _, _ = constants
1268
+
1269
+ # To allow computation in a single vectorized call, find the maximum number
1270
+ # of points (over all slices) at which the function needs to be evaluated.
1271
+ # Note: if `inclusive` is `True`, then we want `1` more term in the sum.
1272
+ # I didn't think it was great style to use `True` as `1` in Python, so I
1273
+ # explicitly converted it to an `int` before using it.
1274
+ inclusive_adjustment = int(inclusive)
1275
+ steps = xp.round((b - a) / step) + inclusive_adjustment
1276
+ # Equivalently, steps = xp.round((b - a) / step) + inclusive
1277
+ max_steps = int(xp.max(steps))
1278
+
1279
+ # In each slice, the function will be evaluated at the same number of points,
1280
+ # but excessive points (those beyond the right sum limit `b`) are replaced
1281
+ # with NaN to (potentially) reduce the time of these unnecessary calculations.
1282
+ # Use a new last axis for these calculations for consistency with other
1283
+ # elementwise algorithms.
1284
+ a2, b2, step2 = a[:, xp.newaxis], b[:, xp.newaxis], step[:, xp.newaxis]
1285
+ args2 = [arg[:, xp.newaxis] for arg in args]
1286
+ ks = a2 + xp.arange(max_steps, dtype=dtype) * step2
1287
+ i_nan = ks >= (b2 + inclusive_adjustment*step2/2)
1288
+ ks[i_nan] = xp.nan
1289
+ fs = f(ks, *args2)
1290
+
1291
+ # The function evaluated at NaN is NaN, and NaNs are zeroed in the sum.
1292
+ # In some cases it may be faster to loop over slices than to vectorize
1293
+ # like this. This is an optimization that can be added later.
1294
+ fs[i_nan] = zero
1295
+ nfev = max_steps - i_nan.sum(axis=-1)
1296
+ S = special.logsumexp(fs, axis=-1) if log else xp.sum(fs, axis=-1)
1297
+ # Rough, non-conservative error estimate. See gh-19667 for improvement ideas.
1298
+ E = xp.real(S) + math.log(eps) if log else eps * abs(S)
1299
+ return S, E, nfev
1300
+
1301
+
1302
+ def _integral_bound(f, a, b, step, args, constants, xp):
1303
+ # Estimate the sum with integral approximation
1304
+ dtype, log, _, _, rtol, atol, maxterms = constants
1305
+ log2 = xp.asarray(math.log(2), dtype=dtype)
1306
+
1307
+ # Get a lower bound on the sum and compute effective absolute tolerance
1308
+ lb = tanhsinh(f, a, b, args=args, atol=atol, rtol=rtol, log=log)
1309
+ tol = xp.broadcast_to(xp.asarray(atol), lb.integral.shape)
1310
+ if log:
1311
+ tol = special.logsumexp(xp.stack((tol, rtol + lb.integral)), axis=0)
1312
+ else:
1313
+ tol = tol + rtol*lb.integral
1314
+ i_skip = lb.status == -3 # avoid unnecessary f_evals if integral is divergent
1315
+ tol[i_skip] = xp.nan
1316
+ status = lb.status
1317
+
1318
+ # As in `_direct`, we'll need a temporary new axis for points
1319
+ # at which to evaluate the function. Append axis at the end for
1320
+ # consistency with other elementwise algorithms.
1321
+ a2 = a[..., xp.newaxis]
1322
+ step2 = step[..., xp.newaxis]
1323
+ args2 = [arg[..., xp.newaxis] for arg in args]
1324
+
1325
+ # Find the location of a term that is less than the tolerance (if possible)
1326
+ log2maxterms = math.floor(math.log2(maxterms)) if maxterms else 0
1327
+ n_steps = xp.concat((2**xp.arange(0, log2maxterms), xp.asarray([maxterms])))
1328
+ n_steps = xp.astype(n_steps, dtype)
1329
+ nfev = len(n_steps) * 2
1330
+ ks = a2 + n_steps * step2
1331
+ fks = f(ks, *args2)
1332
+ fksp1 = f(ks + step2, *args2) # check that the function is decreasing
1333
+ fk_insufficient = (fks > tol[:, xp.newaxis]) | (fksp1 > fks)
1334
+ n_fk_insufficient = xp.sum(fk_insufficient, axis=-1)
1335
+ nt = xp.minimum(n_fk_insufficient, n_steps.shape[-1]-1)
1336
+ n_steps = n_steps[nt]
1337
+
1338
+ # If `maxterms` is insufficient (i.e. either the magnitude of the last term of the
1339
+ # partial sum exceeds the tolerance or the function is not decreasing), finish the
1340
+ # calculation, but report nonzero status. (Improvement: separate the status codes
1341
+ # for these two cases.)
1342
+ i_fk_insufficient = (n_fk_insufficient == nfev//2)
1343
+
1344
+ # Directly evaluate the sum up to this term
1345
+ k = a + n_steps * step
1346
+ left, left_error, left_nfev = _direct(f, a, k, step, args,
1347
+ constants, xp, inclusive=False)
1348
+ left_is_pos_inf = xp.isinf(left) & (left > 0)
1349
+ i_skip |= left_is_pos_inf # if sum is infinite, no sense in continuing
1350
+ status[left_is_pos_inf] = -3
1351
+ k[i_skip] = xp.nan
1352
+
1353
+ # Use integration to estimate the remaining sum
1354
+ # Possible optimization for future work: if there were no terms less than
1355
+ # the tolerance, there is no need to compute the integral to better accuracy.
1356
+ # Something like:
1357
+ # atol = xp.maximum(atol, xp.minimum(fk/2 - fb/2))
1358
+ # rtol = xp.maximum(rtol, xp.minimum((fk/2 - fb/2)/left))
1359
+ # where `fk`/`fb` are currently calculated below.
1360
+ right = tanhsinh(f, k, b, args=args, atol=atol, rtol=rtol, log=log)
1361
+
1362
+ # Calculate the full estimate and error from the pieces
1363
+ fk = fks[xp.arange(len(fks)), nt]
1364
+
1365
+ # fb = f(b, *args), but some functions return NaN at infinity.
1366
+ # instead of 0 like they must (for the sum to be convergent).
1367
+ fb = xp.full_like(fk, -xp.inf) if log else xp.zeros_like(fk)
1368
+ i = xp.isfinite(b)
1369
+ if xp.any(i): # better not call `f` with empty arrays
1370
+ fb[i] = f(b[i], *[arg[i] for arg in args])
1371
+ nfev = nfev + xp.asarray(i, dtype=left_nfev.dtype)
1372
+
1373
+ if log:
1374
+ log_step = xp.log(step)
1375
+ S_terms = (left, right.integral - log_step, fk - log2, fb - log2)
1376
+ S = special.logsumexp(xp.stack(S_terms), axis=0)
1377
+ E_terms = (left_error, right.error - log_step, fk-log2, fb-log2+xp.pi*1j)
1378
+ E = xp.real(special.logsumexp(xp.stack(E_terms), axis=0))
1379
+ else:
1380
+ S = left + right.integral/step + fk/2 + fb/2
1381
+ E = left_error + right.error/step + fk/2 - fb/2
1382
+ status[~i_skip] = right.status[~i_skip]
1383
+
1384
+ status[(status == 0) & i_fk_insufficient] = -4
1385
+ return S, E, status, left_nfev + right.nfev + nfev + lb.nfev