scipy 1.16.2__cp313-cp313t-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.cp313t-win_arm64.lib +0 -0
  4. scipy/_cyutility.cp313t-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.cp313t-win_arm64.lib +0 -0
  13. scipy/_lib/_ccallback_c.cp313t-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.cp313t-win_arm64.lib +0 -0
  18. scipy/_lib/_fpumode.cp313t-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.cp313t-win_arm64.lib +0 -0
  23. scipy/_lib/_test_ccallback.cp313t-win_arm64.pyd +0 -0
  24. scipy/_lib/_test_deprecation_call.cp313t-win_arm64.lib +0 -0
  25. scipy/_lib/_test_deprecation_call.cp313t-win_arm64.pyd +0 -0
  26. scipy/_lib/_test_deprecation_def.cp313t-win_arm64.lib +0 -0
  27. scipy/_lib/_test_deprecation_def.cp313t-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.cp313t-win_arm64.lib +0 -0
  35. scipy/_lib/_uarray/_uarray.cp313t-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.cp313t-win_arm64.lib +0 -0
  101. scipy/_lib/messagestream.cp313t-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.cp313t-win_arm64.lib +0 -0
  148. scipy/cluster/_hierarchy.cp313t-win_arm64.pyd +0 -0
  149. scipy/cluster/_optimal_leaf_ordering.cp313t-win_arm64.lib +0 -0
  150. scipy/cluster/_optimal_leaf_ordering.cp313t-win_arm64.pyd +0 -0
  151. scipy/cluster/_vq.cp313t-win_arm64.lib +0 -0
  152. scipy/cluster/_vq.cp313t-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.cp313t-win_arm64.lib +0 -0
  193. scipy/fft/_pocketfft/pypocketfft.cp313t-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.cp313t-win_arm64.lib +0 -0
  215. scipy/fftpack/convolve.cp313t-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.cp313t-win_arm64.lib +0 -0
  233. scipy/integrate/_dop.cp313t-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.cp313t-win_arm64.lib +0 -0
  248. scipy/integrate/_lsoda.cp313t-win_arm64.pyd +0 -0
  249. scipy/integrate/_ode.py +1395 -0
  250. scipy/integrate/_odepack.cp313t-win_arm64.lib +0 -0
  251. scipy/integrate/_odepack.cp313t-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.cp313t-win_arm64.lib +0 -0
  255. scipy/integrate/_quadpack.cp313t-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.cp313t-win_arm64.lib +0 -0
  265. scipy/integrate/_test_multivariate.cp313t-win_arm64.pyd +0 -0
  266. scipy/integrate/_test_odeint_banded.cp313t-win_arm64.lib +0 -0
  267. scipy/integrate/_test_odeint_banded.cp313t-win_arm64.pyd +0 -0
  268. scipy/integrate/_vode.cp313t-win_arm64.lib +0 -0
  269. scipy/integrate/_vode.cp313t-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.cp313t-win_arm64.lib +0 -0
  290. scipy/interpolate/_dfitpack.cp313t-win_arm64.pyd +0 -0
  291. scipy/interpolate/_dierckx.cp313t-win_arm64.lib +0 -0
  292. scipy/interpolate/_dierckx.cp313t-win_arm64.pyd +0 -0
  293. scipy/interpolate/_fitpack.cp313t-win_arm64.lib +0 -0
  294. scipy/interpolate/_fitpack.cp313t-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.cp313t-win_arm64.lib +0 -0
  300. scipy/interpolate/_interpnd.cp313t-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.cp313t-win_arm64.lib +0 -0
  307. scipy/interpolate/_ppoly.cp313t-win_arm64.pyd +0 -0
  308. scipy/interpolate/_rbf.py +290 -0
  309. scipy/interpolate/_rbfinterp.py +550 -0
  310. scipy/interpolate/_rbfinterp_pythran.cp313t-win_arm64.lib +0 -0
  311. scipy/interpolate/_rbfinterp_pythran.cp313t-win_arm64.pyd +0 -0
  312. scipy/interpolate/_rgi.py +764 -0
  313. scipy/interpolate/_rgi_cython.cp313t-win_arm64.lib +0 -0
  314. scipy/interpolate/_rgi_cython.cp313t-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.cp313t-win_arm64.lib +0 -0
  343. scipy/io/_fast_matrix_market/_fmm_core.cp313t-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.cp313t-win_arm64.lib +0 -0
  355. scipy/io/_test_fortran.cp313t-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.cp313t-win_arm64.lib +0 -0
  386. scipy/io/matlab/_mio5_utils.cp313t-win_arm64.pyd +0 -0
  387. scipy/io/matlab/_mio_utils.cp313t-win_arm64.lib +0 -0
  388. scipy/io/matlab/_mio_utils.cp313t-win_arm64.pyd +0 -0
  389. scipy/io/matlab/_miobase.py +435 -0
  390. scipy/io/matlab/_streams.cp313t-win_arm64.lib +0 -0
  391. scipy/io/matlab/_streams.cp313t-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.cp313t-win_arm64.lib +0 -0
  623. scipy/linalg/_cythonized_array_utils.cp313t-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.cp313t-win_arm64.lib +0 -0
  630. scipy/linalg/_decomp_interpolative.cp313t-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.cp313t-win_arm64.lib +0 -0
  634. scipy/linalg/_decomp_lu_cython.cp313t-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.cp313t-win_arm64.lib +0 -0
  642. scipy/linalg/_decomp_update.cp313t-win_arm64.pyd +0 -0
  643. scipy/linalg/_expm_frechet.py +417 -0
  644. scipy/linalg/_fblas.cp313t-win_arm64.lib +0 -0
  645. scipy/linalg/_fblas.cp313t-win_arm64.pyd +0 -0
  646. scipy/linalg/_flapack.cp313t-win_arm64.lib +0 -0
  647. scipy/linalg/_flapack.cp313t-win_arm64.pyd +0 -0
  648. scipy/linalg/_lapack_subroutines.h +1521 -0
  649. scipy/linalg/_linalg_pythran.cp313t-win_arm64.lib +0 -0
  650. scipy/linalg/_linalg_pythran.cp313t-win_arm64.pyd +0 -0
  651. scipy/linalg/_matfuncs.py +1050 -0
  652. scipy/linalg/_matfuncs_expm.cp313t-win_arm64.lib +0 -0
  653. scipy/linalg/_matfuncs_expm.cp313t-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.cp313t-win_arm64.lib +0 -0
  657. scipy/linalg/_matfuncs_schur_sqrtm.cp313t-win_arm64.pyd +0 -0
  658. scipy/linalg/_matfuncs_sqrtm.py +107 -0
  659. scipy/linalg/_matfuncs_sqrtm_triu.cp313t-win_arm64.lib +0 -0
  660. scipy/linalg/_matfuncs_sqrtm_triu.cp313t-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.cp313t-win_arm64.lib +0 -0
  665. scipy/linalg/_solve_toeplitz.cp313t-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.cp313t-win_arm64.lib +0 -0
  672. scipy/linalg/cython_blas.cp313t-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.cp313t-win_arm64.lib +0 -0
  676. scipy/linalg/cython_lapack.cp313t-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.cp313t-win_arm64.lib +0 -0
  728. scipy/ndimage/_ctest.cp313t-win_arm64.pyd +0 -0
  729. scipy/ndimage/_cytest.cp313t-win_arm64.lib +0 -0
  730. scipy/ndimage/_cytest.cp313t-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.cp313t-win_arm64.lib +0 -0
  738. scipy/ndimage/_nd_image.cp313t-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.cp313t-win_arm64.lib +0 -0
  742. scipy/ndimage/_ni_label.cp313t-win_arm64.pyd +0 -0
  743. scipy/ndimage/_ni_support.py +139 -0
  744. scipy/ndimage/_rank_filter_1d.cp313t-win_arm64.lib +0 -0
  745. scipy/ndimage/_rank_filter_1d.cp313t-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.cp313t-win_arm64.lib +0 -0
  768. scipy/odr/__odrpack.cp313t-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.cp313t-win_arm64.lib +0 -0
  780. scipy/optimize/_bglu_dense.cp313t-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.cp313t-win_arm64.lib +0 -0
  790. scipy/optimize/_direct.cp313t-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.cp313t-win_arm64.lib +0 -0
  795. scipy/optimize/_group_columns.cp313t-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.cp313t-win_arm64.lib +0 -0
  799. scipy/optimize/_highspy/_core.cp313t-win_arm64.pyd +0 -0
  800. scipy/optimize/_highspy/_highs_options.cp313t-win_arm64.lib +0 -0
  801. scipy/optimize/_highspy/_highs_options.cp313t-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.cp313t-win_arm64.lib +0 -0
  805. scipy/optimize/_lbfgsb.cp313t-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.cp313t-win_arm64.lib +0 -0
  816. scipy/optimize/_lsap.cp313t-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.cp313t-win_arm64.lib +0 -0
  822. scipy/optimize/_lsq/givens_elimination.cp313t-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.cp313t-win_arm64.lib +0 -0
  830. scipy/optimize/_minpack.cp313t-win_arm64.pyd +0 -0
  831. scipy/optimize/_minpack_py.py +1178 -0
  832. scipy/optimize/_moduleTNC.cp313t-win_arm64.lib +0 -0
  833. scipy/optimize/_moduleTNC.cp313t-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.cp313t-win_arm64.lib +0 -0
  839. scipy/optimize/_pava_pybind.cp313t-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.cp313t-win_arm64.lib +0 -0
  850. scipy/optimize/_slsqplib.cp313t-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.cp313t-win_arm64.lib +0 -0
  855. scipy/optimize/_trlib/_trlib.cp313t-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.cp313t-win_arm64.lib +0 -0
  877. scipy/optimize/_zeros.cp313t-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.cp313t-win_arm64.lib +0 -0
  882. scipy/optimize/cython_optimize/_zeros.cp313t-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.cp313t-win_arm64.lib +0 -0
  953. scipy/signal/_max_len_seq_inner.cp313t-win_arm64.pyd +0 -0
  954. scipy/signal/_peak_finding.py +1310 -0
  955. scipy/signal/_peak_finding_utils.cp313t-win_arm64.lib +0 -0
  956. scipy/signal/_peak_finding_utils.cp313t-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.cp313t-win_arm64.lib +0 -0
  963. scipy/signal/_sigtools.cp313t-win_arm64.pyd +0 -0
  964. scipy/signal/_sosfilt.cp313t-win_arm64.lib +0 -0
  965. scipy/signal/_sosfilt.cp313t-win_arm64.pyd +0 -0
  966. scipy/signal/_spectral_py.py +2471 -0
  967. scipy/signal/_spline.cp313t-win_arm64.lib +0 -0
  968. scipy/signal/_spline.cp313t-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.cp313t-win_arm64.lib +0 -0
  974. scipy/signal/_upfirdn_apply.cp313t-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.cp313t-win_arm64.lib +0 -0
  1021. scipy/sparse/_csparsetools.cp313t-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.cp313t-win_arm64.lib +0 -0
  1032. scipy/sparse/_sparsetools.cp313t-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.cp313t-win_arm64.lib +0 -0
  1043. scipy/sparse/csgraph/_flow.cp313t-win_arm64.pyd +0 -0
  1044. scipy/sparse/csgraph/_laplacian.py +563 -0
  1045. scipy/sparse/csgraph/_matching.cp313t-win_arm64.lib +0 -0
  1046. scipy/sparse/csgraph/_matching.cp313t-win_arm64.pyd +0 -0
  1047. scipy/sparse/csgraph/_min_spanning_tree.cp313t-win_arm64.lib +0 -0
  1048. scipy/sparse/csgraph/_min_spanning_tree.cp313t-win_arm64.pyd +0 -0
  1049. scipy/sparse/csgraph/_reordering.cp313t-win_arm64.lib +0 -0
  1050. scipy/sparse/csgraph/_reordering.cp313t-win_arm64.pyd +0 -0
  1051. scipy/sparse/csgraph/_shortest_path.cp313t-win_arm64.lib +0 -0
  1052. scipy/sparse/csgraph/_shortest_path.cp313t-win_arm64.pyd +0 -0
  1053. scipy/sparse/csgraph/_tools.cp313t-win_arm64.lib +0 -0
  1054. scipy/sparse/csgraph/_tools.cp313t-win_arm64.pyd +0 -0
  1055. scipy/sparse/csgraph/_traversal.cp313t-win_arm64.lib +0 -0
  1056. scipy/sparse/csgraph/_traversal.cp313t-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.cp313t-win_arm64.lib +0 -0
  1079. scipy/sparse/linalg/_dsolve/_superlu.cp313t-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.cp313t-win_arm64.lib +0 -0
  1089. scipy/sparse/linalg/_eigen/arpack/_arpack.cp313t-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.cp313t-win_arm64.lib +0 -0
  1122. scipy/sparse/linalg/_propack/_cpropack.cp313t-win_arm64.pyd +0 -0
  1123. scipy/sparse/linalg/_propack/_dpropack.cp313t-win_arm64.lib +0 -0
  1124. scipy/sparse/linalg/_propack/_dpropack.cp313t-win_arm64.pyd +0 -0
  1125. scipy/sparse/linalg/_propack/_spropack.cp313t-win_arm64.lib +0 -0
  1126. scipy/sparse/linalg/_propack/_spropack.cp313t-win_arm64.pyd +0 -0
  1127. scipy/sparse/linalg/_propack/_zpropack.cp313t-win_arm64.lib +0 -0
  1128. scipy/sparse/linalg/_propack/_zpropack.cp313t-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.cp313t-win_arm64.lib +0 -0
  1170. scipy/spatial/_ckdtree.cp313t-win_arm64.pyd +0 -0
  1171. scipy/spatial/_distance_pybind.cp313t-win_arm64.lib +0 -0
  1172. scipy/spatial/_distance_pybind.cp313t-win_arm64.pyd +0 -0
  1173. scipy/spatial/_distance_wrap.cp313t-win_arm64.lib +0 -0
  1174. scipy/spatial/_distance_wrap.cp313t-win_arm64.pyd +0 -0
  1175. scipy/spatial/_geometric_slerp.py +238 -0
  1176. scipy/spatial/_hausdorff.cp313t-win_arm64.lib +0 -0
  1177. scipy/spatial/_hausdorff.cp313t-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.cp313t-win_arm64.lib +0 -0
  1182. scipy/spatial/_qhull.cp313t-win_arm64.pyd +0 -0
  1183. scipy/spatial/_qhull.pyi +213 -0
  1184. scipy/spatial/_spherical_voronoi.py +341 -0
  1185. scipy/spatial/_voronoi.cp313t-win_arm64.lib +0 -0
  1186. scipy/spatial/_voronoi.cp313t-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.cp313t-win_arm64.lib +0 -0
  1236. scipy/spatial/transform/_rigid_transform.cp313t-win_arm64.pyd +0 -0
  1237. scipy/spatial/transform/_rotation.cp313t-win_arm64.lib +0 -0
  1238. scipy/spatial/transform/_rotation.cp313t-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.cp313t-win_arm64.lib +0 -0
  1252. scipy/special/_comb.cp313t-win_arm64.pyd +0 -0
  1253. scipy/special/_ellip_harm.py +214 -0
  1254. scipy/special/_ellip_harm_2.cp313t-win_arm64.lib +0 -0
  1255. scipy/special/_ellip_harm_2.cp313t-win_arm64.pyd +0 -0
  1256. scipy/special/_gufuncs.cp313t-win_arm64.lib +0 -0
  1257. scipy/special/_gufuncs.cp313t-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.cp313t-win_arm64.lib +0 -0
  1281. scipy/special/_specfun.cp313t-win_arm64.pyd +0 -0
  1282. scipy/special/_special_ufuncs.cp313t-win_arm64.lib +0 -0
  1283. scipy/special/_special_ufuncs.cp313t-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.cp313t-win_arm64.lib +0 -0
  1288. scipy/special/_test_internal.cp313t-win_arm64.pyd +0 -0
  1289. scipy/special/_test_internal.pyi +9 -0
  1290. scipy/special/_testutils.py +321 -0
  1291. scipy/special/_ufuncs.cp313t-win_arm64.lib +0 -0
  1292. scipy/special/_ufuncs.cp313t-win_arm64.pyd +0 -0
  1293. scipy/special/_ufuncs.pyi +522 -0
  1294. scipy/special/_ufuncs.pyx +13173 -0
  1295. scipy/special/_ufuncs_cxx.cp313t-win_arm64.lib +0 -0
  1296. scipy/special/_ufuncs_cxx.cp313t-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.cp313t-win_arm64.lib +0 -0
  1304. scipy/special/cython_special.cp313t-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.cp313t-win_arm64.lib +0 -0
  1376. scipy/stats/_ansari_swilk_statistics.cp313t-win_arm64.pyd +0 -0
  1377. scipy/stats/_axis_nan_policy.py +692 -0
  1378. scipy/stats/_biasedurn.cp313t-win_arm64.lib +0 -0
  1379. scipy/stats/_biasedurn.cp313t-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.cp313t-win_arm64.lib +0 -0
  1404. scipy/stats/_levy_stable/levyst.cp313t-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.cp313t-win_arm64.lib +0 -0
  1418. scipy/stats/_qmc_cy.cp313t-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.cp313t-win_arm64.lib +0 -0
  1422. scipy/stats/_qmvnt_cy.cp313t-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.cp313t-win_arm64.lib +0 -0
  1426. scipy/stats/_rcont/rcont.cp313t-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.cp313t-win_arm64.lib +0 -0
  1433. scipy/stats/_sobol.cp313t-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.cp313t-win_arm64.lib +0 -0
  1437. scipy/stats/_stats.cp313t-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.cp313t-win_arm64.lib +0 -0
  1442. scipy/stats/_stats_pythran.cp313t-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.cp313t-win_arm64.lib +0 -0
  1447. scipy/stats/_unuran/unuran_wrapper.cp313t-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,3147 @@
1
+ """
2
+ Distance computations (:mod:`scipy.spatial.distance`)
3
+ =====================================================
4
+
5
+ .. sectionauthor:: Damian Eads
6
+
7
+ Function reference
8
+ ------------------
9
+
10
+ Distance matrix computation from a collection of raw observation vectors
11
+ stored in a rectangular array.
12
+
13
+ .. autosummary::
14
+ :toctree: generated/
15
+
16
+ pdist -- pairwise distances between observation vectors.
17
+ cdist -- distances between two collections of observation vectors
18
+ squareform -- convert distance matrix to a condensed one and vice versa
19
+ directed_hausdorff -- directed Hausdorff distance between arrays
20
+
21
+ Predicates for checking the validity of distance matrices, both
22
+ condensed and redundant. Also contained in this module are functions
23
+ for computing the number of observations in a distance matrix.
24
+
25
+ .. autosummary::
26
+ :toctree: generated/
27
+
28
+ is_valid_dm -- checks for a valid distance matrix
29
+ is_valid_y -- checks for a valid condensed distance matrix
30
+ num_obs_dm -- # of observations in a distance matrix
31
+ num_obs_y -- # of observations in a condensed distance matrix
32
+
33
+ Distance functions between two numeric vectors ``u`` and ``v``. Computing
34
+ distances over a large collection of vectors is inefficient for these
35
+ functions. Use ``pdist`` for this purpose.
36
+
37
+ .. autosummary::
38
+ :toctree: generated/
39
+
40
+ braycurtis -- the Bray-Curtis distance.
41
+ canberra -- the Canberra distance.
42
+ chebyshev -- the Chebyshev distance.
43
+ cityblock -- the Manhattan distance.
44
+ correlation -- the Correlation distance.
45
+ cosine -- the Cosine distance.
46
+ euclidean -- the Euclidean distance.
47
+ jensenshannon -- the Jensen-Shannon distance.
48
+ mahalanobis -- the Mahalanobis distance.
49
+ minkowski -- the Minkowski distance.
50
+ seuclidean -- the normalized Euclidean distance.
51
+ sqeuclidean -- the squared Euclidean distance.
52
+
53
+ Distance functions between two boolean vectors (representing sets) ``u`` and
54
+ ``v``. As in the case of numerical vectors, ``pdist`` is more efficient for
55
+ computing the distances between all pairs.
56
+
57
+ .. autosummary::
58
+ :toctree: generated/
59
+
60
+ dice -- the Dice dissimilarity.
61
+ hamming -- the Hamming distance.
62
+ jaccard -- the Jaccard distance.
63
+ kulczynski1 -- the Kulczynski 1 distance.
64
+ rogerstanimoto -- the Rogers-Tanimoto dissimilarity.
65
+ russellrao -- the Russell-Rao dissimilarity.
66
+ sokalmichener -- the Sokal-Michener dissimilarity.
67
+ sokalsneath -- the Sokal-Sneath dissimilarity.
68
+ yule -- the Yule dissimilarity.
69
+
70
+ :func:`hamming` also operates over discrete numerical vectors.
71
+ """
72
+
73
+ # Copyright (C) Damian Eads, 2007-2008. New BSD License.
74
+
75
+ __all__ = [
76
+ 'braycurtis',
77
+ 'canberra',
78
+ 'cdist',
79
+ 'chebyshev',
80
+ 'cityblock',
81
+ 'correlation',
82
+ 'cosine',
83
+ 'dice',
84
+ 'directed_hausdorff',
85
+ 'euclidean',
86
+ 'hamming',
87
+ 'is_valid_dm',
88
+ 'is_valid_y',
89
+ 'jaccard',
90
+ 'jensenshannon',
91
+ 'kulczynski1',
92
+ 'mahalanobis',
93
+ 'minkowski',
94
+ 'num_obs_dm',
95
+ 'num_obs_y',
96
+ 'pdist',
97
+ 'rogerstanimoto',
98
+ 'russellrao',
99
+ 'seuclidean',
100
+ 'sokalmichener',
101
+ 'sokalsneath',
102
+ 'sqeuclidean',
103
+ 'squareform',
104
+ 'yule'
105
+ ]
106
+
107
+
108
+ import math
109
+ import warnings
110
+ import dataclasses
111
+ from collections.abc import Callable
112
+ from functools import partial
113
+
114
+ import numpy as np
115
+
116
+ from scipy._lib._array_api import _asarray
117
+ from scipy._lib._util import _asarray_validated, _transition_to_rng
118
+ from scipy._lib import array_api_extra as xpx
119
+ from scipy._lib.deprecation import _deprecated
120
+ from scipy.linalg import norm
121
+ from scipy.special import rel_entr
122
+ from . import _hausdorff, _distance_pybind, _distance_wrap
123
+
124
+
125
+ def _copy_array_if_base_present(a):
126
+ """Copy the array if its base points to a parent array."""
127
+ if a.base is not None:
128
+ return a.copy()
129
+ return a
130
+
131
+
132
+ def _correlation_cdist_wrap(XA, XB, dm, **kwargs):
133
+ XA = XA - XA.mean(axis=1, keepdims=True)
134
+ XB = XB - XB.mean(axis=1, keepdims=True)
135
+ _distance_wrap.cdist_cosine_double_wrap(XA, XB, dm, **kwargs)
136
+
137
+
138
+ def _correlation_pdist_wrap(X, dm, **kwargs):
139
+ X2 = X - X.mean(axis=1, keepdims=True)
140
+ _distance_wrap.pdist_cosine_double_wrap(X2, dm, **kwargs)
141
+
142
+
143
+ def _convert_to_type(X, out_type):
144
+ return np.ascontiguousarray(X, dtype=out_type)
145
+
146
+
147
+ def _nbool_correspond_all(u, v, w=None):
148
+ if u.dtype == v.dtype == bool and w is None:
149
+ not_u = ~u
150
+ not_v = ~v
151
+ nff = (not_u & not_v).sum()
152
+ nft = (not_u & v).sum()
153
+ ntf = (u & not_v).sum()
154
+ ntt = (u & v).sum()
155
+ else:
156
+ dtype = np.result_type(int, u.dtype, v.dtype)
157
+ u = u.astype(dtype)
158
+ v = v.astype(dtype)
159
+ not_u = 1.0 - u
160
+ not_v = 1.0 - v
161
+ if w is not None:
162
+ not_u = w * not_u
163
+ u = w * u
164
+ nff = (not_u * not_v).sum()
165
+ nft = (not_u * v).sum()
166
+ ntf = (u * not_v).sum()
167
+ ntt = (u * v).sum()
168
+ return (nff, nft, ntf, ntt)
169
+
170
+
171
+ def _nbool_correspond_ft_tf(u, v, w=None):
172
+ if u.dtype == v.dtype == bool and w is None:
173
+ not_u = ~u
174
+ not_v = ~v
175
+ nft = (not_u & v).sum()
176
+ ntf = (u & not_v).sum()
177
+ else:
178
+ dtype = np.result_type(int, u.dtype, v.dtype)
179
+ u = u.astype(dtype)
180
+ v = v.astype(dtype)
181
+ not_u = 1.0 - u
182
+ not_v = 1.0 - v
183
+ if w is not None:
184
+ not_u = w * not_u
185
+ u = w * u
186
+ nft = (not_u * v).sum()
187
+ ntf = (u * not_v).sum()
188
+ return (nft, ntf)
189
+
190
+
191
+ def _validate_cdist_input(XA, XB, mA, mB, n, metric_info, **kwargs):
192
+ # get supported types
193
+ types = metric_info.types
194
+ # choose best type
195
+ typ = types[types.index(XA.dtype)] if XA.dtype in types else types[0]
196
+ # validate data
197
+ XA = _convert_to_type(XA, out_type=typ)
198
+ XB = _convert_to_type(XB, out_type=typ)
199
+
200
+ # validate kwargs
201
+ _validate_kwargs = metric_info.validator
202
+ if _validate_kwargs:
203
+ kwargs = _validate_kwargs((XA, XB), mA + mB, n, **kwargs)
204
+ return XA, XB, typ, kwargs
205
+
206
+
207
+ def _validate_weight_with_size(X, m, n, **kwargs):
208
+ w = kwargs.pop('w', None)
209
+ if w is None:
210
+ return kwargs
211
+
212
+ if w.ndim != 1 or w.shape[0] != n:
213
+ raise ValueError("Weights must have same size as input vector. "
214
+ f"{w.shape[0]} vs. {n}")
215
+
216
+ kwargs['w'] = _validate_weights(w)
217
+ return kwargs
218
+
219
+
220
+ def _validate_hamming_kwargs(X, m, n, **kwargs):
221
+ w = kwargs.get('w', np.ones((n,), dtype='double'))
222
+
223
+ if w.ndim != 1 or w.shape[0] != n:
224
+ raise ValueError(f"Weights must have same size as input vector. "
225
+ f"{w.shape[0]} vs. {n}")
226
+
227
+ kwargs['w'] = _validate_weights(w)
228
+ return kwargs
229
+
230
+
231
+ def _validate_mahalanobis_kwargs(X, m, n, **kwargs):
232
+ VI = kwargs.pop('VI', None)
233
+ if VI is None:
234
+ if m <= n:
235
+ # There are fewer observations than the dimension of
236
+ # the observations.
237
+ raise ValueError(
238
+ f"The number of observations ({m}) is too small; "
239
+ f"the covariance matrix is singular. For observations "
240
+ f"with {n} dimensions, at least {n + 1} observations are required.")
241
+ if isinstance(X, tuple):
242
+ X = np.vstack(X)
243
+ CV = np.atleast_2d(np.cov(X.astype(np.float64, copy=False).T))
244
+ VI = np.linalg.inv(CV).T.copy()
245
+ kwargs["VI"] = _convert_to_double(VI)
246
+ return kwargs
247
+
248
+
249
+ def _validate_minkowski_kwargs(X, m, n, **kwargs):
250
+ kwargs = _validate_weight_with_size(X, m, n, **kwargs)
251
+ if 'p' not in kwargs:
252
+ kwargs['p'] = 2.
253
+ else:
254
+ if kwargs['p'] <= 0:
255
+ raise ValueError("p must be greater than 0")
256
+
257
+ return kwargs
258
+
259
+
260
+ def _validate_pdist_input(X, m, n, metric_info, **kwargs):
261
+ # get supported types
262
+ types = metric_info.types
263
+ # choose best type
264
+ typ = types[types.index(X.dtype)] if X.dtype in types else types[0]
265
+ # validate data
266
+ X = _convert_to_type(X, out_type=typ)
267
+
268
+ # validate kwargs
269
+ _validate_kwargs = metric_info.validator
270
+ if _validate_kwargs:
271
+ kwargs = _validate_kwargs(X, m, n, **kwargs)
272
+ return X, typ, kwargs
273
+
274
+
275
+ def _validate_seuclidean_kwargs(X, m, n, **kwargs):
276
+ V = kwargs.pop('V', None)
277
+ if V is None:
278
+ if isinstance(X, tuple):
279
+ X = np.vstack(X)
280
+ V = np.var(X.astype(np.float64, copy=False), axis=0, ddof=1)
281
+ else:
282
+ V = np.asarray(V, order='c')
283
+ if len(V.shape) != 1:
284
+ raise ValueError('Variance vector V must '
285
+ 'be one-dimensional.')
286
+ if V.shape[0] != n:
287
+ raise ValueError('Variance vector V must be of the same '
288
+ 'dimension as the vectors on which the distances '
289
+ 'are computed.')
290
+ kwargs['V'] = _convert_to_double(V)
291
+ return kwargs
292
+
293
+
294
+ def _validate_vector(u, dtype=None):
295
+ # XXX Is order='c' really necessary?
296
+ u = np.asarray(u, dtype=dtype, order='c')
297
+ if u.ndim == 1:
298
+ return u
299
+ raise ValueError("Input vector should be 1-D.")
300
+
301
+
302
+ def _validate_weights(w, dtype=np.float64):
303
+ w = _validate_vector(w, dtype=dtype)
304
+ if np.any(w < 0):
305
+ raise ValueError("Input weights should be all non-negative")
306
+ return w
307
+
308
+
309
+ @_transition_to_rng('seed', position_num=2, replace_doc=False)
310
+ def directed_hausdorff(u, v, rng=0):
311
+ """
312
+ Compute the directed Hausdorff distance between two 2-D arrays.
313
+
314
+ Distances between pairs are calculated using a Euclidean metric.
315
+
316
+ Parameters
317
+ ----------
318
+ u : (M,N) array_like
319
+ Input array with M points in N dimensions.
320
+ v : (O,N) array_like
321
+ Input array with O points in N dimensions.
322
+ rng : int or `numpy.random.Generator` or None, optional
323
+ Pseudorandom number generator state. Default is 0 so the
324
+ shuffling of `u` and `v` is reproducible.
325
+
326
+ If `rng` is passed by keyword, types other than `numpy.random.Generator` are
327
+ passed to `numpy.random.default_rng` to instantiate a ``Generator``.
328
+ If `rng` is already a ``Generator`` instance, then the provided instance is
329
+ used.
330
+
331
+ If this argument is passed by position or `seed` is passed by keyword,
332
+ legacy behavior for the argument `seed` applies:
333
+
334
+ - If `seed` is None, a new ``RandomState`` instance is used. The state is
335
+ initialized using data from ``/dev/urandom`` (or the Windows analogue)
336
+ if available or from the system clock otherwise.
337
+ - If `seed` is an int, a new ``RandomState`` instance is used,
338
+ seeded with `seed`.
339
+ - If `seed` is already a ``Generator`` or ``RandomState`` instance, then
340
+ that instance is used.
341
+
342
+ .. versionchanged:: 1.15.0
343
+ As part of the `SPEC-007 <https://scientific-python.org/specs/spec-0007/>`_
344
+ transition from use of `numpy.random.RandomState` to
345
+ `numpy.random.Generator`, this keyword was changed from `seed` to `rng`.
346
+ For an interim period, both keywords will continue to work, although only
347
+ one may be specified at a time. After the interim period, function calls
348
+ using the `seed` keyword will emit warnings. The behavior of both `seed`
349
+ and `rng` are outlined above, but only the `rng` keyword should be used in
350
+ new code.
351
+
352
+ Returns
353
+ -------
354
+ d : double
355
+ The directed Hausdorff distance between arrays `u` and `v`,
356
+
357
+ index_1 : int
358
+ index of point contributing to Hausdorff pair in `u`
359
+
360
+ index_2 : int
361
+ index of point contributing to Hausdorff pair in `v`
362
+
363
+ Raises
364
+ ------
365
+ ValueError
366
+ An exception is thrown if `u` and `v` do not have
367
+ the same number of columns.
368
+
369
+ See Also
370
+ --------
371
+ scipy.spatial.procrustes : Another similarity test for two data sets
372
+
373
+ Notes
374
+ -----
375
+ Uses the early break technique and the random sampling approach
376
+ described by [1]_. Although worst-case performance is ``O(m * o)``
377
+ (as with the brute force algorithm), this is unlikely in practice
378
+ as the input data would have to require the algorithm to explore
379
+ every single point interaction, and after the algorithm shuffles
380
+ the input points at that. The best case performance is O(m), which
381
+ is satisfied by selecting an inner loop distance that is less than
382
+ cmax and leads to an early break as often as possible. The authors
383
+ have formally shown that the average runtime is closer to O(m).
384
+
385
+ .. versionadded:: 0.19.0
386
+
387
+ References
388
+ ----------
389
+ .. [1] A. A. Taha and A. Hanbury, "An efficient algorithm for
390
+ calculating the exact Hausdorff distance." IEEE Transactions On
391
+ Pattern Analysis And Machine Intelligence, vol. 37 pp. 2153-63,
392
+ 2015.
393
+
394
+ Examples
395
+ --------
396
+ Find the directed Hausdorff distance between two 2-D arrays of
397
+ coordinates:
398
+
399
+ >>> from scipy.spatial.distance import directed_hausdorff
400
+ >>> import numpy as np
401
+ >>> u = np.array([(1.0, 0.0),
402
+ ... (0.0, 1.0),
403
+ ... (-1.0, 0.0),
404
+ ... (0.0, -1.0)])
405
+ >>> v = np.array([(2.0, 0.0),
406
+ ... (0.0, 2.0),
407
+ ... (-2.0, 0.0),
408
+ ... (0.0, -4.0)])
409
+
410
+ >>> directed_hausdorff(u, v)[0]
411
+ 2.23606797749979
412
+ >>> directed_hausdorff(v, u)[0]
413
+ 3.0
414
+
415
+ Find the general (symmetric) Hausdorff distance between two 2-D
416
+ arrays of coordinates:
417
+
418
+ >>> max(directed_hausdorff(u, v)[0], directed_hausdorff(v, u)[0])
419
+ 3.0
420
+
421
+ Find the indices of the points that generate the Hausdorff distance
422
+ (the Hausdorff pair):
423
+
424
+ >>> directed_hausdorff(v, u)[1:]
425
+ (3, 3)
426
+
427
+ """
428
+ u = np.asarray(u, dtype=np.float64, order='c')
429
+ v = np.asarray(v, dtype=np.float64, order='c')
430
+ if u.shape[1] != v.shape[1]:
431
+ raise ValueError('u and v need to have the same '
432
+ 'number of columns')
433
+ result = _hausdorff.directed_hausdorff(u, v, rng)
434
+ return result
435
+
436
+
437
+ def minkowski(u, v, p=2, w=None):
438
+ """
439
+ Compute the Minkowski distance between two 1-D arrays.
440
+
441
+ The Minkowski distance between 1-D arrays `u` and `v`,
442
+ is defined as
443
+
444
+ .. math::
445
+
446
+ {\\|u-v\\|}_p = (\\sum{|u_i - v_i|^p})^{1/p}.
447
+
448
+
449
+ \\left(\\sum{w_i(|(u_i - v_i)|^p)}\\right)^{1/p}.
450
+
451
+ Parameters
452
+ ----------
453
+ u : (N,) array_like
454
+ Input array.
455
+ v : (N,) array_like
456
+ Input array.
457
+ p : scalar
458
+ The order of the norm of the difference :math:`{\\|u-v\\|}_p`. Note
459
+ that for :math:`0 < p < 1`, the triangle inequality only holds with
460
+ an additional multiplicative factor, i.e. it is only a quasi-metric.
461
+ w : (N,) array_like, optional
462
+ The weights for each value in `u` and `v`. Default is None,
463
+ which gives each value a weight of 1.0
464
+
465
+ Returns
466
+ -------
467
+ minkowski : double
468
+ The Minkowski distance between vectors `u` and `v`.
469
+
470
+ Examples
471
+ --------
472
+ >>> from scipy.spatial import distance
473
+ >>> distance.minkowski([1, 0, 0], [0, 1, 0], 1)
474
+ 2.0
475
+ >>> distance.minkowski([1, 0, 0], [0, 1, 0], 2)
476
+ 1.4142135623730951
477
+ >>> distance.minkowski([1, 0, 0], [0, 1, 0], 3)
478
+ 1.2599210498948732
479
+ >>> distance.minkowski([1, 1, 0], [0, 1, 0], 1)
480
+ 1.0
481
+ >>> distance.minkowski([1, 1, 0], [0, 1, 0], 2)
482
+ 1.0
483
+ >>> distance.minkowski([1, 1, 0], [0, 1, 0], 3)
484
+ 1.0
485
+
486
+ """
487
+ u = _validate_vector(u)
488
+ v = _validate_vector(v)
489
+ if p <= 0:
490
+ raise ValueError("p must be greater than 0")
491
+ u_v = u - v
492
+ if w is not None:
493
+ w = _validate_weights(w)
494
+ if p == 1:
495
+ root_w = w
496
+ elif p == 2:
497
+ # better precision and speed
498
+ root_w = np.sqrt(w)
499
+ elif p == np.inf:
500
+ root_w = (w != 0)
501
+ else:
502
+ root_w = np.power(w, 1/p)
503
+ u_v = root_w * u_v
504
+ dist = norm(u_v, ord=p)
505
+ return dist
506
+
507
+
508
+ def euclidean(u, v, w=None):
509
+ """
510
+ Computes the Euclidean distance between two 1-D arrays.
511
+
512
+ The Euclidean distance between 1-D arrays `u` and `v`, is defined as
513
+
514
+ .. math::
515
+
516
+ {\\|u-v\\|}_2
517
+
518
+ \\left(\\sum{(w_i |(u_i - v_i)|^2)}\\right)^{1/2}
519
+
520
+ Parameters
521
+ ----------
522
+ u : (N,) array_like
523
+ Input array.
524
+ v : (N,) array_like
525
+ Input array.
526
+ w : (N,) array_like, optional
527
+ The weights for each value in `u` and `v`. Default is None,
528
+ which gives each value a weight of 1.0
529
+
530
+ Returns
531
+ -------
532
+ euclidean : double
533
+ The Euclidean distance between vectors `u` and `v`.
534
+
535
+ Examples
536
+ --------
537
+ >>> from scipy.spatial import distance
538
+ >>> distance.euclidean([1, 0, 0], [0, 1, 0])
539
+ 1.4142135623730951
540
+ >>> distance.euclidean([1, 1, 0], [0, 1, 0])
541
+ 1.0
542
+
543
+ """
544
+ return minkowski(u, v, p=2, w=w)
545
+
546
+
547
+ def sqeuclidean(u, v, w=None):
548
+ """
549
+ Compute the squared Euclidean distance between two 1-D arrays.
550
+
551
+ The squared Euclidean distance between `u` and `v` is defined as
552
+
553
+ .. math::
554
+
555
+ \\sum_i{w_i |u_i - v_i|^2}
556
+
557
+ Parameters
558
+ ----------
559
+ u : (N,) array_like
560
+ Input array.
561
+ v : (N,) array_like
562
+ Input array.
563
+ w : (N,) array_like, optional
564
+ The weights for each value in `u` and `v`. Default is None,
565
+ which gives each value a weight of 1.0
566
+
567
+ Returns
568
+ -------
569
+ sqeuclidean : double
570
+ The squared Euclidean distance between vectors `u` and `v`.
571
+
572
+ Examples
573
+ --------
574
+ >>> from scipy.spatial import distance
575
+ >>> distance.sqeuclidean([1, 0, 0], [0, 1, 0])
576
+ 2.0
577
+ >>> distance.sqeuclidean([1, 1, 0], [0, 1, 0])
578
+ 1.0
579
+
580
+ """
581
+ # Preserve float dtypes, but convert everything else to np.float64
582
+ # for stability.
583
+ utype, vtype = None, None
584
+ if not (hasattr(u, "dtype") and np.issubdtype(u.dtype, np.inexact)):
585
+ utype = np.float64
586
+ if not (hasattr(v, "dtype") and np.issubdtype(v.dtype, np.inexact)):
587
+ vtype = np.float64
588
+
589
+ u = _validate_vector(u, dtype=utype)
590
+ v = _validate_vector(v, dtype=vtype)
591
+ u_v = u - v
592
+ u_v_w = u_v # only want weights applied once
593
+ if w is not None:
594
+ w = _validate_weights(w)
595
+ u_v_w = w * u_v
596
+ return np.dot(u_v, u_v_w)
597
+
598
+
599
+ def correlation(u, v, w=None, centered=True):
600
+ """
601
+ Compute the correlation distance between two 1-D arrays.
602
+
603
+ The correlation distance between `u` and `v`, is
604
+ defined as
605
+
606
+ .. math::
607
+
608
+ 1 - \\frac{(u - \\bar{u}) \\cdot (v - \\bar{v})}
609
+ {{\\|(u - \\bar{u})\\|}_2 {\\|(v - \\bar{v})\\|}_2}
610
+
611
+ where :math:`\\bar{u}` is the mean of the elements of `u`
612
+ and :math:`x \\cdot y` is the dot product of :math:`x` and :math:`y`.
613
+
614
+ Parameters
615
+ ----------
616
+ u : (N,) array_like of floats
617
+ Input array.
618
+
619
+ .. deprecated:: 1.15.0
620
+ Complex `u` is deprecated and will raise an error in SciPy 1.17.0
621
+ v : (N,) array_like of floats
622
+ Input array.
623
+
624
+ .. deprecated:: 1.15.0
625
+ Complex `v` is deprecated and will raise an error in SciPy 1.17.0
626
+ w : (N,) array_like of floats, optional
627
+ The weights for each value in `u` and `v`. Default is None,
628
+ which gives each value a weight of 1.0
629
+ centered : bool, optional
630
+ If True, `u` and `v` will be centered. Default is True.
631
+
632
+ Returns
633
+ -------
634
+ correlation : double
635
+ The correlation distance between 1-D array `u` and `v`.
636
+
637
+ Examples
638
+ --------
639
+ Find the correlation between two arrays.
640
+
641
+ >>> from scipy.spatial.distance import correlation
642
+ >>> correlation([1, 0, 1], [1, 1, 0])
643
+ 1.5
644
+
645
+ Using a weighting array, the correlation can be calculated as:
646
+
647
+ >>> correlation([1, 0, 1], [1, 1, 0], w=[0.9, 0.1, 0.1])
648
+ 1.1
649
+
650
+ If centering is not needed, the correlation can be calculated as:
651
+
652
+ >>> correlation([1, 0, 1], [1, 1, 0], centered=False)
653
+ 0.5
654
+ """
655
+ u = _validate_vector(u)
656
+ v = _validate_vector(v)
657
+ if np.iscomplexobj(u) or np.iscomplexobj(v):
658
+ message = (
659
+ "Complex `u` and `v` are deprecated and will raise an error in "
660
+ "SciPy 1.17.0.")
661
+ warnings.warn(message, DeprecationWarning, stacklevel=2)
662
+ if w is not None:
663
+ w = _validate_weights(w)
664
+ w = w / w.sum()
665
+ if centered:
666
+ if w is not None:
667
+ umu = np.dot(u, w)
668
+ vmu = np.dot(v, w)
669
+ else:
670
+ umu = np.mean(u)
671
+ vmu = np.mean(v)
672
+ u = u - umu
673
+ v = v - vmu
674
+ if w is not None:
675
+ vw = v * w
676
+ uw = u * w
677
+ else:
678
+ vw, uw = v, u
679
+ uv = np.dot(u, vw)
680
+ uu = np.dot(u, uw)
681
+ vv = np.dot(v, vw)
682
+ dist = 1.0 - uv / math.sqrt(uu * vv)
683
+ # Clip the result to avoid rounding error
684
+ return np.clip(dist, 0.0, 2.0)
685
+
686
+
687
+ def cosine(u, v, w=None):
688
+ """
689
+ Compute the Cosine distance between 1-D arrays.
690
+
691
+ The Cosine distance between `u` and `v`, is defined as
692
+
693
+ .. math::
694
+
695
+ 1 - \\frac{u \\cdot v}
696
+ {\\|u\\|_2 \\|v\\|_2}.
697
+
698
+ where :math:`u \\cdot v` is the dot product of :math:`u` and
699
+ :math:`v`.
700
+
701
+ Parameters
702
+ ----------
703
+ u : (N,) array_like of floats
704
+ Input array.
705
+
706
+ .. deprecated:: 1.15.0
707
+ Complex `u` is deprecated and will raise an error in SciPy 1.17.0
708
+ v : (N,) array_like of floats
709
+ Input array.
710
+
711
+ .. deprecated:: 1.15.0
712
+ Complex `v` is deprecated and will raise an error in SciPy 1.17.0
713
+ w : (N,) array_like of floats, optional
714
+ The weights for each value in `u` and `v`. Default is None,
715
+ which gives each value a weight of 1.0
716
+
717
+ Returns
718
+ -------
719
+ cosine : double
720
+ The Cosine distance between vectors `u` and `v`.
721
+
722
+ Examples
723
+ --------
724
+ >>> from scipy.spatial import distance
725
+ >>> distance.cosine([1, 0, 0], [0, 1, 0])
726
+ 1.0
727
+ >>> distance.cosine([100, 0, 0], [0, 1, 0])
728
+ 1.0
729
+ >>> distance.cosine([1, 1, 0], [0, 1, 0])
730
+ 0.29289321881345254
731
+
732
+ """
733
+ # cosine distance is also referred to as 'uncentered correlation',
734
+ # or 'reflective correlation'
735
+ return correlation(u, v, w=w, centered=False)
736
+
737
+
738
+ def hamming(u, v, w=None):
739
+ """
740
+ Compute the Hamming distance between two 1-D arrays.
741
+
742
+ The Hamming distance between 1-D arrays `u` and `v`, is simply the
743
+ proportion of disagreeing components in `u` and `v`. If `u` and `v` are
744
+ boolean vectors, the Hamming distance is
745
+
746
+ .. math::
747
+
748
+ \\frac{c_{01} + c_{10}}{n}
749
+
750
+ where :math:`c_{ij}` is the number of occurrences of
751
+ :math:`\\mathtt{u[k]} = i` and :math:`\\mathtt{v[k]} = j` for
752
+ :math:`k < n`.
753
+
754
+ Parameters
755
+ ----------
756
+ u : (N,) array_like
757
+ Input array.
758
+ v : (N,) array_like
759
+ Input array.
760
+ w : (N,) array_like, optional
761
+ The weights for each value in `u` and `v`. Default is None,
762
+ which gives each value a weight of 1.0
763
+
764
+ Returns
765
+ -------
766
+ hamming : double
767
+ The Hamming distance between vectors `u` and `v`.
768
+
769
+ Examples
770
+ --------
771
+ >>> from scipy.spatial import distance
772
+ >>> distance.hamming([1, 0, 0], [0, 1, 0])
773
+ 0.66666666666666663
774
+ >>> distance.hamming([1, 0, 0], [1, 1, 0])
775
+ 0.33333333333333331
776
+ >>> distance.hamming([1, 0, 0], [2, 0, 0])
777
+ 0.33333333333333331
778
+ >>> distance.hamming([1, 0, 0], [3, 0, 0])
779
+ 0.33333333333333331
780
+
781
+ """
782
+ u = _validate_vector(u)
783
+ v = _validate_vector(v)
784
+ if u.shape != v.shape:
785
+ raise ValueError('The 1d arrays must have equal lengths.')
786
+ u_ne_v = u != v
787
+ if w is not None:
788
+ w = _validate_weights(w)
789
+ if w.shape != u.shape:
790
+ raise ValueError("'w' should have the same length as 'u' and 'v'.")
791
+ w = w / w.sum()
792
+ return np.dot(u_ne_v, w)
793
+ return np.mean(u_ne_v)
794
+
795
+
796
+ def jaccard(u, v, w=None):
797
+ r"""
798
+ Compute the Jaccard dissimilarity between two boolean vectors.
799
+
800
+ Given boolean vectors :math:`u \equiv (u_1, \cdots, u_n)`
801
+ and :math:`v \equiv (v_1, \cdots, v_n)` that are not both zero,
802
+ their *Jaccard dissimilarity* is defined as ([1]_, p. 26)
803
+
804
+ .. math::
805
+
806
+ d_\textrm{jaccard}(u, v) := \frac{c_{10} + c_{01}}
807
+ {c_{11} + c_{10} + c_{01}}
808
+
809
+ where
810
+
811
+ .. math::
812
+
813
+ c_{ij} := \sum_{1 \le k \le n, u_k=i, v_k=j} 1
814
+
815
+ for :math:`i, j \in \{ 0, 1\}`. If :math:`u` and :math:`v` are both zero,
816
+ their Jaccard dissimilarity is defined to be zero. [2]_
817
+
818
+ If a (non-negative) weight vector :math:`w \equiv (w_1, \cdots, w_n)`
819
+ is supplied, the *weighted Jaccard dissimilarity* is defined similarly
820
+ but with :math:`c_{ij}` replaced by
821
+
822
+ .. math::
823
+
824
+ \tilde{c}_{ij} := \sum_{1 \le k \le n, u_k=i, v_k=j} w_k
825
+
826
+ Parameters
827
+ ----------
828
+ u : (N,) array_like of bools
829
+ Input vector.
830
+ v : (N,) array_like of bools
831
+ Input vector.
832
+ w : (N,) array_like of floats, optional
833
+ Weights for each pair of :math:`(u_k, v_k)`. Default is ``None``,
834
+ which gives each pair a weight of ``1.0``.
835
+
836
+ Returns
837
+ -------
838
+ jaccard : float
839
+ The Jaccard dissimilarity between vectors `u` and `v`, optionally
840
+ weighted by `w` if supplied.
841
+
842
+ Notes
843
+ -----
844
+ The Jaccard dissimilarity satisfies the triangle inequality and is
845
+ qualified as a metric. [2]_
846
+
847
+ The *Jaccard index*, or *Jaccard similarity coefficient*, is equal to
848
+ one minus the Jaccard dissimilarity. [3]_
849
+
850
+ The dissimilarity between general (finite) sets may be computed by
851
+ encoding them as boolean vectors and computing the dissimilarity
852
+ between the encoded vectors.
853
+ For example, subsets :math:`A,B` of :math:`\{ 1, 2, ..., n \}` may be
854
+ encoded into boolean vectors :math:`u, v` by setting
855
+ :math:`u_k := 1_{k \in A}`, :math:`v_k := 1_{k \in B}`
856
+ for :math:`k = 1,2,\cdots,n`.
857
+
858
+ .. versionchanged:: 1.2.0
859
+ Previously, if all (positively weighted) elements in `u` and `v` are
860
+ zero, the function would return ``nan``. This was changed to return
861
+ ``0`` instead.
862
+
863
+ .. versionchanged:: 1.15.0
864
+ Non-0/1 numeric input used to produce an ad hoc result. Since 1.15.0,
865
+ numeric input is converted to Boolean before computation.
866
+
867
+ References
868
+ ----------
869
+ .. [1] Kaufman, L. and Rousseeuw, P. J. (1990). "Finding Groups in Data:
870
+ An Introduction to Cluster Analysis." John Wiley & Sons, Inc.
871
+ .. [2] Kosub, S. (2019). "A note on the triangle inequality for the
872
+ Jaccard distance." *Pattern Recognition Letters*, 120:36-38.
873
+ .. [3] https://en.wikipedia.org/wiki/Jaccard_index
874
+
875
+ Examples
876
+ --------
877
+ >>> from scipy.spatial import distance
878
+
879
+ Non-zero vectors with no matching 1s have dissimilarity of 1.0:
880
+
881
+ >>> distance.jaccard([1, 0, 0], [0, 1, 0])
882
+ 1.0
883
+
884
+ Vectors with some matching 1s have dissimilarity less than 1.0:
885
+
886
+ >>> distance.jaccard([1, 0, 0, 0], [1, 1, 1, 0])
887
+ 0.6666666666666666
888
+
889
+ Identical vectors, including zero vectors, have dissimilarity of 0.0:
890
+
891
+ >>> distance.jaccard([1, 0, 0], [1, 0, 0])
892
+ 0.0
893
+ >>> distance.jaccard([0, 0, 0], [0, 0, 0])
894
+ 0.0
895
+
896
+ The following example computes the dissimilarity from a confusion matrix
897
+ directly by setting the weight vector to the frequency of True Positive,
898
+ False Negative, False Positive, and True Negative:
899
+
900
+ >>> distance.jaccard([1, 1, 0, 0], [1, 0, 1, 0], [31, 41, 59, 26])
901
+ 0.7633587786259542 # (41+59)/(31+41+59)
902
+
903
+ """
904
+ u = _validate_vector(u)
905
+ v = _validate_vector(v)
906
+
907
+ unequal = np.bitwise_xor(u != 0, v != 0)
908
+ nonzero = np.bitwise_or(u != 0, v != 0)
909
+ if w is not None:
910
+ w = _validate_weights(w)
911
+ unequal = w * unequal
912
+ nonzero = w * nonzero
913
+ a = np.float64(unequal.sum())
914
+ b = np.float64(nonzero.sum())
915
+ return (a / b) if b != 0 else np.float64(0)
916
+
917
+
918
+ _deprecated_kulczynski1 = _deprecated(
919
+ "The kulczynski1 metric is deprecated since SciPy 1.15.0 and will be "
920
+ "removed in SciPy 1.17.0. Replace usage of 'kulczynski1(u, v)' with "
921
+ "'1/jaccard(u, v) - 1'."
922
+ )
923
+
924
+
925
+ @_deprecated_kulczynski1
926
+ def kulczynski1(u, v, *, w=None):
927
+ """
928
+ Compute the Kulczynski 1 dissimilarity between two boolean 1-D arrays.
929
+
930
+ .. deprecated:: 1.15.0
931
+ This function is deprecated and will be removed in SciPy 1.17.0.
932
+ Replace usage of ``kulczynski1(u, v)`` with ``1/jaccard(u, v) - 1``.
933
+
934
+ The Kulczynski 1 dissimilarity between two boolean 1-D arrays `u` and `v`
935
+ of length ``n``, is defined as
936
+
937
+ .. math::
938
+
939
+ \\frac{c_{11}}
940
+ {c_{01} + c_{10}}
941
+
942
+ where :math:`c_{ij}` is the number of occurrences of
943
+ :math:`\\mathtt{u[k]} = i` and :math:`\\mathtt{v[k]} = j` for
944
+ :math:`k \\in {0, 1, ..., n-1}`.
945
+
946
+ Parameters
947
+ ----------
948
+ u : (N,) array_like, bool
949
+ Input array.
950
+ v : (N,) array_like, bool
951
+ Input array.
952
+ w : (N,) array_like, optional
953
+ The weights for each value in `u` and `v`. Default is None,
954
+ which gives each value a weight of 1.0
955
+
956
+ Returns
957
+ -------
958
+ kulczynski1 : float
959
+ The Kulczynski 1 distance between vectors `u` and `v`.
960
+
961
+ Notes
962
+ -----
963
+ This measure has a minimum value of 0 and no upper limit.
964
+ It is un-defined when there are no non-matches.
965
+
966
+ .. versionadded:: 1.8.0
967
+
968
+ References
969
+ ----------
970
+ .. [1] Kulczynski S. et al. Bulletin
971
+ International de l'Academie Polonaise des Sciences
972
+ et des Lettres, Classe des Sciences Mathematiques
973
+ et Naturelles, Serie B (Sciences Naturelles). 1927;
974
+ Supplement II: 57-203.
975
+
976
+ Examples
977
+ --------
978
+ >>> from scipy.spatial import distance
979
+ >>> distance.kulczynski1([1, 0, 0], [0, 1, 0])
980
+ 0.0
981
+ >>> distance.kulczynski1([True, False, False], [True, True, False])
982
+ 1.0
983
+ >>> distance.kulczynski1([True, False, False], [True])
984
+ 0.5
985
+ >>> distance.kulczynski1([1, 0, 0], [3, 1, 0])
986
+ -3.0
987
+
988
+ """
989
+ u = _validate_vector(u)
990
+ v = _validate_vector(v)
991
+ if w is not None:
992
+ w = _validate_weights(w)
993
+ (_, nft, ntf, ntt) = _nbool_correspond_all(u, v, w=w)
994
+
995
+ return ntt / (ntf + nft)
996
+
997
+
998
+ def seuclidean(u, v, V):
999
+ """
1000
+ Return the standardized Euclidean distance between two 1-D arrays.
1001
+
1002
+ The standardized Euclidean distance between two n-vectors `u` and `v` is
1003
+
1004
+ .. math::
1005
+
1006
+ \\sqrt{\\sum\\limits_i \\frac{1}{V_i} \\left(u_i-v_i \\right)^2}
1007
+
1008
+ ``V`` is the variance vector; ``V[I]`` is the variance computed over all the i-th
1009
+ components of the points. If not passed, it is automatically computed.
1010
+
1011
+ Parameters
1012
+ ----------
1013
+ u : (N,) array_like
1014
+ Input array.
1015
+ v : (N,) array_like
1016
+ Input array.
1017
+ V : (N,) array_like
1018
+ `V` is an 1-D array of component variances. It is usually computed
1019
+ among a larger collection of vectors.
1020
+
1021
+ Returns
1022
+ -------
1023
+ seuclidean : double
1024
+ The standardized Euclidean distance between vectors `u` and `v`.
1025
+
1026
+ Examples
1027
+ --------
1028
+ >>> from scipy.spatial import distance
1029
+ >>> distance.seuclidean([1, 0, 0], [0, 1, 0], [0.1, 0.1, 0.1])
1030
+ 4.4721359549995796
1031
+ >>> distance.seuclidean([1, 0, 0], [0, 1, 0], [1, 0.1, 0.1])
1032
+ 3.3166247903553998
1033
+ >>> distance.seuclidean([1, 0, 0], [0, 1, 0], [10, 0.1, 0.1])
1034
+ 3.1780497164141406
1035
+
1036
+ """
1037
+ u = _validate_vector(u)
1038
+ v = _validate_vector(v)
1039
+ V = _validate_vector(V, dtype=np.float64)
1040
+ if V.shape[0] != u.shape[0] or u.shape[0] != v.shape[0]:
1041
+ raise TypeError('V must be a 1-D array of the same dimension '
1042
+ 'as u and v.')
1043
+ return euclidean(u, v, w=1/V)
1044
+
1045
+
1046
+ def cityblock(u, v, w=None):
1047
+ """
1048
+ Compute the City Block (Manhattan) distance.
1049
+
1050
+ Computes the Manhattan distance between two 1-D arrays `u` and `v`,
1051
+ which is defined as
1052
+
1053
+ .. math::
1054
+
1055
+ \\sum_i {\\left| u_i - v_i \\right|}.
1056
+
1057
+ Parameters
1058
+ ----------
1059
+ u : (N,) array_like
1060
+ Input array.
1061
+ v : (N,) array_like
1062
+ Input array.
1063
+ w : (N,) array_like, optional
1064
+ The weights for each value in `u` and `v`. Default is None,
1065
+ which gives each value a weight of 1.0
1066
+
1067
+ Returns
1068
+ -------
1069
+ cityblock : double
1070
+ The City Block (Manhattan) distance between vectors `u` and `v`.
1071
+
1072
+ Examples
1073
+ --------
1074
+ >>> from scipy.spatial import distance
1075
+ >>> distance.cityblock([1, 0, 0], [0, 1, 0])
1076
+ 2
1077
+ >>> distance.cityblock([1, 0, 0], [0, 2, 0])
1078
+ 3
1079
+ >>> distance.cityblock([1, 0, 0], [1, 1, 0])
1080
+ 1
1081
+
1082
+ """
1083
+ u = _validate_vector(u)
1084
+ v = _validate_vector(v)
1085
+ l1_diff = abs(u - v)
1086
+ if w is not None:
1087
+ w = _validate_weights(w)
1088
+ l1_diff = w * l1_diff
1089
+ return l1_diff.sum()
1090
+
1091
+
1092
+ def mahalanobis(u, v, VI):
1093
+ """
1094
+ Compute the Mahalanobis distance between two 1-D arrays.
1095
+
1096
+ The Mahalanobis distance between 1-D arrays `u` and `v`, is defined as
1097
+
1098
+ .. math::
1099
+
1100
+ \\sqrt{ (u-v) V^{-1} (u-v)^T }
1101
+
1102
+ where ``V`` is the covariance matrix. Note that the argument `VI`
1103
+ is the inverse of ``V``.
1104
+
1105
+ Parameters
1106
+ ----------
1107
+ u : (N,) array_like
1108
+ Input array.
1109
+ v : (N,) array_like
1110
+ Input array.
1111
+ VI : array_like
1112
+ The inverse of the covariance matrix.
1113
+
1114
+ Returns
1115
+ -------
1116
+ mahalanobis : double
1117
+ The Mahalanobis distance between vectors `u` and `v`.
1118
+
1119
+ Examples
1120
+ --------
1121
+ >>> from scipy.spatial import distance
1122
+ >>> iv = [[1, 0.5, 0.5], [0.5, 1, 0.5], [0.5, 0.5, 1]]
1123
+ >>> distance.mahalanobis([1, 0, 0], [0, 1, 0], iv)
1124
+ 1.0
1125
+ >>> distance.mahalanobis([0, 2, 0], [0, 1, 0], iv)
1126
+ 1.0
1127
+ >>> distance.mahalanobis([2, 0, 0], [0, 1, 0], iv)
1128
+ 1.7320508075688772
1129
+
1130
+ """
1131
+ u = _validate_vector(u)
1132
+ v = _validate_vector(v)
1133
+ VI = np.atleast_2d(VI)
1134
+ delta = u - v
1135
+ m = np.dot(np.dot(delta, VI), delta)
1136
+ return np.sqrt(m)
1137
+
1138
+
1139
+ def chebyshev(u, v, w=None):
1140
+ r"""
1141
+ Compute the Chebyshev distance.
1142
+
1143
+ The *Chebyshev distance* between real vectors
1144
+ :math:`u \equiv (u_1, \cdots, u_n)` and
1145
+ :math:`v \equiv (v_1, \cdots, v_n)` is defined as [1]_
1146
+
1147
+ .. math::
1148
+
1149
+ d_\textrm{chebyshev}(u,v) := \max_{1 \le i \le n} |u_i-v_i|
1150
+
1151
+ If a (non-negative) weight vector :math:`w \equiv (w_1, \cdots, w_n)`
1152
+ is supplied, the *weighted Chebyshev distance* is defined to be the
1153
+ weighted Minkowski distance of infinite order; that is,
1154
+
1155
+ .. math::
1156
+
1157
+ \begin{align}
1158
+ d_\textrm{chebyshev}(u,v;w) &:= \lim_{p\rightarrow \infty}
1159
+ \left( \sum_{i=1}^n w_i | u_i-v_i |^p \right)^\frac{1}{p} \\
1160
+ &= \max_{1 \le i \le n} 1_{w_i > 0} | u_i - v_i |
1161
+ \end{align}
1162
+
1163
+ Parameters
1164
+ ----------
1165
+ u : (N,) array_like of floats
1166
+ Input vector.
1167
+ v : (N,) array_like of floats
1168
+ Input vector.
1169
+ w : (N,) array_like of floats, optional
1170
+ Weight vector. Default is ``None``, which gives all pairs
1171
+ :math:`(u_i, v_i)` the same weight ``1.0``.
1172
+
1173
+ Returns
1174
+ -------
1175
+ chebyshev : float
1176
+ The Chebyshev distance between vectors `u` and `v`, optionally weighted
1177
+ by `w`.
1178
+
1179
+ References
1180
+ ----------
1181
+ .. [1] https://en.wikipedia.org/wiki/Chebyshev_distance
1182
+
1183
+ Examples
1184
+ --------
1185
+ >>> from scipy.spatial import distance
1186
+ >>> distance.chebyshev([1, 0, 0], [0, 1, 0])
1187
+ 1
1188
+ >>> distance.chebyshev([1, 1, 0], [0, 1, 0])
1189
+ 1
1190
+
1191
+ """
1192
+ u = _validate_vector(u)
1193
+ v = _validate_vector(v)
1194
+ if w is not None:
1195
+ w = _validate_weights(w)
1196
+ return max((w > 0) * abs(u - v))
1197
+ return max(abs(u - v))
1198
+
1199
+
1200
+ def braycurtis(u, v, w=None):
1201
+ """
1202
+ Compute the Bray-Curtis distance between two 1-D arrays.
1203
+
1204
+ Bray-Curtis distance is defined as
1205
+
1206
+ .. math::
1207
+
1208
+ \\sum{|u_i-v_i|} / \\sum{|u_i+v_i|}
1209
+
1210
+ The Bray-Curtis distance is in the range [0, 1] if all coordinates are
1211
+ positive, and is undefined if the inputs are of length zero.
1212
+
1213
+ Parameters
1214
+ ----------
1215
+ u : (N,) array_like
1216
+ Input array.
1217
+ v : (N,) array_like
1218
+ Input array.
1219
+ w : (N,) array_like, optional
1220
+ The weights for each value in `u` and `v`. Default is None,
1221
+ which gives each value a weight of 1.0
1222
+
1223
+ Returns
1224
+ -------
1225
+ braycurtis : double
1226
+ The Bray-Curtis distance between 1-D arrays `u` and `v`.
1227
+
1228
+ Examples
1229
+ --------
1230
+ >>> from scipy.spatial import distance
1231
+ >>> distance.braycurtis([1, 0, 0], [0, 1, 0])
1232
+ 1.0
1233
+ >>> distance.braycurtis([1, 1, 0], [0, 1, 0])
1234
+ 0.33333333333333331
1235
+
1236
+ """
1237
+ u = _validate_vector(u)
1238
+ v = _validate_vector(v, dtype=np.float64)
1239
+ l1_diff = abs(u - v)
1240
+ l1_sum = abs(u + v)
1241
+ if w is not None:
1242
+ w = _validate_weights(w)
1243
+ l1_diff = w * l1_diff
1244
+ l1_sum = w * l1_sum
1245
+ return l1_diff.sum() / l1_sum.sum()
1246
+
1247
+
1248
+ def canberra(u, v, w=None):
1249
+ """
1250
+ Compute the Canberra distance between two 1-D arrays.
1251
+
1252
+ The Canberra distance is defined as
1253
+
1254
+ .. math::
1255
+
1256
+ d(u,v) = \\sum_i \\frac{|u_i-v_i|}
1257
+ {|u_i|+|v_i|}.
1258
+
1259
+ Parameters
1260
+ ----------
1261
+ u : (N,) array_like
1262
+ Input array.
1263
+ v : (N,) array_like
1264
+ Input array.
1265
+ w : (N,) array_like, optional
1266
+ The weights for each value in `u` and `v`. Default is None,
1267
+ which gives each value a weight of 1.0
1268
+
1269
+ Returns
1270
+ -------
1271
+ canberra : double
1272
+ The Canberra distance between vectors `u` and `v`.
1273
+
1274
+ Notes
1275
+ -----
1276
+ When ``u[i]`` and ``v[i]`` are 0 for given i, then the fraction 0/0 = 0 is
1277
+ used in the calculation.
1278
+
1279
+ Examples
1280
+ --------
1281
+ >>> from scipy.spatial import distance
1282
+ >>> distance.canberra([1, 0, 0], [0, 1, 0])
1283
+ 2.0
1284
+ >>> distance.canberra([1, 1, 0], [0, 1, 0])
1285
+ 1.0
1286
+
1287
+ """
1288
+ u = _validate_vector(u)
1289
+ v = _validate_vector(v, dtype=np.float64)
1290
+ if w is not None:
1291
+ w = _validate_weights(w)
1292
+ with np.errstate(invalid='ignore'):
1293
+ abs_uv = abs(u - v)
1294
+ abs_u = abs(u)
1295
+ abs_v = abs(v)
1296
+ d = abs_uv / (abs_u + abs_v)
1297
+ if w is not None:
1298
+ d = w * d
1299
+ d = np.nansum(d)
1300
+ return d
1301
+
1302
+
1303
+ def jensenshannon(p, q, base=None, *, axis=0, keepdims=False):
1304
+ """
1305
+ Compute the Jensen-Shannon distance (metric) between
1306
+ two probability arrays. This is the square root
1307
+ of the Jensen-Shannon divergence.
1308
+
1309
+ The Jensen-Shannon distance between two probability
1310
+ vectors `p` and `q` is defined as,
1311
+
1312
+ .. math::
1313
+
1314
+ \\sqrt{\\frac{D(p \\parallel m) + D(q \\parallel m)}{2}}
1315
+
1316
+ where :math:`m` is the pointwise mean of :math:`p` and :math:`q`
1317
+ and :math:`D` is the Kullback-Leibler divergence.
1318
+
1319
+ This routine will normalize `p` and `q` if they don't sum to 1.0.
1320
+
1321
+ Parameters
1322
+ ----------
1323
+ p : (N,) array_like
1324
+ left probability vector
1325
+ q : (N,) array_like
1326
+ right probability vector
1327
+ base : double, optional
1328
+ the base of the logarithm used to compute the output
1329
+ if not given, then the routine uses the default base of
1330
+ scipy.stats.entropy.
1331
+ axis : int, optional
1332
+ Axis along which the Jensen-Shannon distances are computed. The default
1333
+ is 0.
1334
+
1335
+ .. versionadded:: 1.7.0
1336
+ keepdims : bool, optional
1337
+ If this is set to `True`, the reduced axes are left in the
1338
+ result as dimensions with size one. With this option,
1339
+ the result will broadcast correctly against the input array.
1340
+ Default is False.
1341
+
1342
+ .. versionadded:: 1.7.0
1343
+
1344
+ Returns
1345
+ -------
1346
+ js : double or ndarray
1347
+ The Jensen-Shannon distances between `p` and `q` along the `axis`.
1348
+
1349
+ Notes
1350
+ -----
1351
+
1352
+ .. versionadded:: 1.2.0
1353
+
1354
+ Examples
1355
+ --------
1356
+ >>> from scipy.spatial import distance
1357
+ >>> import numpy as np
1358
+ >>> distance.jensenshannon([1.0, 0.0, 0.0], [0.0, 1.0, 0.0], 2.0)
1359
+ 1.0
1360
+ >>> distance.jensenshannon([1.0, 0.0], [0.5, 0.5])
1361
+ 0.46450140402245893
1362
+ >>> distance.jensenshannon([1.0, 0.0, 0.0], [1.0, 0.0, 0.0])
1363
+ 0.0
1364
+ >>> a = np.array([[1, 2, 3, 4],
1365
+ ... [5, 6, 7, 8],
1366
+ ... [9, 10, 11, 12]])
1367
+ >>> b = np.array([[13, 14, 15, 16],
1368
+ ... [17, 18, 19, 20],
1369
+ ... [21, 22, 23, 24]])
1370
+ >>> distance.jensenshannon(a, b, axis=0)
1371
+ array([0.1954288, 0.1447697, 0.1138377, 0.0927636])
1372
+ >>> distance.jensenshannon(a, b, axis=1)
1373
+ array([0.1402339, 0.0399106, 0.0201815])
1374
+
1375
+ """
1376
+ p = np.asarray(p)
1377
+ q = np.asarray(q)
1378
+ p = p / np.sum(p, axis=axis, keepdims=True)
1379
+ q = q / np.sum(q, axis=axis, keepdims=True)
1380
+ m = (p + q) / 2.0
1381
+ left = rel_entr(p, m)
1382
+ right = rel_entr(q, m)
1383
+ left_sum = np.sum(left, axis=axis, keepdims=keepdims)
1384
+ right_sum = np.sum(right, axis=axis, keepdims=keepdims)
1385
+ js = left_sum + right_sum
1386
+ if base is not None:
1387
+ js /= np.log(base)
1388
+ return np.sqrt(js / 2.0)
1389
+
1390
+
1391
+ def yule(u, v, w=None):
1392
+ """
1393
+ Compute the Yule dissimilarity between two boolean 1-D arrays.
1394
+
1395
+ The Yule dissimilarity is defined as
1396
+
1397
+ .. math::
1398
+
1399
+ \\frac{R}{c_{TT} * c_{FF} + \\frac{R}{2}}
1400
+
1401
+ where :math:`c_{ij}` is the number of occurrences of
1402
+ :math:`\\mathtt{u[k]} = i` and :math:`\\mathtt{v[k]} = j` for
1403
+ :math:`k < n` and :math:`R = 2.0 * c_{TF} * c_{FT}`.
1404
+
1405
+ Parameters
1406
+ ----------
1407
+ u : (N,) array_like, bool
1408
+ Input array.
1409
+ v : (N,) array_like, bool
1410
+ Input array.
1411
+ w : (N,) array_like, optional
1412
+ The weights for each value in `u` and `v`. Default is None,
1413
+ which gives each value a weight of 1.0
1414
+
1415
+ Returns
1416
+ -------
1417
+ yule : double
1418
+ The Yule dissimilarity between vectors `u` and `v`.
1419
+
1420
+ Examples
1421
+ --------
1422
+ >>> from scipy.spatial import distance
1423
+ >>> distance.yule([1, 0, 0], [0, 1, 0])
1424
+ 2.0
1425
+ >>> distance.yule([1, 1, 0], [0, 1, 0])
1426
+ 0.0
1427
+
1428
+ """
1429
+ u = _validate_vector(u)
1430
+ v = _validate_vector(v)
1431
+ if w is not None:
1432
+ w = _validate_weights(w)
1433
+ (nff, nft, ntf, ntt) = _nbool_correspond_all(u, v, w=w)
1434
+ half_R = ntf * nft
1435
+ if half_R == 0:
1436
+ return 0.0
1437
+ else:
1438
+ return float(2.0 * half_R / (ntt * nff + half_R))
1439
+
1440
+
1441
+ def dice(u, v, w=None):
1442
+ """
1443
+ Compute the Dice dissimilarity between two boolean 1-D arrays.
1444
+
1445
+ The Dice dissimilarity between `u` and `v`, is
1446
+
1447
+ .. math::
1448
+
1449
+ \\frac{c_{TF} + c_{FT}}
1450
+ {2c_{TT} + c_{FT} + c_{TF}}
1451
+
1452
+ where :math:`c_{ij}` is the number of occurrences of
1453
+ :math:`\\mathtt{u[k]} = i` and :math:`\\mathtt{v[k]} = j` for
1454
+ :math:`k < n`.
1455
+
1456
+ Parameters
1457
+ ----------
1458
+ u : (N,) array_like, bool
1459
+ Input 1-D array.
1460
+ v : (N,) array_like, bool
1461
+ Input 1-D array.
1462
+ w : (N,) array_like, optional
1463
+ The weights for each value in `u` and `v`. Default is None,
1464
+ which gives each value a weight of 1.0
1465
+
1466
+ Returns
1467
+ -------
1468
+ dice : double
1469
+ The Dice dissimilarity between 1-D arrays `u` and `v`.
1470
+
1471
+ Notes
1472
+ -----
1473
+ This function computes the Dice dissimilarity index. To compute the
1474
+ Dice similarity index, convert one to the other with similarity =
1475
+ 1 - dissimilarity.
1476
+
1477
+ Examples
1478
+ --------
1479
+ >>> from scipy.spatial import distance
1480
+ >>> distance.dice([1, 0, 0], [0, 1, 0])
1481
+ 1.0
1482
+ >>> distance.dice([1, 0, 0], [1, 1, 0])
1483
+ 0.3333333333333333
1484
+ >>> distance.dice([1, 0, 0], [2, 0, 0])
1485
+ -0.3333333333333333
1486
+
1487
+ """
1488
+ u = _validate_vector(u)
1489
+ v = _validate_vector(v)
1490
+ if w is not None:
1491
+ w = _validate_weights(w)
1492
+ if u.dtype == v.dtype == bool and w is None:
1493
+ ntt = (u & v).sum()
1494
+ else:
1495
+ dtype = np.result_type(int, u.dtype, v.dtype)
1496
+ u = u.astype(dtype)
1497
+ v = v.astype(dtype)
1498
+ if w is None:
1499
+ ntt = (u * v).sum()
1500
+ else:
1501
+ ntt = (u * v * w).sum()
1502
+ (nft, ntf) = _nbool_correspond_ft_tf(u, v, w=w)
1503
+ return float((ntf + nft) / np.array(2.0 * ntt + ntf + nft))
1504
+
1505
+
1506
+ def rogerstanimoto(u, v, w=None):
1507
+ """
1508
+ Compute the Rogers-Tanimoto dissimilarity between two boolean 1-D arrays.
1509
+
1510
+ The Rogers-Tanimoto dissimilarity between two boolean 1-D arrays
1511
+ `u` and `v`, is defined as
1512
+
1513
+ .. math::
1514
+ \\frac{R}
1515
+ {c_{TT} + c_{FF} + R}
1516
+
1517
+ where :math:`c_{ij}` is the number of occurrences of
1518
+ :math:`\\mathtt{u[k]} = i` and :math:`\\mathtt{v[k]} = j` for
1519
+ :math:`k < n` and :math:`R = 2(c_{TF} + c_{FT})`.
1520
+
1521
+ Parameters
1522
+ ----------
1523
+ u : (N,) array_like, bool
1524
+ Input array.
1525
+ v : (N,) array_like, bool
1526
+ Input array.
1527
+ w : (N,) array_like, optional
1528
+ The weights for each value in `u` and `v`. Default is None,
1529
+ which gives each value a weight of 1.0
1530
+
1531
+ Returns
1532
+ -------
1533
+ rogerstanimoto : double
1534
+ The Rogers-Tanimoto dissimilarity between vectors
1535
+ `u` and `v`.
1536
+
1537
+ Examples
1538
+ --------
1539
+ >>> from scipy.spatial import distance
1540
+ >>> distance.rogerstanimoto([1, 0, 0], [0, 1, 0])
1541
+ 0.8
1542
+ >>> distance.rogerstanimoto([1, 0, 0], [1, 1, 0])
1543
+ 0.5
1544
+ >>> distance.rogerstanimoto([1, 0, 0], [2, 0, 0])
1545
+ -1.0
1546
+
1547
+ """
1548
+ u = _validate_vector(u)
1549
+ v = _validate_vector(v)
1550
+ if w is not None:
1551
+ w = _validate_weights(w)
1552
+ (nff, nft, ntf, ntt) = _nbool_correspond_all(u, v, w=w)
1553
+ return float(2.0 * (ntf + nft)) / float(ntt + nff + (2.0 * (ntf + nft)))
1554
+
1555
+
1556
+ def russellrao(u, v, w=None):
1557
+ """
1558
+ Compute the Russell-Rao dissimilarity between two boolean 1-D arrays.
1559
+
1560
+ The Russell-Rao dissimilarity between two boolean 1-D arrays, `u` and
1561
+ `v`, is defined as
1562
+
1563
+ .. math::
1564
+
1565
+ \\frac{n - c_{TT}}
1566
+ {n}
1567
+
1568
+ where :math:`c_{ij}` is the number of occurrences of
1569
+ :math:`\\mathtt{u[k]} = i` and :math:`\\mathtt{v[k]} = j` for
1570
+ :math:`k < n`.
1571
+
1572
+ Parameters
1573
+ ----------
1574
+ u : (N,) array_like, bool
1575
+ Input array.
1576
+ v : (N,) array_like, bool
1577
+ Input array.
1578
+ w : (N,) array_like, optional
1579
+ The weights for each value in `u` and `v`. Default is None,
1580
+ which gives each value a weight of 1.0
1581
+
1582
+ Returns
1583
+ -------
1584
+ russellrao : double
1585
+ The Russell-Rao dissimilarity between vectors `u` and `v`.
1586
+
1587
+ Examples
1588
+ --------
1589
+ >>> from scipy.spatial import distance
1590
+ >>> distance.russellrao([1, 0, 0], [0, 1, 0])
1591
+ 1.0
1592
+ >>> distance.russellrao([1, 0, 0], [1, 1, 0])
1593
+ 0.6666666666666666
1594
+ >>> distance.russellrao([1, 0, 0], [2, 0, 0])
1595
+ 0.3333333333333333
1596
+
1597
+ """
1598
+ u = _validate_vector(u)
1599
+ v = _validate_vector(v)
1600
+ if u.dtype == v.dtype == bool and w is None:
1601
+ ntt = (u & v).sum()
1602
+ n = float(len(u))
1603
+ elif w is None:
1604
+ ntt = (u * v).sum()
1605
+ n = float(len(u))
1606
+ else:
1607
+ w = _validate_weights(w)
1608
+ ntt = (u * v * w).sum()
1609
+ n = w.sum()
1610
+ return float(n - ntt) / n
1611
+
1612
+
1613
+ _deprecated_sokalmichener = _deprecated(
1614
+ "The sokalmichener metric is deprecated since SciPy 1.15.0 and will be "
1615
+ "removed in SciPy 1.17.0. Replace usage of 'sokalmichener(u, v)' with "
1616
+ "'rogerstanimoto(u, v)'."
1617
+ )
1618
+
1619
+
1620
+ @_deprecated_sokalmichener
1621
+ def sokalmichener(u, v, w=None):
1622
+ """
1623
+ Compute the Sokal-Michener dissimilarity between two boolean 1-D arrays.
1624
+
1625
+ .. deprecated:: 1.15.0
1626
+ This function is deprecated and will be removed in SciPy 1.17.0.
1627
+ Replace usage of ``sokalmichener(u, v)`` with ``rogerstanimoto(u, v)``.
1628
+
1629
+ The Sokal-Michener dissimilarity between boolean 1-D arrays `u` and `v`,
1630
+ is defined as
1631
+
1632
+ .. math::
1633
+
1634
+ \\frac{R}
1635
+ {S + R}
1636
+
1637
+ where :math:`c_{ij}` is the number of occurrences of
1638
+ :math:`\\mathtt{u[k]} = i` and :math:`\\mathtt{v[k]} = j` for
1639
+ :math:`k < n`, :math:`R = 2 * (c_{TF} + c_{FT})` and
1640
+ :math:`S = c_{FF} + c_{TT}`.
1641
+
1642
+ Parameters
1643
+ ----------
1644
+ u : (N,) array_like, bool
1645
+ Input array.
1646
+ v : (N,) array_like, bool
1647
+ Input array.
1648
+ w : (N,) array_like, optional
1649
+ The weights for each value in `u` and `v`. Default is None,
1650
+ which gives each value a weight of 1.0
1651
+
1652
+ Returns
1653
+ -------
1654
+ sokalmichener : double
1655
+ The Sokal-Michener dissimilarity between vectors `u` and `v`.
1656
+
1657
+ Examples
1658
+ --------
1659
+ >>> from scipy.spatial import distance
1660
+ >>> distance.sokalmichener([1, 0, 0], [0, 1, 0])
1661
+ 0.8
1662
+ >>> distance.sokalmichener([1, 0, 0], [1, 1, 0])
1663
+ 0.5
1664
+ >>> distance.sokalmichener([1, 0, 0], [2, 0, 0])
1665
+ -1.0
1666
+
1667
+ """
1668
+ u = _validate_vector(u)
1669
+ v = _validate_vector(v)
1670
+ if w is not None:
1671
+ w = _validate_weights(w)
1672
+ nff, nft, ntf, ntt = _nbool_correspond_all(u, v, w=w)
1673
+ return float(2.0 * (ntf + nft)) / float(ntt + nff + 2.0 * (ntf + nft))
1674
+
1675
+
1676
+ def sokalsneath(u, v, w=None):
1677
+ """
1678
+ Compute the Sokal-Sneath dissimilarity between two boolean 1-D arrays.
1679
+
1680
+ The Sokal-Sneath dissimilarity between `u` and `v`,
1681
+
1682
+ .. math::
1683
+
1684
+ \\frac{R}
1685
+ {c_{TT} + R}
1686
+
1687
+ where :math:`c_{ij}` is the number of occurrences of
1688
+ :math:`\\mathtt{u[k]} = i` and :math:`\\mathtt{v[k]} = j` for
1689
+ :math:`k < n` and :math:`R = 2(c_{TF} + c_{FT})`.
1690
+
1691
+ Parameters
1692
+ ----------
1693
+ u : (N,) array_like, bool
1694
+ Input array.
1695
+ v : (N,) array_like, bool
1696
+ Input array.
1697
+ w : (N,) array_like, optional
1698
+ The weights for each value in `u` and `v`. Default is None,
1699
+ which gives each value a weight of 1.0
1700
+
1701
+ Returns
1702
+ -------
1703
+ sokalsneath : double
1704
+ The Sokal-Sneath dissimilarity between vectors `u` and `v`.
1705
+
1706
+ Examples
1707
+ --------
1708
+ >>> from scipy.spatial import distance
1709
+ >>> distance.sokalsneath([1, 0, 0], [0, 1, 0])
1710
+ 1.0
1711
+ >>> distance.sokalsneath([1, 0, 0], [1, 1, 0])
1712
+ 0.66666666666666663
1713
+ >>> distance.sokalsneath([1, 0, 0], [2, 1, 0])
1714
+ 0.0
1715
+ >>> distance.sokalsneath([1, 0, 0], [3, 1, 0])
1716
+ -2.0
1717
+
1718
+ """
1719
+ u = _validate_vector(u)
1720
+ v = _validate_vector(v)
1721
+ if u.dtype == v.dtype == bool and w is None:
1722
+ ntt = (u & v).sum()
1723
+ elif w is None:
1724
+ ntt = (u * v).sum()
1725
+ else:
1726
+ w = _validate_weights(w)
1727
+ ntt = (u * v * w).sum()
1728
+ (nft, ntf) = _nbool_correspond_ft_tf(u, v, w=w)
1729
+ denom = np.array(ntt + 2.0 * (ntf + nft))
1730
+ if not denom.any():
1731
+ raise ValueError('Sokal-Sneath dissimilarity is not defined for '
1732
+ 'vectors that are entirely false.')
1733
+ return float(2.0 * (ntf + nft)) / denom
1734
+
1735
+
1736
+ _convert_to_double = partial(_convert_to_type, out_type=np.float64)
1737
+ _convert_to_bool = partial(_convert_to_type, out_type=bool)
1738
+
1739
+ # adding python-only wrappers to _distance_wrap module
1740
+ _distance_wrap.pdist_correlation_double_wrap = _correlation_pdist_wrap
1741
+ _distance_wrap.cdist_correlation_double_wrap = _correlation_cdist_wrap
1742
+
1743
+
1744
+ @dataclasses.dataclass(frozen=True)
1745
+ class CDistMetricWrapper:
1746
+ metric_name: str
1747
+
1748
+ def __call__(self, XA, XB, *, out=None, **kwargs):
1749
+ XA = np.ascontiguousarray(XA)
1750
+ XB = np.ascontiguousarray(XB)
1751
+ mA, n = XA.shape
1752
+ mB, _ = XB.shape
1753
+ metric_name = self.metric_name
1754
+ metric_info = _METRICS[metric_name]
1755
+ XA, XB, typ, kwargs = _validate_cdist_input(
1756
+ XA, XB, mA, mB, n, metric_info, **kwargs)
1757
+
1758
+ w = kwargs.pop('w', None)
1759
+ if w is not None:
1760
+ metric = metric_info.dist_func
1761
+ return _cdist_callable(
1762
+ XA, XB, metric=metric, out=out, w=w, **kwargs)
1763
+
1764
+ dm = _prepare_out_argument(out, np.float64, (mA, mB))
1765
+ # get cdist wrapper
1766
+ cdist_fn = getattr(_distance_wrap, f'cdist_{metric_name}_{typ}_wrap')
1767
+ cdist_fn(XA, XB, dm, **kwargs)
1768
+ return dm
1769
+
1770
+
1771
+ @dataclasses.dataclass(frozen=True)
1772
+ class PDistMetricWrapper:
1773
+ metric_name: str
1774
+
1775
+ def __call__(self, X, *, out=None, **kwargs):
1776
+ X = np.ascontiguousarray(X)
1777
+ m, n = X.shape
1778
+ metric_name = self.metric_name
1779
+ metric_info = _METRICS[metric_name]
1780
+ X, typ, kwargs = _validate_pdist_input(
1781
+ X, m, n, metric_info, **kwargs)
1782
+ out_size = (m * (m - 1)) // 2
1783
+ w = kwargs.pop('w', None)
1784
+ if w is not None:
1785
+ metric = metric_info.dist_func
1786
+ return _pdist_callable(
1787
+ X, metric=metric, out=out, w=w, **kwargs)
1788
+
1789
+ dm = _prepare_out_argument(out, np.float64, (out_size,))
1790
+ # get pdist wrapper
1791
+ pdist_fn = getattr(_distance_wrap, f'pdist_{metric_name}_{typ}_wrap')
1792
+ pdist_fn(X, dm, **kwargs)
1793
+ return dm
1794
+
1795
+
1796
+ @dataclasses.dataclass(frozen=True)
1797
+ class MetricInfo:
1798
+ # Name of python distance function
1799
+ canonical_name: str
1800
+ # All aliases, including canonical_name
1801
+ aka: set[str]
1802
+ # unvectorized distance function
1803
+ dist_func: Callable
1804
+ # Optimized cdist function
1805
+ cdist_func: Callable
1806
+ # Optimized pdist function
1807
+ pdist_func: Callable
1808
+ # function that checks kwargs and computes default values:
1809
+ # f(X, m, n, **kwargs)
1810
+ validator: Callable | None = None
1811
+ # list of supported types:
1812
+ # X (pdist) and XA (cdist) are used to choose the type. if there is no
1813
+ # match the first type is used. Default double
1814
+ types: list[str] = dataclasses.field(default_factory=lambda: ['double'])
1815
+ # true if out array must be C-contiguous
1816
+ requires_contiguous_out: bool = True
1817
+
1818
+
1819
+ # Registry of implemented metrics:
1820
+ _METRIC_INFOS = [
1821
+ MetricInfo(
1822
+ canonical_name='braycurtis',
1823
+ aka={'braycurtis'},
1824
+ dist_func=braycurtis,
1825
+ cdist_func=_distance_pybind.cdist_braycurtis,
1826
+ pdist_func=_distance_pybind.pdist_braycurtis,
1827
+ ),
1828
+ MetricInfo(
1829
+ canonical_name='canberra',
1830
+ aka={'canberra'},
1831
+ dist_func=canberra,
1832
+ cdist_func=_distance_pybind.cdist_canberra,
1833
+ pdist_func=_distance_pybind.pdist_canberra,
1834
+ ),
1835
+ MetricInfo(
1836
+ canonical_name='chebyshev',
1837
+ aka={'chebychev', 'chebyshev', 'cheby', 'cheb', 'ch'},
1838
+ dist_func=chebyshev,
1839
+ cdist_func=_distance_pybind.cdist_chebyshev,
1840
+ pdist_func=_distance_pybind.pdist_chebyshev,
1841
+ ),
1842
+ MetricInfo(
1843
+ canonical_name='cityblock',
1844
+ aka={'cityblock', 'cblock', 'cb', 'c'},
1845
+ dist_func=cityblock,
1846
+ cdist_func=_distance_pybind.cdist_cityblock,
1847
+ pdist_func=_distance_pybind.pdist_cityblock,
1848
+ ),
1849
+ MetricInfo(
1850
+ canonical_name='correlation',
1851
+ aka={'correlation', 'co'},
1852
+ dist_func=correlation,
1853
+ cdist_func=CDistMetricWrapper('correlation'),
1854
+ pdist_func=PDistMetricWrapper('correlation'),
1855
+ ),
1856
+ MetricInfo(
1857
+ canonical_name='cosine',
1858
+ aka={'cosine', 'cos'},
1859
+ dist_func=cosine,
1860
+ cdist_func=CDistMetricWrapper('cosine'),
1861
+ pdist_func=PDistMetricWrapper('cosine'),
1862
+ ),
1863
+ MetricInfo(
1864
+ canonical_name='dice',
1865
+ aka={'dice'},
1866
+ types=['bool'],
1867
+ dist_func=dice,
1868
+ cdist_func=_distance_pybind.cdist_dice,
1869
+ pdist_func=_distance_pybind.pdist_dice,
1870
+ ),
1871
+ MetricInfo(
1872
+ canonical_name='euclidean',
1873
+ aka={'euclidean', 'euclid', 'eu', 'e'},
1874
+ dist_func=euclidean,
1875
+ cdist_func=_distance_pybind.cdist_euclidean,
1876
+ pdist_func=_distance_pybind.pdist_euclidean,
1877
+ ),
1878
+ MetricInfo(
1879
+ canonical_name='hamming',
1880
+ aka={'matching', 'hamming', 'hamm', 'ha', 'h'},
1881
+ types=['double', 'bool'],
1882
+ validator=_validate_hamming_kwargs,
1883
+ dist_func=hamming,
1884
+ cdist_func=_distance_pybind.cdist_hamming,
1885
+ pdist_func=_distance_pybind.pdist_hamming,
1886
+ ),
1887
+ MetricInfo(
1888
+ canonical_name='jaccard',
1889
+ aka={'jaccard', 'jacc', 'ja', 'j'},
1890
+ types=['double', 'bool'],
1891
+ dist_func=jaccard,
1892
+ cdist_func=_distance_pybind.cdist_jaccard,
1893
+ pdist_func=_distance_pybind.pdist_jaccard,
1894
+ ),
1895
+ MetricInfo(
1896
+ canonical_name='jensenshannon',
1897
+ aka={'jensenshannon', 'js'},
1898
+ dist_func=jensenshannon,
1899
+ cdist_func=CDistMetricWrapper('jensenshannon'),
1900
+ pdist_func=PDistMetricWrapper('jensenshannon'),
1901
+ ),
1902
+ MetricInfo(
1903
+ canonical_name='kulczynski1',
1904
+ aka={'kulczynski1'},
1905
+ types=['bool'],
1906
+ dist_func=kulczynski1,
1907
+ cdist_func=_deprecated_kulczynski1(_distance_pybind.cdist_kulczynski1),
1908
+ pdist_func=_deprecated_kulczynski1(_distance_pybind.pdist_kulczynski1),
1909
+ ),
1910
+ MetricInfo(
1911
+ canonical_name='mahalanobis',
1912
+ aka={'mahalanobis', 'mahal', 'mah'},
1913
+ validator=_validate_mahalanobis_kwargs,
1914
+ dist_func=mahalanobis,
1915
+ cdist_func=CDistMetricWrapper('mahalanobis'),
1916
+ pdist_func=PDistMetricWrapper('mahalanobis'),
1917
+ ),
1918
+ MetricInfo(
1919
+ canonical_name='minkowski',
1920
+ aka={'minkowski', 'mi', 'm', 'pnorm'},
1921
+ validator=_validate_minkowski_kwargs,
1922
+ dist_func=minkowski,
1923
+ cdist_func=_distance_pybind.cdist_minkowski,
1924
+ pdist_func=_distance_pybind.pdist_minkowski,
1925
+ ),
1926
+ MetricInfo(
1927
+ canonical_name='rogerstanimoto',
1928
+ aka={'rogerstanimoto'},
1929
+ types=['bool'],
1930
+ dist_func=rogerstanimoto,
1931
+ cdist_func=_distance_pybind.cdist_rogerstanimoto,
1932
+ pdist_func=_distance_pybind.pdist_rogerstanimoto,
1933
+ ),
1934
+ MetricInfo(
1935
+ canonical_name='russellrao',
1936
+ aka={'russellrao'},
1937
+ types=['bool'],
1938
+ dist_func=russellrao,
1939
+ cdist_func=_distance_pybind.cdist_russellrao,
1940
+ pdist_func=_distance_pybind.pdist_russellrao,
1941
+ ),
1942
+ MetricInfo(
1943
+ canonical_name='seuclidean',
1944
+ aka={'seuclidean', 'se', 's'},
1945
+ validator=_validate_seuclidean_kwargs,
1946
+ dist_func=seuclidean,
1947
+ cdist_func=CDistMetricWrapper('seuclidean'),
1948
+ pdist_func=PDistMetricWrapper('seuclidean'),
1949
+ ),
1950
+ MetricInfo(
1951
+ canonical_name='sokalmichener',
1952
+ aka={'sokalmichener'},
1953
+ types=['bool'],
1954
+ dist_func=sokalmichener,
1955
+ cdist_func=_deprecated_sokalmichener(_distance_pybind.cdist_sokalmichener),
1956
+ pdist_func=_deprecated_sokalmichener(_distance_pybind.pdist_sokalmichener),
1957
+ ),
1958
+ MetricInfo(
1959
+ canonical_name='sokalsneath',
1960
+ aka={'sokalsneath'},
1961
+ types=['bool'],
1962
+ dist_func=sokalsneath,
1963
+ cdist_func=_distance_pybind.cdist_sokalsneath,
1964
+ pdist_func=_distance_pybind.pdist_sokalsneath,
1965
+ ),
1966
+ MetricInfo(
1967
+ canonical_name='sqeuclidean',
1968
+ aka={'sqeuclidean', 'sqe', 'sqeuclid'},
1969
+ dist_func=sqeuclidean,
1970
+ cdist_func=_distance_pybind.cdist_sqeuclidean,
1971
+ pdist_func=_distance_pybind.pdist_sqeuclidean,
1972
+ ),
1973
+ MetricInfo(
1974
+ canonical_name='yule',
1975
+ aka={'yule'},
1976
+ types=['bool'],
1977
+ dist_func=yule,
1978
+ cdist_func=_distance_pybind.cdist_yule,
1979
+ pdist_func=_distance_pybind.pdist_yule,
1980
+ ),
1981
+ ]
1982
+
1983
+ _METRICS = {info.canonical_name: info for info in _METRIC_INFOS}
1984
+ _METRIC_ALIAS = {alias: info
1985
+ for info in _METRIC_INFOS
1986
+ for alias in info.aka}
1987
+
1988
+ _METRICS_NAMES = list(_METRICS.keys())
1989
+
1990
+ _TEST_METRICS = {'test_' + info.canonical_name: info for info in _METRIC_INFOS}
1991
+
1992
+
1993
+ def pdist(X, metric='euclidean', *, out=None, **kwargs):
1994
+ """
1995
+ Pairwise distances between observations in n-dimensional space.
1996
+
1997
+ See Notes for common calling conventions.
1998
+
1999
+ Parameters
2000
+ ----------
2001
+ X : array_like
2002
+ An m by n array of m original observations in an
2003
+ n-dimensional space.
2004
+ metric : str or function, optional
2005
+ The distance metric to use. The distance function can
2006
+ be 'braycurtis', 'canberra', 'chebyshev', 'cityblock',
2007
+ 'correlation', 'cosine', 'dice', 'euclidean', 'hamming',
2008
+ 'jaccard', 'jensenshannon', 'kulczynski1',
2009
+ 'mahalanobis', 'matching', 'minkowski', 'rogerstanimoto',
2010
+ 'russellrao', 'seuclidean', 'sokalmichener', 'sokalsneath',
2011
+ 'sqeuclidean', 'yule'.
2012
+ out : ndarray, optional
2013
+ The output array.
2014
+ If not None, condensed distance matrix Y is stored in this array.
2015
+ **kwargs : dict, optional
2016
+ Extra arguments to `metric`: refer to each metric documentation for a
2017
+ list of all possible arguments.
2018
+
2019
+ Some possible arguments:
2020
+
2021
+ p : scalar
2022
+ The p-norm to apply for Minkowski, weighted and unweighted.
2023
+ Default: 2.
2024
+
2025
+ w : ndarray
2026
+ The weight vector for metrics that support weights (e.g., Minkowski).
2027
+
2028
+ V : ndarray
2029
+ The variance vector for standardized Euclidean.
2030
+ Default: var(X, axis=0, ddof=1)
2031
+
2032
+ VI : ndarray
2033
+ The inverse of the covariance matrix for Mahalanobis.
2034
+ Default: inv(cov(X.T)).T
2035
+
2036
+ Returns
2037
+ -------
2038
+ Y : ndarray
2039
+ Returns a condensed distance matrix Y. For each :math:`i` and :math:`j`
2040
+ (where :math:`i<j<m`),where m is the number of original observations.
2041
+ The metric ``dist(u=X[i], v=X[j])`` is computed and stored in entry ``m
2042
+ * i + j - ((i + 2) * (i + 1)) // 2``.
2043
+
2044
+ See Also
2045
+ --------
2046
+ squareform : converts between condensed distance matrices and
2047
+ square distance matrices.
2048
+
2049
+ Notes
2050
+ -----
2051
+ See ``squareform`` for information on how to calculate the index of
2052
+ this entry or to convert the condensed distance matrix to a
2053
+ redundant square matrix.
2054
+
2055
+ The following are common calling conventions.
2056
+
2057
+ 1. ``Y = pdist(X, 'euclidean')``
2058
+
2059
+ Computes the distance between m points using Euclidean distance
2060
+ (2-norm) as the distance metric between the points. The points
2061
+ are arranged as m n-dimensional row vectors in the matrix X.
2062
+
2063
+ 2. ``Y = pdist(X, 'minkowski', p=2.)``
2064
+
2065
+ Computes the distances using the Minkowski distance
2066
+ :math:`\\|u-v\\|_p` (:math:`p`-norm) where :math:`p > 0` (note
2067
+ that this is only a quasi-metric if :math:`0 < p < 1`).
2068
+
2069
+ 3. ``Y = pdist(X, 'cityblock')``
2070
+
2071
+ Computes the city block or Manhattan distance between the
2072
+ points.
2073
+
2074
+ 4. ``Y = pdist(X, 'seuclidean', V=None)``
2075
+
2076
+ Computes the standardized Euclidean distance. The standardized
2077
+ Euclidean distance between two n-vectors ``u`` and ``v`` is
2078
+
2079
+ .. math::
2080
+
2081
+ \\sqrt{\\sum {(u_i-v_i)^2 / V[x_i]}}
2082
+
2083
+
2084
+ V is the variance vector; V[i] is the variance computed over all
2085
+ the i'th components of the points. If not passed, it is
2086
+ automatically computed.
2087
+
2088
+ 5. ``Y = pdist(X, 'sqeuclidean')``
2089
+
2090
+ Computes the squared Euclidean distance :math:`\\|u-v\\|_2^2` between
2091
+ the vectors.
2092
+
2093
+ 6. ``Y = pdist(X, 'cosine')``
2094
+
2095
+ Computes the cosine distance between vectors u and v,
2096
+
2097
+ .. math::
2098
+
2099
+ 1 - \\frac{u \\cdot v}
2100
+ {{\\|u\\|}_2 {\\|v\\|}_2}
2101
+
2102
+ where :math:`\\|*\\|_2` is the 2-norm of its argument ``*``, and
2103
+ :math:`u \\cdot v` is the dot product of ``u`` and ``v``.
2104
+
2105
+ 7. ``Y = pdist(X, 'correlation')``
2106
+
2107
+ Computes the correlation distance between vectors u and v. This is
2108
+
2109
+ .. math::
2110
+
2111
+ 1 - \\frac{(u - \\bar{u}) \\cdot (v - \\bar{v})}
2112
+ {{\\|(u - \\bar{u})\\|}_2 {\\|(v - \\bar{v})\\|}_2}
2113
+
2114
+ where :math:`\\bar{v}` is the mean of the elements of vector v,
2115
+ and :math:`x \\cdot y` is the dot product of :math:`x` and :math:`y`.
2116
+
2117
+ 8. ``Y = pdist(X, 'hamming')``
2118
+
2119
+ Computes the normalized Hamming distance, or the proportion of
2120
+ those vector elements between two n-vectors ``u`` and ``v``
2121
+ which disagree. To save memory, the matrix ``X`` can be of type
2122
+ boolean.
2123
+
2124
+ 9. ``Y = pdist(X, 'jaccard')``
2125
+
2126
+ Computes the Jaccard distance between the points. Given two
2127
+ vectors, ``u`` and ``v``, the Jaccard distance is the
2128
+ proportion of those elements ``u[i]`` and ``v[i]`` that
2129
+ disagree.
2130
+
2131
+ 10. ``Y = pdist(X, 'jensenshannon')``
2132
+
2133
+ Computes the Jensen-Shannon distance between two probability arrays.
2134
+ Given two probability vectors, :math:`p` and :math:`q`, the
2135
+ Jensen-Shannon distance is
2136
+
2137
+ .. math::
2138
+
2139
+ \\sqrt{\\frac{D(p \\parallel m) + D(q \\parallel m)}{2}}
2140
+
2141
+ where :math:`m` is the pointwise mean of :math:`p` and :math:`q`
2142
+ and :math:`D` is the Kullback-Leibler divergence.
2143
+
2144
+ 11. ``Y = pdist(X, 'chebyshev')``
2145
+
2146
+ Computes the Chebyshev distance between the points. The
2147
+ Chebyshev distance between two n-vectors ``u`` and ``v`` is the
2148
+ maximum norm-1 distance between their respective elements. More
2149
+ precisely, the distance is given by
2150
+
2151
+ .. math::
2152
+
2153
+ d(u,v) = \\max_i {|u_i-v_i|}
2154
+
2155
+ 12. ``Y = pdist(X, 'canberra')``
2156
+
2157
+ Computes the Canberra distance between the points. The
2158
+ Canberra distance between two points ``u`` and ``v`` is
2159
+
2160
+ .. math::
2161
+
2162
+ d(u,v) = \\sum_i \\frac{|u_i-v_i|}
2163
+ {|u_i|+|v_i|}
2164
+
2165
+
2166
+ 13. ``Y = pdist(X, 'braycurtis')``
2167
+
2168
+ Computes the Bray-Curtis distance between the points. The
2169
+ Bray-Curtis distance between two points ``u`` and ``v`` is
2170
+
2171
+
2172
+ .. math::
2173
+
2174
+ d(u,v) = \\frac{\\sum_i {|u_i-v_i|}}
2175
+ {\\sum_i {|u_i+v_i|}}
2176
+
2177
+ 14. ``Y = pdist(X, 'mahalanobis', VI=None)``
2178
+
2179
+ Computes the Mahalanobis distance between the points. The
2180
+ Mahalanobis distance between two points ``u`` and ``v`` is
2181
+ :math:`\\sqrt{(u-v)(1/V)(u-v)^T}` where :math:`(1/V)` (the ``VI``
2182
+ variable) is the inverse covariance. If ``VI`` is not None,
2183
+ ``VI`` will be used as the inverse covariance matrix.
2184
+
2185
+ 15. ``Y = pdist(X, 'yule')``
2186
+
2187
+ Computes the Yule distance between each pair of boolean
2188
+ vectors. (see yule function documentation)
2189
+
2190
+ 16. ``Y = pdist(X, 'matching')``
2191
+
2192
+ Synonym for 'hamming'.
2193
+
2194
+ 17. ``Y = pdist(X, 'dice')``
2195
+
2196
+ Computes the Dice distance between each pair of boolean
2197
+ vectors. (see dice function documentation)
2198
+
2199
+ 18. ``Y = pdist(X, 'kulczynski1')``
2200
+
2201
+ Computes the kulczynski1 distance between each pair of
2202
+ boolean vectors. (see kulczynski1 function documentation)
2203
+
2204
+ .. deprecated:: 1.15.0
2205
+ This metric is deprecated and will be removed in SciPy 1.17.0.
2206
+ Replace usage of ``pdist(X, 'kulczynski1')`` with
2207
+ ``1 / pdist(X, 'jaccard') - 1``.
2208
+
2209
+ 19. ``Y = pdist(X, 'rogerstanimoto')``
2210
+
2211
+ Computes the Rogers-Tanimoto distance between each pair of
2212
+ boolean vectors. (see rogerstanimoto function documentation)
2213
+
2214
+ 20. ``Y = pdist(X, 'russellrao')``
2215
+
2216
+ Computes the Russell-Rao distance between each pair of
2217
+ boolean vectors. (see russellrao function documentation)
2218
+
2219
+ 21. ``Y = pdist(X, 'sokalmichener')``
2220
+
2221
+ Computes the Sokal-Michener distance between each pair of
2222
+ boolean vectors. (see sokalmichener function documentation)
2223
+
2224
+ .. deprecated:: 1.15.0
2225
+ This metric is deprecated and will be removed in SciPy 1.17.0.
2226
+ Replace usage of ``pdist(X, 'sokalmichener')`` with
2227
+ ``pdist(X, 'rogerstanimoto')``.
2228
+
2229
+ 22. ``Y = pdist(X, 'sokalsneath')``
2230
+
2231
+ Computes the Sokal-Sneath distance between each pair of
2232
+ boolean vectors. (see sokalsneath function documentation)
2233
+
2234
+ 23. ``Y = pdist(X, 'kulczynski1')``
2235
+
2236
+ Computes the Kulczynski 1 distance between each pair of
2237
+ boolean vectors. (see kulczynski1 function documentation)
2238
+
2239
+ 24. ``Y = pdist(X, f)``
2240
+
2241
+ Computes the distance between all pairs of vectors in X
2242
+ using the user supplied 2-arity function f. For example,
2243
+ Euclidean distance between the vectors could be computed
2244
+ as follows::
2245
+
2246
+ dm = pdist(X, lambda u, v: np.sqrt(((u-v)**2).sum()))
2247
+
2248
+ Note that you should avoid passing a reference to one of
2249
+ the distance functions defined in this library. For example,::
2250
+
2251
+ dm = pdist(X, sokalsneath)
2252
+
2253
+ would calculate the pair-wise distances between the vectors in
2254
+ X using the Python function sokalsneath. This would result in
2255
+ sokalsneath being called :math:`{n \\choose 2}` times, which
2256
+ is inefficient. Instead, the optimized C version is more
2257
+ efficient, and we call it using the following syntax.::
2258
+
2259
+ dm = pdist(X, 'sokalsneath')
2260
+
2261
+ Examples
2262
+ --------
2263
+ >>> import numpy as np
2264
+ >>> from scipy.spatial.distance import pdist
2265
+
2266
+ ``x`` is an array of five points in three-dimensional space.
2267
+
2268
+ >>> x = np.array([[2, 0, 2], [2, 2, 3], [-2, 4, 5], [0, 1, 9], [2, 2, 4]])
2269
+
2270
+ ``pdist(x)`` with no additional arguments computes the 10 pairwise
2271
+ Euclidean distances:
2272
+
2273
+ >>> pdist(x)
2274
+ array([2.23606798, 6.40312424, 7.34846923, 2.82842712, 4.89897949,
2275
+ 6.40312424, 1. , 5.38516481, 4.58257569, 5.47722558])
2276
+
2277
+ The following computes the pairwise Minkowski distances with ``p = 3.5``:
2278
+
2279
+ >>> pdist(x, metric='minkowski', p=3.5)
2280
+ array([2.04898923, 5.1154929 , 7.02700737, 2.43802731, 4.19042714,
2281
+ 6.03956994, 1. , 4.45128103, 4.10636143, 5.0619695 ])
2282
+
2283
+ The pairwise city block or Manhattan distances:
2284
+
2285
+ >>> pdist(x, metric='cityblock')
2286
+ array([ 3., 11., 10., 4., 8., 9., 1., 9., 7., 8.])
2287
+
2288
+ """
2289
+ # You can also call this as:
2290
+ # Y = pdist(X, 'test_abc')
2291
+ # where 'abc' is the metric being tested. This computes the distance
2292
+ # between all pairs of vectors in X using the distance metric 'abc' but
2293
+ # with a more succinct, verifiable, but less efficient implementation.
2294
+
2295
+ X = _asarray(X)
2296
+ if X.ndim != 2:
2297
+ raise ValueError(f'A 2-dimensional array must be passed. (Shape was {X.shape}).')
2298
+
2299
+ n = X.shape[0]
2300
+ return xpx.lazy_apply(_np_pdist, X, out,
2301
+ # lazy_apply doesn't support Array kwargs
2302
+ kwargs.pop('w', None),
2303
+ kwargs.pop('V', None),
2304
+ kwargs.pop('VI', None),
2305
+ # See src/distance_pybind.cpp::pdist
2306
+ shape=((n * (n - 1)) // 2, ), dtype=X.dtype,
2307
+ as_numpy=True, metric=metric, **kwargs)
2308
+
2309
+
2310
+ def _np_pdist(X, out, w, V, VI, metric='euclidean', **kwargs):
2311
+
2312
+ X = _asarray_validated(X, sparse_ok=False, objects_ok=True, mask_ok=True,
2313
+ check_finite=False)
2314
+ m, n = X.shape
2315
+
2316
+ if w is not None:
2317
+ kwargs["w"] = w
2318
+ if V is not None:
2319
+ kwargs["V"] = V
2320
+ if VI is not None:
2321
+ kwargs["VI"] = VI
2322
+
2323
+ if callable(metric):
2324
+ mstr = getattr(metric, '__name__', 'UnknownCustomMetric')
2325
+ metric_info = _METRIC_ALIAS.get(mstr, None)
2326
+
2327
+ if metric_info is not None:
2328
+ X, typ, kwargs = _validate_pdist_input(
2329
+ X, m, n, metric_info, **kwargs)
2330
+
2331
+ return _pdist_callable(X, metric=metric, out=out, **kwargs)
2332
+ elif isinstance(metric, str):
2333
+ mstr = metric.lower()
2334
+ metric_info = _METRIC_ALIAS.get(mstr, None)
2335
+
2336
+ if metric_info is not None:
2337
+ pdist_fn = metric_info.pdist_func
2338
+ return pdist_fn(X, out=out, **kwargs)
2339
+ elif mstr.startswith("test_"):
2340
+ metric_info = _TEST_METRICS.get(mstr, None)
2341
+ if metric_info is None:
2342
+ raise ValueError(f'Unknown "Test" Distance Metric: {mstr[5:]}')
2343
+ X, typ, kwargs = _validate_pdist_input(
2344
+ X, m, n, metric_info, **kwargs)
2345
+ return _pdist_callable(
2346
+ X, metric=metric_info.dist_func, out=out, **kwargs)
2347
+ else:
2348
+ raise ValueError(f'Unknown Distance Metric: {mstr}')
2349
+ else:
2350
+ raise TypeError('2nd argument metric must be a string identifier '
2351
+ 'or a function.')
2352
+
2353
+
2354
+ def squareform(X, force="no", checks=True):
2355
+ """
2356
+ Convert a vector-form distance vector to a square-form distance
2357
+ matrix, and vice-versa.
2358
+
2359
+ Parameters
2360
+ ----------
2361
+ X : array_like
2362
+ Either a condensed or redundant distance matrix.
2363
+ force : str, optional
2364
+ As with MATLAB(TM), if force is equal to ``'tovector'`` or
2365
+ ``'tomatrix'``, the input will be treated as a distance matrix or
2366
+ distance vector respectively.
2367
+ checks : bool, optional
2368
+ If set to False, no checks will be made for matrix
2369
+ symmetry nor zero diagonals. This is useful if it is known that
2370
+ ``X - X.T1`` is small and ``diag(X)`` is close to zero.
2371
+ These values are ignored any way so they do not disrupt the
2372
+ squareform transformation.
2373
+
2374
+ Returns
2375
+ -------
2376
+ Y : ndarray
2377
+ If a condensed distance matrix is passed, a redundant one is
2378
+ returned, or if a redundant one is passed, a condensed distance
2379
+ matrix is returned.
2380
+
2381
+ Notes
2382
+ -----
2383
+ 1. ``v = squareform(X)``
2384
+
2385
+ Given a square n-by-n symmetric distance matrix ``X``,
2386
+ ``v = squareform(X)`` returns a ``n * (n-1) / 2``
2387
+ (i.e. binomial coefficient n choose 2) sized vector `v`
2388
+ where :math:`v[{n \\choose 2} - {n-i \\choose 2} + (j-i-1)]`
2389
+ is the distance between distinct points ``i`` and ``j``.
2390
+ If ``X`` is non-square or asymmetric, an error is raised.
2391
+
2392
+ 2. ``X = squareform(v)``
2393
+
2394
+ Given a ``n * (n-1) / 2`` sized vector ``v``
2395
+ for some integer ``n >= 1`` encoding distances as described,
2396
+ ``X = squareform(v)`` returns a n-by-n distance matrix ``X``.
2397
+ The ``X[i, j]`` and ``X[j, i]`` values are set to
2398
+ :math:`v[{n \\choose 2} - {n-i \\choose 2} + (j-i-1)]`
2399
+ and all diagonal elements are zero.
2400
+
2401
+ In SciPy 0.19.0, ``squareform`` stopped casting all input types to
2402
+ float64, and started returning arrays of the same dtype as the input.
2403
+
2404
+ Examples
2405
+ --------
2406
+ >>> import numpy as np
2407
+ >>> from scipy.spatial.distance import pdist, squareform
2408
+
2409
+ ``x`` is an array of five points in three-dimensional space.
2410
+
2411
+ >>> x = np.array([[2, 0, 2], [2, 2, 3], [-2, 4, 5], [0, 1, 9], [2, 2, 4]])
2412
+
2413
+ ``pdist(x)`` computes the Euclidean distances between each pair of
2414
+ points in ``x``. The distances are returned in a one-dimensional
2415
+ array with length ``5*(5 - 1)/2 = 10``.
2416
+
2417
+ >>> distvec = pdist(x)
2418
+ >>> distvec
2419
+ array([2.23606798, 6.40312424, 7.34846923, 2.82842712, 4.89897949,
2420
+ 6.40312424, 1. , 5.38516481, 4.58257569, 5.47722558])
2421
+
2422
+ ``squareform(distvec)`` returns the 5x5 distance matrix.
2423
+
2424
+ >>> m = squareform(distvec)
2425
+ >>> m
2426
+ array([[0. , 2.23606798, 6.40312424, 7.34846923, 2.82842712],
2427
+ [2.23606798, 0. , 4.89897949, 6.40312424, 1. ],
2428
+ [6.40312424, 4.89897949, 0. , 5.38516481, 4.58257569],
2429
+ [7.34846923, 6.40312424, 5.38516481, 0. , 5.47722558],
2430
+ [2.82842712, 1. , 4.58257569, 5.47722558, 0. ]])
2431
+
2432
+ When given a square distance matrix ``m``, ``squareform(m)`` returns
2433
+ the one-dimensional condensed distance vector associated with the
2434
+ matrix. In this case, we recover ``distvec``.
2435
+
2436
+ >>> squareform(m)
2437
+ array([2.23606798, 6.40312424, 7.34846923, 2.82842712, 4.89897949,
2438
+ 6.40312424, 1. , 5.38516481, 4.58257569, 5.47722558])
2439
+ """
2440
+ X = np.ascontiguousarray(X)
2441
+
2442
+ s = X.shape
2443
+
2444
+ if force.lower() == 'tomatrix':
2445
+ if len(s) != 1:
2446
+ raise ValueError("Forcing 'tomatrix' but input X is not a "
2447
+ "distance vector.")
2448
+ elif force.lower() == 'tovector':
2449
+ if len(s) != 2:
2450
+ raise ValueError("Forcing 'tovector' but input X is not a "
2451
+ "distance matrix.")
2452
+
2453
+ # X = squareform(v)
2454
+ if len(s) == 1:
2455
+ if s[0] == 0:
2456
+ return np.zeros((1, 1), dtype=X.dtype)
2457
+
2458
+ # Grab the closest value to the square root of the number
2459
+ # of elements times 2 to see if the number of elements
2460
+ # is indeed a binomial coefficient.
2461
+ d = int(np.ceil(np.sqrt(s[0] * 2)))
2462
+
2463
+ # Check that v is of valid dimensions.
2464
+ if d * (d - 1) != s[0] * 2:
2465
+ raise ValueError('Incompatible vector size. It must be a binomial '
2466
+ 'coefficient n choose 2 for some integer n >= 2.')
2467
+
2468
+ # Allocate memory for the distance matrix.
2469
+ M = np.zeros((d, d), dtype=X.dtype)
2470
+
2471
+ # Since the C code does not support striding using strides.
2472
+ # The dimensions are used instead.
2473
+ X = _copy_array_if_base_present(X)
2474
+
2475
+ # Fill in the values of the distance matrix.
2476
+ _distance_wrap.to_squareform_from_vector_wrap(M, X)
2477
+
2478
+ # Return the distance matrix.
2479
+ return M
2480
+ elif len(s) == 2:
2481
+ if s[0] != s[1]:
2482
+ raise ValueError('The matrix argument must be square.')
2483
+ if checks:
2484
+ is_valid_dm(X, throw=True, name='X')
2485
+
2486
+ # One-side of the dimensions is set here.
2487
+ d = s[0]
2488
+
2489
+ if d <= 1:
2490
+ return np.array([], dtype=X.dtype)
2491
+
2492
+ # Create a vector.
2493
+ v = np.zeros((d * (d - 1)) // 2, dtype=X.dtype)
2494
+
2495
+ # Since the C code does not support striding using strides.
2496
+ # The dimensions are used instead.
2497
+ X = _copy_array_if_base_present(X)
2498
+
2499
+ # Convert the vector to squareform.
2500
+ _distance_wrap.to_vector_from_squareform_wrap(X, v)
2501
+ return v
2502
+ else:
2503
+ raise ValueError("The first argument must be one or two dimensional "
2504
+ f"array. A {len(s)}-dimensional array is not permitted")
2505
+
2506
+
2507
+ def is_valid_dm(D, tol=0.0, throw=False, name="D", warning=False):
2508
+ """
2509
+ Return True if input array is a valid distance matrix.
2510
+
2511
+ Distance matrices must be 2-dimensional numpy arrays.
2512
+ They must have a zero-diagonal, and they must be symmetric.
2513
+
2514
+ Parameters
2515
+ ----------
2516
+ D : array_like
2517
+ The candidate object to test for validity.
2518
+ tol : float, optional
2519
+ The distance matrix should be symmetric. `tol` is the maximum
2520
+ difference between entries ``ij`` and ``ji`` for the distance
2521
+ metric to be considered symmetric.
2522
+ throw : bool, optional
2523
+ An exception is thrown if the distance matrix passed is not valid.
2524
+ name : str, optional
2525
+ The name of the variable to checked. This is useful if
2526
+ throw is set to True so the offending variable can be identified
2527
+ in the exception message when an exception is thrown.
2528
+ warning : bool, optional
2529
+ Instead of throwing an exception, a warning message is
2530
+ raised.
2531
+
2532
+ Returns
2533
+ -------
2534
+ valid : bool
2535
+ True if the variable `D` passed is a valid distance matrix.
2536
+
2537
+ Notes
2538
+ -----
2539
+ Small numerical differences in `D` and `D.T` and non-zeroness of
2540
+ the diagonal are ignored if they are within the tolerance specified
2541
+ by `tol`.
2542
+
2543
+ Examples
2544
+ --------
2545
+ >>> import numpy as np
2546
+ >>> from scipy.spatial.distance import is_valid_dm
2547
+
2548
+ This matrix is a valid distance matrix.
2549
+
2550
+ >>> d = np.array([[0.0, 1.1, 1.2, 1.3],
2551
+ ... [1.1, 0.0, 1.0, 1.4],
2552
+ ... [1.2, 1.0, 0.0, 1.5],
2553
+ ... [1.3, 1.4, 1.5, 0.0]])
2554
+ >>> is_valid_dm(d)
2555
+ True
2556
+
2557
+ In the following examples, the input is not a valid distance matrix.
2558
+
2559
+ Not square:
2560
+
2561
+ >>> is_valid_dm([[0, 2, 2], [2, 0, 2]])
2562
+ False
2563
+
2564
+ Nonzero diagonal element:
2565
+
2566
+ >>> is_valid_dm([[0, 1, 1], [1, 2, 3], [1, 3, 0]])
2567
+ False
2568
+
2569
+ Not symmetric:
2570
+
2571
+ >>> is_valid_dm([[0, 1, 3], [2, 0, 1], [3, 1, 0]])
2572
+ False
2573
+
2574
+ """
2575
+ D = np.asarray(D, order='c')
2576
+ valid = True
2577
+ try:
2578
+ s = D.shape
2579
+ if len(D.shape) != 2:
2580
+ if name:
2581
+ raise ValueError(f"Distance matrix '{name}' must have shape=2 "
2582
+ "(i.e. be two-dimensional).")
2583
+ else:
2584
+ raise ValueError('Distance matrix must have shape=2 (i.e. '
2585
+ 'be two-dimensional).')
2586
+ if tol == 0.0:
2587
+ if not (D == D.T).all():
2588
+ if name:
2589
+ raise ValueError(f"Distance matrix '{name}' must be symmetric.")
2590
+ else:
2591
+ raise ValueError('Distance matrix must be symmetric.')
2592
+ if not (D[range(0, s[0]), range(0, s[0])] == 0).all():
2593
+ if name:
2594
+ raise ValueError(f"Distance matrix '{name}' diagonal must be zero.")
2595
+ else:
2596
+ raise ValueError('Distance matrix diagonal must be zero.')
2597
+ else:
2598
+ if not (D - D.T <= tol).all():
2599
+ if name:
2600
+ raise ValueError(f'Distance matrix \'{name}\' must be '
2601
+ f'symmetric within tolerance {tol:5.5f}.')
2602
+ else:
2603
+ raise ValueError('Distance matrix must be symmetric within '
2604
+ f'tolerance {tol:5.5f}.')
2605
+ if not (D[range(0, s[0]), range(0, s[0])] <= tol).all():
2606
+ if name:
2607
+ raise ValueError(f'Distance matrix \'{name}\' diagonal must be '
2608
+ f'close to zero within tolerance {tol:5.5f}.')
2609
+ else:
2610
+ raise ValueError(('Distance matrix \'{}\' diagonal must be close '
2611
+ 'to zero within tolerance {:5.5f}.').format(*tol))
2612
+ except Exception as e:
2613
+ if throw:
2614
+ raise
2615
+ if warning:
2616
+ warnings.warn(str(e), stacklevel=2)
2617
+ valid = False
2618
+ return valid
2619
+
2620
+
2621
+ def is_valid_y(y, warning=False, throw=False, name=None):
2622
+ """
2623
+ Return True if the input array is a valid condensed distance matrix.
2624
+
2625
+ Condensed distance matrices must be 1-dimensional numpy arrays.
2626
+ Their length must be a binomial coefficient :math:`{n \\choose 2}`
2627
+ for some positive integer n.
2628
+
2629
+ Parameters
2630
+ ----------
2631
+ y : array_like
2632
+ The condensed distance matrix.
2633
+ warning : bool, optional
2634
+ Invokes a warning if the variable passed is not a valid
2635
+ condensed distance matrix. The warning message explains why
2636
+ the distance matrix is not valid. `name` is used when
2637
+ referencing the offending variable.
2638
+ throw : bool, optional
2639
+ Throws an exception if the variable passed is not a valid
2640
+ condensed distance matrix.
2641
+ name : str, optional
2642
+ Used when referencing the offending variable in the
2643
+ warning or exception message.
2644
+
2645
+ Returns
2646
+ -------
2647
+ bool
2648
+ True if the input array is a valid condensed distance matrix,
2649
+ False otherwise.
2650
+
2651
+ Examples
2652
+ --------
2653
+ >>> from scipy.spatial.distance import is_valid_y
2654
+
2655
+ This vector is a valid condensed distance matrix. The length is 6,
2656
+ which corresponds to ``n = 4``, since ``4*(4 - 1)/2`` is 6.
2657
+
2658
+ >>> v = [1.0, 1.2, 1.0, 0.5, 1.3, 0.9]
2659
+ >>> is_valid_y(v)
2660
+ True
2661
+
2662
+ An input vector with length, say, 7, is not a valid condensed distance
2663
+ matrix.
2664
+
2665
+ >>> is_valid_y([1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7])
2666
+ False
2667
+
2668
+ """
2669
+ y = _asarray(y)
2670
+ name_str = f"'{name}' " if name else ""
2671
+ try:
2672
+ if len(y.shape) != 1:
2673
+ raise ValueError(f"Condensed distance matrix {name_str}must "
2674
+ "have shape=1 (i.e. be one-dimensional).")
2675
+ n = y.shape[0]
2676
+ d = int(np.ceil(np.sqrt(n * 2)))
2677
+ if (d * (d - 1) / 2) != n:
2678
+ raise ValueError(f"Length n of condensed distance matrix {name_str}"
2679
+ "must be a binomial coefficient, i.e. "
2680
+ "there must be a k such that (k \\choose 2)=n)!")
2681
+ except Exception as e:
2682
+ if throw:
2683
+ raise
2684
+ if warning:
2685
+ warnings.warn(str(e), stacklevel=2)
2686
+ return False
2687
+ return True
2688
+
2689
+
2690
+ def num_obs_dm(d):
2691
+ """
2692
+ Return the number of original observations that correspond to a
2693
+ square, redundant distance matrix.
2694
+
2695
+ Parameters
2696
+ ----------
2697
+ d : array_like
2698
+ The target distance matrix.
2699
+
2700
+ Returns
2701
+ -------
2702
+ num_obs_dm : int
2703
+ The number of observations in the redundant distance matrix.
2704
+
2705
+ Examples
2706
+ --------
2707
+ Find the number of original observations corresponding
2708
+ to a square redundant distance matrix d.
2709
+
2710
+ >>> from scipy.spatial.distance import num_obs_dm
2711
+ >>> d = [[0, 100, 200], [100, 0, 150], [200, 150, 0]]
2712
+ >>> num_obs_dm(d)
2713
+ 3
2714
+ """
2715
+ d = np.asarray(d, order='c')
2716
+ is_valid_dm(d, tol=np.inf, throw=True, name='d')
2717
+ return d.shape[0]
2718
+
2719
+
2720
+ def num_obs_y(Y):
2721
+ """
2722
+ Return the number of original observations that correspond to a
2723
+ condensed distance matrix.
2724
+
2725
+ Parameters
2726
+ ----------
2727
+ Y : array_like
2728
+ Condensed distance matrix.
2729
+
2730
+ Returns
2731
+ -------
2732
+ n : int
2733
+ The number of observations in the condensed distance matrix `Y`.
2734
+
2735
+ Examples
2736
+ --------
2737
+ Find the number of original observations corresponding to a
2738
+ condensed distance matrix Y.
2739
+
2740
+ >>> from scipy.spatial.distance import num_obs_y
2741
+ >>> Y = [1, 2, 3.5, 7, 10, 4]
2742
+ >>> num_obs_y(Y)
2743
+ 4
2744
+ """
2745
+ Y = _asarray(Y)
2746
+ is_valid_y(Y, throw=True, name='Y')
2747
+ k = Y.shape[0]
2748
+ if k == 0:
2749
+ raise ValueError("The number of observations cannot be determined on "
2750
+ "an empty distance matrix.")
2751
+ d = int(np.ceil(np.sqrt(k * 2)))
2752
+ if (d * (d - 1) / 2) != k:
2753
+ raise ValueError("Invalid condensed distance matrix passed. Must be "
2754
+ "some k where k=(n choose 2) for some n >= 2.")
2755
+ return d
2756
+
2757
+
2758
+ def _prepare_out_argument(out, dtype, expected_shape):
2759
+ if out is None:
2760
+ return np.empty(expected_shape, dtype=dtype)
2761
+
2762
+ if out.shape != expected_shape:
2763
+ raise ValueError("Output array has incorrect shape.")
2764
+ if not out.flags.c_contiguous:
2765
+ raise ValueError("Output array must be C-contiguous.")
2766
+ if out.dtype != np.float64:
2767
+ raise ValueError("Output array must be double type.")
2768
+ return out
2769
+
2770
+
2771
+ def _pdist_callable(X, *, out, metric, **kwargs):
2772
+ n = X.shape[0]
2773
+ out_size = (n * (n - 1)) // 2
2774
+ dm = _prepare_out_argument(out, np.float64, (out_size,))
2775
+ k = 0
2776
+ for i in range(X.shape[0] - 1):
2777
+ for j in range(i + 1, X.shape[0]):
2778
+ dm[k] = metric(X[i], X[j], **kwargs)
2779
+ k += 1
2780
+ return dm
2781
+
2782
+
2783
+ def _cdist_callable(XA, XB, *, out, metric, **kwargs):
2784
+ mA = XA.shape[0]
2785
+ mB = XB.shape[0]
2786
+ dm = _prepare_out_argument(out, np.float64, (mA, mB))
2787
+ for i in range(mA):
2788
+ for j in range(mB):
2789
+ dm[i, j] = metric(XA[i], XB[j], **kwargs)
2790
+ return dm
2791
+
2792
+
2793
+ def cdist(XA, XB, metric='euclidean', *, out=None, **kwargs):
2794
+ """
2795
+ Compute distance between each pair of the two collections of inputs.
2796
+
2797
+ See Notes for common calling conventions.
2798
+
2799
+ Parameters
2800
+ ----------
2801
+ XA : array_like
2802
+ An :math:`m_A` by :math:`n` array of :math:`m_A`
2803
+ original observations in an :math:`n`-dimensional space.
2804
+ Inputs are converted to float type.
2805
+ XB : array_like
2806
+ An :math:`m_B` by :math:`n` array of :math:`m_B`
2807
+ original observations in an :math:`n`-dimensional space.
2808
+ Inputs are converted to float type.
2809
+ metric : str or callable, optional
2810
+ The distance metric to use. If a string, the distance function can be
2811
+ 'braycurtis', 'canberra', 'chebyshev', 'cityblock', 'correlation',
2812
+ 'cosine', 'dice', 'euclidean', 'hamming', 'jaccard', 'jensenshannon',
2813
+ 'kulczynski1', 'mahalanobis', 'matching', 'minkowski',
2814
+ 'rogerstanimoto', 'russellrao', 'seuclidean', 'sokalmichener',
2815
+ 'sokalsneath', 'sqeuclidean', 'yule'.
2816
+ **kwargs : dict, optional
2817
+ Extra arguments to `metric`: refer to each metric documentation for a
2818
+ list of all possible arguments.
2819
+
2820
+ Some possible arguments:
2821
+
2822
+ p : scalar
2823
+ The p-norm to apply for Minkowski, weighted and unweighted.
2824
+ Default: 2.
2825
+
2826
+ w : array_like
2827
+ The weight vector for metrics that support weights (e.g., Minkowski).
2828
+
2829
+ V : array_like
2830
+ The variance vector for standardized Euclidean.
2831
+ Default: var(vstack([XA, XB]), axis=0, ddof=1)
2832
+
2833
+ VI : array_like
2834
+ The inverse of the covariance matrix for Mahalanobis.
2835
+ Default: inv(cov(vstack([XA, XB].T))).T
2836
+
2837
+ out : ndarray
2838
+ The output array
2839
+ If not None, the distance matrix Y is stored in this array.
2840
+
2841
+ Returns
2842
+ -------
2843
+ Y : ndarray
2844
+ A :math:`m_A` by :math:`m_B` distance matrix is returned.
2845
+ For each :math:`i` and :math:`j`, the metric
2846
+ ``dist(u=XA[i], v=XB[j])`` is computed and stored in the
2847
+ :math:`ij` th entry.
2848
+
2849
+ Raises
2850
+ ------
2851
+ ValueError
2852
+ An exception is thrown if `XA` and `XB` do not have
2853
+ the same number of columns.
2854
+
2855
+ Notes
2856
+ -----
2857
+ The following are common calling conventions:
2858
+
2859
+ 1. ``Y = cdist(XA, XB, 'euclidean')``
2860
+
2861
+ Computes the distance between :math:`m` points using
2862
+ Euclidean distance (2-norm) as the distance metric between the
2863
+ points. The points are arranged as :math:`m`
2864
+ :math:`n`-dimensional row vectors in the matrix X.
2865
+
2866
+ 2. ``Y = cdist(XA, XB, 'minkowski', p=2.)``
2867
+
2868
+ Computes the distances using the Minkowski distance
2869
+ :math:`\\|u-v\\|_p` (:math:`p`-norm) where :math:`p > 0` (note
2870
+ that this is only a quasi-metric if :math:`0 < p < 1`).
2871
+
2872
+ 3. ``Y = cdist(XA, XB, 'cityblock')``
2873
+
2874
+ Computes the city block or Manhattan distance between the
2875
+ points.
2876
+
2877
+ 4. ``Y = cdist(XA, XB, 'seuclidean', V=None)``
2878
+
2879
+ Computes the standardized Euclidean distance. The standardized
2880
+ Euclidean distance between two n-vectors ``u`` and ``v`` is
2881
+
2882
+ .. math::
2883
+
2884
+ \\sqrt{\\sum {(u_i-v_i)^2 / V[x_i]}}.
2885
+
2886
+ V is the variance vector; V[i] is the variance computed over all
2887
+ the i'th components of the points. If not passed, it is
2888
+ automatically computed.
2889
+
2890
+ 5. ``Y = cdist(XA, XB, 'sqeuclidean')``
2891
+
2892
+ Computes the squared Euclidean distance :math:`\\|u-v\\|_2^2` between
2893
+ the vectors.
2894
+
2895
+ 6. ``Y = cdist(XA, XB, 'cosine')``
2896
+
2897
+ Computes the cosine distance between vectors u and v,
2898
+
2899
+ .. math::
2900
+
2901
+ 1 - \\frac{u \\cdot v}
2902
+ {{\\|u\\|}_2 {\\|v\\|}_2}
2903
+
2904
+ where :math:`\\|*\\|_2` is the 2-norm of its argument ``*``, and
2905
+ :math:`u \\cdot v` is the dot product of :math:`u` and :math:`v`.
2906
+
2907
+ 7. ``Y = cdist(XA, XB, 'correlation')``
2908
+
2909
+ Computes the correlation distance between vectors u and v. This is
2910
+
2911
+ .. math::
2912
+
2913
+ 1 - \\frac{(u - \\bar{u}) \\cdot (v - \\bar{v})}
2914
+ {{\\|(u - \\bar{u})\\|}_2 {\\|(v - \\bar{v})\\|}_2}
2915
+
2916
+ where :math:`\\bar{v}` is the mean of the elements of vector v,
2917
+ and :math:`x \\cdot y` is the dot product of :math:`x` and :math:`y`.
2918
+
2919
+
2920
+ 8. ``Y = cdist(XA, XB, 'hamming')``
2921
+
2922
+ Computes the normalized Hamming distance, or the proportion of
2923
+ those vector elements between two n-vectors ``u`` and ``v``
2924
+ which disagree. To save memory, the matrix ``X`` can be of type
2925
+ boolean.
2926
+
2927
+ 9. ``Y = cdist(XA, XB, 'jaccard')``
2928
+
2929
+ Computes the Jaccard distance between the points. Given two
2930
+ vectors, ``u`` and ``v``, the Jaccard distance is the
2931
+ proportion of those elements ``u[i]`` and ``v[i]`` that
2932
+ disagree where at least one of them is non-zero.
2933
+
2934
+ 10. ``Y = cdist(XA, XB, 'jensenshannon')``
2935
+
2936
+ Computes the Jensen-Shannon distance between two probability arrays.
2937
+ Given two probability vectors, :math:`p` and :math:`q`, the
2938
+ Jensen-Shannon distance is
2939
+
2940
+ .. math::
2941
+
2942
+ \\sqrt{\\frac{D(p \\parallel m) + D(q \\parallel m)}{2}}
2943
+
2944
+ where :math:`m` is the pointwise mean of :math:`p` and :math:`q`
2945
+ and :math:`D` is the Kullback-Leibler divergence.
2946
+
2947
+ 11. ``Y = cdist(XA, XB, 'chebyshev')``
2948
+
2949
+ Computes the Chebyshev distance between the points. The
2950
+ Chebyshev distance between two n-vectors ``u`` and ``v`` is the
2951
+ maximum norm-1 distance between their respective elements. More
2952
+ precisely, the distance is given by
2953
+
2954
+ .. math::
2955
+
2956
+ d(u,v) = \\max_i {|u_i-v_i|}.
2957
+
2958
+ 12. ``Y = cdist(XA, XB, 'canberra')``
2959
+
2960
+ Computes the Canberra distance between the points. The
2961
+ Canberra distance between two points ``u`` and ``v`` is
2962
+
2963
+ .. math::
2964
+
2965
+ d(u,v) = \\sum_i \\frac{|u_i-v_i|}
2966
+ {|u_i|+|v_i|}.
2967
+
2968
+ 13. ``Y = cdist(XA, XB, 'braycurtis')``
2969
+
2970
+ Computes the Bray-Curtis distance between the points. The
2971
+ Bray-Curtis distance between two points ``u`` and ``v`` is
2972
+
2973
+
2974
+ .. math::
2975
+
2976
+ d(u,v) = \\frac{\\sum_i (|u_i-v_i|)}
2977
+ {\\sum_i (|u_i+v_i|)}
2978
+
2979
+ 14. ``Y = cdist(XA, XB, 'mahalanobis', VI=None)``
2980
+
2981
+ Computes the Mahalanobis distance between the points. The
2982
+ Mahalanobis distance between two points ``u`` and ``v`` is
2983
+ :math:`\\sqrt{(u-v)(1/V)(u-v)^T}` where :math:`(1/V)` (the ``VI``
2984
+ variable) is the inverse covariance. If ``VI`` is not None,
2985
+ ``VI`` will be used as the inverse covariance matrix.
2986
+
2987
+ 15. ``Y = cdist(XA, XB, 'yule')``
2988
+
2989
+ Computes the Yule distance between the boolean
2990
+ vectors. (see `yule` function documentation)
2991
+
2992
+ 16. ``Y = cdist(XA, XB, 'matching')``
2993
+
2994
+ Synonym for 'hamming'.
2995
+
2996
+ 17. ``Y = cdist(XA, XB, 'dice')``
2997
+
2998
+ Computes the Dice distance between the boolean vectors. (see
2999
+ `dice` function documentation)
3000
+
3001
+ 18. ``Y = cdist(XA, XB, 'kulczynski1')``
3002
+
3003
+ Computes the kulczynski distance between the boolean
3004
+ vectors. (see `kulczynski1` function documentation)
3005
+
3006
+ .. deprecated:: 1.15.0
3007
+ This metric is deprecated and will be removed in SciPy 1.17.0.
3008
+ Replace usage of ``cdist(XA, XB, 'kulczynski1')`` with
3009
+ ``1 / cdist(XA, XB, 'jaccard') - 1``.
3010
+
3011
+ 19. ``Y = cdist(XA, XB, 'rogerstanimoto')``
3012
+
3013
+ Computes the Rogers-Tanimoto distance between the boolean
3014
+ vectors. (see `rogerstanimoto` function documentation)
3015
+
3016
+ 20. ``Y = cdist(XA, XB, 'russellrao')``
3017
+
3018
+ Computes the Russell-Rao distance between the boolean
3019
+ vectors. (see `russellrao` function documentation)
3020
+
3021
+ 21. ``Y = cdist(XA, XB, 'sokalmichener')``
3022
+
3023
+ Computes the Sokal-Michener distance between the boolean
3024
+ vectors. (see `sokalmichener` function documentation)
3025
+
3026
+ .. deprecated:: 1.15.0
3027
+ This metric is deprecated and will be removed in SciPy 1.17.0.
3028
+ Replace usage of ``cdist(XA, XB, 'sokalmichener')`` with
3029
+ ``cdist(XA, XB, 'rogerstanimoto')``.
3030
+
3031
+ 22. ``Y = cdist(XA, XB, 'sokalsneath')``
3032
+
3033
+ Computes the Sokal-Sneath distance between the vectors. (see
3034
+ `sokalsneath` function documentation)
3035
+
3036
+ 23. ``Y = cdist(XA, XB, f)``
3037
+
3038
+ Computes the distance between all pairs of vectors in X
3039
+ using the user supplied 2-arity function f. For example,
3040
+ Euclidean distance between the vectors could be computed
3041
+ as follows::
3042
+
3043
+ dm = cdist(XA, XB, lambda u, v: np.sqrt(((u-v)**2).sum()))
3044
+
3045
+ Note that you should avoid passing a reference to one of
3046
+ the distance functions defined in this library. For example,::
3047
+
3048
+ dm = cdist(XA, XB, sokalsneath)
3049
+
3050
+ would calculate the pair-wise distances between the vectors in
3051
+ X using the Python function `sokalsneath`. This would result in
3052
+ sokalsneath being called :math:`{n \\choose 2}` times, which
3053
+ is inefficient. Instead, the optimized C version is more
3054
+ efficient, and we call it using the following syntax::
3055
+
3056
+ dm = cdist(XA, XB, 'sokalsneath')
3057
+
3058
+ Examples
3059
+ --------
3060
+ Find the Euclidean distances between four 2-D coordinates:
3061
+
3062
+ >>> from scipy.spatial import distance
3063
+ >>> import numpy as np
3064
+ >>> coords = [(35.0456, -85.2672),
3065
+ ... (35.1174, -89.9711),
3066
+ ... (35.9728, -83.9422),
3067
+ ... (36.1667, -86.7833)]
3068
+ >>> distance.cdist(coords, coords, 'euclidean')
3069
+ array([[ 0. , 4.7044, 1.6172, 1.8856],
3070
+ [ 4.7044, 0. , 6.0893, 3.3561],
3071
+ [ 1.6172, 6.0893, 0. , 2.8477],
3072
+ [ 1.8856, 3.3561, 2.8477, 0. ]])
3073
+
3074
+
3075
+ Find the Manhattan distance from a 3-D point to the corners of the unit
3076
+ cube:
3077
+
3078
+ >>> a = np.array([[0, 0, 0],
3079
+ ... [0, 0, 1],
3080
+ ... [0, 1, 0],
3081
+ ... [0, 1, 1],
3082
+ ... [1, 0, 0],
3083
+ ... [1, 0, 1],
3084
+ ... [1, 1, 0],
3085
+ ... [1, 1, 1]])
3086
+ >>> b = np.array([[ 0.1, 0.2, 0.4]])
3087
+ >>> distance.cdist(a, b, 'cityblock')
3088
+ array([[ 0.7],
3089
+ [ 0.9],
3090
+ [ 1.3],
3091
+ [ 1.5],
3092
+ [ 1.5],
3093
+ [ 1.7],
3094
+ [ 2.1],
3095
+ [ 2.3]])
3096
+
3097
+ """
3098
+ # You can also call this as:
3099
+ # Y = cdist(XA, XB, 'test_abc')
3100
+ # where 'abc' is the metric being tested. This computes the distance
3101
+ # between all pairs of vectors in XA and XB using the distance metric 'abc'
3102
+ # but with a more succinct, verifiable, but less efficient implementation.
3103
+
3104
+ XA = np.asarray(XA)
3105
+ XB = np.asarray(XB)
3106
+
3107
+ s = XA.shape
3108
+ sB = XB.shape
3109
+
3110
+ if len(s) != 2:
3111
+ raise ValueError('XA must be a 2-dimensional array.')
3112
+ if len(sB) != 2:
3113
+ raise ValueError('XB must be a 2-dimensional array.')
3114
+ if s[1] != sB[1]:
3115
+ raise ValueError('XA and XB must have the same number of columns '
3116
+ '(i.e. feature dimension.)')
3117
+
3118
+ mA = s[0]
3119
+ mB = sB[0]
3120
+ n = s[1]
3121
+
3122
+ if callable(metric):
3123
+ mstr = getattr(metric, '__name__', 'Unknown')
3124
+ metric_info = _METRIC_ALIAS.get(mstr, None)
3125
+ if metric_info is not None:
3126
+ XA, XB, typ, kwargs = _validate_cdist_input(
3127
+ XA, XB, mA, mB, n, metric_info, **kwargs)
3128
+ return _cdist_callable(XA, XB, metric=metric, out=out, **kwargs)
3129
+ elif isinstance(metric, str):
3130
+ mstr = metric.lower()
3131
+ metric_info = _METRIC_ALIAS.get(mstr, None)
3132
+ if metric_info is not None:
3133
+ cdist_fn = metric_info.cdist_func
3134
+ return cdist_fn(XA, XB, out=out, **kwargs)
3135
+ elif mstr.startswith("test_"):
3136
+ metric_info = _TEST_METRICS.get(mstr, None)
3137
+ if metric_info is None:
3138
+ raise ValueError(f'Unknown "Test" Distance Metric: {mstr[5:]}')
3139
+ XA, XB, typ, kwargs = _validate_cdist_input(
3140
+ XA, XB, mA, mB, n, metric_info, **kwargs)
3141
+ return _cdist_callable(
3142
+ XA, XB, metric=metric_info.dist_func, out=out, **kwargs)
3143
+ else:
3144
+ raise ValueError(f'Unknown Distance Metric: {mstr}')
3145
+ else:
3146
+ raise TypeError('2nd argument metric must be a string identifier '
3147
+ 'or a function.')