scipy 1.16.1__cp314-cp314-win_amd64.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 (1529) hide show
  1. scipy/__config__.py +161 -0
  2. scipy/__init__.py +150 -0
  3. scipy/_cyutility.cp314-win_amd64.dll.a +0 -0
  4. scipy/_cyutility.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  13. scipy/_lib/_ccallback_c.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  18. scipy/_lib/_fpumode.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  23. scipy/_lib/_test_ccallback.cp314-win_amd64.pyd +0 -0
  24. scipy/_lib/_test_deprecation_call.cp314-win_amd64.dll.a +0 -0
  25. scipy/_lib/_test_deprecation_call.cp314-win_amd64.pyd +0 -0
  26. scipy/_lib/_test_deprecation_def.cp314-win_amd64.dll.a +0 -0
  27. scipy/_lib/_test_deprecation_def.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  35. scipy/_lib/_uarray/_uarray.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  101. scipy/_lib/messagestream.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  148. scipy/cluster/_hierarchy.cp314-win_amd64.pyd +0 -0
  149. scipy/cluster/_optimal_leaf_ordering.cp314-win_amd64.dll.a +0 -0
  150. scipy/cluster/_optimal_leaf_ordering.cp314-win_amd64.pyd +0 -0
  151. scipy/cluster/_vq.cp314-win_amd64.dll.a +0 -0
  152. scipy/cluster/_vq.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  193. scipy/fft/_pocketfft/pypocketfft.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  215. scipy/fftpack/convolve.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  233. scipy/integrate/_dop.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  248. scipy/integrate/_lsoda.cp314-win_amd64.pyd +0 -0
  249. scipy/integrate/_ode.py +1395 -0
  250. scipy/integrate/_odepack.cp314-win_amd64.dll.a +0 -0
  251. scipy/integrate/_odepack.cp314-win_amd64.pyd +0 -0
  252. scipy/integrate/_odepack_py.py +273 -0
  253. scipy/integrate/_quad_vec.py +674 -0
  254. scipy/integrate/_quadpack.cp314-win_amd64.dll.a +0 -0
  255. scipy/integrate/_quadpack.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  265. scipy/integrate/_test_multivariate.cp314-win_amd64.pyd +0 -0
  266. scipy/integrate/_test_odeint_banded.cp314-win_amd64.dll.a +0 -0
  267. scipy/integrate/_test_odeint_banded.cp314-win_amd64.pyd +0 -0
  268. scipy/integrate/_vode.cp314-win_amd64.dll.a +0 -0
  269. scipy/integrate/_vode.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  290. scipy/interpolate/_dfitpack.cp314-win_amd64.pyd +0 -0
  291. scipy/interpolate/_dierckx.cp314-win_amd64.dll.a +0 -0
  292. scipy/interpolate/_dierckx.cp314-win_amd64.pyd +0 -0
  293. scipy/interpolate/_fitpack.cp314-win_amd64.dll.a +0 -0
  294. scipy/interpolate/_fitpack.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  300. scipy/interpolate/_interpnd.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  307. scipy/interpolate/_ppoly.cp314-win_amd64.pyd +0 -0
  308. scipy/interpolate/_rbf.py +290 -0
  309. scipy/interpolate/_rbfinterp.py +550 -0
  310. scipy/interpolate/_rbfinterp_pythran.cp314-win_amd64.dll.a +0 -0
  311. scipy/interpolate/_rbfinterp_pythran.cp314-win_amd64.pyd +0 -0
  312. scipy/interpolate/_rgi.py +764 -0
  313. scipy/interpolate/_rgi_cython.cp314-win_amd64.dll.a +0 -0
  314. scipy/interpolate/_rgi_cython.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  343. scipy/io/_fast_matrix_market/_fmm_core.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  355. scipy/io/_test_fortran.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  386. scipy/io/matlab/_mio5_utils.cp314-win_amd64.pyd +0 -0
  387. scipy/io/matlab/_mio_utils.cp314-win_amd64.dll.a +0 -0
  388. scipy/io/matlab/_mio_utils.cp314-win_amd64.pyd +0 -0
  389. scipy/io/matlab/_miobase.py +435 -0
  390. scipy/io/matlab/_streams.cp314-win_amd64.dll.a +0 -0
  391. scipy/io/matlab/_streams.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  623. scipy/linalg/_cythonized_array_utils.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  630. scipy/linalg/_decomp_interpolative.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  634. scipy/linalg/_decomp_lu_cython.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  642. scipy/linalg/_decomp_update.cp314-win_amd64.pyd +0 -0
  643. scipy/linalg/_expm_frechet.py +417 -0
  644. scipy/linalg/_fblas.cp314-win_amd64.dll.a +0 -0
  645. scipy/linalg/_fblas.cp314-win_amd64.pyd +0 -0
  646. scipy/linalg/_flapack.cp314-win_amd64.dll.a +0 -0
  647. scipy/linalg/_flapack.cp314-win_amd64.pyd +0 -0
  648. scipy/linalg/_lapack_subroutines.h +1521 -0
  649. scipy/linalg/_linalg_pythran.cp314-win_amd64.dll.a +0 -0
  650. scipy/linalg/_linalg_pythran.cp314-win_amd64.pyd +0 -0
  651. scipy/linalg/_matfuncs.py +1050 -0
  652. scipy/linalg/_matfuncs_expm.cp314-win_amd64.dll.a +0 -0
  653. scipy/linalg/_matfuncs_expm.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  657. scipy/linalg/_matfuncs_schur_sqrtm.cp314-win_amd64.pyd +0 -0
  658. scipy/linalg/_matfuncs_sqrtm.py +107 -0
  659. scipy/linalg/_matfuncs_sqrtm_triu.cp314-win_amd64.dll.a +0 -0
  660. scipy/linalg/_matfuncs_sqrtm_triu.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  665. scipy/linalg/_solve_toeplitz.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  672. scipy/linalg/cython_blas.cp314-win_amd64.pyd +0 -0
  673. scipy/linalg/cython_blas.pxd +169 -0
  674. scipy/linalg/cython_blas.pyx +1432 -0
  675. scipy/linalg/cython_lapack.cp314-win_amd64.dll.a +0 -0
  676. scipy/linalg/cython_lapack.cp314-win_amd64.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 +3616 -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.cp314-win_amd64.dll.a +0 -0
  728. scipy/ndimage/_ctest.cp314-win_amd64.pyd +0 -0
  729. scipy/ndimage/_cytest.cp314-win_amd64.dll.a +0 -0
  730. scipy/ndimage/_cytest.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  738. scipy/ndimage/_nd_image.cp314-win_amd64.pyd +0 -0
  739. scipy/ndimage/_ndimage_api.py +16 -0
  740. scipy/ndimage/_ni_docstrings.py +214 -0
  741. scipy/ndimage/_ni_label.cp314-win_amd64.dll.a +0 -0
  742. scipy/ndimage/_ni_label.cp314-win_amd64.pyd +0 -0
  743. scipy/ndimage/_ni_support.py +139 -0
  744. scipy/ndimage/_rank_filter_1d.cp314-win_amd64.dll.a +0 -0
  745. scipy/ndimage/_rank_filter_1d.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  768. scipy/odr/__odrpack.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  780. scipy/optimize/_bglu_dense.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  790. scipy/optimize/_direct.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  795. scipy/optimize/_group_columns.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  799. scipy/optimize/_highspy/_core.cp314-win_amd64.pyd +0 -0
  800. scipy/optimize/_highspy/_highs_options.cp314-win_amd64.dll.a +0 -0
  801. scipy/optimize/_highspy/_highs_options.cp314-win_amd64.pyd +0 -0
  802. scipy/optimize/_highspy/_highs_wrapper.py +338 -0
  803. scipy/optimize/_isotonic.py +157 -0
  804. scipy/optimize/_lbfgsb.cp314-win_amd64.dll.a +0 -0
  805. scipy/optimize/_lbfgsb.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  816. scipy/optimize/_lsap.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  822. scipy/optimize/_lsq/givens_elimination.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  830. scipy/optimize/_minpack.cp314-win_amd64.pyd +0 -0
  831. scipy/optimize/_minpack_py.py +1178 -0
  832. scipy/optimize/_moduleTNC.cp314-win_amd64.dll.a +0 -0
  833. scipy/optimize/_moduleTNC.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  839. scipy/optimize/_pava_pybind.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  850. scipy/optimize/_slsqplib.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  855. scipy/optimize/_trlib/_trlib.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  877. scipy/optimize/_zeros.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  882. scipy/optimize/cython_optimize/_zeros.cp314-win_amd64.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 +3335 -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.cp314-win_amd64.dll.a +0 -0
  953. scipy/signal/_max_len_seq_inner.cp314-win_amd64.pyd +0 -0
  954. scipy/signal/_peak_finding.py +1310 -0
  955. scipy/signal/_peak_finding_utils.cp314-win_amd64.dll.a +0 -0
  956. scipy/signal/_peak_finding_utils.cp314-win_amd64.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 +2187 -0
  960. scipy/signal/_signal_api.py +30 -0
  961. scipy/signal/_signaltools.py +5309 -0
  962. scipy/signal/_sigtools.cp314-win_amd64.dll.a +0 -0
  963. scipy/signal/_sigtools.cp314-win_amd64.pyd +0 -0
  964. scipy/signal/_sosfilt.cp314-win_amd64.dll.a +0 -0
  965. scipy/signal/_sosfilt.cp314-win_amd64.pyd +0 -0
  966. scipy/signal/_spectral_py.py +2471 -0
  967. scipy/signal/_spline.cp314-win_amd64.dll.a +0 -0
  968. scipy/signal/_spline.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  974. scipy/signal/_upfirdn_apply.cp314-win_amd64.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 +1098 -0
  1001. scipy/signal/tests/test_signaltools.py +4729 -0
  1002. scipy/signal/tests/test_spectral.py +2103 -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.cp314-win_amd64.dll.a +0 -0
  1021. scipy/sparse/_csparsetools.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  1032. scipy/sparse/_sparsetools.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  1043. scipy/sparse/csgraph/_flow.cp314-win_amd64.pyd +0 -0
  1044. scipy/sparse/csgraph/_laplacian.py +563 -0
  1045. scipy/sparse/csgraph/_matching.cp314-win_amd64.dll.a +0 -0
  1046. scipy/sparse/csgraph/_matching.cp314-win_amd64.pyd +0 -0
  1047. scipy/sparse/csgraph/_min_spanning_tree.cp314-win_amd64.dll.a +0 -0
  1048. scipy/sparse/csgraph/_min_spanning_tree.cp314-win_amd64.pyd +0 -0
  1049. scipy/sparse/csgraph/_reordering.cp314-win_amd64.dll.a +0 -0
  1050. scipy/sparse/csgraph/_reordering.cp314-win_amd64.pyd +0 -0
  1051. scipy/sparse/csgraph/_shortest_path.cp314-win_amd64.dll.a +0 -0
  1052. scipy/sparse/csgraph/_shortest_path.cp314-win_amd64.pyd +0 -0
  1053. scipy/sparse/csgraph/_tools.cp314-win_amd64.dll.a +0 -0
  1054. scipy/sparse/csgraph/_tools.cp314-win_amd64.pyd +0 -0
  1055. scipy/sparse/csgraph/_traversal.cp314-win_amd64.dll.a +0 -0
  1056. scipy/sparse/csgraph/_traversal.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  1079. scipy/sparse/linalg/_dsolve/_superlu.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  1089. scipy/sparse/linalg/_eigen/arpack/_arpack.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  1122. scipy/sparse/linalg/_propack/_cpropack.cp314-win_amd64.pyd +0 -0
  1123. scipy/sparse/linalg/_propack/_dpropack.cp314-win_amd64.dll.a +0 -0
  1124. scipy/sparse/linalg/_propack/_dpropack.cp314-win_amd64.pyd +0 -0
  1125. scipy/sparse/linalg/_propack/_spropack.cp314-win_amd64.dll.a +0 -0
  1126. scipy/sparse/linalg/_propack/_spropack.cp314-win_amd64.pyd +0 -0
  1127. scipy/sparse/linalg/_propack/_zpropack.cp314-win_amd64.dll.a +0 -0
  1128. scipy/sparse/linalg/_propack/_zpropack.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  1170. scipy/spatial/_ckdtree.cp314-win_amd64.pyd +0 -0
  1171. scipy/spatial/_distance_pybind.cp314-win_amd64.dll.a +0 -0
  1172. scipy/spatial/_distance_pybind.cp314-win_amd64.pyd +0 -0
  1173. scipy/spatial/_distance_wrap.cp314-win_amd64.dll.a +0 -0
  1174. scipy/spatial/_distance_wrap.cp314-win_amd64.pyd +0 -0
  1175. scipy/spatial/_geometric_slerp.py +238 -0
  1176. scipy/spatial/_hausdorff.cp314-win_amd64.dll.a +0 -0
  1177. scipy/spatial/_hausdorff.cp314-win_amd64.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.cp314-win_amd64.dll.a +0 -0
  1182. scipy/spatial/_qhull.cp314-win_amd64.pyd +0 -0
  1183. scipy/spatial/_qhull.pyi +213 -0
  1184. scipy/spatial/_spherical_voronoi.py +341 -0
  1185. scipy/spatial/_voronoi.cp314-win_amd64.dll.a +0 -0
  1186. scipy/spatial/_voronoi.cp314-win_amd64.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/tests/__init__.py +0 -0
  1194. scipy/spatial/tests/data/cdist-X1.txt +10 -0
  1195. scipy/spatial/tests/data/cdist-X2.txt +20 -0
  1196. scipy/spatial/tests/data/degenerate_pointset.npz +0 -0
  1197. scipy/spatial/tests/data/iris.txt +150 -0
  1198. scipy/spatial/tests/data/pdist-boolean-inp.txt +20 -0
  1199. scipy/spatial/tests/data/pdist-chebyshev-ml-iris.txt +1 -0
  1200. scipy/spatial/tests/data/pdist-chebyshev-ml.txt +1 -0
  1201. scipy/spatial/tests/data/pdist-cityblock-ml-iris.txt +1 -0
  1202. scipy/spatial/tests/data/pdist-cityblock-ml.txt +1 -0
  1203. scipy/spatial/tests/data/pdist-correlation-ml-iris.txt +1 -0
  1204. scipy/spatial/tests/data/pdist-correlation-ml.txt +1 -0
  1205. scipy/spatial/tests/data/pdist-cosine-ml-iris.txt +1 -0
  1206. scipy/spatial/tests/data/pdist-cosine-ml.txt +1 -0
  1207. scipy/spatial/tests/data/pdist-double-inp.txt +20 -0
  1208. scipy/spatial/tests/data/pdist-euclidean-ml-iris.txt +1 -0
  1209. scipy/spatial/tests/data/pdist-euclidean-ml.txt +1 -0
  1210. scipy/spatial/tests/data/pdist-hamming-ml.txt +1 -0
  1211. scipy/spatial/tests/data/pdist-jaccard-ml.txt +1 -0
  1212. scipy/spatial/tests/data/pdist-jensenshannon-ml-iris.txt +1 -0
  1213. scipy/spatial/tests/data/pdist-jensenshannon-ml.txt +1 -0
  1214. scipy/spatial/tests/data/pdist-minkowski-3.2-ml-iris.txt +1 -0
  1215. scipy/spatial/tests/data/pdist-minkowski-3.2-ml.txt +1 -0
  1216. scipy/spatial/tests/data/pdist-minkowski-5.8-ml-iris.txt +1 -0
  1217. scipy/spatial/tests/data/pdist-seuclidean-ml-iris.txt +1 -0
  1218. scipy/spatial/tests/data/pdist-seuclidean-ml.txt +1 -0
  1219. scipy/spatial/tests/data/pdist-spearman-ml.txt +1 -0
  1220. scipy/spatial/tests/data/random-bool-data.txt +100 -0
  1221. scipy/spatial/tests/data/random-double-data.txt +100 -0
  1222. scipy/spatial/tests/data/random-int-data.txt +100 -0
  1223. scipy/spatial/tests/data/random-uint-data.txt +100 -0
  1224. scipy/spatial/tests/data/selfdual-4d-polytope.txt +27 -0
  1225. scipy/spatial/tests/test__plotutils.py +91 -0
  1226. scipy/spatial/tests/test__procrustes.py +116 -0
  1227. scipy/spatial/tests/test_distance.py +2388 -0
  1228. scipy/spatial/tests/test_hausdorff.py +199 -0
  1229. scipy/spatial/tests/test_kdtree.py +1536 -0
  1230. scipy/spatial/tests/test_qhull.py +1313 -0
  1231. scipy/spatial/tests/test_slerp.py +417 -0
  1232. scipy/spatial/tests/test_spherical_voronoi.py +358 -0
  1233. scipy/spatial/transform/__init__.py +31 -0
  1234. scipy/spatial/transform/_rigid_transform.cp314-win_amd64.dll.a +0 -0
  1235. scipy/spatial/transform/_rigid_transform.cp314-win_amd64.pyd +0 -0
  1236. scipy/spatial/transform/_rotation.cp314-win_amd64.dll.a +0 -0
  1237. scipy/spatial/transform/_rotation.cp314-win_amd64.pyd +0 -0
  1238. scipy/spatial/transform/_rotation_groups.py +140 -0
  1239. scipy/spatial/transform/_rotation_spline.py +460 -0
  1240. scipy/spatial/transform/rotation.py +21 -0
  1241. scipy/spatial/transform/tests/__init__.py +0 -0
  1242. scipy/spatial/transform/tests/test_rigid_transform.py +1221 -0
  1243. scipy/spatial/transform/tests/test_rotation.py +2569 -0
  1244. scipy/spatial/transform/tests/test_rotation_groups.py +169 -0
  1245. scipy/spatial/transform/tests/test_rotation_spline.py +183 -0
  1246. scipy/special/__init__.pxd +1 -0
  1247. scipy/special/__init__.py +841 -0
  1248. scipy/special/_add_newdocs.py +9961 -0
  1249. scipy/special/_basic.py +3576 -0
  1250. scipy/special/_comb.cp314-win_amd64.dll.a +0 -0
  1251. scipy/special/_comb.cp314-win_amd64.pyd +0 -0
  1252. scipy/special/_ellip_harm.py +214 -0
  1253. scipy/special/_ellip_harm_2.cp314-win_amd64.dll.a +0 -0
  1254. scipy/special/_ellip_harm_2.cp314-win_amd64.pyd +0 -0
  1255. scipy/special/_gufuncs.cp314-win_amd64.dll.a +0 -0
  1256. scipy/special/_gufuncs.cp314-win_amd64.pyd +0 -0
  1257. scipy/special/_input_validation.py +17 -0
  1258. scipy/special/_lambertw.py +149 -0
  1259. scipy/special/_logsumexp.py +426 -0
  1260. scipy/special/_mptestutils.py +453 -0
  1261. scipy/special/_multiufuncs.py +610 -0
  1262. scipy/special/_orthogonal.py +2592 -0
  1263. scipy/special/_orthogonal.pyi +330 -0
  1264. scipy/special/_precompute/__init__.py +0 -0
  1265. scipy/special/_precompute/cosine_cdf.py +17 -0
  1266. scipy/special/_precompute/expn_asy.py +54 -0
  1267. scipy/special/_precompute/gammainc_asy.py +116 -0
  1268. scipy/special/_precompute/gammainc_data.py +124 -0
  1269. scipy/special/_precompute/hyp2f1_data.py +484 -0
  1270. scipy/special/_precompute/lambertw.py +68 -0
  1271. scipy/special/_precompute/loggamma.py +43 -0
  1272. scipy/special/_precompute/struve_convergence.py +131 -0
  1273. scipy/special/_precompute/utils.py +38 -0
  1274. scipy/special/_precompute/wright_bessel.py +342 -0
  1275. scipy/special/_precompute/wright_bessel_data.py +152 -0
  1276. scipy/special/_precompute/wrightomega.py +41 -0
  1277. scipy/special/_precompute/zetac.py +27 -0
  1278. scipy/special/_sf_error.py +15 -0
  1279. scipy/special/_specfun.cp314-win_amd64.dll.a +0 -0
  1280. scipy/special/_specfun.cp314-win_amd64.pyd +0 -0
  1281. scipy/special/_special_ufuncs.cp314-win_amd64.dll.a +0 -0
  1282. scipy/special/_special_ufuncs.cp314-win_amd64.pyd +0 -0
  1283. scipy/special/_spfun_stats.py +106 -0
  1284. scipy/special/_spherical_bessel.py +397 -0
  1285. scipy/special/_support_alternative_backends.py +295 -0
  1286. scipy/special/_test_internal.cp314-win_amd64.dll.a +0 -0
  1287. scipy/special/_test_internal.cp314-win_amd64.pyd +0 -0
  1288. scipy/special/_test_internal.pyi +9 -0
  1289. scipy/special/_testutils.py +321 -0
  1290. scipy/special/_ufuncs.cp314-win_amd64.dll.a +0 -0
  1291. scipy/special/_ufuncs.cp314-win_amd64.pyd +0 -0
  1292. scipy/special/_ufuncs.pyi +522 -0
  1293. scipy/special/_ufuncs.pyx +13173 -0
  1294. scipy/special/_ufuncs_cxx.cp314-win_amd64.dll.a +0 -0
  1295. scipy/special/_ufuncs_cxx.cp314-win_amd64.pyd +0 -0
  1296. scipy/special/_ufuncs_cxx.pxd +142 -0
  1297. scipy/special/_ufuncs_cxx.pyx +427 -0
  1298. scipy/special/_ufuncs_cxx_defs.h +147 -0
  1299. scipy/special/_ufuncs_defs.h +57 -0
  1300. scipy/special/add_newdocs.py +15 -0
  1301. scipy/special/basic.py +87 -0
  1302. scipy/special/cython_special.cp314-win_amd64.dll.a +0 -0
  1303. scipy/special/cython_special.cp314-win_amd64.pyd +0 -0
  1304. scipy/special/cython_special.pxd +259 -0
  1305. scipy/special/cython_special.pyi +3 -0
  1306. scipy/special/orthogonal.py +45 -0
  1307. scipy/special/sf_error.py +20 -0
  1308. scipy/special/specfun.py +24 -0
  1309. scipy/special/spfun_stats.py +17 -0
  1310. scipy/special/tests/__init__.py +0 -0
  1311. scipy/special/tests/_cython_examples/extending.pyx +12 -0
  1312. scipy/special/tests/_cython_examples/meson.build +34 -0
  1313. scipy/special/tests/data/__init__.py +0 -0
  1314. scipy/special/tests/data/boost.npz +0 -0
  1315. scipy/special/tests/data/gsl.npz +0 -0
  1316. scipy/special/tests/data/local.npz +0 -0
  1317. scipy/special/tests/test_basic.py +4815 -0
  1318. scipy/special/tests/test_bdtr.py +112 -0
  1319. scipy/special/tests/test_boost_ufuncs.py +64 -0
  1320. scipy/special/tests/test_boxcox.py +125 -0
  1321. scipy/special/tests/test_cdflib.py +712 -0
  1322. scipy/special/tests/test_cdft_asymptotic.py +49 -0
  1323. scipy/special/tests/test_cephes_intp_cast.py +29 -0
  1324. scipy/special/tests/test_cosine_distr.py +83 -0
  1325. scipy/special/tests/test_cython_special.py +363 -0
  1326. scipy/special/tests/test_data.py +719 -0
  1327. scipy/special/tests/test_dd.py +42 -0
  1328. scipy/special/tests/test_digamma.py +45 -0
  1329. scipy/special/tests/test_ellip_harm.py +278 -0
  1330. scipy/special/tests/test_erfinv.py +89 -0
  1331. scipy/special/tests/test_exponential_integrals.py +118 -0
  1332. scipy/special/tests/test_extending.py +28 -0
  1333. scipy/special/tests/test_faddeeva.py +85 -0
  1334. scipy/special/tests/test_gamma.py +12 -0
  1335. scipy/special/tests/test_gammainc.py +152 -0
  1336. scipy/special/tests/test_hyp2f1.py +2566 -0
  1337. scipy/special/tests/test_hypergeometric.py +234 -0
  1338. scipy/special/tests/test_iv_ratio.py +249 -0
  1339. scipy/special/tests/test_kolmogorov.py +491 -0
  1340. scipy/special/tests/test_lambertw.py +109 -0
  1341. scipy/special/tests/test_legendre.py +1518 -0
  1342. scipy/special/tests/test_log1mexp.py +85 -0
  1343. scipy/special/tests/test_loggamma.py +70 -0
  1344. scipy/special/tests/test_logit.py +162 -0
  1345. scipy/special/tests/test_logsumexp.py +469 -0
  1346. scipy/special/tests/test_mpmath.py +2293 -0
  1347. scipy/special/tests/test_nan_inputs.py +65 -0
  1348. scipy/special/tests/test_ndtr.py +77 -0
  1349. scipy/special/tests/test_ndtri_exp.py +94 -0
  1350. scipy/special/tests/test_orthogonal.py +821 -0
  1351. scipy/special/tests/test_orthogonal_eval.py +275 -0
  1352. scipy/special/tests/test_owens_t.py +53 -0
  1353. scipy/special/tests/test_pcf.py +24 -0
  1354. scipy/special/tests/test_pdtr.py +48 -0
  1355. scipy/special/tests/test_powm1.py +65 -0
  1356. scipy/special/tests/test_precompute_expn_asy.py +24 -0
  1357. scipy/special/tests/test_precompute_gammainc.py +108 -0
  1358. scipy/special/tests/test_precompute_utils.py +36 -0
  1359. scipy/special/tests/test_round.py +18 -0
  1360. scipy/special/tests/test_sf_error.py +146 -0
  1361. scipy/special/tests/test_sici.py +36 -0
  1362. scipy/special/tests/test_specfun.py +48 -0
  1363. scipy/special/tests/test_spence.py +32 -0
  1364. scipy/special/tests/test_spfun_stats.py +61 -0
  1365. scipy/special/tests/test_sph_harm.py +85 -0
  1366. scipy/special/tests/test_spherical_bessel.py +400 -0
  1367. scipy/special/tests/test_support_alternative_backends.py +248 -0
  1368. scipy/special/tests/test_trig.py +72 -0
  1369. scipy/special/tests/test_ufunc_signatures.py +46 -0
  1370. scipy/special/tests/test_wright_bessel.py +205 -0
  1371. scipy/special/tests/test_wrightomega.py +117 -0
  1372. scipy/special/tests/test_zeta.py +301 -0
  1373. scipy/stats/__init__.py +670 -0
  1374. scipy/stats/_ansari_swilk_statistics.cp314-win_amd64.dll.a +0 -0
  1375. scipy/stats/_ansari_swilk_statistics.cp314-win_amd64.pyd +0 -0
  1376. scipy/stats/_axis_nan_policy.py +692 -0
  1377. scipy/stats/_biasedurn.cp314-win_amd64.dll.a +0 -0
  1378. scipy/stats/_biasedurn.cp314-win_amd64.pyd +0 -0
  1379. scipy/stats/_biasedurn.pxd +27 -0
  1380. scipy/stats/_binned_statistic.py +795 -0
  1381. scipy/stats/_binomtest.py +375 -0
  1382. scipy/stats/_bws_test.py +177 -0
  1383. scipy/stats/_censored_data.py +459 -0
  1384. scipy/stats/_common.py +5 -0
  1385. scipy/stats/_constants.py +42 -0
  1386. scipy/stats/_continued_fraction.py +387 -0
  1387. scipy/stats/_continuous_distns.py +12486 -0
  1388. scipy/stats/_correlation.py +210 -0
  1389. scipy/stats/_covariance.py +636 -0
  1390. scipy/stats/_crosstab.py +204 -0
  1391. scipy/stats/_discrete_distns.py +2098 -0
  1392. scipy/stats/_distn_infrastructure.py +4201 -0
  1393. scipy/stats/_distr_params.py +299 -0
  1394. scipy/stats/_distribution_infrastructure.py +5750 -0
  1395. scipy/stats/_entropy.py +428 -0
  1396. scipy/stats/_finite_differences.py +145 -0
  1397. scipy/stats/_fit.py +1351 -0
  1398. scipy/stats/_hypotests.py +2060 -0
  1399. scipy/stats/_kde.py +732 -0
  1400. scipy/stats/_ksstats.py +600 -0
  1401. scipy/stats/_levy_stable/__init__.py +1231 -0
  1402. scipy/stats/_levy_stable/levyst.cp314-win_amd64.dll.a +0 -0
  1403. scipy/stats/_levy_stable/levyst.cp314-win_amd64.pyd +0 -0
  1404. scipy/stats/_mannwhitneyu.py +492 -0
  1405. scipy/stats/_mgc.py +550 -0
  1406. scipy/stats/_morestats.py +4626 -0
  1407. scipy/stats/_mstats_basic.py +3658 -0
  1408. scipy/stats/_mstats_extras.py +521 -0
  1409. scipy/stats/_multicomp.py +449 -0
  1410. scipy/stats/_multivariate.py +7281 -0
  1411. scipy/stats/_new_distributions.py +452 -0
  1412. scipy/stats/_odds_ratio.py +466 -0
  1413. scipy/stats/_page_trend_test.py +486 -0
  1414. scipy/stats/_probability_distribution.py +1964 -0
  1415. scipy/stats/_qmc.py +2956 -0
  1416. scipy/stats/_qmc_cy.cp314-win_amd64.dll.a +0 -0
  1417. scipy/stats/_qmc_cy.cp314-win_amd64.pyd +0 -0
  1418. scipy/stats/_qmc_cy.pyi +54 -0
  1419. scipy/stats/_qmvnt.py +454 -0
  1420. scipy/stats/_qmvnt_cy.cp314-win_amd64.dll.a +0 -0
  1421. scipy/stats/_qmvnt_cy.cp314-win_amd64.pyd +0 -0
  1422. scipy/stats/_quantile.py +335 -0
  1423. scipy/stats/_rcont/__init__.py +4 -0
  1424. scipy/stats/_rcont/rcont.cp314-win_amd64.dll.a +0 -0
  1425. scipy/stats/_rcont/rcont.cp314-win_amd64.pyd +0 -0
  1426. scipy/stats/_relative_risk.py +263 -0
  1427. scipy/stats/_resampling.py +2352 -0
  1428. scipy/stats/_result_classes.py +40 -0
  1429. scipy/stats/_sampling.py +1314 -0
  1430. scipy/stats/_sensitivity_analysis.py +713 -0
  1431. scipy/stats/_sobol.cp314-win_amd64.dll.a +0 -0
  1432. scipy/stats/_sobol.cp314-win_amd64.pyd +0 -0
  1433. scipy/stats/_sobol.pyi +54 -0
  1434. scipy/stats/_sobol_direction_numbers.npz +0 -0
  1435. scipy/stats/_stats.cp314-win_amd64.dll.a +0 -0
  1436. scipy/stats/_stats.cp314-win_amd64.pyd +0 -0
  1437. scipy/stats/_stats.pxd +10 -0
  1438. scipy/stats/_stats_mstats_common.py +322 -0
  1439. scipy/stats/_stats_py.py +11089 -0
  1440. scipy/stats/_stats_pythran.cp314-win_amd64.dll.a +0 -0
  1441. scipy/stats/_stats_pythran.cp314-win_amd64.pyd +0 -0
  1442. scipy/stats/_survival.py +683 -0
  1443. scipy/stats/_tukeylambda_stats.py +199 -0
  1444. scipy/stats/_unuran/__init__.py +0 -0
  1445. scipy/stats/_unuran/unuran_wrapper.cp314-win_amd64.dll.a +0 -0
  1446. scipy/stats/_unuran/unuran_wrapper.cp314-win_amd64.pyd +0 -0
  1447. scipy/stats/_unuran/unuran_wrapper.pyi +179 -0
  1448. scipy/stats/_variation.py +126 -0
  1449. scipy/stats/_warnings_errors.py +38 -0
  1450. scipy/stats/_wilcoxon.py +265 -0
  1451. scipy/stats/biasedurn.py +16 -0
  1452. scipy/stats/contingency.py +521 -0
  1453. scipy/stats/distributions.py +24 -0
  1454. scipy/stats/kde.py +18 -0
  1455. scipy/stats/morestats.py +27 -0
  1456. scipy/stats/mstats.py +140 -0
  1457. scipy/stats/mstats_basic.py +42 -0
  1458. scipy/stats/mstats_extras.py +25 -0
  1459. scipy/stats/mvn.py +17 -0
  1460. scipy/stats/qmc.py +236 -0
  1461. scipy/stats/sampling.py +73 -0
  1462. scipy/stats/stats.py +41 -0
  1463. scipy/stats/tests/__init__.py +0 -0
  1464. scipy/stats/tests/common_tests.py +356 -0
  1465. scipy/stats/tests/data/_mvt.py +171 -0
  1466. scipy/stats/tests/data/fisher_exact_results_from_r.py +607 -0
  1467. scipy/stats/tests/data/jf_skew_t_gamlss_pdf_data.npy +0 -0
  1468. scipy/stats/tests/data/levy_stable/stable-Z1-cdf-sample-data.npy +0 -0
  1469. scipy/stats/tests/data/levy_stable/stable-Z1-pdf-sample-data.npy +0 -0
  1470. scipy/stats/tests/data/levy_stable/stable-loc-scale-sample-data.npy +0 -0
  1471. scipy/stats/tests/data/nist_anova/AtmWtAg.dat +108 -0
  1472. scipy/stats/tests/data/nist_anova/SiRstv.dat +85 -0
  1473. scipy/stats/tests/data/nist_anova/SmLs01.dat +249 -0
  1474. scipy/stats/tests/data/nist_anova/SmLs02.dat +1869 -0
  1475. scipy/stats/tests/data/nist_anova/SmLs03.dat +18069 -0
  1476. scipy/stats/tests/data/nist_anova/SmLs04.dat +249 -0
  1477. scipy/stats/tests/data/nist_anova/SmLs05.dat +1869 -0
  1478. scipy/stats/tests/data/nist_anova/SmLs06.dat +18069 -0
  1479. scipy/stats/tests/data/nist_anova/SmLs07.dat +249 -0
  1480. scipy/stats/tests/data/nist_anova/SmLs08.dat +1869 -0
  1481. scipy/stats/tests/data/nist_anova/SmLs09.dat +18069 -0
  1482. scipy/stats/tests/data/nist_linregress/Norris.dat +97 -0
  1483. scipy/stats/tests/data/rel_breitwigner_pdf_sample_data_ROOT.npy +0 -0
  1484. scipy/stats/tests/data/studentized_range_mpmath_ref.json +1499 -0
  1485. scipy/stats/tests/test_axis_nan_policy.py +1388 -0
  1486. scipy/stats/tests/test_binned_statistic.py +568 -0
  1487. scipy/stats/tests/test_censored_data.py +152 -0
  1488. scipy/stats/tests/test_contingency.py +294 -0
  1489. scipy/stats/tests/test_continued_fraction.py +173 -0
  1490. scipy/stats/tests/test_continuous.py +2198 -0
  1491. scipy/stats/tests/test_continuous_basic.py +1053 -0
  1492. scipy/stats/tests/test_continuous_fit_censored.py +683 -0
  1493. scipy/stats/tests/test_correlation.py +80 -0
  1494. scipy/stats/tests/test_crosstab.py +115 -0
  1495. scipy/stats/tests/test_discrete_basic.py +580 -0
  1496. scipy/stats/tests/test_discrete_distns.py +700 -0
  1497. scipy/stats/tests/test_distributions.py +10413 -0
  1498. scipy/stats/tests/test_entropy.py +322 -0
  1499. scipy/stats/tests/test_fast_gen_inversion.py +435 -0
  1500. scipy/stats/tests/test_fit.py +1090 -0
  1501. scipy/stats/tests/test_hypotests.py +1991 -0
  1502. scipy/stats/tests/test_kdeoth.py +676 -0
  1503. scipy/stats/tests/test_marray.py +289 -0
  1504. scipy/stats/tests/test_mgc.py +217 -0
  1505. scipy/stats/tests/test_morestats.py +3259 -0
  1506. scipy/stats/tests/test_mstats_basic.py +2071 -0
  1507. scipy/stats/tests/test_mstats_extras.py +172 -0
  1508. scipy/stats/tests/test_multicomp.py +405 -0
  1509. scipy/stats/tests/test_multivariate.py +4381 -0
  1510. scipy/stats/tests/test_odds_ratio.py +148 -0
  1511. scipy/stats/tests/test_qmc.py +1492 -0
  1512. scipy/stats/tests/test_quantile.py +199 -0
  1513. scipy/stats/tests/test_rank.py +345 -0
  1514. scipy/stats/tests/test_relative_risk.py +95 -0
  1515. scipy/stats/tests/test_resampling.py +2000 -0
  1516. scipy/stats/tests/test_sampling.py +1450 -0
  1517. scipy/stats/tests/test_sensitivity_analysis.py +310 -0
  1518. scipy/stats/tests/test_stats.py +9707 -0
  1519. scipy/stats/tests/test_survival.py +466 -0
  1520. scipy/stats/tests/test_tukeylambda_stats.py +85 -0
  1521. scipy/stats/tests/test_variation.py +216 -0
  1522. scipy/version.py +12 -0
  1523. scipy-1.16.1-cp314-cp314-win_amd64.whl +0 -0
  1524. scipy-1.16.1.dist-info/DELVEWHEEL +2 -0
  1525. scipy-1.16.1.dist-info/LICENSE.txt +912 -0
  1526. scipy-1.16.1.dist-info/METADATA +1061 -0
  1527. scipy-1.16.1.dist-info/RECORD +1529 -0
  1528. scipy-1.16.1.dist-info/WHEEL +4 -0
  1529. scipy.libs/libscipy_openblas-6b2103f2ae4d8547998b5d188e9801fb.dll +0 -0
@@ -0,0 +1,3616 @@
1
+ #
2
+ # Created by: Pearu Peterson, September 2002
3
+ #
4
+
5
+ from functools import reduce
6
+ import random
7
+
8
+ from numpy.testing import (assert_equal, assert_array_almost_equal, assert_,
9
+ assert_allclose, assert_almost_equal,
10
+ assert_array_equal)
11
+ import pytest
12
+ from pytest import raises as assert_raises
13
+
14
+ import numpy as np
15
+ from numpy import (eye, ones, zeros, zeros_like, triu, tril, tril_indices,
16
+ triu_indices)
17
+
18
+ from numpy.random import rand, randint, seed
19
+
20
+ from scipy.linalg import (_flapack as flapack, lapack, inv, svd, cholesky,
21
+ solve, ldl, norm, block_diag, qr, eigh, qz)
22
+ from scipy.linalg._basic import _to_banded
23
+ from scipy.linalg.lapack import _compute_lwork
24
+ from scipy.stats import ortho_group, unitary_group
25
+
26
+ import scipy.sparse as sps
27
+ try:
28
+ from scipy.__config__ import CONFIG
29
+ except ImportError:
30
+ CONFIG = None
31
+
32
+ try:
33
+ from scipy.linalg import _clapack as clapack
34
+ except ImportError:
35
+ clapack = None
36
+ from scipy.linalg.lapack import get_lapack_funcs
37
+ from scipy.linalg.blas import get_blas_funcs
38
+
39
+ REAL_DTYPES = [np.float32, np.float64]
40
+ COMPLEX_DTYPES = [np.complex64, np.complex128]
41
+ DTYPES = REAL_DTYPES + COMPLEX_DTYPES
42
+
43
+ blas_provider = blas_version = None
44
+ if CONFIG is not None:
45
+ blas_provider = CONFIG['Build Dependencies']['blas']['name']
46
+ blas_version = CONFIG['Build Dependencies']['blas']['version']
47
+
48
+
49
+ def generate_random_dtype_array(shape, dtype, rng):
50
+ # generates a random matrix of desired data type of shape
51
+ if dtype in COMPLEX_DTYPES:
52
+ return (rng.rand(*shape)
53
+ + rng.rand(*shape)*1.0j).astype(dtype)
54
+ return rng.rand(*shape).astype(dtype)
55
+
56
+
57
+ def test_lapack_documented():
58
+ """Test that all entries are in the doc."""
59
+ if lapack.__doc__ is None: # just in case there is a python -OO
60
+ pytest.skip('lapack.__doc__ is None')
61
+ names = set(lapack.__doc__.split())
62
+ ignore_list = {
63
+ "absolute_import",
64
+ "clapack",
65
+ "division",
66
+ "find_best_lapack_type",
67
+ "flapack",
68
+ "print_function",
69
+ "HAS_ILP64",
70
+ "np",
71
+ }
72
+ missing = list()
73
+ for name in dir(lapack):
74
+ if (not name.startswith('_') and name not in ignore_list and
75
+ name not in names):
76
+ missing.append(name)
77
+ assert missing == [], 'Name(s) missing from lapack.__doc__ or ignore_list'
78
+
79
+
80
+ class TestFlapackSimple:
81
+
82
+ def test_gebal(self):
83
+ a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
84
+ a1 = [[1, 0, 0, 3e-4],
85
+ [4, 0, 0, 2e-3],
86
+ [7, 1, 0, 0],
87
+ [0, 1, 0, 0]]
88
+ for p in 'sdzc':
89
+ f = getattr(flapack, p+'gebal', None)
90
+ if f is None:
91
+ continue
92
+ ba, lo, hi, pivscale, info = f(a)
93
+ assert_(not info, repr(info))
94
+ assert_array_almost_equal(ba, a)
95
+ assert_equal((lo, hi), (0, len(a[0])-1))
96
+ assert_array_almost_equal(pivscale, np.ones(len(a)))
97
+
98
+ ba, lo, hi, pivscale, info = f(a1, permute=1, scale=1)
99
+ assert_(not info, repr(info))
100
+ # print(a1)
101
+ # print(ba, lo, hi, pivscale)
102
+
103
+ def test_gehrd(self):
104
+ a = [[-149, -50, -154],
105
+ [537, 180, 546],
106
+ [-27, -9, -25]]
107
+ for p in 'd':
108
+ f = getattr(flapack, p+'gehrd', None)
109
+ if f is None:
110
+ continue
111
+ ht, tau, info = f(a)
112
+ assert_(not info, repr(info))
113
+
114
+ def test_trsyl(self):
115
+ a = np.array([[1, 2], [0, 4]])
116
+ b = np.array([[5, 6], [0, 8]])
117
+ c = np.array([[9, 10], [11, 12]])
118
+ trans = 'T'
119
+
120
+ # Test single and double implementations, including most
121
+ # of the options
122
+ for dtype in 'fdFD':
123
+ a1, b1, c1 = a.astype(dtype), b.astype(dtype), c.astype(dtype)
124
+ trsyl, = get_lapack_funcs(('trsyl',), (a1,))
125
+ if dtype.isupper(): # is complex dtype
126
+ a1[0] += 1j
127
+ trans = 'C'
128
+
129
+ x, scale, info = trsyl(a1, b1, c1)
130
+ assert_array_almost_equal(np.dot(a1, x) + np.dot(x, b1),
131
+ scale * c1)
132
+
133
+ x, scale, info = trsyl(a1, b1, c1, trana=trans, tranb=trans)
134
+ assert_array_almost_equal(
135
+ np.dot(a1.conjugate().T, x) + np.dot(x, b1.conjugate().T),
136
+ scale * c1, decimal=4)
137
+
138
+ x, scale, info = trsyl(a1, b1, c1, isgn=-1)
139
+ assert_array_almost_equal(np.dot(a1, x) - np.dot(x, b1),
140
+ scale * c1, decimal=4)
141
+
142
+ def test_lange(self):
143
+ a = np.array([
144
+ [-149, -50, -154],
145
+ [537, 180, 546],
146
+ [-27, -9, -25]])
147
+
148
+ for dtype in 'fdFD':
149
+ for norm_str in 'Mm1OoIiFfEe':
150
+ a1 = a.astype(dtype)
151
+ if dtype.isupper():
152
+ # is complex dtype
153
+ a1[0, 0] += 1j
154
+
155
+ lange, = get_lapack_funcs(('lange',), (a1,))
156
+ value = lange(norm_str, a1)
157
+
158
+ if norm_str in 'FfEe':
159
+ if dtype in 'Ff':
160
+ decimal = 3
161
+ else:
162
+ decimal = 7
163
+ ref = np.sqrt(np.sum(np.square(np.abs(a1))))
164
+ assert_almost_equal(value, ref, decimal)
165
+ else:
166
+ if norm_str in 'Mm':
167
+ ref = np.max(np.abs(a1))
168
+ elif norm_str in '1Oo':
169
+ ref = np.max(np.sum(np.abs(a1), axis=0))
170
+ elif norm_str in 'Ii':
171
+ ref = np.max(np.sum(np.abs(a1), axis=1))
172
+
173
+ assert_equal(value, ref)
174
+
175
+
176
+ class TestLapack:
177
+
178
+ def test_flapack(self):
179
+ if hasattr(flapack, 'empty_module'):
180
+ # flapack module is empty
181
+ pass
182
+
183
+ def test_clapack(self):
184
+ if hasattr(clapack, 'empty_module'):
185
+ # clapack module is empty
186
+ pass
187
+
188
+
189
+ class TestLeastSquaresSolvers:
190
+
191
+ def test_gels(self):
192
+ seed(1234)
193
+ # Test fat/tall matrix argument handling - gh-issue #8329
194
+ for ind, dtype in enumerate(DTYPES):
195
+ m = 10
196
+ n = 20
197
+ nrhs = 1
198
+ a1 = rand(m, n).astype(dtype)
199
+ b1 = rand(n).astype(dtype)
200
+ gls, glslw = get_lapack_funcs(('gels', 'gels_lwork'), dtype=dtype)
201
+
202
+ # Request of sizes
203
+ lwork = _compute_lwork(glslw, m, n, nrhs)
204
+ _, _, info = gls(a1, b1, lwork=lwork)
205
+ assert_(info >= 0)
206
+ _, _, info = gls(a1, b1, trans='TTCC'[ind], lwork=lwork)
207
+ assert_(info >= 0)
208
+
209
+ for dtype in REAL_DTYPES:
210
+ a1 = np.array([[1.0, 2.0],
211
+ [4.0, 5.0],
212
+ [7.0, 8.0]], dtype=dtype)
213
+ b1 = np.array([16.0, 17.0, 20.0], dtype=dtype)
214
+ gels, gels_lwork, geqrf = get_lapack_funcs(
215
+ ('gels', 'gels_lwork', 'geqrf'), (a1, b1))
216
+
217
+ m, n = a1.shape
218
+ if len(b1.shape) == 2:
219
+ nrhs = b1.shape[1]
220
+ else:
221
+ nrhs = 1
222
+
223
+ # Request of sizes
224
+ lwork = _compute_lwork(gels_lwork, m, n, nrhs)
225
+
226
+ lqr, x, info = gels(a1, b1, lwork=lwork)
227
+ assert_allclose(x[:-1], np.array([-14.333333333333323,
228
+ 14.999999999999991],
229
+ dtype=dtype),
230
+ rtol=25*np.finfo(dtype).eps)
231
+ lqr_truth, _, _, _ = geqrf(a1)
232
+ assert_array_equal(lqr, lqr_truth)
233
+
234
+ for dtype in COMPLEX_DTYPES:
235
+ a1 = np.array([[1.0+4.0j, 2.0],
236
+ [4.0+0.5j, 5.0-3.0j],
237
+ [7.0-2.0j, 8.0+0.7j]], dtype=dtype)
238
+ b1 = np.array([16.0, 17.0+2.0j, 20.0-4.0j], dtype=dtype)
239
+ gels, gels_lwork, geqrf = get_lapack_funcs(
240
+ ('gels', 'gels_lwork', 'geqrf'), (a1, b1))
241
+
242
+ m, n = a1.shape
243
+ if len(b1.shape) == 2:
244
+ nrhs = b1.shape[1]
245
+ else:
246
+ nrhs = 1
247
+
248
+ # Request of sizes
249
+ lwork = _compute_lwork(gels_lwork, m, n, nrhs)
250
+
251
+ lqr, x, info = gels(a1, b1, lwork=lwork)
252
+ assert_allclose(x[:-1],
253
+ np.array([1.161753632288328-1.901075709391912j,
254
+ 1.735882340522193+1.521240901196909j],
255
+ dtype=dtype), rtol=25*np.finfo(dtype).eps)
256
+ lqr_truth, _, _, _ = geqrf(a1)
257
+ assert_array_equal(lqr, lqr_truth)
258
+
259
+ def test_gelsd(self):
260
+ for dtype in REAL_DTYPES:
261
+ a1 = np.array([[1.0, 2.0],
262
+ [4.0, 5.0],
263
+ [7.0, 8.0]], dtype=dtype)
264
+ b1 = np.array([16.0, 17.0, 20.0], dtype=dtype)
265
+ gelsd, gelsd_lwork = get_lapack_funcs(('gelsd', 'gelsd_lwork'),
266
+ (a1, b1))
267
+
268
+ m, n = a1.shape
269
+ if len(b1.shape) == 2:
270
+ nrhs = b1.shape[1]
271
+ else:
272
+ nrhs = 1
273
+
274
+ # Request of sizes
275
+ work, iwork, info = gelsd_lwork(m, n, nrhs, -1)
276
+ lwork = int(np.real(work))
277
+ iwork_size = iwork
278
+
279
+ x, s, rank, info = gelsd(a1, b1, lwork, iwork_size,
280
+ -1, False, False)
281
+ assert_allclose(x[:-1], np.array([-14.333333333333323,
282
+ 14.999999999999991],
283
+ dtype=dtype),
284
+ rtol=25*np.finfo(dtype).eps)
285
+ assert_allclose(s, np.array([12.596017180511966,
286
+ 0.583396253199685], dtype=dtype),
287
+ rtol=25*np.finfo(dtype).eps)
288
+
289
+ for dtype in COMPLEX_DTYPES:
290
+ a1 = np.array([[1.0+4.0j, 2.0],
291
+ [4.0+0.5j, 5.0-3.0j],
292
+ [7.0-2.0j, 8.0+0.7j]], dtype=dtype)
293
+ b1 = np.array([16.0, 17.0+2.0j, 20.0-4.0j], dtype=dtype)
294
+ gelsd, gelsd_lwork = get_lapack_funcs(('gelsd', 'gelsd_lwork'),
295
+ (a1, b1))
296
+
297
+ m, n = a1.shape
298
+ if len(b1.shape) == 2:
299
+ nrhs = b1.shape[1]
300
+ else:
301
+ nrhs = 1
302
+
303
+ # Request of sizes
304
+ work, rwork, iwork, info = gelsd_lwork(m, n, nrhs, -1)
305
+ lwork = int(np.real(work))
306
+ rwork_size = int(rwork)
307
+ iwork_size = iwork
308
+
309
+ x, s, rank, info = gelsd(a1, b1, lwork, rwork_size, iwork_size,
310
+ -1, False, False)
311
+ assert_allclose(x[:-1],
312
+ np.array([1.161753632288328-1.901075709391912j,
313
+ 1.735882340522193+1.521240901196909j],
314
+ dtype=dtype), rtol=25*np.finfo(dtype).eps)
315
+ assert_allclose(s,
316
+ np.array([13.035514762572043, 4.337666985231382],
317
+ dtype=dtype), rtol=25*np.finfo(dtype).eps)
318
+
319
+ def test_gelss(self):
320
+
321
+ for dtype in REAL_DTYPES:
322
+ a1 = np.array([[1.0, 2.0],
323
+ [4.0, 5.0],
324
+ [7.0, 8.0]], dtype=dtype)
325
+ b1 = np.array([16.0, 17.0, 20.0], dtype=dtype)
326
+ gelss, gelss_lwork = get_lapack_funcs(('gelss', 'gelss_lwork'),
327
+ (a1, b1))
328
+
329
+ m, n = a1.shape
330
+ if len(b1.shape) == 2:
331
+ nrhs = b1.shape[1]
332
+ else:
333
+ nrhs = 1
334
+
335
+ # Request of sizes
336
+ work, info = gelss_lwork(m, n, nrhs, -1)
337
+ lwork = int(np.real(work))
338
+
339
+ v, x, s, rank, work, info = gelss(a1, b1, -1, lwork, False, False)
340
+ assert_allclose(x[:-1], np.array([-14.333333333333323,
341
+ 14.999999999999991],
342
+ dtype=dtype),
343
+ rtol=25*np.finfo(dtype).eps)
344
+ assert_allclose(s, np.array([12.596017180511966,
345
+ 0.583396253199685], dtype=dtype),
346
+ rtol=25*np.finfo(dtype).eps)
347
+
348
+ for dtype in COMPLEX_DTYPES:
349
+ a1 = np.array([[1.0+4.0j, 2.0],
350
+ [4.0+0.5j, 5.0-3.0j],
351
+ [7.0-2.0j, 8.0+0.7j]], dtype=dtype)
352
+ b1 = np.array([16.0, 17.0+2.0j, 20.0-4.0j], dtype=dtype)
353
+ gelss, gelss_lwork = get_lapack_funcs(('gelss', 'gelss_lwork'),
354
+ (a1, b1))
355
+
356
+ m, n = a1.shape
357
+ if len(b1.shape) == 2:
358
+ nrhs = b1.shape[1]
359
+ else:
360
+ nrhs = 1
361
+
362
+ # Request of sizes
363
+ work, info = gelss_lwork(m, n, nrhs, -1)
364
+ lwork = int(np.real(work))
365
+
366
+ v, x, s, rank, work, info = gelss(a1, b1, -1, lwork, False, False)
367
+ assert_allclose(x[:-1],
368
+ np.array([1.161753632288328-1.901075709391912j,
369
+ 1.735882340522193+1.521240901196909j],
370
+ dtype=dtype),
371
+ rtol=25*np.finfo(dtype).eps)
372
+ assert_allclose(s, np.array([13.035514762572043,
373
+ 4.337666985231382], dtype=dtype),
374
+ rtol=25*np.finfo(dtype).eps)
375
+
376
+ def test_gelsy(self):
377
+
378
+ for dtype in REAL_DTYPES:
379
+ a1 = np.array([[1.0, 2.0],
380
+ [4.0, 5.0],
381
+ [7.0, 8.0]], dtype=dtype)
382
+ b1 = np.array([16.0, 17.0, 20.0], dtype=dtype)
383
+ gelsy, gelsy_lwork = get_lapack_funcs(('gelsy', 'gelss_lwork'),
384
+ (a1, b1))
385
+
386
+ m, n = a1.shape
387
+ if len(b1.shape) == 2:
388
+ nrhs = b1.shape[1]
389
+ else:
390
+ nrhs = 1
391
+
392
+ # Request of sizes
393
+ work, info = gelsy_lwork(m, n, nrhs, 10*np.finfo(dtype).eps)
394
+ lwork = int(np.real(work))
395
+
396
+ jptv = np.zeros((a1.shape[1], 1), dtype=np.int32)
397
+ v, x, j, rank, info = gelsy(a1, b1, jptv, np.finfo(dtype).eps,
398
+ lwork, False, False)
399
+ assert_allclose(x[:-1], np.array([-14.333333333333323,
400
+ 14.999999999999991],
401
+ dtype=dtype),
402
+ rtol=25*np.finfo(dtype).eps)
403
+
404
+ for dtype in COMPLEX_DTYPES:
405
+ a1 = np.array([[1.0+4.0j, 2.0],
406
+ [4.0+0.5j, 5.0-3.0j],
407
+ [7.0-2.0j, 8.0+0.7j]], dtype=dtype)
408
+ b1 = np.array([16.0, 17.0+2.0j, 20.0-4.0j], dtype=dtype)
409
+ gelsy, gelsy_lwork = get_lapack_funcs(('gelsy', 'gelss_lwork'),
410
+ (a1, b1))
411
+
412
+ m, n = a1.shape
413
+ if len(b1.shape) == 2:
414
+ nrhs = b1.shape[1]
415
+ else:
416
+ nrhs = 1
417
+
418
+ # Request of sizes
419
+ work, info = gelsy_lwork(m, n, nrhs, 10*np.finfo(dtype).eps)
420
+ lwork = int(np.real(work))
421
+
422
+ jptv = np.zeros((a1.shape[1], 1), dtype=np.int32)
423
+ v, x, j, rank, info = gelsy(a1, b1, jptv, np.finfo(dtype).eps,
424
+ lwork, False, False)
425
+ assert_allclose(x[:-1],
426
+ np.array([1.161753632288328-1.901075709391912j,
427
+ 1.735882340522193+1.521240901196909j],
428
+ dtype=dtype),
429
+ rtol=25*np.finfo(dtype).eps)
430
+
431
+
432
+ @pytest.mark.parametrize('dtype', DTYPES)
433
+ @pytest.mark.parametrize('shape', [(3, 4), (5, 2), (2**18, 2**18)])
434
+ def test_geqrf_lwork(dtype, shape):
435
+ geqrf_lwork = get_lapack_funcs(('geqrf_lwork'), dtype=dtype)
436
+ m, n = shape
437
+ lwork, info = geqrf_lwork(m=m, n=n)
438
+ assert_equal(info, 0)
439
+
440
+
441
+ class TestRegression:
442
+
443
+ def test_ticket_1645(self):
444
+ # Check that RQ routines have correct lwork
445
+ for dtype in DTYPES:
446
+ a = np.zeros((300, 2), dtype=dtype)
447
+
448
+ gerqf, = get_lapack_funcs(['gerqf'], [a])
449
+ assert_raises(Exception, gerqf, a, lwork=2)
450
+ rq, tau, work, info = gerqf(a)
451
+
452
+ if dtype in REAL_DTYPES:
453
+ orgrq, = get_lapack_funcs(['orgrq'], [a])
454
+ assert_raises(Exception, orgrq, rq[-2:], tau, lwork=1)
455
+ orgrq(rq[-2:], tau, lwork=2)
456
+ elif dtype in COMPLEX_DTYPES:
457
+ ungrq, = get_lapack_funcs(['ungrq'], [a])
458
+ assert_raises(Exception, ungrq, rq[-2:], tau, lwork=1)
459
+ ungrq(rq[-2:], tau, lwork=2)
460
+
461
+
462
+ class TestDpotr:
463
+ def test_gh_2691(self):
464
+ # 'lower' argument of dportf/dpotri
465
+ for lower in [True, False]:
466
+ for clean in [True, False]:
467
+ np.random.seed(42)
468
+ x = np.random.normal(size=(3, 3))
469
+ a = x.dot(x.T)
470
+
471
+ dpotrf, dpotri = get_lapack_funcs(("potrf", "potri"), (a, ))
472
+
473
+ c, info = dpotrf(a, lower, clean=clean)
474
+ dpt = dpotri(c, lower)[0]
475
+
476
+ if lower:
477
+ assert_allclose(np.tril(dpt), np.tril(inv(a)))
478
+ else:
479
+ assert_allclose(np.triu(dpt), np.triu(inv(a)))
480
+
481
+
482
+ class TestDlasd4:
483
+ def test_sing_val_update(self):
484
+
485
+ sigmas = np.array([4., 3., 2., 0])
486
+ m_vec = np.array([3.12, 5.7, -4.8, -2.2])
487
+
488
+ M = np.hstack((np.vstack((np.diag(sigmas[0:-1]),
489
+ np.zeros((1, len(m_vec) - 1)))),
490
+ m_vec[:, np.newaxis]))
491
+ SM = svd(M, full_matrices=False, compute_uv=False, overwrite_a=False,
492
+ check_finite=False)
493
+
494
+ it_len = len(sigmas)
495
+ sgm = np.concatenate((sigmas[::-1], [sigmas[0] + it_len*norm(m_vec)]))
496
+ mvc = np.concatenate((m_vec[::-1], (0,)))
497
+
498
+ lasd4 = get_lapack_funcs('lasd4', (sigmas,))
499
+
500
+ roots = []
501
+ for i in range(0, it_len):
502
+ res = lasd4(i, sgm, mvc)
503
+ roots.append(res[1])
504
+
505
+ assert_(
506
+ (res[3] <= 0),
507
+ f"LAPACK root finding dlasd4 failed to find the singular value {i}"
508
+ )
509
+ roots = np.array(roots)[::-1]
510
+
511
+ assert_((not np.any(np.isnan(roots)), "There are NaN roots"))
512
+ assert_allclose(SM, roots, atol=100*np.finfo(np.float64).eps,
513
+ rtol=100*np.finfo(np.float64).eps)
514
+
515
+
516
+ class TestTbtrs:
517
+
518
+ @pytest.mark.parametrize('dtype', DTYPES)
519
+ def test_nag_example_f07vef_f07vsf(self, dtype):
520
+ """Test real (f07vef) and complex (f07vsf) examples from NAG
521
+
522
+ Examples available from:
523
+ * https://www.nag.com/numeric/fl/nagdoc_latest/html/f07/f07vef.html
524
+ * https://www.nag.com/numeric/fl/nagdoc_latest/html/f07/f07vsf.html
525
+
526
+ """
527
+ if dtype in REAL_DTYPES:
528
+ ab = np.array([[-4.16, 4.78, 6.32, 0.16],
529
+ [-2.25, 5.86, -4.82, 0]],
530
+ dtype=dtype)
531
+ b = np.array([[-16.64, -4.16],
532
+ [-13.78, -16.59],
533
+ [13.10, -4.94],
534
+ [-14.14, -9.96]],
535
+ dtype=dtype)
536
+ x_out = np.array([[4, 1],
537
+ [-1, -3],
538
+ [3, 2],
539
+ [2, -2]],
540
+ dtype=dtype)
541
+ elif dtype in COMPLEX_DTYPES:
542
+ ab = np.array([[-1.94+4.43j, 4.12-4.27j, 0.43-2.66j, 0.44+0.1j],
543
+ [-3.39+3.44j, -1.84+5.52j, 1.74 - 0.04j, 0],
544
+ [1.62+3.68j, -2.77-1.93j, 0, 0]],
545
+ dtype=dtype)
546
+ b = np.array([[-8.86 - 3.88j, -24.09 - 5.27j],
547
+ [-15.57 - 23.41j, -57.97 + 8.14j],
548
+ [-7.63 + 22.78j, 19.09 - 29.51j],
549
+ [-14.74 - 2.40j, 19.17 + 21.33j]],
550
+ dtype=dtype)
551
+ x_out = np.array([[2j, 1 + 5j],
552
+ [1 - 3j, -7 - 2j],
553
+ [-4.001887 - 4.988417j, 3.026830 + 4.003182j],
554
+ [1.996158 - 1.045105j, -6.103357 - 8.986653j]],
555
+ dtype=dtype)
556
+ else:
557
+ raise ValueError(f"Datatype {dtype} not understood.")
558
+
559
+ tbtrs = get_lapack_funcs(('tbtrs'), dtype=dtype)
560
+ x, info = tbtrs(ab=ab, b=b, uplo='L')
561
+ assert_equal(info, 0)
562
+ assert_allclose(x, x_out, rtol=0, atol=1e-5)
563
+
564
+ @pytest.mark.parametrize('dtype,trans',
565
+ [(dtype, trans)
566
+ for dtype in DTYPES for trans in ['N', 'T', 'C']
567
+ if not (trans == 'C' and dtype in REAL_DTYPES)])
568
+ @pytest.mark.parametrize('uplo', ['U', 'L'])
569
+ @pytest.mark.parametrize('diag', ['N', 'U'])
570
+ def test_random_matrices(self, dtype, trans, uplo, diag):
571
+ rng = np.random.RandomState(1724)
572
+
573
+ # n, nrhs, kd are used to specify A and b.
574
+ # A is of shape n x n with kd super/sub-diagonals
575
+ # b is of shape n x nrhs matrix
576
+ n, nrhs, kd = 4, 3, 2
577
+ tbtrs = get_lapack_funcs('tbtrs', dtype=dtype)
578
+
579
+ is_upper = (uplo == 'U')
580
+ ku = kd * is_upper
581
+ kl = kd - ku
582
+
583
+ # Construct the diagonal and kd super/sub diagonals of A with
584
+ # the corresponding offsets.
585
+ band_offsets = range(ku, -kl - 1, -1)
586
+ band_widths = [n - abs(x) for x in band_offsets]
587
+ bands = [generate_random_dtype_array((width,), dtype, rng)
588
+ for width in band_widths]
589
+
590
+ if diag == 'U': # A must be unit triangular
591
+ bands[ku] = np.ones(n, dtype=dtype)
592
+
593
+ # Construct the diagonal banded matrix A from the bands and offsets.
594
+ a = sps.diags(bands, band_offsets, format='dia')
595
+
596
+ # Convert A into banded storage form
597
+ ab = np.zeros((kd + 1, n), dtype)
598
+ for row, k in enumerate(band_offsets):
599
+ ab[row, max(k, 0):min(n+k, n)] = a.diagonal(k)
600
+
601
+ # The RHS values.
602
+ b = generate_random_dtype_array((n, nrhs), dtype, rng)
603
+
604
+ x, info = tbtrs(ab=ab, b=b, uplo=uplo, trans=trans, diag=diag)
605
+ assert_equal(info, 0)
606
+
607
+ if trans == 'N':
608
+ assert_allclose(a @ x, b, rtol=5e-5)
609
+ elif trans == 'T':
610
+ assert_allclose(a.T @ x, b, rtol=5e-5)
611
+ elif trans == 'C':
612
+ assert_allclose(a.T.conjugate() @ x, b, rtol=5e-5)
613
+ else:
614
+ raise ValueError('Invalid trans argument')
615
+
616
+ @pytest.mark.parametrize('uplo,trans,diag',
617
+ [['U', 'N', 'Invalid'],
618
+ ['U', 'Invalid', 'N'],
619
+ ['Invalid', 'N', 'N']])
620
+ def test_invalid_argument_raises_exception(self, uplo, trans, diag):
621
+ """Test if invalid values of uplo, trans and diag raise exceptions"""
622
+ # Argument checks occur independently of used datatype.
623
+ # This mean we must not parameterize all available datatypes.
624
+ tbtrs = get_lapack_funcs('tbtrs', dtype=np.float64)
625
+ ab = rand(4, 2)
626
+ b = rand(2, 4)
627
+ assert_raises(Exception, tbtrs, ab, b, uplo, trans, diag)
628
+
629
+ def test_zero_element_in_diagonal(self):
630
+ """Test if a matrix with a zero diagonal element is singular
631
+
632
+ If the i-th diagonal of A is zero, ?tbtrs should return `i` in `info`
633
+ indicating the provided matrix is singular.
634
+
635
+ Note that ?tbtrs requires the matrix A to be stored in banded form.
636
+ In this form the diagonal corresponds to the last row."""
637
+ ab = np.ones((3, 4), dtype=float)
638
+ b = np.ones(4, dtype=float)
639
+ tbtrs = get_lapack_funcs('tbtrs', dtype=float)
640
+
641
+ ab[-1, 3] = 0
642
+ _, info = tbtrs(ab=ab, b=b, uplo='U')
643
+ assert_equal(info, 4)
644
+
645
+ @pytest.mark.parametrize('ldab,n,ldb,nrhs', [
646
+ (5, 5, 0, 5),
647
+ (5, 5, 3, 5)
648
+ ])
649
+ def test_invalid_matrix_shapes(self, ldab, n, ldb, nrhs):
650
+ """Test ?tbtrs fails correctly if shapes are invalid."""
651
+ ab = np.ones((ldab, n), dtype=float)
652
+ b = np.ones((ldb, nrhs), dtype=float)
653
+ tbtrs = get_lapack_funcs('tbtrs', dtype=float)
654
+ assert_raises(Exception, tbtrs, ab, b)
655
+
656
+
657
+
658
+ @pytest.mark.parametrize('dtype', DTYPES)
659
+ @pytest.mark.parametrize('norm', ['I', '1', 'O'])
660
+ @pytest.mark.parametrize('uplo', ['U', 'L'])
661
+ @pytest.mark.parametrize('diag', ['N', 'U'])
662
+ @pytest.mark.parametrize('n', [3, 10])
663
+ def test_trcon(dtype, norm, uplo, diag, n):
664
+ # Simple way to get deterministic (unlike `hash`) integer seed based on arguments
665
+ random.seed(f"{dtype}{norm}{uplo}{diag}{n}")
666
+ rng = np.random.default_rng(random.randint(0, 9999999999999))
667
+
668
+ A = rng.random(size=(n, n)) + rng.random(size=(n, n))*1j
669
+ # make the condition numbers more interesting
670
+ offset = rng.permuted(np.logspace(0, rng.integers(0, 10), n))
671
+ A += offset
672
+ A = A.real if np.issubdtype(dtype, np.floating) else A
673
+ A = np.triu(A) if uplo == 'U' else np.tril(A)
674
+ if diag == 'U':
675
+ A /= np.diag(A)[:, np.newaxis]
676
+ A = A.astype(dtype)
677
+
678
+ trcon = get_lapack_funcs('trcon', (A,))
679
+ res, _ = trcon(A, norm=norm, uplo=uplo, diag=diag)
680
+
681
+ if norm == 'I':
682
+ norm_A = np.linalg.norm(A, ord=np.inf)
683
+ norm_inv_A = np.linalg.norm(np.linalg.inv(A), ord=np.inf)
684
+ ref = 1 / (norm_A * norm_inv_A)
685
+ else:
686
+ anorm = np.linalg.norm(A, ord=1)
687
+ gecon, getrf = get_lapack_funcs(('gecon', 'getrf'), (A,))
688
+ lu, ipvt, info = getrf(A)
689
+ ref, _ = gecon(lu, anorm, norm=norm)
690
+
691
+ # This is an estimate of reciprocal condition number; we just need order of
692
+ # magnitude. In testing, we observed that much smaller rtol is OK in almost
693
+ # all cases... but sometimes it isn't.
694
+ rtol = 1 # np.finfo(dtype).eps**0.75
695
+ assert_allclose(res, ref, rtol=rtol)
696
+
697
+
698
+ def test_lartg():
699
+ for dtype in 'fdFD':
700
+ lartg = get_lapack_funcs('lartg', dtype=dtype)
701
+
702
+ f = np.array(3, dtype)
703
+ g = np.array(4, dtype)
704
+
705
+ if np.iscomplexobj(g):
706
+ g *= 1j
707
+
708
+ cs, sn, r = lartg(f, g)
709
+
710
+ assert_allclose(cs, 3.0/5.0)
711
+ assert_allclose(r, 5.0)
712
+
713
+ if np.iscomplexobj(g):
714
+ assert_allclose(sn, -4.0j/5.0)
715
+ assert_(isinstance(r, complex))
716
+ assert_(isinstance(cs, float))
717
+ else:
718
+ assert_allclose(sn, 4.0/5.0)
719
+
720
+
721
+ def test_rot():
722
+ # srot, drot from blas and crot and zrot from lapack.
723
+
724
+ for dtype in 'fdFD':
725
+ c = 0.6
726
+ s = 0.8
727
+
728
+ u = np.full(4, 3, dtype)
729
+ v = np.full(4, 4, dtype)
730
+ atol = 10**-(np.finfo(dtype).precision-1)
731
+
732
+ if dtype in 'fd':
733
+ rot = get_blas_funcs('rot', dtype=dtype)
734
+ f = 4
735
+ else:
736
+ rot = get_lapack_funcs('rot', dtype=dtype)
737
+ s *= -1j
738
+ v *= 1j
739
+ f = 4j
740
+
741
+ assert_allclose(rot(u, v, c, s), [[5, 5, 5, 5],
742
+ [0, 0, 0, 0]], atol=atol)
743
+ assert_allclose(rot(u, v, c, s, n=2), [[5, 5, 3, 3],
744
+ [0, 0, f, f]], atol=atol)
745
+ assert_allclose(rot(u, v, c, s, offx=2, offy=2),
746
+ [[3, 3, 5, 5], [f, f, 0, 0]], atol=atol)
747
+ assert_allclose(rot(u, v, c, s, incx=2, offy=2, n=2),
748
+ [[5, 3, 5, 3], [f, f, 0, 0]], atol=atol)
749
+ assert_allclose(rot(u, v, c, s, offx=2, incy=2, n=2),
750
+ [[3, 3, 5, 5], [0, f, 0, f]], atol=atol)
751
+ assert_allclose(rot(u, v, c, s, offx=2, incx=2, offy=2, incy=2, n=1),
752
+ [[3, 3, 5, 3], [f, f, 0, f]], atol=atol)
753
+ assert_allclose(rot(u, v, c, s, incx=-2, incy=-2, n=2),
754
+ [[5, 3, 5, 3], [0, f, 0, f]], atol=atol)
755
+
756
+ a, b = rot(u, v, c, s, overwrite_x=1, overwrite_y=1)
757
+ assert_(a is u)
758
+ assert_(b is v)
759
+ assert_allclose(a, [5, 5, 5, 5], atol=atol)
760
+ assert_allclose(b, [0, 0, 0, 0], atol=atol)
761
+
762
+
763
+ def test_larfg_larf():
764
+ np.random.seed(1234)
765
+ a0 = np.random.random((4, 4))
766
+ a0 = a0.T.dot(a0)
767
+
768
+ a0j = np.random.random((4, 4)) + 1j*np.random.random((4, 4))
769
+ a0j = a0j.T.conj().dot(a0j)
770
+
771
+ # our test here will be to do one step of reducing a hermetian matrix to
772
+ # tridiagonal form using householder transforms.
773
+
774
+ for dtype in 'fdFD':
775
+ larfg, larf = get_lapack_funcs(['larfg', 'larf'], dtype=dtype)
776
+
777
+ if dtype in 'FD':
778
+ a = a0j.copy()
779
+ else:
780
+ a = a0.copy()
781
+
782
+ # generate a householder transform to clear a[2:,0]
783
+ alpha, x, tau = larfg(a.shape[0]-1, a[1, 0], a[2:, 0])
784
+
785
+ # create expected output
786
+ expected = np.zeros_like(a[:, 0])
787
+ expected[0] = a[0, 0]
788
+ expected[1] = alpha
789
+
790
+ # assemble householder vector
791
+ v = np.zeros_like(a[1:, 0])
792
+ v[0] = 1.0
793
+ v[1:] = x
794
+
795
+ # apply transform from the left
796
+ a[1:, :] = larf(v, tau.conjugate(), a[1:, :], np.zeros(a.shape[1]))
797
+
798
+ # apply transform from the right
799
+ a[:, 1:] = larf(v, tau, a[:, 1:], np.zeros(a.shape[0]), side='R')
800
+
801
+ assert_allclose(a[:, 0], expected, atol=1e-5)
802
+ assert_allclose(a[0, :], expected, atol=1e-5)
803
+
804
+
805
+ def test_sgesdd_lwork_bug_workaround():
806
+ # Test that SGESDD lwork is sufficiently large for LAPACK.
807
+ #
808
+ # This checks that _compute_lwork() correctly works around a bug in
809
+ # LAPACK versions older than 3.10.1.
810
+
811
+ sgesdd_lwork = get_lapack_funcs('gesdd_lwork', dtype=np.float32,
812
+ ilp64='preferred')
813
+ n = 9537
814
+ lwork = _compute_lwork(sgesdd_lwork, n, n,
815
+ compute_uv=True, full_matrices=True)
816
+ # If we called the Fortran function SGESDD directly with IWORK=-1, the
817
+ # LAPACK bug would result in lwork being 272929856, which was too small.
818
+ # (The result was returned in a single precision float, which does not
819
+ # have sufficient precision to represent the exact integer value that it
820
+ # computed internally.) The work-around implemented in _compute_lwork()
821
+ # will convert that to 272929888. If we are using LAPACK 3.10.1 or later
822
+ # (such as in OpenBLAS 0.3.21 or later), the work-around will return
823
+ # 272929920, because it does not know which version of LAPACK is being
824
+ # used, so it always applies the correction to whatever it is given. We
825
+ # will accept either 272929888 or 272929920.
826
+ # Note that the acceptable values are a LAPACK implementation detail.
827
+ # If a future version of LAPACK changes how SGESDD works, and therefore
828
+ # changes the required LWORK size, the acceptable values might have to
829
+ # be updated.
830
+ assert lwork == 272929888 or lwork == 272929920
831
+
832
+
833
+ class TestSytrd:
834
+ @pytest.mark.parametrize('dtype', REAL_DTYPES)
835
+ def test_sytrd_with_zero_dim_array(self, dtype):
836
+ # Assert that a 0x0 matrix raises an error
837
+ A = np.zeros((0, 0), dtype=dtype)
838
+ sytrd = get_lapack_funcs('sytrd', (A,))
839
+ assert_raises(ValueError, sytrd, A)
840
+
841
+ @pytest.mark.parametrize('dtype', REAL_DTYPES)
842
+ @pytest.mark.parametrize('n', (1, 3))
843
+ def test_sytrd(self, dtype, n):
844
+ A = np.zeros((n, n), dtype=dtype)
845
+
846
+ sytrd, sytrd_lwork = \
847
+ get_lapack_funcs(('sytrd', 'sytrd_lwork'), (A,))
848
+
849
+ # some upper triangular array
850
+ A[np.triu_indices_from(A)] = \
851
+ np.arange(1, n*(n+1)//2+1, dtype=dtype)
852
+
853
+ # query lwork
854
+ lwork, info = sytrd_lwork(n)
855
+ assert_equal(info, 0)
856
+
857
+ # check lower=1 behavior (shouldn't do much since the matrix is
858
+ # upper triangular)
859
+ data, d, e, tau, info = sytrd(A, lower=1, lwork=lwork)
860
+ assert_equal(info, 0)
861
+
862
+ assert_allclose(data, A, atol=5*np.finfo(dtype).eps, rtol=1.0)
863
+ assert_allclose(d, np.diag(A))
864
+ assert_allclose(e, 0.0)
865
+ assert_allclose(tau, 0.0)
866
+
867
+ # and now for the proper test (lower=0 is the default)
868
+ data, d, e, tau, info = sytrd(A, lwork=lwork)
869
+ assert_equal(info, 0)
870
+
871
+ # assert Q^T*A*Q = tridiag(e, d, e)
872
+
873
+ # build tridiagonal matrix
874
+ T = np.zeros_like(A, dtype=dtype)
875
+ k = np.arange(A.shape[0])
876
+ T[k, k] = d
877
+ k2 = np.arange(A.shape[0]-1)
878
+ T[k2+1, k2] = e
879
+ T[k2, k2+1] = e
880
+
881
+ # build Q
882
+ Q = np.eye(n, n, dtype=dtype)
883
+ for i in range(n-1):
884
+ v = np.zeros(n, dtype=dtype)
885
+ v[:i] = data[:i, i+1]
886
+ v[i] = 1.0
887
+ H = np.eye(n, n, dtype=dtype) - tau[i] * np.outer(v, v)
888
+ Q = np.dot(H, Q)
889
+
890
+ # Make matrix fully symmetric
891
+ i_lower = np.tril_indices(n, -1)
892
+ A[i_lower] = A.T[i_lower]
893
+
894
+ QTAQ = np.dot(Q.T, np.dot(A, Q))
895
+
896
+ # disable rtol here since some values in QTAQ and T are very close
897
+ # to 0.
898
+ assert_allclose(QTAQ, T, atol=5*np.finfo(dtype).eps, rtol=1.0)
899
+
900
+
901
+ class TestHetrd:
902
+ @pytest.mark.parametrize('complex_dtype', COMPLEX_DTYPES)
903
+ def test_hetrd_with_zero_dim_array(self, complex_dtype):
904
+ # Assert that a 0x0 matrix raises an error
905
+ A = np.zeros((0, 0), dtype=complex_dtype)
906
+ hetrd = get_lapack_funcs('hetrd', (A,))
907
+ assert_raises(ValueError, hetrd, A)
908
+
909
+ @pytest.mark.parametrize('real_dtype,complex_dtype',
910
+ zip(REAL_DTYPES, COMPLEX_DTYPES))
911
+ @pytest.mark.parametrize('n', (1, 3))
912
+ def test_hetrd(self, n, real_dtype, complex_dtype):
913
+ A = np.zeros((n, n), dtype=complex_dtype)
914
+ hetrd, hetrd_lwork = \
915
+ get_lapack_funcs(('hetrd', 'hetrd_lwork'), (A,))
916
+
917
+ # some upper triangular array
918
+ A[np.triu_indices_from(A)] = (
919
+ np.arange(1, n*(n+1)//2+1, dtype=real_dtype)
920
+ + 1j * np.arange(1, n*(n+1)//2+1, dtype=real_dtype)
921
+ )
922
+ np.fill_diagonal(A, np.real(np.diag(A)))
923
+
924
+ # test query lwork
925
+ for x in [0, 1]:
926
+ _, info = hetrd_lwork(n, lower=x)
927
+ assert_equal(info, 0)
928
+ # lwork returns complex which segfaults hetrd call (gh-10388)
929
+ # use the safe and recommended option
930
+ lwork = _compute_lwork(hetrd_lwork, n)
931
+
932
+ # check lower=1 behavior (shouldn't do much since the matrix is
933
+ # upper triangular)
934
+ data, d, e, tau, info = hetrd(A, lower=1, lwork=lwork)
935
+ assert_equal(info, 0)
936
+
937
+ assert_allclose(data, A, atol=5*np.finfo(real_dtype).eps, rtol=1.0)
938
+
939
+ assert_allclose(d, np.real(np.diag(A)))
940
+ assert_allclose(e, 0.0)
941
+ assert_allclose(tau, 0.0)
942
+
943
+ # and now for the proper test (lower=0 is the default)
944
+ data, d, e, tau, info = hetrd(A, lwork=lwork)
945
+ assert_equal(info, 0)
946
+
947
+ # assert Q^T*A*Q = tridiag(e, d, e)
948
+
949
+ # build tridiagonal matrix
950
+ T = np.zeros_like(A, dtype=real_dtype)
951
+ k = np.arange(A.shape[0], dtype=int)
952
+ T[k, k] = d
953
+ k2 = np.arange(A.shape[0]-1, dtype=int)
954
+ T[k2+1, k2] = e
955
+ T[k2, k2+1] = e
956
+
957
+ # build Q
958
+ Q = np.eye(n, n, dtype=complex_dtype)
959
+ for i in range(n-1):
960
+ v = np.zeros(n, dtype=complex_dtype)
961
+ v[:i] = data[:i, i+1]
962
+ v[i] = 1.0
963
+ H = np.eye(n, n, dtype=complex_dtype) \
964
+ - tau[i] * np.outer(v, np.conj(v))
965
+ Q = np.dot(H, Q)
966
+
967
+ # Make matrix fully Hermitian
968
+ i_lower = np.tril_indices(n, -1)
969
+ A[i_lower] = np.conj(A.T[i_lower])
970
+
971
+ QHAQ = np.dot(np.conj(Q.T), np.dot(A, Q))
972
+
973
+ # disable rtol here since some values in QTAQ and T are very close
974
+ # to 0.
975
+ assert_allclose(
976
+ QHAQ, T, atol=10*np.finfo(real_dtype).eps, rtol=1.0
977
+ )
978
+
979
+
980
+ def test_gglse():
981
+ # Example data taken from NAG manual
982
+ for ind, dtype in enumerate(DTYPES):
983
+ # DTYPES = <s,d,c,z> gglse
984
+ func, func_lwork = get_lapack_funcs(('gglse', 'gglse_lwork'),
985
+ dtype=dtype)
986
+ lwork = _compute_lwork(func_lwork, m=6, n=4, p=2)
987
+ # For <s,d>gglse
988
+ if ind < 2:
989
+ a = np.array([[-0.57, -1.28, -0.39, 0.25],
990
+ [-1.93, 1.08, -0.31, -2.14],
991
+ [2.30, 0.24, 0.40, -0.35],
992
+ [-1.93, 0.64, -0.66, 0.08],
993
+ [0.15, 0.30, 0.15, -2.13],
994
+ [-0.02, 1.03, -1.43, 0.50]], dtype=dtype)
995
+ c = np.array([-1.50, -2.14, 1.23, -0.54, -1.68, 0.82], dtype=dtype)
996
+ d = np.array([0., 0.], dtype=dtype)
997
+ # For <s,d>gglse
998
+ else:
999
+ a = np.array([[0.96-0.81j, -0.03+0.96j, -0.91+2.06j, -0.05+0.41j],
1000
+ [-0.98+1.98j, -1.20+0.19j, -0.66+0.42j, -0.81+0.56j],
1001
+ [0.62-0.46j, 1.01+0.02j, 0.63-0.17j, -1.11+0.60j],
1002
+ [0.37+0.38j, 0.19-0.54j, -0.98-0.36j, 0.22-0.20j],
1003
+ [0.83+0.51j, 0.20+0.01j, -0.17-0.46j, 1.47+1.59j],
1004
+ [1.08-0.28j, 0.20-0.12j, -0.07+1.23j, 0.26+0.26j]])
1005
+ c = np.array([[-2.54+0.09j],
1006
+ [1.65-2.26j],
1007
+ [-2.11-3.96j],
1008
+ [1.82+3.30j],
1009
+ [-6.41+3.77j],
1010
+ [2.07+0.66j]])
1011
+ d = np.zeros(2, dtype=dtype)
1012
+
1013
+ b = np.array([[1., 0., -1., 0.], [0., 1., 0., -1.]], dtype=dtype)
1014
+
1015
+ _, _, _, result, _ = func(a, b, c, d, lwork=lwork)
1016
+ if ind < 2:
1017
+ expected = np.array([0.48904455,
1018
+ 0.99754786,
1019
+ 0.48904455,
1020
+ 0.99754786])
1021
+ else:
1022
+ expected = np.array([1.08742917-1.96205783j,
1023
+ -0.74093902+3.72973919j,
1024
+ 1.08742917-1.96205759j,
1025
+ -0.74093896+3.72973895j])
1026
+ assert_array_almost_equal(result, expected, decimal=4)
1027
+
1028
+
1029
+ def test_sycon_hecon():
1030
+ seed(1234)
1031
+ for ind, dtype in enumerate(DTYPES+COMPLEX_DTYPES):
1032
+ # DTYPES + COMPLEX DTYPES = <s,d,c,z> sycon + <c,z>hecon
1033
+ n = 10
1034
+ # For <s,d,c,z>sycon
1035
+ if ind < 4:
1036
+ func_lwork = get_lapack_funcs('sytrf_lwork', dtype=dtype)
1037
+ funcon, functrf = get_lapack_funcs(('sycon', 'sytrf'), dtype=dtype)
1038
+ A = (rand(n, n)).astype(dtype)
1039
+ # For <c,z>hecon
1040
+ else:
1041
+ func_lwork = get_lapack_funcs('hetrf_lwork', dtype=dtype)
1042
+ funcon, functrf = get_lapack_funcs(('hecon', 'hetrf'), dtype=dtype)
1043
+ A = (rand(n, n) + rand(n, n)*1j).astype(dtype)
1044
+
1045
+ # Since sycon only refers to upper/lower part, conj() is safe here.
1046
+ A = (A + A.conj().T)/2 + 2*np.eye(n, dtype=dtype)
1047
+
1048
+ anorm = norm(A, 1)
1049
+ lwork = _compute_lwork(func_lwork, n)
1050
+ ldu, ipiv, _ = functrf(A, lwork=lwork, lower=1)
1051
+ rcond, _ = funcon(a=ldu, ipiv=ipiv, anorm=anorm, lower=1)
1052
+ # The error is at most 1-fold
1053
+ assert_(abs(1/rcond - np.linalg.cond(A, p=1))*rcond < 1)
1054
+
1055
+
1056
+ def test_sygst():
1057
+ seed(1234)
1058
+ for ind, dtype in enumerate(REAL_DTYPES):
1059
+ # DTYPES = <s,d> sygst
1060
+ n = 10
1061
+
1062
+ potrf, sygst, syevd, sygvd = get_lapack_funcs(('potrf', 'sygst',
1063
+ 'syevd', 'sygvd'),
1064
+ dtype=dtype)
1065
+
1066
+ A = rand(n, n).astype(dtype)
1067
+ A = (A + A.T)/2
1068
+ # B must be positive definite
1069
+ B = rand(n, n).astype(dtype)
1070
+ B = (B + B.T)/2 + 2 * np.eye(n, dtype=dtype)
1071
+
1072
+ # Perform eig (sygvd)
1073
+ eig_gvd, _, info = sygvd(A, B)
1074
+ assert_(info == 0)
1075
+
1076
+ # Convert to std problem potrf
1077
+ b, info = potrf(B)
1078
+ assert_(info == 0)
1079
+ a, info = sygst(A, b)
1080
+ assert_(info == 0)
1081
+
1082
+ eig, _, info = syevd(a)
1083
+ assert_(info == 0)
1084
+ assert_allclose(eig, eig_gvd, rtol=1.2e-4)
1085
+
1086
+
1087
+ def test_hegst():
1088
+ seed(1234)
1089
+ for ind, dtype in enumerate(COMPLEX_DTYPES):
1090
+ # DTYPES = <c,z> hegst
1091
+ n = 10
1092
+
1093
+ potrf, hegst, heevd, hegvd = get_lapack_funcs(('potrf', 'hegst',
1094
+ 'heevd', 'hegvd'),
1095
+ dtype=dtype)
1096
+
1097
+ A = rand(n, n).astype(dtype) + 1j * rand(n, n).astype(dtype)
1098
+ A = (A + A.conj().T)/2
1099
+ # B must be positive definite
1100
+ B = rand(n, n).astype(dtype) + 1j * rand(n, n).astype(dtype)
1101
+ B = (B + B.conj().T)/2 + 2 * np.eye(n, dtype=dtype)
1102
+
1103
+ # Perform eig (hegvd)
1104
+ eig_gvd, _, info = hegvd(A, B)
1105
+ assert_(info == 0)
1106
+
1107
+ # Convert to std problem potrf
1108
+ b, info = potrf(B)
1109
+ assert_(info == 0)
1110
+ a, info = hegst(A, b)
1111
+ assert_(info == 0)
1112
+
1113
+ eig, _, info = heevd(a)
1114
+ assert_(info == 0)
1115
+ assert_allclose(eig, eig_gvd, rtol=1e-4)
1116
+
1117
+
1118
+ def test_tzrzf():
1119
+ """
1120
+ This test performs an RZ decomposition in which an m x n upper trapezoidal
1121
+ array M (m <= n) is factorized as M = [R 0] * Z where R is upper triangular
1122
+ and Z is unitary.
1123
+ """
1124
+ rng = np.random.RandomState(1234)
1125
+ m, n = 10, 15
1126
+ for ind, dtype in enumerate(DTYPES):
1127
+ tzrzf, tzrzf_lw = get_lapack_funcs(('tzrzf', 'tzrzf_lwork'),
1128
+ dtype=dtype)
1129
+ lwork = _compute_lwork(tzrzf_lw, m, n)
1130
+
1131
+ if ind < 2:
1132
+ A = triu(rng.rand(m, n).astype(dtype))
1133
+ else:
1134
+ A = triu((rng.rand(m, n) + rng.rand(m, n)*1j).astype(dtype))
1135
+
1136
+ # assert wrong shape arg, f2py returns generic error
1137
+ assert_raises(Exception, tzrzf, A.T)
1138
+ rz, tau, info = tzrzf(A, lwork=lwork)
1139
+ # Check success
1140
+ assert_(info == 0)
1141
+
1142
+ # Get Z manually for comparison
1143
+ R = np.hstack((rz[:, :m], np.zeros((m, n-m), dtype=dtype)))
1144
+ V = np.hstack((np.eye(m, dtype=dtype), rz[:, m:]))
1145
+ Id = np.eye(n, dtype=dtype)
1146
+ ref = [Id-tau[x]*V[[x], :].T.dot(V[[x], :].conj()) for x in range(m)]
1147
+ Z = reduce(np.dot, ref)
1148
+ assert_allclose(R.dot(Z) - A, zeros_like(A, dtype=dtype),
1149
+ atol=10*np.spacing(dtype(1.0).real), rtol=0.)
1150
+
1151
+
1152
+ def test_tfsm():
1153
+ """
1154
+ Test for solving a linear system with the coefficient matrix is a
1155
+ triangular array stored in Full Packed (RFP) format.
1156
+ """
1157
+ rng = np.random.RandomState(1234)
1158
+ for ind, dtype in enumerate(DTYPES):
1159
+ n = 20
1160
+ if ind > 1:
1161
+ A = triu(rng.rand(n, n) + rng.rand(n, n)*1j + eye(n)).astype(dtype)
1162
+ trans = 'C'
1163
+ else:
1164
+ A = triu(rng.rand(n, n) + eye(n)).astype(dtype)
1165
+ trans = 'T'
1166
+
1167
+ trttf, tfttr, tfsm = get_lapack_funcs(('trttf', 'tfttr', 'tfsm'),
1168
+ dtype=dtype)
1169
+
1170
+ Afp, _ = trttf(A)
1171
+ B = rng.rand(n, 2).astype(dtype)
1172
+ soln = tfsm(-1, Afp, B)
1173
+ assert_array_almost_equal(soln, solve(-A, B),
1174
+ decimal=4 if ind % 2 == 0 else 6)
1175
+
1176
+ soln = tfsm(-1, Afp, B, trans=trans)
1177
+ assert_array_almost_equal(soln, solve(-A.conj().T, B),
1178
+ decimal=4 if ind % 2 == 0 else 6)
1179
+
1180
+ # Make A, unit diagonal
1181
+ A[np.arange(n), np.arange(n)] = dtype(1.)
1182
+ soln = tfsm(-1, Afp, B, trans=trans, diag='U')
1183
+ assert_array_almost_equal(soln, solve(-A.conj().T, B),
1184
+ decimal=4 if ind % 2 == 0 else 6)
1185
+
1186
+ # Change side
1187
+ B2 = rng.rand(3, n).astype(dtype)
1188
+ soln = tfsm(-1, Afp, B2, trans=trans, diag='U', side='R')
1189
+ assert_array_almost_equal(soln, solve(-A, B2.T).conj().T,
1190
+ decimal=4 if ind % 2 == 0 else 6)
1191
+
1192
+
1193
+ def test_ormrz_unmrz():
1194
+ """
1195
+ This test performs a matrix multiplication with an arbitrary m x n matrix C
1196
+ and a unitary matrix Q without explicitly forming the array. The array data
1197
+ is encoded in the rectangular part of A which is obtained from ?TZRZF. Q
1198
+ size is inferred by m, n, side keywords.
1199
+ """
1200
+ rng = np.random.RandomState(1234)
1201
+ qm, qn, cn = 10, 15, 15
1202
+ for ind, dtype in enumerate(DTYPES):
1203
+ tzrzf, tzrzf_lw = get_lapack_funcs(('tzrzf', 'tzrzf_lwork'),
1204
+ dtype=dtype)
1205
+ lwork_rz = _compute_lwork(tzrzf_lw, qm, qn)
1206
+
1207
+ if ind < 2:
1208
+ A = triu(rng.rand(qm, qn).astype(dtype))
1209
+ C = rng.rand(cn, cn).astype(dtype)
1210
+ orun_mrz, orun_mrz_lw = get_lapack_funcs(('ormrz', 'ormrz_lwork'),
1211
+ dtype=dtype)
1212
+ else:
1213
+ A = triu((rng.rand(qm, qn) + rng.rand(qm, qn)*1j).astype(dtype))
1214
+ C = (rng.rand(cn, cn) + rand(cn, cn)*1j).astype(dtype)
1215
+ orun_mrz, orun_mrz_lw = get_lapack_funcs(('unmrz', 'unmrz_lwork'),
1216
+ dtype=dtype)
1217
+
1218
+ lwork_mrz = _compute_lwork(orun_mrz_lw, cn, cn)
1219
+ rz, tau, info = tzrzf(A, lwork=lwork_rz)
1220
+
1221
+ # Get Q manually for comparison
1222
+ V = np.hstack((np.eye(qm, dtype=dtype), rz[:, qm:]))
1223
+ Id = np.eye(qn, dtype=dtype)
1224
+ ref = [Id-tau[x]*V[[x], :].T.dot(V[[x], :].conj()) for x in range(qm)]
1225
+ Q = reduce(np.dot, ref)
1226
+
1227
+ # Now that we have Q, we can test whether lapack results agree with
1228
+ # each case of CQ, CQ^H, QC, and QC^H
1229
+ trans = 'T' if ind < 2 else 'C'
1230
+ tol = 10*np.spacing(dtype(1.0).real)
1231
+
1232
+ cq, info = orun_mrz(rz, tau, C, lwork=lwork_mrz)
1233
+ assert_(info == 0)
1234
+ assert_allclose(cq - Q.dot(C), zeros_like(C), atol=tol, rtol=0.)
1235
+
1236
+ cq, info = orun_mrz(rz, tau, C, trans=trans, lwork=lwork_mrz)
1237
+ assert_(info == 0)
1238
+ assert_allclose(cq - Q.conj().T.dot(C), zeros_like(C), atol=tol,
1239
+ rtol=0.)
1240
+
1241
+ cq, info = orun_mrz(rz, tau, C, side='R', lwork=lwork_mrz)
1242
+ assert_(info == 0)
1243
+ assert_allclose(cq - C.dot(Q), zeros_like(C), atol=tol, rtol=0.)
1244
+
1245
+ cq, info = orun_mrz(rz, tau, C, side='R', trans=trans, lwork=lwork_mrz)
1246
+ assert_(info == 0)
1247
+ assert_allclose(cq - C.dot(Q.conj().T), zeros_like(C), atol=tol,
1248
+ rtol=0.)
1249
+
1250
+
1251
+ def test_tfttr_trttf():
1252
+ """
1253
+ Test conversion routines between the Rectangular Full Packed (RFP) format
1254
+ and Standard Triangular Array (TR)
1255
+ """
1256
+ rng = np.random.RandomState(1234)
1257
+ for ind, dtype in enumerate(DTYPES):
1258
+ n = 20
1259
+ if ind > 1:
1260
+ A_full = (rng.rand(n, n) + rng.rand(n, n)*1j).astype(dtype)
1261
+ transr = 'C'
1262
+ else:
1263
+ A_full = (rng.rand(n, n)).astype(dtype)
1264
+ transr = 'T'
1265
+
1266
+ trttf, tfttr = get_lapack_funcs(('trttf', 'tfttr'), dtype=dtype)
1267
+ A_tf_U, info = trttf(A_full)
1268
+ assert_(info == 0)
1269
+ A_tf_L, info = trttf(A_full, uplo='L')
1270
+ assert_(info == 0)
1271
+ A_tf_U_T, info = trttf(A_full, transr=transr, uplo='U')
1272
+ assert_(info == 0)
1273
+ A_tf_L_T, info = trttf(A_full, transr=transr, uplo='L')
1274
+ assert_(info == 0)
1275
+
1276
+ # Create the RFP array manually (n is even!)
1277
+ A_tf_U_m = zeros((n+1, n//2), dtype=dtype)
1278
+ A_tf_U_m[:-1, :] = triu(A_full)[:, n//2:]
1279
+ A_tf_U_m[n//2+1:, :] += triu(A_full)[:n//2, :n//2].conj().T
1280
+
1281
+ A_tf_L_m = zeros((n+1, n//2), dtype=dtype)
1282
+ A_tf_L_m[1:, :] = tril(A_full)[:, :n//2]
1283
+ A_tf_L_m[:n//2, :] += tril(A_full)[n//2:, n//2:].conj().T
1284
+
1285
+ assert_array_almost_equal(A_tf_U, A_tf_U_m.reshape(-1, order='F'))
1286
+ assert_array_almost_equal(A_tf_U_T,
1287
+ A_tf_U_m.conj().T.reshape(-1, order='F'))
1288
+
1289
+ assert_array_almost_equal(A_tf_L, A_tf_L_m.reshape(-1, order='F'))
1290
+ assert_array_almost_equal(A_tf_L_T,
1291
+ A_tf_L_m.conj().T.reshape(-1, order='F'))
1292
+
1293
+ # Get the original array from RFP
1294
+ A_tr_U, info = tfttr(n, A_tf_U)
1295
+ assert_(info == 0)
1296
+ A_tr_L, info = tfttr(n, A_tf_L, uplo='L')
1297
+ assert_(info == 0)
1298
+ A_tr_U_T, info = tfttr(n, A_tf_U_T, transr=transr, uplo='U')
1299
+ assert_(info == 0)
1300
+ A_tr_L_T, info = tfttr(n, A_tf_L_T, transr=transr, uplo='L')
1301
+ assert_(info == 0)
1302
+
1303
+ assert_array_almost_equal(A_tr_U, triu(A_full))
1304
+ assert_array_almost_equal(A_tr_U_T, triu(A_full))
1305
+ assert_array_almost_equal(A_tr_L, tril(A_full))
1306
+ assert_array_almost_equal(A_tr_L_T, tril(A_full))
1307
+
1308
+
1309
+ def test_tpttr_trttp():
1310
+ """
1311
+ Test conversion routines between the Rectangular Full Packed (RFP) format
1312
+ and Standard Triangular Array (TR)
1313
+ """
1314
+ rng = np.random.RandomState(1234)
1315
+ for ind, dtype in enumerate(DTYPES):
1316
+ n = 20
1317
+ if ind > 1:
1318
+ A_full = (rng.rand(n, n) + rng.rand(n, n)*1j).astype(dtype)
1319
+ else:
1320
+ A_full = (rng.rand(n, n)).astype(dtype)
1321
+
1322
+ trttp, tpttr = get_lapack_funcs(('trttp', 'tpttr'), dtype=dtype)
1323
+ A_tp_U, info = trttp(A_full)
1324
+ assert_(info == 0)
1325
+ A_tp_L, info = trttp(A_full, uplo='L')
1326
+ assert_(info == 0)
1327
+
1328
+ # Create the TP array manually
1329
+ inds = tril_indices(n)
1330
+ A_tp_U_m = zeros(n*(n+1)//2, dtype=dtype)
1331
+ A_tp_U_m[:] = (triu(A_full).T)[inds]
1332
+
1333
+ inds = triu_indices(n)
1334
+ A_tp_L_m = zeros(n*(n+1)//2, dtype=dtype)
1335
+ A_tp_L_m[:] = (tril(A_full).T)[inds]
1336
+
1337
+ assert_array_almost_equal(A_tp_U, A_tp_U_m)
1338
+ assert_array_almost_equal(A_tp_L, A_tp_L_m)
1339
+
1340
+ # Get the original array from TP
1341
+ A_tr_U, info = tpttr(n, A_tp_U)
1342
+ assert_(info == 0)
1343
+ A_tr_L, info = tpttr(n, A_tp_L, uplo='L')
1344
+ assert_(info == 0)
1345
+
1346
+ assert_array_almost_equal(A_tr_U, triu(A_full))
1347
+ assert_array_almost_equal(A_tr_L, tril(A_full))
1348
+
1349
+
1350
+ def test_pftrf():
1351
+ """
1352
+ Test Cholesky factorization of a positive definite Rectangular Full
1353
+ Packed (RFP) format array
1354
+ """
1355
+ rng = np.random.RandomState(1234)
1356
+ for ind, dtype in enumerate(DTYPES):
1357
+ n = 20
1358
+ if ind > 1:
1359
+ A = (rng.rand(n, n) + rng.rand(n, n)*1j).astype(dtype)
1360
+ A = A + A.conj().T + n*eye(n)
1361
+ else:
1362
+ A = (rng.rand(n, n)).astype(dtype)
1363
+ A = A + A.T + n*eye(n)
1364
+
1365
+ pftrf, trttf, tfttr = get_lapack_funcs(('pftrf', 'trttf', 'tfttr'),
1366
+ dtype=dtype)
1367
+
1368
+ # Get the original array from TP
1369
+ Afp, info = trttf(A)
1370
+ Achol_rfp, info = pftrf(n, Afp)
1371
+ assert_(info == 0)
1372
+ A_chol_r, _ = tfttr(n, Achol_rfp)
1373
+ Achol = cholesky(A)
1374
+ assert_array_almost_equal(A_chol_r, Achol)
1375
+
1376
+
1377
+ def test_pftri():
1378
+ """
1379
+ Test Cholesky factorization of a positive definite Rectangular Full
1380
+ Packed (RFP) format array to find its inverse
1381
+ """
1382
+ rng = np.random.RandomState(1234)
1383
+ for ind, dtype in enumerate(DTYPES):
1384
+ n = 20
1385
+ if ind > 1:
1386
+ A = (rng.rand(n, n) + rng.rand(n, n)*1j).astype(dtype)
1387
+ A = A + A.conj().T + n*eye(n)
1388
+ else:
1389
+ A = (rng.rand(n, n)).astype(dtype)
1390
+ A = A + A.T + n*eye(n)
1391
+
1392
+ pftri, pftrf, trttf, tfttr = get_lapack_funcs(('pftri',
1393
+ 'pftrf',
1394
+ 'trttf',
1395
+ 'tfttr'),
1396
+ dtype=dtype)
1397
+
1398
+ # Get the original array from TP
1399
+ Afp, info = trttf(A)
1400
+ A_chol_rfp, info = pftrf(n, Afp)
1401
+ A_inv_rfp, info = pftri(n, A_chol_rfp)
1402
+ assert_(info == 0)
1403
+ A_inv_r, _ = tfttr(n, A_inv_rfp)
1404
+ Ainv = inv(A)
1405
+ assert_array_almost_equal(A_inv_r, triu(Ainv),
1406
+ decimal=4 if ind % 2 == 0 else 6)
1407
+
1408
+
1409
+ def test_pftrs():
1410
+ """
1411
+ Test Cholesky factorization of a positive definite Rectangular Full
1412
+ Packed (RFP) format array and solve a linear system
1413
+ """
1414
+ rng = np.random.RandomState(1234)
1415
+ for ind, dtype in enumerate(DTYPES):
1416
+ n = 20
1417
+ if ind > 1:
1418
+ A = (rng.rand(n, n) + rng.rand(n, n)*1j).astype(dtype)
1419
+ A = A + A.conj().T + n*eye(n)
1420
+ else:
1421
+ A = (rng.rand(n, n)).astype(dtype)
1422
+ A = A + A.T + n*eye(n)
1423
+
1424
+ B = ones((n, 3), dtype=dtype)
1425
+ Bf1 = ones((n+2, 3), dtype=dtype)
1426
+ Bf2 = ones((n-2, 3), dtype=dtype)
1427
+ pftrs, pftrf, trttf, tfttr = get_lapack_funcs(('pftrs',
1428
+ 'pftrf',
1429
+ 'trttf',
1430
+ 'tfttr'),
1431
+ dtype=dtype)
1432
+
1433
+ # Get the original array from TP
1434
+ Afp, info = trttf(A)
1435
+ A_chol_rfp, info = pftrf(n, Afp)
1436
+ # larger B arrays shouldn't segfault
1437
+ soln, info = pftrs(n, A_chol_rfp, Bf1)
1438
+ assert_(info == 0)
1439
+ assert_raises(Exception, pftrs, n, A_chol_rfp, Bf2)
1440
+ soln, info = pftrs(n, A_chol_rfp, B)
1441
+ assert_(info == 0)
1442
+ assert_array_almost_equal(solve(A, B), soln,
1443
+ decimal=4 if ind % 2 == 0 else 6)
1444
+
1445
+
1446
+ def test_sfrk_hfrk():
1447
+ """
1448
+ Test for performing a symmetric rank-k operation for matrix in RFP format.
1449
+ """
1450
+ rng = np.random.RandomState(1234)
1451
+ for ind, dtype in enumerate(DTYPES):
1452
+ n = 20
1453
+ if ind > 1:
1454
+ A = (rng.rand(n, n) + rng.rand(n, n)*1j).astype(dtype)
1455
+ A = A + A.conj().T + n*eye(n)
1456
+ else:
1457
+ A = (rng.rand(n, n)).astype(dtype)
1458
+ A = A + A.T + n*eye(n)
1459
+
1460
+ prefix = 's'if ind < 2 else 'h'
1461
+ trttf, tfttr, shfrk = get_lapack_funcs(('trttf', 'tfttr', f'{prefix}frk'),
1462
+ dtype=dtype)
1463
+
1464
+ Afp, _ = trttf(A)
1465
+ C = rng.rand(n, 2).astype(dtype)
1466
+ Afp_out = shfrk(n, 2, -1, C, 2, Afp)
1467
+ A_out, _ = tfttr(n, Afp_out)
1468
+ assert_array_almost_equal(A_out, triu(-C.dot(C.conj().T) + 2*A),
1469
+ decimal=4 if ind % 2 == 0 else 6)
1470
+
1471
+
1472
+ def test_syconv():
1473
+ """
1474
+ Test for going back and forth between the returned format of he/sytrf to
1475
+ L and D factors/permutations.
1476
+ """
1477
+ rng = np.random.RandomState(1234)
1478
+ for ind, dtype in enumerate(DTYPES):
1479
+ n = 10
1480
+
1481
+ if ind > 1:
1482
+ A = (rng.randint(-30, 30, (n, n)) +
1483
+ rng.randint(-30, 30, (n, n))*1j).astype(dtype)
1484
+
1485
+ A = A + A.conj().T
1486
+ else:
1487
+ A = rng.randint(-30, 30, (n, n)).astype(dtype)
1488
+ A = A + A.T + n*eye(n)
1489
+
1490
+ tol = 100*np.spacing(dtype(1.0).real)
1491
+ syconv, trf, trf_lwork = get_lapack_funcs(('syconv', 'sytrf',
1492
+ 'sytrf_lwork'), dtype=dtype)
1493
+ lw = _compute_lwork(trf_lwork, n, lower=1)
1494
+ L, D, perm = ldl(A, lower=1, hermitian=False)
1495
+ lw = _compute_lwork(trf_lwork, n, lower=1)
1496
+ ldu, ipiv, info = trf(A, lower=1, lwork=lw)
1497
+ a, e, info = syconv(ldu, ipiv, lower=1)
1498
+ assert_allclose(tril(a, -1,), tril(L[perm, :], -1), atol=tol, rtol=0.)
1499
+
1500
+ # Test also upper
1501
+ U, D, perm = ldl(A, lower=0, hermitian=False)
1502
+ ldu, ipiv, info = trf(A, lower=0)
1503
+ a, e, info = syconv(ldu, ipiv, lower=0)
1504
+ assert_allclose(triu(a, 1), triu(U[perm, :], 1), atol=tol, rtol=0.)
1505
+
1506
+
1507
+ class TestBlockedQR:
1508
+ """
1509
+ Tests for the blocked QR factorization, namely through geqrt, gemqrt, tpqrt
1510
+ and tpmqr.
1511
+ """
1512
+
1513
+ def test_geqrt_gemqrt(self):
1514
+ rng = np.random.RandomState(1234)
1515
+ for ind, dtype in enumerate(DTYPES):
1516
+ n = 20
1517
+
1518
+ if ind > 1:
1519
+ A = (rng.rand(n, n) + rng.rand(n, n)*1j).astype(dtype)
1520
+ else:
1521
+ A = (rng.rand(n, n)).astype(dtype)
1522
+
1523
+ tol = 100*np.spacing(dtype(1.0).real)
1524
+ geqrt, gemqrt = get_lapack_funcs(('geqrt', 'gemqrt'), dtype=dtype)
1525
+
1526
+ a, t, info = geqrt(n, A)
1527
+ assert info == 0
1528
+
1529
+ # Extract elementary reflectors from lower triangle, adding the
1530
+ # main diagonal of ones.
1531
+ v = np.tril(a, -1) + np.eye(n, dtype=dtype)
1532
+ # Generate the block Householder transform I - VTV^H
1533
+ Q = np.eye(n, dtype=dtype) - v @ t @ v.T.conj()
1534
+ R = np.triu(a)
1535
+
1536
+ # Test columns of Q are orthogonal
1537
+ assert_allclose(Q.T.conj() @ Q, np.eye(n, dtype=dtype), atol=tol,
1538
+ rtol=0.)
1539
+ assert_allclose(Q @ R, A, atol=tol, rtol=0.)
1540
+
1541
+ if ind > 1:
1542
+ C = (rng.rand(n, n) + rng.rand(n, n)*1j).astype(dtype)
1543
+ transpose = 'C'
1544
+ else:
1545
+ C = (rng.rand(n, n)).astype(dtype)
1546
+ transpose = 'T'
1547
+
1548
+ for side in ('L', 'R'):
1549
+ for trans in ('N', transpose):
1550
+ c, info = gemqrt(a, t, C, side=side, trans=trans)
1551
+ assert info == 0
1552
+
1553
+ if trans == transpose:
1554
+ q = Q.T.conj()
1555
+ else:
1556
+ q = Q
1557
+
1558
+ if side == 'L':
1559
+ qC = q @ C
1560
+ else:
1561
+ qC = C @ q
1562
+
1563
+ assert_allclose(c, qC, atol=tol, rtol=0.)
1564
+
1565
+ # Test default arguments
1566
+ if (side, trans) == ('L', 'N'):
1567
+ c_default, info = gemqrt(a, t, C)
1568
+ assert info == 0
1569
+ assert_equal(c_default, c)
1570
+
1571
+ # Test invalid side/trans
1572
+ assert_raises(Exception, gemqrt, a, t, C, side='A')
1573
+ assert_raises(Exception, gemqrt, a, t, C, trans='A')
1574
+
1575
+ def test_tpqrt_tpmqrt(self):
1576
+ rng = np.random.RandomState(1234)
1577
+ for ind, dtype in enumerate(DTYPES):
1578
+ n = 20
1579
+
1580
+ if ind > 1:
1581
+ A = (rng.rand(n, n) + rng.rand(n, n)*1j).astype(dtype)
1582
+ B = (rng.rand(n, n) + rng.rand(n, n)*1j).astype(dtype)
1583
+ else:
1584
+ A = (rng.rand(n, n)).astype(dtype)
1585
+ B = (rng.rand(n, n)).astype(dtype)
1586
+
1587
+ tol = 100*np.spacing(dtype(1.0).real)
1588
+ tpqrt, tpmqrt = get_lapack_funcs(('tpqrt', 'tpmqrt'), dtype=dtype)
1589
+
1590
+ # Test for the range of pentagonal B, from square to upper
1591
+ # triangular
1592
+ for l in (0, n // 2, n):
1593
+ a, b, t, info = tpqrt(l, n, A, B)
1594
+ assert info == 0
1595
+
1596
+ # Check that lower triangular part of A has not been modified
1597
+ assert_equal(np.tril(a, -1), np.tril(A, -1))
1598
+ # Check that elements not part of the pentagonal portion of B
1599
+ # have not been modified.
1600
+ assert_equal(np.tril(b, l - n - 1), np.tril(B, l - n - 1))
1601
+
1602
+ # Extract pentagonal portion of B
1603
+ B_pent, b_pent = np.triu(B, l - n), np.triu(b, l - n)
1604
+
1605
+ # Generate elementary reflectors
1606
+ v = np.concatenate((np.eye(n, dtype=dtype), b_pent))
1607
+ # Generate the block Householder transform I - VTV^H
1608
+ Q = np.eye(2 * n, dtype=dtype) - v @ t @ v.T.conj()
1609
+ R = np.concatenate((np.triu(a), np.zeros_like(a)))
1610
+
1611
+ # Test columns of Q are orthogonal
1612
+ assert_allclose(Q.T.conj() @ Q, np.eye(2 * n, dtype=dtype),
1613
+ atol=tol, rtol=0.)
1614
+ assert_allclose(Q @ R, np.concatenate((np.triu(A), B_pent)),
1615
+ atol=tol, rtol=0.)
1616
+
1617
+ if ind > 1:
1618
+ C = (rng.rand(n, n) + rng.rand(n, n)*1j).astype(dtype)
1619
+ D = (rng.rand(n, n) + rng.rand(n, n)*1j).astype(dtype)
1620
+ transpose = 'C'
1621
+ else:
1622
+ C = (rng.rand(n, n)).astype(dtype)
1623
+ D = (rng.rand(n, n)).astype(dtype)
1624
+ transpose = 'T'
1625
+
1626
+ for side in ('L', 'R'):
1627
+ for trans in ('N', transpose):
1628
+ c, d, info = tpmqrt(l, b, t, C, D, side=side,
1629
+ trans=trans)
1630
+ assert info == 0
1631
+
1632
+ if trans == transpose:
1633
+ q = Q.T.conj()
1634
+ else:
1635
+ q = Q
1636
+
1637
+ if side == 'L':
1638
+ cd = np.concatenate((c, d), axis=0)
1639
+ CD = np.concatenate((C, D), axis=0)
1640
+ qCD = q @ CD
1641
+ else:
1642
+ cd = np.concatenate((c, d), axis=1)
1643
+ CD = np.concatenate((C, D), axis=1)
1644
+ qCD = CD @ q
1645
+
1646
+ assert_allclose(cd, qCD, atol=tol, rtol=0.)
1647
+
1648
+ if (side, trans) == ('L', 'N'):
1649
+ c_default, d_default, info = tpmqrt(l, b, t, C, D)
1650
+ assert info == 0
1651
+ assert_equal(c_default, c)
1652
+ assert_equal(d_default, d)
1653
+
1654
+ # Test invalid side/trans
1655
+ assert_raises(Exception, tpmqrt, l, b, t, C, D, side='A')
1656
+ assert_raises(Exception, tpmqrt, l, b, t, C, D, trans='A')
1657
+
1658
+
1659
+ def test_pstrf():
1660
+ rng = np.random.RandomState(1234)
1661
+ for ind, dtype in enumerate(DTYPES):
1662
+ # DTYPES = <s, d, c, z> pstrf
1663
+ n = 10
1664
+ r = 2
1665
+ pstrf = get_lapack_funcs('pstrf', dtype=dtype)
1666
+
1667
+ # Create positive semidefinite A
1668
+ if ind > 1:
1669
+ A = rng.rand(n, n-r).astype(dtype) + 1j * rng.rand(n, n-r).astype(dtype)
1670
+ A = A @ A.conj().T
1671
+ else:
1672
+ A = rng.rand(n, n-r).astype(dtype)
1673
+ A = A @ A.T
1674
+
1675
+ c, piv, r_c, info = pstrf(A)
1676
+ U = triu(c)
1677
+ U[r_c - n:, r_c - n:] = 0.
1678
+
1679
+ assert_equal(info, 1)
1680
+ # python-dbg 3.5.2 runs cause trouble with the following assertion.
1681
+ # assert_equal(r_c, n - r)
1682
+ single_atol = 1000 * np.finfo(np.float32).eps
1683
+ double_atol = 1000 * np.finfo(np.float64).eps
1684
+ atol = single_atol if ind in [0, 2] else double_atol
1685
+ assert_allclose(A[piv-1][:, piv-1], U.conj().T @ U, rtol=0., atol=atol)
1686
+
1687
+ c, piv, r_c, info = pstrf(A, lower=1)
1688
+ L = tril(c)
1689
+ L[r_c - n:, r_c - n:] = 0.
1690
+
1691
+ assert_equal(info, 1)
1692
+ # assert_equal(r_c, n - r)
1693
+ single_atol = 1000 * np.finfo(np.float32).eps
1694
+ double_atol = 1000 * np.finfo(np.float64).eps
1695
+ atol = single_atol if ind in [0, 2] else double_atol
1696
+ assert_allclose(A[piv-1][:, piv-1], L @ L.conj().T, rtol=0., atol=atol)
1697
+
1698
+
1699
+ def test_pstf2():
1700
+ rng = np.random.RandomState(1234)
1701
+ for ind, dtype in enumerate(DTYPES):
1702
+ # DTYPES = <s, d, c, z> pstf2
1703
+ n = 10
1704
+ r = 2
1705
+ pstf2 = get_lapack_funcs('pstf2', dtype=dtype)
1706
+
1707
+ # Create positive semidefinite A
1708
+ if ind > 1:
1709
+ A = rng.rand(n, n-r).astype(dtype) + 1j * rng.rand(n, n-r).astype(dtype)
1710
+ A = A @ A.conj().T
1711
+ else:
1712
+ A = rng.rand(n, n-r).astype(dtype)
1713
+ A = A @ A.T
1714
+
1715
+ c, piv, r_c, info = pstf2(A)
1716
+ U = triu(c)
1717
+ U[r_c - n:, r_c - n:] = 0.
1718
+
1719
+ assert_equal(info, 1)
1720
+ # python-dbg 3.5.2 runs cause trouble with the commented assertions.
1721
+ # assert_equal(r_c, n - r)
1722
+ single_atol = 1000 * np.finfo(np.float32).eps
1723
+ double_atol = 1000 * np.finfo(np.float64).eps
1724
+ atol = single_atol if ind in [0, 2] else double_atol
1725
+ assert_allclose(A[piv-1][:, piv-1], U.conj().T @ U, rtol=0., atol=atol)
1726
+
1727
+ c, piv, r_c, info = pstf2(A, lower=1)
1728
+ L = tril(c)
1729
+ L[r_c - n:, r_c - n:] = 0.
1730
+
1731
+ assert_equal(info, 1)
1732
+ # assert_equal(r_c, n - r)
1733
+ single_atol = 1000 * np.finfo(np.float32).eps
1734
+ double_atol = 1000 * np.finfo(np.float64).eps
1735
+ atol = single_atol if ind in [0, 2] else double_atol
1736
+ assert_allclose(A[piv-1][:, piv-1], L @ L.conj().T, rtol=0., atol=atol)
1737
+
1738
+
1739
+ def test_geequ():
1740
+ desired_real = np.array([[0.6250, 1.0000, 0.0393, -0.4269],
1741
+ [1.0000, -0.5619, -1.0000, -1.0000],
1742
+ [0.5874, -1.0000, -0.0596, -0.5341],
1743
+ [-1.0000, -0.5946, -0.0294, 0.9957]])
1744
+
1745
+ desired_cplx = np.array([[-0.2816+0.5359*1j,
1746
+ 0.0812+0.9188*1j,
1747
+ -0.7439-0.2561*1j],
1748
+ [-0.3562-0.2954*1j,
1749
+ 0.9566-0.0434*1j,
1750
+ -0.0174+0.1555*1j],
1751
+ [0.8607+0.1393*1j,
1752
+ -0.2759+0.7241*1j,
1753
+ -0.1642-0.1365*1j]])
1754
+
1755
+ for ind, dtype in enumerate(DTYPES):
1756
+ if ind < 2:
1757
+ # Use examples from the NAG documentation
1758
+ A = np.array([[1.80e+10, 2.88e+10, 2.05e+00, -8.90e+09],
1759
+ [5.25e+00, -2.95e+00, -9.50e-09, -3.80e+00],
1760
+ [1.58e+00, -2.69e+00, -2.90e-10, -1.04e+00],
1761
+ [-1.11e+00, -6.60e-01, -5.90e-11, 8.00e-01]])
1762
+ A = A.astype(dtype)
1763
+ else:
1764
+ A = np.array([[-1.34e+00, 0.28e+10, -6.39e+00],
1765
+ [-1.70e+00, 3.31e+10, -0.15e+00],
1766
+ [2.41e-10, -0.56e+00, -0.83e-10]], dtype=dtype)
1767
+ A += np.array([[2.55e+00, 3.17e+10, -2.20e+00],
1768
+ [-1.41e+00, -0.15e+10, 1.34e+00],
1769
+ [0.39e-10, 1.47e+00, -0.69e-10]])*1j
1770
+
1771
+ A = A.astype(dtype)
1772
+
1773
+ geequ = get_lapack_funcs('geequ', dtype=dtype)
1774
+ r, c, rowcnd, colcnd, amax, info = geequ(A)
1775
+
1776
+ if ind < 2:
1777
+ assert_allclose(desired_real.astype(dtype), r[:, None]*A*c,
1778
+ rtol=0, atol=1e-4)
1779
+ else:
1780
+ assert_allclose(desired_cplx.astype(dtype), r[:, None]*A*c,
1781
+ rtol=0, atol=1e-4)
1782
+
1783
+
1784
+ def test_syequb():
1785
+ desired_log2s = np.array([0, 0, 0, 0, 0, 0, -1, -1, -2, -3])
1786
+
1787
+ for ind, dtype in enumerate(DTYPES):
1788
+ A = np.eye(10, dtype=dtype)
1789
+ alpha = dtype(1. if ind < 2 else 1.j)
1790
+ d = np.array([alpha * 2.**x for x in range(-5, 5)], dtype=dtype)
1791
+ A += np.rot90(np.diag(d))
1792
+
1793
+ syequb = get_lapack_funcs('syequb', dtype=dtype)
1794
+ s, scond, amax, info = syequb(A)
1795
+
1796
+ assert_equal(np.log2(s).astype(int), desired_log2s)
1797
+
1798
+
1799
+ @pytest.mark.skipif(True,
1800
+ reason="Failing on some OpenBLAS version, see gh-12276")
1801
+ def test_heequb():
1802
+ # zheequb has a bug for versions =< LAPACK 3.9.0
1803
+ # See Reference-LAPACK gh-61 and gh-408
1804
+ # Hence the zheequb test is customized accordingly to avoid
1805
+ # work scaling.
1806
+ A = np.diag([2]*5 + [1002]*5) + np.diag(np.ones(9), k=1)*1j
1807
+ s, scond, amax, info = lapack.zheequb(A)
1808
+ assert_equal(info, 0)
1809
+ assert_allclose(np.log2(s), [0., -1.]*2 + [0.] + [-4]*5)
1810
+
1811
+ A = np.diag(2**np.abs(np.arange(-5, 6)) + 0j)
1812
+ A[5, 5] = 1024
1813
+ A[5, 0] = 16j
1814
+ s, scond, amax, info = lapack.cheequb(A.astype(np.complex64), lower=1)
1815
+ assert_equal(info, 0)
1816
+ assert_allclose(np.log2(s), [-2, -1, -1, 0, 0, -5, 0, -1, -1, -2, -2])
1817
+
1818
+
1819
+ def test_getc2_gesc2():
1820
+ rng = np.random.RandomState(42)
1821
+ n = 10
1822
+ desired_real = rng.rand(n)
1823
+ desired_cplx = rng.rand(n) + rng.rand(n)*1j
1824
+
1825
+ for ind, dtype in enumerate(DTYPES):
1826
+ if ind < 2:
1827
+ A = rng.rand(n, n)
1828
+ A = A.astype(dtype)
1829
+ b = A @ desired_real
1830
+ b = b.astype(dtype)
1831
+ else:
1832
+ A = rng.rand(n, n) + rng.rand(n, n)*1j
1833
+ A = A.astype(dtype)
1834
+ b = A @ desired_cplx
1835
+ b = b.astype(dtype)
1836
+
1837
+ getc2 = get_lapack_funcs('getc2', dtype=dtype)
1838
+ gesc2 = get_lapack_funcs('gesc2', dtype=dtype)
1839
+ lu, ipiv, jpiv, info = getc2(A, overwrite_a=0)
1840
+ x, scale = gesc2(lu, b, ipiv, jpiv, overwrite_rhs=0)
1841
+
1842
+ if ind < 2:
1843
+ assert_array_almost_equal(desired_real.astype(dtype),
1844
+ x/scale, decimal=4)
1845
+ else:
1846
+ assert_array_almost_equal(desired_cplx.astype(dtype),
1847
+ x/scale, decimal=4)
1848
+
1849
+
1850
+ @pytest.mark.parametrize('size', [(6, 5), (5, 5)])
1851
+ @pytest.mark.parametrize('dtype', REAL_DTYPES)
1852
+ @pytest.mark.parametrize('joba', range(6)) # 'C', 'E', 'F', 'G', 'A', 'R'
1853
+ @pytest.mark.parametrize('jobu', range(4)) # 'U', 'F', 'W', 'N'
1854
+ @pytest.mark.parametrize('jobv', range(4)) # 'V', 'J', 'W', 'N'
1855
+ @pytest.mark.parametrize('jobr', [0, 1])
1856
+ @pytest.mark.parametrize('jobp', [0, 1])
1857
+ def test_gejsv_general(size, dtype, joba, jobu, jobv, jobr, jobp, jobt=0):
1858
+ """Test the lapack routine ?gejsv.
1859
+
1860
+ This function tests that a singular value decomposition can be performed
1861
+ on the random M-by-N matrix A. The test performs the SVD using ?gejsv
1862
+ then performs the following checks:
1863
+
1864
+ * ?gejsv exist successfully (info == 0)
1865
+ * The returned singular values are correct
1866
+ * `A` can be reconstructed from `u`, `SIGMA`, `v`
1867
+ * Ensure that u.T @ u is the identity matrix
1868
+ * Ensure that v.T @ v is the identity matrix
1869
+ * The reported matrix rank
1870
+ * The reported number of singular values
1871
+ * If denormalized floats are required
1872
+
1873
+ Notes
1874
+ -----
1875
+ joba specifies several choices effecting the calculation's accuracy
1876
+ Although all arguments are tested, the tests only check that the correct
1877
+ solution is returned - NOT that the prescribed actions are performed
1878
+ internally.
1879
+
1880
+ jobt is, as of v3.9.0, still experimental and removed to cut down number of
1881
+ test cases. However keyword itself is tested externally.
1882
+ """
1883
+ rng = np.random.RandomState(42)
1884
+
1885
+ # Define some constants for later use:
1886
+ m, n = size
1887
+ atol = 100 * np.finfo(dtype).eps
1888
+ A = generate_random_dtype_array(size, dtype, rng)
1889
+ gejsv = get_lapack_funcs('gejsv', dtype=dtype)
1890
+
1891
+ # Set up checks for invalid job? combinations
1892
+ # if an invalid combination occurs we set the appropriate
1893
+ # exit status.
1894
+ lsvec = jobu < 2 # Calculate left singular vectors
1895
+ rsvec = jobv < 2 # Calculate right singular vectors
1896
+ l2tran = (jobt == 1) and (m == n)
1897
+ is_complex = np.iscomplexobj(A)
1898
+
1899
+ invalid_real_jobv = (jobv == 1) and (not lsvec) and (not is_complex)
1900
+ invalid_cplx_jobu = (jobu == 2) and not (rsvec and l2tran) and is_complex
1901
+ invalid_cplx_jobv = (jobv == 2) and not (lsvec and l2tran) and is_complex
1902
+
1903
+ # Set the exit status to the expected value.
1904
+ # Here we only check for invalid combinations, not individual
1905
+ # parameters.
1906
+ if invalid_cplx_jobu:
1907
+ exit_status = -2
1908
+ elif invalid_real_jobv or invalid_cplx_jobv:
1909
+ exit_status = -3
1910
+ else:
1911
+ exit_status = 0
1912
+
1913
+ if (jobu > 1) and (jobv == 1):
1914
+ assert_raises(Exception, gejsv, A, joba, jobu, jobv, jobr, jobt, jobp)
1915
+ else:
1916
+ sva, u, v, work, iwork, info = gejsv(A,
1917
+ joba=joba,
1918
+ jobu=jobu,
1919
+ jobv=jobv,
1920
+ jobr=jobr,
1921
+ jobt=jobt,
1922
+ jobp=jobp)
1923
+
1924
+ # Check that ?gejsv exited successfully/as expected
1925
+ assert_equal(info, exit_status)
1926
+
1927
+ # If exit_status is non-zero the combination of jobs is invalid.
1928
+ # We test this above but no calculations are performed.
1929
+ if not exit_status:
1930
+
1931
+ # Check the returned singular values
1932
+ sigma = (work[0] / work[1]) * sva[:n]
1933
+ assert_allclose(sigma, svd(A, compute_uv=False), atol=atol)
1934
+
1935
+ if jobu == 1:
1936
+ # If JOBU = 'F', then u contains the M-by-M matrix of
1937
+ # the left singular vectors, including an ONB of the orthogonal
1938
+ # complement of the Range(A)
1939
+ # However, to recalculate A we are concerned about the
1940
+ # first n singular values and so can ignore the latter.
1941
+ # TODO: Add a test for ONB?
1942
+ u = u[:, :n]
1943
+
1944
+ if lsvec and rsvec:
1945
+ assert_allclose(u @ np.diag(sigma) @ v.conj().T, A, atol=atol)
1946
+ if lsvec:
1947
+ assert_allclose(u.conj().T @ u, np.identity(n), atol=atol)
1948
+ if rsvec:
1949
+ assert_allclose(v.conj().T @ v, np.identity(n), atol=atol)
1950
+
1951
+ assert_equal(iwork[0], np.linalg.matrix_rank(A))
1952
+ assert_equal(iwork[1], np.count_nonzero(sigma))
1953
+ # iwork[2] is non-zero if requested accuracy is not warranted for
1954
+ # the data. This should never occur for these tests.
1955
+ assert_equal(iwork[2], 0)
1956
+
1957
+
1958
+ @pytest.mark.parametrize('dtype', REAL_DTYPES)
1959
+ def test_gejsv_edge_arguments(dtype):
1960
+ """Test edge arguments return expected status"""
1961
+ gejsv = get_lapack_funcs('gejsv', dtype=dtype)
1962
+
1963
+ # scalar A
1964
+ sva, u, v, work, iwork, info = gejsv(1.)
1965
+ assert_equal(info, 0)
1966
+ assert_equal(u.shape, (1, 1))
1967
+ assert_equal(v.shape, (1, 1))
1968
+ assert_equal(sva, np.array([1.], dtype=dtype))
1969
+
1970
+ # 1d A
1971
+ A = np.ones((1,), dtype=dtype)
1972
+ sva, u, v, work, iwork, info = gejsv(A)
1973
+ assert_equal(info, 0)
1974
+ assert_equal(u.shape, (1, 1))
1975
+ assert_equal(v.shape, (1, 1))
1976
+ assert_equal(sva, np.array([1.], dtype=dtype))
1977
+
1978
+ # 2d empty A
1979
+ A = np.ones((1, 0), dtype=dtype)
1980
+ sva, u, v, work, iwork, info = gejsv(A)
1981
+ assert_equal(info, 0)
1982
+ assert_equal(u.shape, (1, 0))
1983
+ assert_equal(v.shape, (1, 0))
1984
+ assert_equal(sva, np.array([], dtype=dtype))
1985
+
1986
+ # make sure "overwrite_a" is respected - user reported in gh-13191
1987
+ A = np.sin(np.arange(100).reshape(10, 10)).astype(dtype)
1988
+ A = np.asfortranarray(A + A.T) # make it symmetric and column major
1989
+ Ac = A.copy('A')
1990
+ _ = gejsv(A)
1991
+ assert_allclose(A, Ac)
1992
+
1993
+
1994
+ @pytest.mark.parametrize(('kwargs'),
1995
+ ({'joba': 9},
1996
+ {'jobu': 9},
1997
+ {'jobv': 9},
1998
+ {'jobr': 9},
1999
+ {'jobt': 9},
2000
+ {'jobp': 9})
2001
+ )
2002
+ def test_gejsv_invalid_job_arguments(kwargs):
2003
+ """Test invalid job arguments raise an Exception"""
2004
+ A = np.ones((2, 2), dtype=float)
2005
+ gejsv = get_lapack_funcs('gejsv', dtype=float)
2006
+ assert_raises(Exception, gejsv, A, **kwargs)
2007
+
2008
+
2009
+ @pytest.mark.parametrize("A,sva_expect,u_expect,v_expect",
2010
+ [(np.array([[2.27, -1.54, 1.15, -1.94],
2011
+ [0.28, -1.67, 0.94, -0.78],
2012
+ [-0.48, -3.09, 0.99, -0.21],
2013
+ [1.07, 1.22, 0.79, 0.63],
2014
+ [-2.35, 2.93, -1.45, 2.30],
2015
+ [0.62, -7.39, 1.03, -2.57]]),
2016
+ np.array([9.9966, 3.6831, 1.3569, 0.5000]),
2017
+ np.array([[0.2774, -0.6003, -0.1277, 0.1323],
2018
+ [0.2020, -0.0301, 0.2805, 0.7034],
2019
+ [0.2918, 0.3348, 0.6453, 0.1906],
2020
+ [-0.0938, -0.3699, 0.6781, -0.5399],
2021
+ [-0.4213, 0.5266, 0.0413, -0.0575],
2022
+ [0.7816, 0.3353, -0.1645, -0.3957]]),
2023
+ np.array([[0.1921, -0.8030, 0.0041, -0.5642],
2024
+ [-0.8794, -0.3926, -0.0752, 0.2587],
2025
+ [0.2140, -0.2980, 0.7827, 0.5027],
2026
+ [-0.3795, 0.3351, 0.6178, -0.6017]]))])
2027
+ def test_gejsv_NAG(A, sva_expect, u_expect, v_expect):
2028
+ """
2029
+ This test implements the example found in the NAG manual, f08khf.
2030
+ An example was not found for the complex case.
2031
+ """
2032
+ # NAG manual provides accuracy up to 4 decimals
2033
+ atol = 1e-4
2034
+ gejsv = get_lapack_funcs('gejsv', dtype=A.dtype)
2035
+
2036
+ sva, u, v, work, iwork, info = gejsv(A)
2037
+
2038
+ assert_allclose(sva_expect, sva, atol=atol)
2039
+ assert_allclose(u_expect, u, atol=atol)
2040
+ assert_allclose(v_expect, v, atol=atol)
2041
+
2042
+
2043
+ @pytest.mark.parametrize("dtype", DTYPES)
2044
+ def test_gttrf_gttrs(dtype):
2045
+ # The test uses ?gttrf and ?gttrs to solve a random system for each dtype,
2046
+ # tests that the output of ?gttrf define LU matrices, that input
2047
+ # parameters are unmodified, transposal options function correctly, that
2048
+ # incompatible matrix shapes raise an error, and singular matrices return
2049
+ # non zero info.
2050
+
2051
+ rng = np.random.RandomState(42)
2052
+ n = 10
2053
+ atol = 100 * np.finfo(dtype).eps
2054
+
2055
+ # create the matrix in accordance with the data type
2056
+ du = generate_random_dtype_array((n-1,), dtype=dtype, rng=rng)
2057
+ d = generate_random_dtype_array((n,), dtype=dtype, rng=rng)
2058
+ dl = generate_random_dtype_array((n-1,), dtype=dtype, rng=rng)
2059
+
2060
+ diag_cpy = [dl.copy(), d.copy(), du.copy()]
2061
+
2062
+ A = np.diag(d) + np.diag(dl, -1) + np.diag(du, 1)
2063
+ x = np.random.rand(n)
2064
+ b = A @ x
2065
+
2066
+ gttrf, gttrs = get_lapack_funcs(('gttrf', 'gttrs'), dtype=dtype)
2067
+
2068
+ _dl, _d, _du, du2, ipiv, info = gttrf(dl, d, du)
2069
+ # test to assure that the inputs of ?gttrf are unmodified
2070
+ assert_array_equal(dl, diag_cpy[0])
2071
+ assert_array_equal(d, diag_cpy[1])
2072
+ assert_array_equal(du, diag_cpy[2])
2073
+
2074
+ # generate L and U factors from ?gttrf return values
2075
+ # L/U are lower/upper triangular by construction (initially and at end)
2076
+ U = np.diag(_d, 0) + np.diag(_du, 1) + np.diag(du2, 2)
2077
+ L = np.eye(n, dtype=dtype)
2078
+
2079
+ for i, m in enumerate(_dl):
2080
+ # L is given in a factored form.
2081
+ # See
2082
+ # www.hpcavf.uclan.ac.uk/softwaredoc/sgi_scsl_html/sgi_html/ch03.html
2083
+ piv = ipiv[i] - 1
2084
+ # right multiply by permutation matrix
2085
+ L[:, [i, piv]] = L[:, [piv, i]]
2086
+ # right multiply by Li, rank-one modification of identity
2087
+ L[:, i] += L[:, i+1]*m
2088
+
2089
+ # one last permutation
2090
+ i, piv = -1, ipiv[-1] - 1
2091
+ # right multiply by final permutation matrix
2092
+ L[:, [i, piv]] = L[:, [piv, i]]
2093
+
2094
+ # check that the outputs of ?gttrf define an LU decomposition of A
2095
+ assert_allclose(A, L @ U, atol=atol)
2096
+
2097
+ b_cpy = b.copy()
2098
+ x_gttrs, info = gttrs(_dl, _d, _du, du2, ipiv, b)
2099
+ # test that the inputs of ?gttrs are unmodified
2100
+ assert_array_equal(b, b_cpy)
2101
+ # test that the result of ?gttrs matches the expected input
2102
+ assert_allclose(x, x_gttrs, atol=atol)
2103
+
2104
+ # test that ?gttrf and ?gttrs work with transposal options
2105
+ if dtype in REAL_DTYPES:
2106
+ trans = "T"
2107
+ b_trans = A.T @ x
2108
+ else:
2109
+ trans = "C"
2110
+ b_trans = A.conj().T @ x
2111
+
2112
+ x_gttrs, info = gttrs(_dl, _d, _du, du2, ipiv, b_trans, trans=trans)
2113
+ assert_allclose(x, x_gttrs, atol=atol)
2114
+
2115
+ # test that ValueError is raised with incompatible matrix shapes
2116
+ with assert_raises(ValueError):
2117
+ gttrf(dl[:-1], d, du)
2118
+ with assert_raises(ValueError):
2119
+ gttrf(dl, d[:-1], du)
2120
+ with assert_raises(ValueError):
2121
+ gttrf(dl, d, du[:-1])
2122
+
2123
+ # test that matrix of size n=2 raises exception
2124
+ with assert_raises(ValueError):
2125
+ gttrf(dl[0], d[:1], du[0])
2126
+
2127
+ # test that singular (row of all zeroes) matrix fails via info
2128
+ du[0] = 0
2129
+ d[0] = 0
2130
+ __dl, __d, __du, _du2, _ipiv, _info = gttrf(dl, d, du)
2131
+ np.testing.assert_(__d[info - 1] == 0, (f"?gttrf: _d[info-1] is {__d[info - 1]},"
2132
+ " not the illegal value :0."))
2133
+
2134
+
2135
+ @pytest.mark.parametrize("du, d, dl, du_exp, d_exp, du2_exp, ipiv_exp, b, x",
2136
+ [(np.array([2.1, -1.0, 1.9, 8.0]),
2137
+ np.array([3.0, 2.3, -5.0, -.9, 7.1]),
2138
+ np.array([3.4, 3.6, 7.0, -6.0]),
2139
+ np.array([2.3, -5, -.9, 7.1]),
2140
+ np.array([3.4, 3.6, 7, -6, -1.015373]),
2141
+ np.array([-1, 1.9, 8]),
2142
+ np.array([2, 3, 4, 5, 5]),
2143
+ np.array([[2.7, 6.6],
2144
+ [-0.5, 10.8],
2145
+ [2.6, -3.2],
2146
+ [0.6, -11.2],
2147
+ [2.7, 19.1]
2148
+ ]),
2149
+ np.array([[-4, 5],
2150
+ [7, -4],
2151
+ [3, -3],
2152
+ [-4, -2],
2153
+ [-3, 1]])),
2154
+ (
2155
+ np.array([2 - 1j, 2 + 1j, -1 + 1j, 1 - 1j]),
2156
+ np.array([-1.3 + 1.3j, -1.3 + 1.3j,
2157
+ -1.3 + 3.3j, - .3 + 4.3j,
2158
+ -3.3 + 1.3j]),
2159
+ np.array([1 - 2j, 1 + 1j, 2 - 3j, 1 + 1j]),
2160
+ # du exp
2161
+ np.array([-1.3 + 1.3j, -1.3 + 3.3j,
2162
+ -0.3 + 4.3j, -3.3 + 1.3j]),
2163
+ np.array([1 - 2j, 1 + 1j, 2 - 3j, 1 + 1j,
2164
+ -1.3399 + 0.2875j]),
2165
+ np.array([2 + 1j, -1 + 1j, 1 - 1j]),
2166
+ np.array([2, 3, 4, 5, 5]),
2167
+ np.array([[2.4 - 5j, 2.7 + 6.9j],
2168
+ [3.4 + 18.2j, - 6.9 - 5.3j],
2169
+ [-14.7 + 9.7j, - 6 - .6j],
2170
+ [31.9 - 7.7j, -3.9 + 9.3j],
2171
+ [-1 + 1.6j, -3 + 12.2j]]),
2172
+ np.array([[1 + 1j, 2 - 1j],
2173
+ [3 - 1j, 1 + 2j],
2174
+ [4 + 5j, -1 + 1j],
2175
+ [-1 - 2j, 2 + 1j],
2176
+ [1 - 1j, 2 - 2j]])
2177
+ )])
2178
+ def test_gttrf_gttrs_NAG_f07cdf_f07cef_f07crf_f07csf(du, d, dl, du_exp, d_exp,
2179
+ du2_exp, ipiv_exp, b, x):
2180
+ # test to assure that wrapper is consistent with NAG Library Manual Mark 26
2181
+ # example problems: f07cdf and f07cef (real)
2182
+ # examples: f07crf and f07csf (complex)
2183
+ # (Links may expire, so search for "NAG Library Manual Mark 26" online)
2184
+
2185
+ gttrf, gttrs = get_lapack_funcs(('gttrf', "gttrs"), (du[0], du[0]))
2186
+
2187
+ _dl, _d, _du, du2, ipiv, info = gttrf(dl, d, du)
2188
+ assert_allclose(du2, du2_exp)
2189
+ assert_allclose(_du, du_exp)
2190
+ assert_allclose(_d, d_exp, atol=1e-4) # NAG examples provide 4 decimals.
2191
+ assert_allclose(ipiv, ipiv_exp)
2192
+
2193
+ x_gttrs, info = gttrs(_dl, _d, _du, du2, ipiv, b)
2194
+
2195
+ assert_allclose(x_gttrs, x)
2196
+
2197
+
2198
+ @pytest.mark.parametrize('dtype', DTYPES)
2199
+ @pytest.mark.parametrize('norm', ['1', 'I', 'O'])
2200
+ @pytest.mark.parametrize('n', [3, 10])
2201
+ def test_gtcon(dtype, norm, n):
2202
+ rng = np.random.default_rng(23498324)
2203
+
2204
+ d = rng.random(n) + rng.random(n)*1j
2205
+ dl = rng.random(n - 1) + rng.random(n - 1)*1j
2206
+ du = rng.random(n - 1) + rng.random(n - 1)*1j
2207
+ A = np.diag(d) + np.diag(dl, -1) + np.diag(du, 1)
2208
+ if np.issubdtype(dtype, np.floating):
2209
+ A, d, dl, du = A.real, d.real, dl.real, du.real
2210
+ A, d, dl, du = A.astype(dtype), d.astype(dtype), dl.astype(dtype), du.astype(dtype)
2211
+
2212
+ anorm = np.linalg.norm(A, ord=np.inf if norm == 'I' else 1)
2213
+
2214
+ gttrf, gtcon = get_lapack_funcs(('gttrf', 'gtcon'), (A,))
2215
+ dl, d, du, du2, ipiv, info = gttrf(dl, d, du)
2216
+ res, _ = gtcon(dl, d, du, du2, ipiv, anorm, norm=norm)
2217
+
2218
+ gecon, getrf = get_lapack_funcs(('gecon', 'getrf'), (A,))
2219
+ lu, ipvt, info = getrf(A)
2220
+ ref, _ = gecon(lu, anorm, norm=norm)
2221
+
2222
+ rtol = np.finfo(dtype).eps**0.75
2223
+ assert_allclose(res, ref, rtol=rtol)
2224
+
2225
+
2226
+ @pytest.mark.parametrize('dtype', DTYPES)
2227
+ @pytest.mark.parametrize('shape', [(3, 7), (7, 3), (2**18, 2**18)])
2228
+ def test_geqrfp_lwork(dtype, shape):
2229
+ geqrfp_lwork = get_lapack_funcs(('geqrfp_lwork'), dtype=dtype)
2230
+ m, n = shape
2231
+ lwork, info = geqrfp_lwork(m=m, n=n)
2232
+ assert_equal(info, 0)
2233
+
2234
+
2235
+ @pytest.mark.parametrize("ddtype,dtype",
2236
+ zip(REAL_DTYPES + REAL_DTYPES, DTYPES))
2237
+ def test_pttrf_pttrs(ddtype, dtype):
2238
+ rng = np.random.RandomState(42)
2239
+ # set test tolerance appropriate for dtype
2240
+ atol = 100*np.finfo(dtype).eps
2241
+ # n is the length diagonal of A
2242
+ n = 10
2243
+ # create diagonals according to size and dtype
2244
+
2245
+ # diagonal d should always be real.
2246
+ # add 4 to d so it will be dominant for all dtypes
2247
+ d = generate_random_dtype_array((n,), ddtype, rng) + 4
2248
+ # diagonal e may be real or complex.
2249
+ e = generate_random_dtype_array((n-1,), dtype, rng)
2250
+
2251
+ # assemble diagonals together into matrix
2252
+ A = np.diag(d) + np.diag(e, -1) + np.diag(np.conj(e), 1)
2253
+ # store a copy of diagonals to later verify
2254
+ diag_cpy = [d.copy(), e.copy()]
2255
+
2256
+ pttrf = get_lapack_funcs('pttrf', dtype=dtype)
2257
+
2258
+ _d, _e, info = pttrf(d, e)
2259
+ # test to assure that the inputs of ?pttrf are unmodified
2260
+ assert_array_equal(d, diag_cpy[0])
2261
+ assert_array_equal(e, diag_cpy[1])
2262
+ assert_equal(info, 0, err_msg=f"pttrf: info = {info}, should be 0")
2263
+
2264
+ # test that the factors from pttrf can be recombined to make A
2265
+ L = np.diag(_e, -1) + np.diag(np.ones(n))
2266
+ D = np.diag(_d)
2267
+
2268
+ assert_allclose(A, L@D@L.conjugate().T, atol=atol)
2269
+
2270
+ # generate random solution x
2271
+ x = generate_random_dtype_array((n,), dtype, rng)
2272
+ # determine accompanying b to get soln x
2273
+ b = A@x
2274
+
2275
+ # determine _x from pttrs
2276
+ pttrs = get_lapack_funcs('pttrs', dtype=dtype)
2277
+ _x, info = pttrs(_d, _e.conj(), b)
2278
+ assert_equal(info, 0, err_msg=f"pttrs: info = {info}, should be 0")
2279
+
2280
+ # test that _x from pttrs matches the expected x
2281
+ assert_allclose(x, _x, atol=atol)
2282
+
2283
+
2284
+ @pytest.mark.parametrize("ddtype,dtype",
2285
+ zip(REAL_DTYPES + REAL_DTYPES, DTYPES))
2286
+ def test_pttrf_pttrs_errors_incompatible_shape(ddtype, dtype):
2287
+ n = 10
2288
+ rng = np.random.RandomState(1234)
2289
+ pttrf = get_lapack_funcs('pttrf', dtype=dtype)
2290
+ d = generate_random_dtype_array((n,), ddtype, rng) + 2
2291
+ e = generate_random_dtype_array((n-1,), dtype, rng)
2292
+ # test that ValueError is raised with incompatible matrix shapes
2293
+ assert_raises(ValueError, pttrf, d[:-1], e)
2294
+ assert_raises(ValueError, pttrf, d, e[:-1])
2295
+
2296
+
2297
+ @pytest.mark.parametrize("ddtype,dtype",
2298
+ zip(REAL_DTYPES + REAL_DTYPES, DTYPES))
2299
+ def test_pttrf_pttrs_errors_singular_nonSPD(ddtype, dtype):
2300
+ n = 10
2301
+ rng = np.random.RandomState(42)
2302
+ pttrf = get_lapack_funcs('pttrf', dtype=dtype)
2303
+ d = generate_random_dtype_array((n,), ddtype, rng) + 2
2304
+ e = generate_random_dtype_array((n-1,), dtype, rng)
2305
+ # test that singular (row of all zeroes) matrix fails via info
2306
+ d[0] = 0
2307
+ e[0] = 0
2308
+ _d, _e, info = pttrf(d, e)
2309
+ assert_equal(_d[info - 1], 0,
2310
+ f"?pttrf: _d[info-1] is {_d[info - 1]}, not the illegal value :0.")
2311
+
2312
+ # test with non-spd matrix
2313
+ d = generate_random_dtype_array((n,), ddtype, rng)
2314
+ _d, _e, info = pttrf(d, e)
2315
+ assert_(info != 0, "?pttrf should fail with non-spd matrix, but didn't")
2316
+
2317
+
2318
+ @pytest.mark.parametrize(("d, e, d_expect, e_expect, b, x_expect"), [
2319
+ (np.array([4, 10, 29, 25, 5]),
2320
+ np.array([-2, -6, 15, 8]),
2321
+ np.array([4, 9, 25, 16, 1]),
2322
+ np.array([-.5, -.6667, .6, .5]),
2323
+ np.array([[6, 10], [9, 4], [2, 9], [14, 65],
2324
+ [7, 23]]),
2325
+ np.array([[2.5, 2], [2, -1], [1, -3], [-1, 6],
2326
+ [3, -5]])
2327
+ ), (
2328
+ np.array([16, 41, 46, 21]),
2329
+ np.array([16 + 16j, 18 - 9j, 1 - 4j]),
2330
+ np.array([16, 9, 1, 4]),
2331
+ np.array([1+1j, 2-1j, 1-4j]),
2332
+ np.array([[64+16j, -16-32j], [93+62j, 61-66j],
2333
+ [78-80j, 71-74j], [14-27j, 35+15j]]),
2334
+ np.array([[2+1j, -3-2j], [1+1j, 1+1j], [1-2j, 1-2j],
2335
+ [1-1j, 2+1j]])
2336
+ )])
2337
+ def test_pttrf_pttrs_NAG(d, e, d_expect, e_expect, b, x_expect):
2338
+ # test to assure that wrapper is consistent with NAG Manual Mark 26
2339
+ # example problems: f07jdf and f07jef (real)
2340
+ # examples: f07jrf and f07csf (complex)
2341
+ # NAG examples provide 4 decimals.
2342
+ # (Links expire, so please search for "NAG Library Manual Mark 26" online)
2343
+
2344
+ atol = 1e-4
2345
+ pttrf = get_lapack_funcs('pttrf', dtype=e[0])
2346
+ _d, _e, info = pttrf(d, e)
2347
+ assert_allclose(_d, d_expect, atol=atol)
2348
+ assert_allclose(_e, e_expect, atol=atol)
2349
+
2350
+ pttrs = get_lapack_funcs('pttrs', dtype=e[0])
2351
+ _x, info = pttrs(_d, _e.conj(), b)
2352
+ assert_allclose(_x, x_expect, atol=atol)
2353
+
2354
+ # also test option `lower`
2355
+ if e.dtype in COMPLEX_DTYPES:
2356
+ _x, info = pttrs(_d, _e, b, lower=1)
2357
+ assert_allclose(_x, x_expect, atol=atol)
2358
+
2359
+
2360
+ def pteqr_get_d_e_A_z(dtype, realtype, n, compute_z):
2361
+ # used by ?pteqr tests to build parameters
2362
+ # returns tuple of (d, e, A, z)
2363
+ rng = np.random.RandomState(42)
2364
+ if compute_z == 1:
2365
+ # build Hermitian A from Q**T * tri * Q = A by creating Q and tri
2366
+ A_eig = generate_random_dtype_array((n, n), dtype, rng)
2367
+ A_eig = A_eig + np.diag(np.zeros(n) + 4*n)
2368
+ A_eig = (A_eig + A_eig.conj().T) / 2
2369
+ # obtain right eigenvectors (orthogonal)
2370
+ vr = eigh(A_eig)[1]
2371
+ # create tridiagonal matrix
2372
+ d = generate_random_dtype_array((n,), realtype, rng) + 4
2373
+ e = generate_random_dtype_array((n-1,), realtype, rng)
2374
+ tri = np.diag(d) + np.diag(e, 1) + np.diag(e, -1)
2375
+ # Build A using these factors that sytrd would: (Q**T * tri * Q = A)
2376
+ A = vr @ tri @ vr.conj().T
2377
+ # vr is orthogonal
2378
+ z = vr
2379
+
2380
+ else:
2381
+ # d and e are always real per lapack docs.
2382
+ d = generate_random_dtype_array((n,), realtype, rng)
2383
+ e = generate_random_dtype_array((n-1,), realtype, rng)
2384
+
2385
+ # make SPD
2386
+ d = d + 4
2387
+ A = np.diag(d) + np.diag(e, 1) + np.diag(e, -1)
2388
+ z = np.diag(d) + np.diag(e, -1) + np.diag(e, 1)
2389
+ return (d, e, A, z)
2390
+
2391
+
2392
+ @pytest.mark.parametrize("dtype,realtype",
2393
+ zip(DTYPES, REAL_DTYPES + REAL_DTYPES))
2394
+ @pytest.mark.parametrize("compute_z", range(3))
2395
+ def test_pteqr(dtype, realtype, compute_z):
2396
+ '''
2397
+ Tests the ?pteqr lapack routine for all dtypes and compute_z parameters.
2398
+ It generates random SPD matrix diagonals d and e, and then confirms
2399
+ correct eigenvalues with scipy.linalg.eig. With applicable compute_z=2 it
2400
+ tests that z can reform A.
2401
+ '''
2402
+ seed(42)
2403
+ atol = 1000*np.finfo(dtype).eps
2404
+ pteqr = get_lapack_funcs(('pteqr'), dtype=dtype)
2405
+
2406
+ n = 10
2407
+
2408
+ d, e, A, z = pteqr_get_d_e_A_z(dtype, realtype, n, compute_z)
2409
+
2410
+ d_pteqr, e_pteqr, z_pteqr, info = pteqr(d=d, e=e, z=z, compute_z=compute_z)
2411
+ assert_equal(info, 0, f"info = {info}, should be 0.")
2412
+
2413
+ # compare the routine's eigenvalues with scipy.linalg.eig's.
2414
+ assert_allclose(np.sort(eigh(A)[0]), np.sort(d_pteqr), atol=atol)
2415
+
2416
+ if compute_z:
2417
+ # verify z_pteqr as orthogonal
2418
+ assert_allclose(z_pteqr @ np.conj(z_pteqr).T, np.identity(n),
2419
+ atol=atol)
2420
+ # verify that z_pteqr recombines to A
2421
+ assert_allclose(z_pteqr @ np.diag(d_pteqr) @ np.conj(z_pteqr).T,
2422
+ A, atol=atol)
2423
+
2424
+
2425
+ @pytest.mark.parametrize("dtype,realtype",
2426
+ zip(DTYPES, REAL_DTYPES + REAL_DTYPES))
2427
+ @pytest.mark.parametrize("compute_z", range(3))
2428
+ def test_pteqr_error_non_spd(dtype, realtype, compute_z):
2429
+ seed(42)
2430
+ pteqr = get_lapack_funcs(('pteqr'), dtype=dtype)
2431
+
2432
+ n = 10
2433
+ d, e, A, z = pteqr_get_d_e_A_z(dtype, realtype, n, compute_z)
2434
+
2435
+ # test with non-spd matrix
2436
+ d_pteqr, e_pteqr, z_pteqr, info = pteqr(d - 4, e, z=z, compute_z=compute_z)
2437
+ assert info > 0
2438
+
2439
+
2440
+ @pytest.mark.parametrize("dtype,realtype",
2441
+ zip(DTYPES, REAL_DTYPES + REAL_DTYPES))
2442
+ @pytest.mark.parametrize("compute_z", range(3))
2443
+ def test_pteqr_raise_error_wrong_shape(dtype, realtype, compute_z):
2444
+ seed(42)
2445
+ pteqr = get_lapack_funcs(('pteqr'), dtype=dtype)
2446
+ n = 10
2447
+ d, e, A, z = pteqr_get_d_e_A_z(dtype, realtype, n, compute_z)
2448
+ # test with incorrect/incompatible array sizes
2449
+ assert_raises(ValueError, pteqr, d[:-1], e, z=z, compute_z=compute_z)
2450
+ assert_raises(ValueError, pteqr, d, e[:-1], z=z, compute_z=compute_z)
2451
+ if compute_z:
2452
+ assert_raises(ValueError, pteqr, d, e, z=z[:-1], compute_z=compute_z)
2453
+
2454
+
2455
+ @pytest.mark.parametrize("dtype,realtype",
2456
+ zip(DTYPES, REAL_DTYPES + REAL_DTYPES))
2457
+ @pytest.mark.parametrize("compute_z", range(3))
2458
+ def test_pteqr_error_singular(dtype, realtype, compute_z):
2459
+ seed(42)
2460
+ pteqr = get_lapack_funcs(('pteqr'), dtype=dtype)
2461
+ n = 10
2462
+ d, e, A, z = pteqr_get_d_e_A_z(dtype, realtype, n, compute_z)
2463
+ # test with singular matrix
2464
+ d[0] = 0
2465
+ e[0] = 0
2466
+ d_pteqr, e_pteqr, z_pteqr, info = pteqr(d, e, z=z, compute_z=compute_z)
2467
+ assert info > 0
2468
+
2469
+
2470
+ @pytest.mark.parametrize("compute_z,d,e,d_expect,z_expect",
2471
+ [(2, # "I"
2472
+ np.array([4.16, 5.25, 1.09, .62]),
2473
+ np.array([3.17, -.97, .55]),
2474
+ np.array([8.0023, 1.9926, 1.0014, 0.1237]),
2475
+ np.array([[0.6326, 0.6245, -0.4191, 0.1847],
2476
+ [0.7668, -0.4270, 0.4176, -0.2352],
2477
+ [-0.1082, 0.6071, 0.4594, -0.6393],
2478
+ [-0.0081, 0.2432, 0.6625, 0.7084]])),
2479
+ ])
2480
+ def test_pteqr_NAG_f08jgf(compute_z, d, e, d_expect, z_expect):
2481
+ '''
2482
+ Implements real (f08jgf) example from NAG Manual Mark 26.
2483
+ Tests for correct outputs.
2484
+ '''
2485
+ # the NAG manual has 4 decimals accuracy
2486
+ atol = 1e-4
2487
+ pteqr = get_lapack_funcs(('pteqr'), dtype=d.dtype)
2488
+
2489
+ z = np.diag(d) + np.diag(e, 1) + np.diag(e, -1)
2490
+ _d, _e, _z, info = pteqr(d=d, e=e, z=z, compute_z=compute_z)
2491
+ assert_allclose(_d, d_expect, atol=atol)
2492
+ assert_allclose(np.abs(_z), np.abs(z_expect), atol=atol)
2493
+
2494
+
2495
+ @pytest.mark.parametrize('dtype', DTYPES)
2496
+ @pytest.mark.parametrize('matrix_size', [(3, 4), (7, 6), (6, 6)])
2497
+ def test_geqrfp(dtype, matrix_size):
2498
+ # Tests for all dytpes, tall, wide, and square matrices.
2499
+ # Using the routine with random matrix A, Q and R are obtained and then
2500
+ # tested such that R is upper triangular and non-negative on the diagonal,
2501
+ # and Q is an orthogonal matrix. Verifies that A=Q@R. It also
2502
+ # tests against a matrix that for which the linalg.qr method returns
2503
+ # negative diagonals, and for error messaging.
2504
+
2505
+ # set test tolerance appropriate for dtype
2506
+ rng = np.random.RandomState(42)
2507
+ rtol = 250*np.finfo(dtype).eps
2508
+ atol = 100*np.finfo(dtype).eps
2509
+ # get appropriate ?geqrfp for dtype
2510
+ geqrfp = get_lapack_funcs(('geqrfp'), dtype=dtype)
2511
+ gqr = get_lapack_funcs(("orgqr"), dtype=dtype)
2512
+
2513
+ m, n = matrix_size
2514
+
2515
+ # create random matrix of dimensions m x n
2516
+ A = generate_random_dtype_array((m, n), dtype=dtype, rng=rng)
2517
+ # create qr matrix using geqrfp
2518
+ qr_A, tau, info = geqrfp(A)
2519
+
2520
+ # obtain r from the upper triangular area
2521
+ r = np.triu(qr_A)
2522
+
2523
+ # obtain q from the orgqr lapack routine
2524
+ # based on linalg.qr's extraction strategy of q with orgqr
2525
+
2526
+ if m > n:
2527
+ # this adds an extra column to the end of qr_A
2528
+ # let qqr be an empty m x m matrix
2529
+ qqr = np.zeros((m, m), dtype=dtype)
2530
+ # set first n columns of qqr to qr_A
2531
+ qqr[:, :n] = qr_A
2532
+ # determine q from this qqr
2533
+ # note that m is a sufficient for lwork based on LAPACK documentation
2534
+ q = gqr(qqr, tau=tau, lwork=m)[0]
2535
+ else:
2536
+ q = gqr(qr_A[:, :m], tau=tau, lwork=m)[0]
2537
+
2538
+ # test that q and r still make A
2539
+ assert_allclose(q@r, A, rtol=rtol)
2540
+ # ensure that q is orthogonal (that q @ transposed q is the identity)
2541
+ assert_allclose(np.eye(q.shape[0]), q@(q.conj().T), rtol=rtol,
2542
+ atol=atol)
2543
+ # ensure r is upper tri by comparing original r to r as upper triangular
2544
+ assert_allclose(r, np.triu(r), rtol=rtol)
2545
+ # make sure diagonals of r are positive for this random solution
2546
+ assert_(np.all(np.diag(r) > np.zeros(len(np.diag(r)))))
2547
+ # ensure that info is zero for this success
2548
+ assert_(info == 0)
2549
+
2550
+ # test that this routine gives r diagonals that are positive for a
2551
+ # matrix that returns negatives in the diagonal with scipy.linalg.rq
2552
+ A_negative = generate_random_dtype_array((n, m), dtype=dtype, rng=rng) * -1
2553
+ r_rq_neg, q_rq_neg = qr(A_negative)
2554
+ rq_A_neg, tau_neg, info_neg = geqrfp(A_negative)
2555
+ # assert that any of the entries on the diagonal from linalg.qr
2556
+ # are negative and that all of geqrfp are positive.
2557
+ assert_(np.any(np.diag(r_rq_neg) < 0) and
2558
+ np.all(np.diag(r) > 0))
2559
+
2560
+
2561
+ def test_geqrfp_errors_with_empty_array():
2562
+ # check that empty array raises good error message
2563
+ A_empty = np.array([])
2564
+ geqrfp = get_lapack_funcs('geqrfp', dtype=A_empty.dtype)
2565
+ assert_raises(Exception, geqrfp, A_empty)
2566
+
2567
+
2568
+ @pytest.mark.parametrize("driver", ['ev', 'evd', 'evr', 'evx'])
2569
+ @pytest.mark.parametrize("pfx", ['sy', 'he'])
2570
+ def test_standard_eigh_lworks(pfx, driver):
2571
+ n = 1200 # Some sufficiently big arbitrary number
2572
+ dtype = REAL_DTYPES if pfx == 'sy' else COMPLEX_DTYPES
2573
+ sc_dlw = get_lapack_funcs(pfx+driver+'_lwork', dtype=dtype[0])
2574
+ dz_dlw = get_lapack_funcs(pfx+driver+'_lwork', dtype=dtype[1])
2575
+ try:
2576
+ _compute_lwork(sc_dlw, n, lower=1)
2577
+ _compute_lwork(dz_dlw, n, lower=1)
2578
+ except Exception as e:
2579
+ pytest.fail(f"{pfx+driver}_lwork raised unexpected exception: {e}")
2580
+
2581
+
2582
+ @pytest.mark.parametrize("driver", ['gv', 'gvx'])
2583
+ @pytest.mark.parametrize("pfx", ['sy', 'he'])
2584
+ def test_generalized_eigh_lworks(pfx, driver):
2585
+ n = 1200 # Some sufficiently big arbitrary number
2586
+ dtype = REAL_DTYPES if pfx == 'sy' else COMPLEX_DTYPES
2587
+ sc_dlw = get_lapack_funcs(pfx+driver+'_lwork', dtype=dtype[0])
2588
+ dz_dlw = get_lapack_funcs(pfx+driver+'_lwork', dtype=dtype[1])
2589
+ # Shouldn't raise any exceptions
2590
+ try:
2591
+ _compute_lwork(sc_dlw, n, uplo="L")
2592
+ _compute_lwork(dz_dlw, n, uplo="L")
2593
+ except Exception as e:
2594
+ pytest.fail(f"{pfx+driver}_lwork raised unexpected exception: {e}")
2595
+
2596
+
2597
+ @pytest.mark.parametrize("dtype_", DTYPES)
2598
+ @pytest.mark.parametrize("m", [1, 10, 100, 1000])
2599
+ def test_orcsd_uncsd_lwork(dtype_, m):
2600
+ seed(1234)
2601
+ p = randint(0, m)
2602
+ q = m - p
2603
+ pfx = 'or' if dtype_ in REAL_DTYPES else 'un'
2604
+ dlw = pfx + 'csd_lwork'
2605
+ lw = get_lapack_funcs(dlw, dtype=dtype_)
2606
+ lwval = _compute_lwork(lw, m, p, q)
2607
+ lwval = lwval if pfx == 'un' else (lwval,)
2608
+ assert all([x > 0 for x in lwval])
2609
+
2610
+
2611
+ @pytest.mark.parametrize("dtype_", DTYPES)
2612
+ def test_orcsd_uncsd(dtype_):
2613
+ m, p, q = 250, 80, 170
2614
+
2615
+ pfx = 'or' if dtype_ in REAL_DTYPES else 'un'
2616
+ X = ortho_group.rvs(m) if pfx == 'or' else unitary_group.rvs(m)
2617
+
2618
+ drv, dlw = get_lapack_funcs((pfx + 'csd', pfx + 'csd_lwork'), dtype=dtype_)
2619
+ lwval = _compute_lwork(dlw, m, p, q)
2620
+ lwvals = {'lwork': lwval} if pfx == 'or' else dict(zip(['lwork',
2621
+ 'lrwork'], lwval))
2622
+
2623
+ cs11, cs12, cs21, cs22, theta, u1, u2, v1t, v2t, info =\
2624
+ drv(X[:p, :q], X[:p, q:], X[p:, :q], X[p:, q:], **lwvals)
2625
+
2626
+ assert info == 0
2627
+
2628
+ U = block_diag(u1, u2)
2629
+ VH = block_diag(v1t, v2t)
2630
+ r = min(min(p, q), min(m-p, m-q))
2631
+ n11 = min(p, q) - r
2632
+ n12 = min(p, m-q) - r
2633
+ n21 = min(m-p, q) - r
2634
+ n22 = min(m-p, m-q) - r
2635
+
2636
+ S = np.zeros((m, m), dtype=dtype_)
2637
+ one = dtype_(1.)
2638
+ for i in range(n11):
2639
+ S[i, i] = one
2640
+ for i in range(n22):
2641
+ S[p+i, q+i] = one
2642
+ for i in range(n12):
2643
+ S[i+n11+r, i+n11+r+n21+n22+r] = -one
2644
+ for i in range(n21):
2645
+ S[p+n22+r+i, n11+r+i] = one
2646
+
2647
+ for i in range(r):
2648
+ S[i+n11, i+n11] = np.cos(theta[i])
2649
+ S[p+n22+i, i+r+n21+n22] = np.cos(theta[i])
2650
+
2651
+ S[i+n11, i+n11+n21+n22+r] = -np.sin(theta[i])
2652
+ S[p+n22+i, i+n11] = np.sin(theta[i])
2653
+
2654
+ Xc = U @ S @ VH
2655
+ assert_allclose(X, Xc, rtol=0., atol=1e4*np.finfo(dtype_).eps)
2656
+
2657
+
2658
+ @pytest.mark.parametrize("dtype", DTYPES)
2659
+ @pytest.mark.parametrize("trans_bool", [False, True])
2660
+ @pytest.mark.parametrize("fact", ["F", "N"])
2661
+ def test_gtsvx(dtype, trans_bool, fact):
2662
+ """
2663
+ These tests uses ?gtsvx to solve a random Ax=b system for each dtype.
2664
+ It tests that the outputs define an LU matrix, that inputs are unmodified,
2665
+ transposal options, incompatible shapes, singular matrices, and
2666
+ singular factorizations. It parametrizes DTYPES and the 'fact' value along
2667
+ with the fact related inputs.
2668
+ """
2669
+ rng = np.random.RandomState(42)
2670
+ # set test tolerance appropriate for dtype
2671
+ atol = 100 * np.finfo(dtype).eps
2672
+ # obtain routine
2673
+ gtsvx, gttrf = get_lapack_funcs(('gtsvx', 'gttrf'), dtype=dtype)
2674
+ # Generate random tridiagonal matrix A
2675
+ n = 10
2676
+ dl = generate_random_dtype_array((n-1,), dtype=dtype, rng=rng)
2677
+ d = generate_random_dtype_array((n,), dtype=dtype, rng=rng)
2678
+ du = generate_random_dtype_array((n-1,), dtype=dtype, rng=rng)
2679
+ A = np.diag(dl, -1) + np.diag(d) + np.diag(du, 1)
2680
+ # generate random solution x
2681
+ x = generate_random_dtype_array((n, 2), dtype=dtype, rng=rng)
2682
+ # create b from x for equation Ax=b
2683
+ trans = ("T" if dtype in REAL_DTYPES else "C") if trans_bool else "N"
2684
+ b = (A.conj().T if trans_bool else A) @ x
2685
+
2686
+ # store a copy of the inputs to check they haven't been modified later
2687
+ inputs_cpy = [dl.copy(), d.copy(), du.copy(), b.copy()]
2688
+
2689
+ # set these to None if fact = 'N', or the output of gttrf is fact = 'F'
2690
+ dlf_, df_, duf_, du2f_, ipiv_, info_ = \
2691
+ gttrf(dl, d, du) if fact == 'F' else [None]*6
2692
+
2693
+ gtsvx_out = gtsvx(dl, d, du, b, fact=fact, trans=trans, dlf=dlf_, df=df_,
2694
+ duf=duf_, du2=du2f_, ipiv=ipiv_)
2695
+ dlf, df, duf, du2f, ipiv, x_soln, rcond, ferr, berr, info = gtsvx_out
2696
+ assert_(info == 0, f"?gtsvx info = {info}, should be zero")
2697
+
2698
+ # assure that inputs are unmodified
2699
+ assert_array_equal(dl, inputs_cpy[0])
2700
+ assert_array_equal(d, inputs_cpy[1])
2701
+ assert_array_equal(du, inputs_cpy[2])
2702
+ assert_array_equal(b, inputs_cpy[3])
2703
+
2704
+ # test that x_soln matches the expected x
2705
+ assert_allclose(x, x_soln, atol=atol)
2706
+
2707
+ # assert that the outputs are of correct type or shape
2708
+ # rcond should be a scalar
2709
+ assert_(hasattr(rcond, "__len__") is not True,
2710
+ f"rcond should be scalar but is {rcond}")
2711
+ # ferr should be length of # of cols in x
2712
+ assert_(ferr.shape[0] == b.shape[1], (f"ferr.shape is {ferr.shape[0]} but should"
2713
+ f" be {b.shape[1]}"))
2714
+ # berr should be length of # of cols in x
2715
+ assert_(berr.shape[0] == b.shape[1], (f"berr.shape is {berr.shape[0]} but should"
2716
+ f" be {b.shape[1]}"))
2717
+
2718
+
2719
+ @pytest.mark.parametrize("dtype", DTYPES)
2720
+ @pytest.mark.parametrize("trans_bool", [0, 1])
2721
+ @pytest.mark.parametrize("fact", ["F", "N"])
2722
+ def test_gtsvx_error_singular(dtype, trans_bool, fact):
2723
+ rng = np.random.RandomState(42)
2724
+ # obtain routine
2725
+ gtsvx, gttrf = get_lapack_funcs(('gtsvx', 'gttrf'), dtype=dtype)
2726
+ # Generate random tridiagonal matrix A
2727
+ n = 10
2728
+ dl = generate_random_dtype_array((n-1,), dtype=dtype, rng=rng)
2729
+ d = generate_random_dtype_array((n,), dtype=dtype, rng=rng)
2730
+ du = generate_random_dtype_array((n-1,), dtype=dtype, rng=rng)
2731
+ A = np.diag(dl, -1) + np.diag(d) + np.diag(du, 1)
2732
+ # generate random solution x
2733
+ x = generate_random_dtype_array((n, 2), dtype=dtype, rng=rng)
2734
+ # create b from x for equation Ax=b
2735
+ trans = "T" if dtype in REAL_DTYPES else "C"
2736
+ b = (A.conj().T if trans_bool else A) @ x
2737
+
2738
+ # set these to None if fact = 'N', or the output of gttrf is fact = 'F'
2739
+ dlf_, df_, duf_, du2f_, ipiv_, info_ = \
2740
+ gttrf(dl, d, du) if fact == 'F' else [None]*6
2741
+
2742
+ gtsvx_out = gtsvx(dl, d, du, b, fact=fact, trans=trans, dlf=dlf_, df=df_,
2743
+ duf=duf_, du2=du2f_, ipiv=ipiv_)
2744
+ dlf, df, duf, du2f, ipiv, x_soln, rcond, ferr, berr, info = gtsvx_out
2745
+ # test with singular matrix
2746
+ # no need to test inputs with fact "F" since ?gttrf already does.
2747
+ if fact == "N":
2748
+ # Construct a singular example manually
2749
+ d[-1] = 0
2750
+ dl[-1] = 0
2751
+ # solve using routine
2752
+ gtsvx_out = gtsvx(dl, d, du, b)
2753
+ dlf, df, duf, du2f, ipiv, x_soln, rcond, ferr, berr, info = gtsvx_out
2754
+ # test for the singular matrix.
2755
+ assert info > 0, "info should be > 0 for singular matrix"
2756
+
2757
+ elif fact == 'F':
2758
+ # assuming that a singular factorization is input
2759
+ df_[-1] = 0
2760
+ duf_[-1] = 0
2761
+ du2f_[-1] = 0
2762
+
2763
+ gtsvx_out = gtsvx(dl, d, du, b, fact=fact, dlf=dlf_, df=df_, duf=duf_,
2764
+ du2=du2f_, ipiv=ipiv_)
2765
+ dlf, df, duf, du2f, ipiv, x_soln, rcond, ferr, berr, info = gtsvx_out
2766
+ # info should not be zero and should provide index of illegal value
2767
+ assert info > 0, "info should be > 0 for singular matrix"
2768
+
2769
+
2770
+ @pytest.mark.parametrize("dtype", DTYPES*2)
2771
+ @pytest.mark.parametrize("trans_bool", [False, True])
2772
+ @pytest.mark.parametrize("fact", ["F", "N"])
2773
+ def test_gtsvx_error_incompatible_size(dtype, trans_bool, fact):
2774
+ rng = np.random.RandomState(42)
2775
+ # obtain routine
2776
+ gtsvx, gttrf = get_lapack_funcs(('gtsvx', 'gttrf'), dtype=dtype)
2777
+ # Generate random tridiagonal matrix A
2778
+ n = 10
2779
+ dl = generate_random_dtype_array((n-1,), dtype=dtype, rng=rng)
2780
+ d = generate_random_dtype_array((n,), dtype=dtype, rng=rng)
2781
+ du = generate_random_dtype_array((n-1,), dtype=dtype, rng=rng)
2782
+ A = np.diag(dl, -1) + np.diag(d) + np.diag(du, 1)
2783
+ # generate random solution x
2784
+ x = generate_random_dtype_array((n, 2), dtype=dtype, rng=rng)
2785
+ # create b from x for equation Ax=b
2786
+ trans = "T" if dtype in REAL_DTYPES else "C"
2787
+ b = (A.conj().T if trans_bool else A) @ x
2788
+
2789
+ # set these to None if fact = 'N', or the output of gttrf is fact = 'F'
2790
+ dlf_, df_, duf_, du2f_, ipiv_, info_ = \
2791
+ gttrf(dl, d, du) if fact == 'F' else [None]*6
2792
+
2793
+ if fact == "N":
2794
+ assert_raises(ValueError, gtsvx, dl[:-1], d, du, b,
2795
+ fact=fact, trans=trans, dlf=dlf_, df=df_,
2796
+ duf=duf_, du2=du2f_, ipiv=ipiv_)
2797
+ assert_raises(ValueError, gtsvx, dl, d[:-1], du, b,
2798
+ fact=fact, trans=trans, dlf=dlf_, df=df_,
2799
+ duf=duf_, du2=du2f_, ipiv=ipiv_)
2800
+ assert_raises(ValueError, gtsvx, dl, d, du[:-1], b,
2801
+ fact=fact, trans=trans, dlf=dlf_, df=df_,
2802
+ duf=duf_, du2=du2f_, ipiv=ipiv_)
2803
+ assert_raises(Exception, gtsvx, dl, d, du, b[:-1],
2804
+ fact=fact, trans=trans, dlf=dlf_, df=df_,
2805
+ duf=duf_, du2=du2f_, ipiv=ipiv_)
2806
+ else:
2807
+ assert_raises(ValueError, gtsvx, dl, d, du, b,
2808
+ fact=fact, trans=trans, dlf=dlf_[:-1], df=df_,
2809
+ duf=duf_, du2=du2f_, ipiv=ipiv_)
2810
+ assert_raises(ValueError, gtsvx, dl, d, du, b,
2811
+ fact=fact, trans=trans, dlf=dlf_, df=df_[:-1],
2812
+ duf=duf_, du2=du2f_, ipiv=ipiv_)
2813
+ assert_raises(ValueError, gtsvx, dl, d, du, b,
2814
+ fact=fact, trans=trans, dlf=dlf_, df=df_,
2815
+ duf=duf_[:-1], du2=du2f_, ipiv=ipiv_)
2816
+ assert_raises(ValueError, gtsvx, dl, d, du, b,
2817
+ fact=fact, trans=trans, dlf=dlf_, df=df_,
2818
+ duf=duf_, du2=du2f_[:-1], ipiv=ipiv_)
2819
+
2820
+
2821
+ @pytest.mark.parametrize("du,d,dl,b,x",
2822
+ [(np.array([2.1, -1.0, 1.9, 8.0]),
2823
+ np.array([3.0, 2.3, -5.0, -0.9, 7.1]),
2824
+ np.array([3.4, 3.6, 7.0, -6.0]),
2825
+ np.array([[2.7, 6.6], [-.5, 10.8], [2.6, -3.2],
2826
+ [.6, -11.2], [2.7, 19.1]]),
2827
+ np.array([[-4, 5], [7, -4], [3, -3], [-4, -2],
2828
+ [-3, 1]])),
2829
+ (np.array([2 - 1j, 2 + 1j, -1 + 1j, 1 - 1j]),
2830
+ np.array([-1.3 + 1.3j, -1.3 + 1.3j, -1.3 + 3.3j,
2831
+ -.3 + 4.3j, -3.3 + 1.3j]),
2832
+ np.array([1 - 2j, 1 + 1j, 2 - 3j, 1 + 1j]),
2833
+ np.array([[2.4 - 5j, 2.7 + 6.9j],
2834
+ [3.4 + 18.2j, -6.9 - 5.3j],
2835
+ [-14.7 + 9.7j, -6 - .6j],
2836
+ [31.9 - 7.7j, -3.9 + 9.3j],
2837
+ [-1 + 1.6j, -3 + 12.2j]]),
2838
+ np.array([[1 + 1j, 2 - 1j], [3 - 1j, 1 + 2j],
2839
+ [4 + 5j, -1 + 1j], [-1 - 2j, 2 + 1j],
2840
+ [1 - 1j, 2 - 2j]]))])
2841
+ def test_gtsvx_NAG(du, d, dl, b, x):
2842
+ # Test to ensure wrapper is consistent with NAG Manual Mark 26
2843
+ # example problems: real (f07cbf) and complex (f07cpf)
2844
+ gtsvx = get_lapack_funcs('gtsvx', dtype=d.dtype)
2845
+
2846
+ gtsvx_out = gtsvx(dl, d, du, b)
2847
+ dlf, df, duf, du2f, ipiv, x_soln, rcond, ferr, berr, info = gtsvx_out
2848
+
2849
+ assert_array_almost_equal(x, x_soln)
2850
+
2851
+
2852
+ @pytest.mark.parametrize("dtype,realtype", zip(DTYPES, REAL_DTYPES
2853
+ + REAL_DTYPES))
2854
+ @pytest.mark.parametrize("fact,df_de_lambda",
2855
+ [("F",
2856
+ lambda d, e: get_lapack_funcs('pttrf',
2857
+ dtype=e.dtype)(d, e)),
2858
+ ("N", lambda d, e: (None, None, None))])
2859
+ def test_ptsvx(dtype, realtype, fact, df_de_lambda):
2860
+ '''
2861
+ This tests the ?ptsvx lapack routine wrapper to solve a random system
2862
+ Ax = b for all dtypes and input variations. Tests for: unmodified
2863
+ input parameters, fact options, incompatible matrix shapes raise an error,
2864
+ and singular matrices return info of illegal value.
2865
+ '''
2866
+ rng = np.random.RandomState(42)
2867
+ # set test tolerance appropriate for dtype
2868
+ atol = 100 * np.finfo(dtype).eps
2869
+ ptsvx = get_lapack_funcs('ptsvx', dtype=dtype)
2870
+ n = 5
2871
+ # create diagonals according to size and dtype
2872
+ d = generate_random_dtype_array((n,), realtype, rng) + 4
2873
+ e = generate_random_dtype_array((n-1,), dtype, rng)
2874
+ A = np.diag(d) + np.diag(e, -1) + np.diag(np.conj(e), 1)
2875
+ x_soln = generate_random_dtype_array((n, 2), dtype=dtype, rng=rng)
2876
+ b = A @ x_soln
2877
+
2878
+ # use lambda to determine what df, ef are
2879
+ df, ef, info = df_de_lambda(d, e)
2880
+
2881
+ # create copy to later test that they are unmodified
2882
+ diag_cpy = [d.copy(), e.copy(), b.copy()]
2883
+
2884
+ # solve using routine
2885
+ df, ef, x, rcond, ferr, berr, info = ptsvx(d, e, b, fact=fact,
2886
+ df=df, ef=ef)
2887
+ # d, e, and b should be unmodified
2888
+ assert_array_equal(d, diag_cpy[0])
2889
+ assert_array_equal(e, diag_cpy[1])
2890
+ assert_array_equal(b, diag_cpy[2])
2891
+ assert_(info == 0, f"info should be 0 but is {info}.")
2892
+ assert_array_almost_equal(x_soln, x)
2893
+
2894
+ # test that the factors from ptsvx can be recombined to make A
2895
+ L = np.diag(ef, -1) + np.diag(np.ones(n))
2896
+ D = np.diag(df)
2897
+ assert_allclose(A, L@D@(np.conj(L).T), atol=atol)
2898
+
2899
+ # assert that the outputs are of correct type or shape
2900
+ # rcond should be a scalar
2901
+ assert not hasattr(rcond, "__len__"), \
2902
+ f"rcond should be scalar but is {rcond}"
2903
+ # ferr should be length of # of cols in x
2904
+ assert_(ferr.shape == (2,), (f"ferr.shape is {ferr.shape} but should be "
2905
+ "({x_soln.shape[1]},)"))
2906
+ # berr should be length of # of cols in x
2907
+ assert_(berr.shape == (2,), (f"berr.shape is {berr.shape} but should be "
2908
+ "({x_soln.shape[1]},)"))
2909
+
2910
+
2911
+ @pytest.mark.parametrize("dtype,realtype", zip(DTYPES, REAL_DTYPES
2912
+ + REAL_DTYPES))
2913
+ @pytest.mark.parametrize("fact,df_de_lambda",
2914
+ [("F",
2915
+ lambda d, e: get_lapack_funcs('pttrf',
2916
+ dtype=e.dtype)(d, e)),
2917
+ ("N", lambda d, e: (None, None, None))])
2918
+ def test_ptsvx_error_raise_errors(dtype, realtype, fact, df_de_lambda):
2919
+ rng = np.random.RandomState(42)
2920
+ ptsvx = get_lapack_funcs('ptsvx', dtype=dtype)
2921
+ n = 5
2922
+ # create diagonals according to size and dtype
2923
+ d = generate_random_dtype_array((n,), realtype, rng) + 4
2924
+ e = generate_random_dtype_array((n-1,), dtype, rng)
2925
+ A = np.diag(d) + np.diag(e, -1) + np.diag(np.conj(e), 1)
2926
+ x_soln = generate_random_dtype_array((n, 2), dtype=dtype, rng=rng)
2927
+ b = A @ x_soln
2928
+
2929
+ # use lambda to determine what df, ef are
2930
+ df, ef, info = df_de_lambda(d, e)
2931
+
2932
+ # test with malformatted array sizes
2933
+ assert_raises(ValueError, ptsvx, d[:-1], e, b, fact=fact, df=df, ef=ef)
2934
+ assert_raises(ValueError, ptsvx, d, e[:-1], b, fact=fact, df=df, ef=ef)
2935
+ assert_raises(Exception, ptsvx, d, e, b[:-1], fact=fact, df=df, ef=ef)
2936
+
2937
+
2938
+ @pytest.mark.parametrize("dtype,realtype", zip(DTYPES, REAL_DTYPES
2939
+ + REAL_DTYPES))
2940
+ @pytest.mark.parametrize("fact,df_de_lambda",
2941
+ [("F",
2942
+ lambda d, e: get_lapack_funcs('pttrf',
2943
+ dtype=e.dtype)(d, e)),
2944
+ ("N", lambda d, e: (None, None, None))])
2945
+ def test_ptsvx_non_SPD_singular(dtype, realtype, fact, df_de_lambda):
2946
+ rng = np.random.RandomState(42)
2947
+ ptsvx = get_lapack_funcs('ptsvx', dtype=dtype)
2948
+ n = 5
2949
+ # create diagonals according to size and dtype
2950
+ d = generate_random_dtype_array((n,), realtype, rng) + 4
2951
+ e = generate_random_dtype_array((n-1,), dtype, rng)
2952
+ A = np.diag(d) + np.diag(e, -1) + np.diag(np.conj(e), 1)
2953
+ x_soln = generate_random_dtype_array((n, 2), dtype=dtype, rng=rng)
2954
+ b = A @ x_soln
2955
+
2956
+ # use lambda to determine what df, ef are
2957
+ df, ef, info = df_de_lambda(d, e)
2958
+
2959
+ if fact == "N":
2960
+ d[3] = 0
2961
+ # obtain new df, ef
2962
+ df, ef, info = df_de_lambda(d, e)
2963
+ # solve using routine
2964
+ df, ef, x, rcond, ferr, berr, info = ptsvx(d, e, b)
2965
+ # test for the singular matrix.
2966
+ assert info > 0 and info <= n
2967
+
2968
+ # non SPD matrix
2969
+ d = generate_random_dtype_array((n,), realtype, rng)
2970
+ df, ef, x, rcond, ferr, berr, info = ptsvx(d, e, b)
2971
+ assert info > 0 and info <= n
2972
+ else:
2973
+ # assuming that someone is using a singular factorization
2974
+ df, ef, info = df_de_lambda(d, e)
2975
+ df[0] = 0
2976
+ ef[0] = 0
2977
+ df, ef, x, rcond, ferr, berr, info = ptsvx(d, e, b, fact=fact,
2978
+ df=df, ef=ef)
2979
+ assert info > 0
2980
+
2981
+
2982
+ @pytest.mark.parametrize('d,e,b,x',
2983
+ [(np.array([4, 10, 29, 25, 5]),
2984
+ np.array([-2, -6, 15, 8]),
2985
+ np.array([[6, 10], [9, 4], [2, 9], [14, 65],
2986
+ [7, 23]]),
2987
+ np.array([[2.5, 2], [2, -1], [1, -3],
2988
+ [-1, 6], [3, -5]])),
2989
+ (np.array([16, 41, 46, 21]),
2990
+ np.array([16 + 16j, 18 - 9j, 1 - 4j]),
2991
+ np.array([[64 + 16j, -16 - 32j],
2992
+ [93 + 62j, 61 - 66j],
2993
+ [78 - 80j, 71 - 74j],
2994
+ [14 - 27j, 35 + 15j]]),
2995
+ np.array([[2 + 1j, -3 - 2j],
2996
+ [1 + 1j, 1 + 1j],
2997
+ [1 - 2j, 1 - 2j],
2998
+ [1 - 1j, 2 + 1j]]))])
2999
+ def test_ptsvx_NAG(d, e, b, x):
3000
+ # test to assure that wrapper is consistent with NAG Manual Mark 26
3001
+ # example problems: f07jbf, f07jpf
3002
+ # (Links expire, so please search for "NAG Library Manual Mark 26" online)
3003
+
3004
+ # obtain routine with correct type based on e.dtype
3005
+ ptsvx = get_lapack_funcs('ptsvx', dtype=e.dtype)
3006
+ # solve using routine
3007
+ df, ef, x_ptsvx, rcond, ferr, berr, info = ptsvx(d, e, b)
3008
+ # determine ptsvx's solution and x are the same.
3009
+ assert_array_almost_equal(x, x_ptsvx)
3010
+
3011
+
3012
+ @pytest.mark.parametrize('lower', [False, True])
3013
+ @pytest.mark.parametrize('dtype', DTYPES)
3014
+ def test_pptrs_pptri_pptrf_ppsv_ppcon(dtype, lower):
3015
+ rng = np.random.RandomState(1234)
3016
+ atol = np.finfo(dtype).eps*100
3017
+ # Manual conversion to/from packed format is feasible here.
3018
+ n, nrhs = 10, 4
3019
+ a = generate_random_dtype_array([n, n], dtype=dtype, rng=rng)
3020
+ b = generate_random_dtype_array([n, nrhs], dtype=dtype, rng=rng)
3021
+
3022
+ a = a.conj().T + a + np.eye(n, dtype=dtype) * dtype(5.)
3023
+ if lower:
3024
+ inds = ([x for y in range(n) for x in range(y, n)],
3025
+ [y for y in range(n) for x in range(y, n)])
3026
+ else:
3027
+ inds = ([x for y in range(1, n+1) for x in range(y)],
3028
+ [y-1 for y in range(1, n+1) for x in range(y)])
3029
+ ap = a[inds]
3030
+ ppsv, pptrf, pptrs, pptri, ppcon = get_lapack_funcs(
3031
+ ('ppsv', 'pptrf', 'pptrs', 'pptri', 'ppcon'),
3032
+ dtype=dtype,
3033
+ ilp64="preferred")
3034
+
3035
+ ul, info = pptrf(n, ap, lower=lower)
3036
+ assert_equal(info, 0)
3037
+ aul = cholesky(a, lower=lower)[inds]
3038
+ assert_allclose(ul, aul, rtol=0, atol=atol)
3039
+
3040
+ uli, info = pptri(n, ul, lower=lower)
3041
+ assert_equal(info, 0)
3042
+ auli = inv(a)[inds]
3043
+ assert_allclose(uli, auli, rtol=0, atol=atol)
3044
+
3045
+ x, info = pptrs(n, ul, b, lower=lower)
3046
+ assert_equal(info, 0)
3047
+ bx = solve(a, b)
3048
+ assert_allclose(x, bx, rtol=0, atol=atol)
3049
+
3050
+ xv, info = ppsv(n, ap, b, lower=lower)
3051
+ assert_equal(info, 0)
3052
+ assert_allclose(xv, bx, rtol=0, atol=atol)
3053
+
3054
+ anorm = np.linalg.norm(a, 1)
3055
+ rcond, info = ppcon(n, ap, anorm=anorm, lower=lower)
3056
+ assert_equal(info, 0)
3057
+ assert_(abs(1/rcond - np.linalg.cond(a, p=1))*rcond < 1)
3058
+
3059
+
3060
+ @pytest.mark.parametrize('dtype', DTYPES)
3061
+ def test_gees_trexc(dtype):
3062
+ rng = np.random.RandomState(1234)
3063
+ atol = np.finfo(dtype).eps*100
3064
+
3065
+ n = 10
3066
+ a = generate_random_dtype_array([n, n], dtype=dtype, rng=rng)
3067
+
3068
+ gees, trexc = get_lapack_funcs(('gees', 'trexc'), dtype=dtype)
3069
+
3070
+ result = gees(lambda x: None, a, overwrite_a=False)
3071
+ assert_equal(result[-1], 0)
3072
+
3073
+ t = result[0]
3074
+ z = result[-3]
3075
+
3076
+ d2 = t[6, 6]
3077
+
3078
+ if dtype in COMPLEX_DTYPES:
3079
+ assert_allclose(t, np.triu(t), rtol=0, atol=atol)
3080
+
3081
+ assert_allclose(z @ t @ z.conj().T, a, rtol=0, atol=atol)
3082
+
3083
+ result = trexc(t, z, 7, 1)
3084
+ assert_equal(result[-1], 0)
3085
+
3086
+ t = result[0]
3087
+ z = result[-2]
3088
+
3089
+ if dtype in COMPLEX_DTYPES:
3090
+ assert_allclose(t, np.triu(t), rtol=0, atol=atol)
3091
+
3092
+ assert_allclose(z @ t @ z.conj().T, a, rtol=0, atol=atol)
3093
+
3094
+ assert_allclose(t[0, 0], d2, rtol=0, atol=atol)
3095
+
3096
+
3097
+ @pytest.mark.parametrize(
3098
+ "t, expect, ifst, ilst",
3099
+ [(np.array([[0.80, -0.11, 0.01, 0.03],
3100
+ [0.00, -0.10, 0.25, 0.35],
3101
+ [0.00, -0.65, -0.10, 0.20],
3102
+ [0.00, 0.00, 0.00, -0.10]]),
3103
+ np.array([[-0.1000, -0.6463, 0.0874, 0.2010],
3104
+ [0.2514, -0.1000, 0.0927, 0.3505],
3105
+ [0.0000, 0.0000, 0.8000, -0.0117],
3106
+ [0.0000, 0.0000, 0.0000, -0.1000]]),
3107
+ 2, 1),
3108
+ (np.array([[-6.00 - 7.00j, 0.36 - 0.36j, -0.19 + 0.48j, 0.88 - 0.25j],
3109
+ [0.00 + 0.00j, -5.00 + 2.00j, -0.03 - 0.72j, -0.23 + 0.13j],
3110
+ [0.00 + 0.00j, 0.00 + 0.00j, 8.00 - 1.00j, 0.94 + 0.53j],
3111
+ [0.00 + 0.00j, 0.00 + 0.00j, 0.00 + 0.00j, 3.00 - 4.00j]]),
3112
+ np.array([[-5.0000 + 2.0000j, -0.1574 + 0.7143j,
3113
+ 0.1781 - 0.1913j, 0.3950 + 0.3861j],
3114
+ [0.0000 + 0.0000j, 8.0000 - 1.0000j,
3115
+ 1.0742 + 0.1447j, 0.2515 - 0.3397j],
3116
+ [0.0000 + 0.0000j, 0.0000 + 0.0000j,
3117
+ 3.0000 - 4.0000j, 0.2264 + 0.8962j],
3118
+ [0.0000 + 0.0000j, 0.0000 + 0.0000j,
3119
+ 0.0000 + 0.0000j, -6.0000 - 7.0000j]]),
3120
+ 1, 4)])
3121
+ def test_trexc_NAG(t, ifst, ilst, expect):
3122
+ """
3123
+ This test implements the example found in the NAG manual,
3124
+ f08qfc, f08qtc, f08qgc, f08quc.
3125
+ """
3126
+ # NAG manual provides accuracy up to 4 decimals
3127
+ atol = 1e-4
3128
+ trexc = get_lapack_funcs('trexc', dtype=t.dtype)
3129
+
3130
+ result = trexc(t, t, ifst, ilst, wantq=0)
3131
+ assert_equal(result[-1], 0)
3132
+
3133
+ t = result[0]
3134
+ assert_allclose(expect, t, atol=atol)
3135
+
3136
+
3137
+ @pytest.mark.parametrize('dtype', DTYPES)
3138
+ def test_gges_tgexc(dtype):
3139
+ rng = np.random.RandomState(1234)
3140
+ atol = np.finfo(dtype).eps*100
3141
+
3142
+ n = 10
3143
+ a = generate_random_dtype_array([n, n], dtype=dtype, rng=rng)
3144
+ b = generate_random_dtype_array([n, n], dtype=dtype, rng=rng)
3145
+
3146
+ gges, tgexc = get_lapack_funcs(('gges', 'tgexc'), dtype=dtype)
3147
+
3148
+ result = gges(lambda x: None, a, b, overwrite_a=False, overwrite_b=False)
3149
+ assert_equal(result[-1], 0)
3150
+
3151
+ s = result[0]
3152
+ t = result[1]
3153
+ q = result[-4]
3154
+ z = result[-3]
3155
+
3156
+ d1 = s[0, 0] / t[0, 0]
3157
+ d2 = s[6, 6] / t[6, 6]
3158
+
3159
+ if dtype in COMPLEX_DTYPES:
3160
+ assert_allclose(s, np.triu(s), rtol=0, atol=atol)
3161
+ assert_allclose(t, np.triu(t), rtol=0, atol=atol)
3162
+
3163
+ assert_allclose(q @ s @ z.conj().T, a, rtol=0, atol=atol)
3164
+ assert_allclose(q @ t @ z.conj().T, b, rtol=0, atol=atol)
3165
+
3166
+ result = tgexc(s, t, q, z, 7, 1)
3167
+ assert_equal(result[-1], 0)
3168
+
3169
+ s = result[0]
3170
+ t = result[1]
3171
+ q = result[2]
3172
+ z = result[3]
3173
+
3174
+ if dtype in COMPLEX_DTYPES:
3175
+ assert_allclose(s, np.triu(s), rtol=0, atol=atol)
3176
+ assert_allclose(t, np.triu(t), rtol=0, atol=atol)
3177
+
3178
+ assert_allclose(q @ s @ z.conj().T, a, rtol=0, atol=atol)
3179
+ assert_allclose(q @ t @ z.conj().T, b, rtol=0, atol=atol)
3180
+
3181
+ assert_allclose(s[0, 0] / t[0, 0], d2, rtol=0, atol=atol)
3182
+ assert_allclose(s[1, 1] / t[1, 1], d1, rtol=0, atol=atol)
3183
+
3184
+
3185
+ @pytest.mark.parametrize('dtype', DTYPES)
3186
+ def test_gees_trsen(dtype):
3187
+ rng = np.random.RandomState(1234)
3188
+ atol = np.finfo(dtype).eps*100
3189
+
3190
+ n = 10
3191
+ a = generate_random_dtype_array([n, n], dtype=dtype, rng=rng)
3192
+
3193
+ gees, trsen, trsen_lwork = get_lapack_funcs(
3194
+ ('gees', 'trsen', 'trsen_lwork'), dtype=dtype)
3195
+
3196
+ result = gees(lambda x: None, a, overwrite_a=False)
3197
+ assert_equal(result[-1], 0)
3198
+
3199
+ t = result[0]
3200
+ z = result[-3]
3201
+
3202
+ d2 = t[6, 6]
3203
+
3204
+ if dtype in COMPLEX_DTYPES:
3205
+ assert_allclose(t, np.triu(t), rtol=0, atol=atol)
3206
+
3207
+ assert_allclose(z @ t @ z.conj().T, a, rtol=0, atol=atol)
3208
+
3209
+ select = np.zeros(n)
3210
+ select[6] = 1
3211
+
3212
+ lwork = _compute_lwork(trsen_lwork, select, t)
3213
+
3214
+ if dtype in COMPLEX_DTYPES:
3215
+ result = trsen(select, t, z, lwork=lwork)
3216
+ else:
3217
+ result = trsen(select, t, z, lwork=lwork, liwork=lwork[1])
3218
+ assert_equal(result[-1], 0)
3219
+
3220
+ t = result[0]
3221
+ z = result[1]
3222
+
3223
+ if dtype in COMPLEX_DTYPES:
3224
+ assert_allclose(t, np.triu(t), rtol=0, atol=atol)
3225
+
3226
+ assert_allclose(z @ t @ z.conj().T, a, rtol=0, atol=atol)
3227
+
3228
+ assert_allclose(t[0, 0], d2, rtol=0, atol=atol)
3229
+
3230
+
3231
+ @pytest.mark.parametrize(
3232
+ "t, q, expect, select, expect_s, expect_sep",
3233
+ [(np.array([[0.7995, -0.1144, 0.0060, 0.0336],
3234
+ [0.0000, -0.0994, 0.2478, 0.3474],
3235
+ [0.0000, -0.6483, -0.0994, 0.2026],
3236
+ [0.0000, 0.0000, 0.0000, -0.1007]]),
3237
+ np.array([[0.6551, 0.1037, 0.3450, 0.6641],
3238
+ [0.5236, -0.5807, -0.6141, -0.1068],
3239
+ [-0.5362, -0.3073, -0.2935, 0.7293],
3240
+ [0.0956, 0.7467, -0.6463, 0.1249]]),
3241
+ np.array([[0.3500, 0.4500, -0.1400, -0.1700],
3242
+ [0.0900, 0.0700, -0.5399, 0.3500],
3243
+ [-0.4400, -0.3300, -0.0300, 0.1700],
3244
+ [0.2500, -0.3200, -0.1300, 0.1100]]),
3245
+ np.array([1, 0, 0, 1]),
3246
+ 1.75e+00, 3.22e+00),
3247
+ (np.array([[-6.0004 - 6.9999j, 0.3637 - 0.3656j,
3248
+ -0.1880 + 0.4787j, 0.8785 - 0.2539j],
3249
+ [0.0000 + 0.0000j, -5.0000 + 2.0060j,
3250
+ -0.0307 - 0.7217j, -0.2290 + 0.1313j],
3251
+ [0.0000 + 0.0000j, 0.0000 + 0.0000j,
3252
+ 7.9982 - 0.9964j, 0.9357 + 0.5359j],
3253
+ [0.0000 + 0.0000j, 0.0000 + 0.0000j,
3254
+ 0.0000 + 0.0000j, 3.0023 - 3.9998j]]),
3255
+ np.array([[-0.8347 - 0.1364j, -0.0628 + 0.3806j,
3256
+ 0.2765 - 0.0846j, 0.0633 - 0.2199j],
3257
+ [0.0664 - 0.2968j, 0.2365 + 0.5240j,
3258
+ -0.5877 - 0.4208j, 0.0835 + 0.2183j],
3259
+ [-0.0362 - 0.3215j, 0.3143 - 0.5473j,
3260
+ 0.0576 - 0.5736j, 0.0057 - 0.4058j],
3261
+ [0.0086 + 0.2958j, -0.3416 - 0.0757j,
3262
+ -0.1900 - 0.1600j, 0.8327 - 0.1868j]]),
3263
+ np.array([[-3.9702 - 5.0406j, -4.1108 + 3.7002j,
3264
+ -0.3403 + 1.0098j, 1.2899 - 0.8590j],
3265
+ [0.3397 - 1.5006j, 1.5201 - 0.4301j,
3266
+ 1.8797 - 5.3804j, 3.3606 + 0.6498j],
3267
+ [3.3101 - 3.8506j, 2.4996 + 3.4504j,
3268
+ 0.8802 - 1.0802j, 0.6401 - 1.4800j],
3269
+ [-1.0999 + 0.8199j, 1.8103 - 1.5905j,
3270
+ 3.2502 + 1.3297j, 1.5701 - 3.4397j]]),
3271
+ np.array([1, 0, 0, 1]),
3272
+ 1.02e+00, 1.82e-01)])
3273
+ def test_trsen_NAG(t, q, select, expect, expect_s, expect_sep):
3274
+ """
3275
+ This test implements the example found in the NAG manual,
3276
+ f08qgc, f08quc.
3277
+ """
3278
+ # NAG manual provides accuracy up to 4 and 2 decimals
3279
+ atol = 1e-4
3280
+ atol2 = 1e-2
3281
+ trsen, trsen_lwork = get_lapack_funcs(
3282
+ ('trsen', 'trsen_lwork'), dtype=t.dtype)
3283
+
3284
+ lwork = _compute_lwork(trsen_lwork, select, t)
3285
+
3286
+ if t.dtype in COMPLEX_DTYPES:
3287
+ result = trsen(select, t, q, lwork=lwork)
3288
+ else:
3289
+ result = trsen(select, t, q, lwork=lwork, liwork=lwork[1])
3290
+ assert_equal(result[-1], 0)
3291
+
3292
+ t = result[0]
3293
+ q = result[1]
3294
+ if t.dtype in COMPLEX_DTYPES:
3295
+ s = result[4]
3296
+ sep = result[5]
3297
+ else:
3298
+ s = result[5]
3299
+ sep = result[6]
3300
+
3301
+ assert_allclose(expect, q @ t @ q.conj().T, atol=atol)
3302
+ assert_allclose(expect_s, 1 / s, atol=atol2)
3303
+ assert_allclose(expect_sep, 1 / sep, atol=atol2)
3304
+
3305
+
3306
+ @pytest.mark.parametrize('dtype', DTYPES)
3307
+ def test_gges_tgsen(dtype):
3308
+ rng = np.random.RandomState(1234)
3309
+ atol = np.finfo(dtype).eps*100
3310
+
3311
+ n = 10
3312
+ a = generate_random_dtype_array([n, n], dtype=dtype, rng=rng)
3313
+ b = generate_random_dtype_array([n, n], dtype=dtype, rng=rng)
3314
+
3315
+ gges, tgsen, tgsen_lwork = get_lapack_funcs(
3316
+ ('gges', 'tgsen', 'tgsen_lwork'), dtype=dtype)
3317
+
3318
+ result = gges(lambda x: None, a, b, overwrite_a=False, overwrite_b=False)
3319
+ assert_equal(result[-1], 0)
3320
+
3321
+ s = result[0]
3322
+ t = result[1]
3323
+ q = result[-4]
3324
+ z = result[-3]
3325
+
3326
+ d1 = s[0, 0] / t[0, 0]
3327
+ d2 = s[6, 6] / t[6, 6]
3328
+
3329
+ if dtype in COMPLEX_DTYPES:
3330
+ assert_allclose(s, np.triu(s), rtol=0, atol=atol)
3331
+ assert_allclose(t, np.triu(t), rtol=0, atol=atol)
3332
+
3333
+ assert_allclose(q @ s @ z.conj().T, a, rtol=0, atol=atol)
3334
+ assert_allclose(q @ t @ z.conj().T, b, rtol=0, atol=atol)
3335
+
3336
+ select = np.zeros(n)
3337
+ select[6] = 1
3338
+
3339
+ lwork = _compute_lwork(tgsen_lwork, select, s, t)
3340
+
3341
+ # off-by-one error in LAPACK, see gh-issue #13397
3342
+ lwork = (lwork[0]+1, lwork[1])
3343
+
3344
+ result = tgsen(select, s, t, q, z, lwork=lwork)
3345
+ assert_equal(result[-1], 0)
3346
+
3347
+ s = result[0]
3348
+ t = result[1]
3349
+ q = result[-7]
3350
+ z = result[-6]
3351
+
3352
+ if dtype in COMPLEX_DTYPES:
3353
+ assert_allclose(s, np.triu(s), rtol=0, atol=atol)
3354
+ assert_allclose(t, np.triu(t), rtol=0, atol=atol)
3355
+
3356
+ assert_allclose(q @ s @ z.conj().T, a, rtol=0, atol=atol)
3357
+ assert_allclose(q @ t @ z.conj().T, b, rtol=0, atol=atol)
3358
+
3359
+ assert_allclose(s[0, 0] / t[0, 0], d2, rtol=0, atol=atol)
3360
+ assert_allclose(s[1, 1] / t[1, 1], d1, rtol=0, atol=atol)
3361
+
3362
+
3363
+ @pytest.mark.parametrize(
3364
+ "a, b, c, d, e, f, rans, lans",
3365
+ [(np.array([[4.0, 1.0, 1.0, 2.0],
3366
+ [0.0, 3.0, 4.0, 1.0],
3367
+ [0.0, 1.0, 3.0, 1.0],
3368
+ [0.0, 0.0, 0.0, 6.0]]),
3369
+ np.array([[1.0, 1.0, 1.0, 1.0],
3370
+ [0.0, 3.0, 4.0, 1.0],
3371
+ [0.0, 1.0, 3.0, 1.0],
3372
+ [0.0, 0.0, 0.0, 4.0]]),
3373
+ np.array([[-4.0, 7.0, 1.0, 12.0],
3374
+ [-9.0, 2.0, -2.0, -2.0],
3375
+ [-4.0, 2.0, -2.0, 8.0],
3376
+ [-7.0, 7.0, -6.0, 19.0]]),
3377
+ np.array([[2.0, 1.0, 1.0, 3.0],
3378
+ [0.0, 1.0, 2.0, 1.0],
3379
+ [0.0, 0.0, 1.0, 1.0],
3380
+ [0.0, 0.0, 0.0, 2.0]]),
3381
+ np.array([[1.0, 1.0, 1.0, 2.0],
3382
+ [0.0, 1.0, 4.0, 1.0],
3383
+ [0.0, 0.0, 1.0, 1.0],
3384
+ [0.0, 0.0, 0.0, 1.0]]),
3385
+ np.array([[-7.0, 5.0, 0.0, 7.0],
3386
+ [-5.0, 1.0, -8.0, 0.0],
3387
+ [-1.0, 2.0, -3.0, 5.0],
3388
+ [-3.0, 2.0, 0.0, 5.0]]),
3389
+ np.array([[1.0, 1.0, 1.0, 1.0],
3390
+ [-1.0, 2.0, -1.0, -1.0],
3391
+ [-1.0, 1.0, 3.0, 1.0],
3392
+ [-1.0, 1.0, -1.0, 4.0]]),
3393
+ np.array([[4.0, -1.0, 1.0, -1.0],
3394
+ [1.0, 3.0, -1.0, 1.0],
3395
+ [-1.0, 1.0, 2.0, -1.0],
3396
+ [1.0, -1.0, 1.0, 1.0]]))])
3397
+ @pytest.mark.parametrize('dtype', REAL_DTYPES)
3398
+ def test_tgsyl_NAG(a, b, c, d, e, f, rans, lans, dtype):
3399
+ atol = 1e-4
3400
+
3401
+ tgsyl = get_lapack_funcs(('tgsyl'), dtype=dtype)
3402
+ rout, lout, scale, dif, info = tgsyl(a, b, c, d, e, f)
3403
+
3404
+ assert_equal(info, 0)
3405
+ assert_allclose(scale, 1.0, rtol=0, atol=np.finfo(dtype).eps*100,
3406
+ err_msg="SCALE must be 1.0")
3407
+ assert_allclose(dif, 0.0, rtol=0, atol=np.finfo(dtype).eps*100,
3408
+ err_msg="DIF must be nearly 0")
3409
+ assert_allclose(rout, rans, atol=atol,
3410
+ err_msg="Solution for R is incorrect")
3411
+ assert_allclose(lout, lans, atol=atol,
3412
+ err_msg="Solution for L is incorrect")
3413
+
3414
+
3415
+ @pytest.mark.parametrize('dtype', REAL_DTYPES)
3416
+ @pytest.mark.parametrize('trans', ('N', 'T'))
3417
+ @pytest.mark.parametrize('ijob', [0, 1, 2, 3, 4])
3418
+ def test_tgsyl(dtype, trans, ijob):
3419
+
3420
+ atol = 1e-3 if dtype == np.float32 else 1e-10
3421
+ rng = np.random.default_rng(1685779866898198)
3422
+ m, n = 10, 15
3423
+
3424
+ a, d, *_ = qz(rng.uniform(-10, 10, [m, m]).astype(dtype),
3425
+ rng.uniform(-10, 10, [m, m]).astype(dtype),
3426
+ output='real')
3427
+
3428
+ b, e, *_ = qz(rng.uniform(-10, 10, [n, n]).astype(dtype),
3429
+ rng.uniform(-10, 10, [n, n]).astype(dtype),
3430
+ output='real')
3431
+
3432
+ c = rng.uniform(-2, 2, [m, n]).astype(dtype)
3433
+ f = rng.uniform(-2, 2, [m, n]).astype(dtype)
3434
+
3435
+ tgsyl = get_lapack_funcs(('tgsyl'), dtype=dtype)
3436
+ rout, lout, scale, dif, info = tgsyl(a, b, c, d, e, f,
3437
+ trans=trans, ijob=ijob)
3438
+
3439
+ assert info == 0, "INFO is non-zero"
3440
+ assert scale >= 0.0, "SCALE must be non-negative"
3441
+ if ijob == 0:
3442
+ assert_allclose(dif, 0.0, rtol=0, atol=np.finfo(dtype).eps*100,
3443
+ err_msg="DIF must be 0 for ijob =0")
3444
+ else:
3445
+ assert dif >= 0.0, "DIF must be non-negative"
3446
+
3447
+ # Only DIF is calculated for ijob = 3/4
3448
+ if ijob <= 2:
3449
+ if trans == 'N':
3450
+ lhs1 = a @ rout - lout @ b
3451
+ rhs1 = scale*c
3452
+ lhs2 = d @ rout - lout @ e
3453
+ rhs2 = scale*f
3454
+ elif trans == 'T':
3455
+ lhs1 = np.transpose(a) @ rout + np.transpose(d) @ lout
3456
+ rhs1 = scale*c
3457
+ lhs2 = rout @ np.transpose(b) + lout @ np.transpose(e)
3458
+ rhs2 = -1.0*scale*f
3459
+
3460
+ assert_allclose(lhs1, rhs1, atol=atol, rtol=0.,
3461
+ err_msg='lhs1 and rhs1 do not match')
3462
+ assert_allclose(lhs2, rhs2, atol=atol, rtol=0.,
3463
+ err_msg='lhs2 and rhs2 do not match')
3464
+
3465
+
3466
+ @pytest.mark.parametrize('mtype', ['sy', 'he']) # matrix type
3467
+ @pytest.mark.parametrize('dtype', DTYPES)
3468
+ @pytest.mark.parametrize('lower', (0, 1))
3469
+ def test_sy_hetrs(mtype, dtype, lower):
3470
+ if mtype == 'he' and dtype in REAL_DTYPES:
3471
+ pytest.skip("hetrs not for real dtypes.")
3472
+ rng = np.random.default_rng(1723059677121834)
3473
+ n, nrhs = 20, 5
3474
+ if dtype in COMPLEX_DTYPES:
3475
+ A = (rng.uniform(size=(n, n)) + rng.uniform(size=(n, n))*1j).astype(dtype)
3476
+ else:
3477
+ A = rng.uniform(size=(n, n)).astype(dtype)
3478
+
3479
+ A = A + A.T if mtype == 'sy' else A + A.conj().T
3480
+ b = rng.uniform(size=(n, nrhs)).astype(dtype)
3481
+ names = f'{mtype}trf', f'{mtype}trf_lwork', f'{mtype}trs'
3482
+ trf, trf_lwork, trs = get_lapack_funcs(names, dtype=dtype)
3483
+ lwork = trf_lwork(n, lower=lower)
3484
+ ldu, ipiv, info = trf(A, lwork=lwork, lower=lower)
3485
+ assert info == 0
3486
+ x, info = trs(a=ldu, ipiv=ipiv, b=b, lower=lower)
3487
+ assert info == 0
3488
+ eps = np.finfo(dtype).eps
3489
+ assert_allclose(A@x, b, atol=100*n*eps)
3490
+
3491
+
3492
+ @pytest.mark.parametrize('mtype', ['sy', 'he']) # matrix type
3493
+ @pytest.mark.parametrize('dtype', DTYPES)
3494
+ @pytest.mark.parametrize('lower', (0, 1))
3495
+ def test_sy_he_tri(dtype, lower, mtype):
3496
+ if mtype == 'he' and dtype in REAL_DTYPES:
3497
+ pytest.skip("hetri not for real dtypes.")
3498
+ rng = np.random.default_rng(1723059677121834)
3499
+ n = 20
3500
+ A = rng.random((n, n)) + rng.random((n, n))*1j
3501
+ if np.issubdtype(dtype, np.floating):
3502
+ A = A.real
3503
+ A = A.astype(dtype)
3504
+ A = A + A.T if mtype == 'sy' else A + A.conj().T
3505
+ names = f'{mtype}trf', f'{mtype}tri'
3506
+ trf, tri = get_lapack_funcs(names, dtype=dtype)
3507
+ ldu, ipiv, info = trf(A, lower=lower)
3508
+ assert info == 0
3509
+ A_inv, info = tri(a=ldu, ipiv=ipiv, lower=lower)
3510
+ assert info == 0
3511
+ eps = np.finfo(dtype).eps
3512
+ ref = np.linalg.inv(A)
3513
+ if lower:
3514
+ assert_allclose(np.tril(A_inv), np.tril(ref), atol=100*n*eps)
3515
+ else:
3516
+ assert_allclose(np.triu(A_inv), np.triu(ref), atol=100*n*eps)
3517
+
3518
+
3519
+ @pytest.mark.parametrize('norm', list('Mm1OoIiFfEe'))
3520
+ @pytest.mark.parametrize('uplo, m, n', [('U', 5, 10), ('U', 10, 10),
3521
+ ('L', 10, 5), ('L', 10, 10)])
3522
+ @pytest.mark.parametrize('diag', ['N', 'U'])
3523
+ @pytest.mark.parametrize('dtype', DTYPES)
3524
+ def test_lantr(norm, uplo, m, n, diag, dtype):
3525
+ rng = np.random.default_rng(98426598246982456)
3526
+ A = rng.random(size=(m, n)).astype(dtype)
3527
+ lantr, lange = get_lapack_funcs(('lantr', 'lange'), (A,))
3528
+ res = lantr(norm, A, uplo=uplo, diag=diag)
3529
+
3530
+ # now modify the matrix according to assumptions made by `lantr`
3531
+ A = np.triu(A) if uplo == 'U' else np.tril(A)
3532
+ if diag == 'U':
3533
+ i = np.arange(min(m, n))
3534
+ A[i, i] = 1
3535
+ ref = lange(norm, A)
3536
+
3537
+ assert_allclose(res, ref, rtol=2e-6)
3538
+
3539
+
3540
+ @pytest.mark.parametrize('dtype', DTYPES)
3541
+ @pytest.mark.parametrize('norm', ['1', 'I', 'O'])
3542
+ def test_gbcon(dtype, norm):
3543
+ rng = np.random.default_rng(17273783424)
3544
+
3545
+ # A is of shape n x n with ku/kl super/sub-diagonals
3546
+ n, ku, kl = 10, 2, 2
3547
+ A = rng.random((n, n)) + rng.random((n, n))*1j
3548
+ # make the condition numbers more interesting
3549
+ offset = rng.permuted(np.logspace(0, rng.integers(0, 10), n))
3550
+ A += offset
3551
+ if np.issubdtype(dtype, np.floating):
3552
+ A = A.real
3553
+ A = A.astype(dtype)
3554
+ A[np.triu_indices(n, ku + 1)] = 0
3555
+ A[np.tril_indices(n, -kl - 1)] = 0
3556
+
3557
+ # construct banded form
3558
+ tmp = _to_banded(kl, ku, A)
3559
+ # add rows required by ?gbtrf
3560
+ LDAB = 2*kl + ku + 1
3561
+ ab = np.zeros((LDAB, n), dtype=dtype)
3562
+ ab[kl:, :] = tmp
3563
+
3564
+ anorm = np.linalg.norm(A, ord=np.inf if norm == 'I' else 1)
3565
+ gbcon, gbtrf = get_lapack_funcs(("gbcon", "gbtrf"), (ab,))
3566
+ lu_band, ipiv, _ = gbtrf(ab, kl, ku)
3567
+ res = gbcon(norm=norm, kl=kl, ku=ku, ab=lu_band, ipiv=ipiv,
3568
+ anorm=anorm)[0]
3569
+
3570
+ gecon, getrf = get_lapack_funcs(('gecon', 'getrf'), (A,))
3571
+ lu = getrf(A)[0]
3572
+ ref = gecon(lu, anorm, norm=norm)[0]
3573
+ # This is an estimate of reciprocal condition number; we just need order of
3574
+ # magnitude.
3575
+ assert_allclose(res, ref, rtol=1)
3576
+
3577
+
3578
+ @pytest.mark.parametrize('norm', list('Mm1OoIiFfEe'))
3579
+ @pytest.mark.parametrize('dtype', DTYPES)
3580
+ def test_langb(dtype, norm):
3581
+ rng = np.random.default_rng(17273783424)
3582
+
3583
+ # A is of shape n x n with ku/kl super/sub-diagonals
3584
+ n, ku, kl = 10, 2, 2
3585
+ A = rng.random((n, n)) + rng.random((n, n))*1j
3586
+ if np.issubdtype(dtype, np.floating):
3587
+ A = A.real
3588
+ A = A.astype(dtype)
3589
+ A[np.triu_indices(n, ku + 1)] = 0
3590
+ A[np.tril_indices(n, -kl - 1)] = 0
3591
+ ab = _to_banded(kl, ku, A)
3592
+
3593
+ langb, lange = get_lapack_funcs(('langb', 'lange'), (A,))
3594
+ ref = lange(norm, A)
3595
+ res = langb(norm, kl, ku, ab)
3596
+ assert_allclose(res, ref, rtol=2e-6)
3597
+
3598
+
3599
+ @pytest.mark.parametrize('dtype', REAL_DTYPES)
3600
+ @pytest.mark.parametrize('compute_v', (0, 1))
3601
+ def test_stevd(dtype, compute_v):
3602
+ rng = np.random.default_rng(266474747488348746)
3603
+ n = 10
3604
+ d = rng.random(n, dtype=dtype)
3605
+ e = rng.random(n - 1, dtype=dtype)
3606
+ A = np.diag(e, -1) + np.diag(d) + np.diag(e, 1)
3607
+ ref = np.linalg.eigvalsh(A)
3608
+
3609
+ stevd = get_lapack_funcs('stevd')
3610
+ U, V, info = stevd(d, e, compute_v=compute_v)
3611
+ assert info == 0
3612
+ assert_allclose(np.sort(U), np.sort(ref))
3613
+ if compute_v:
3614
+ eps = np.finfo(dtype).eps
3615
+ assert_allclose(V @ np.diag(U) @ V.T, A, atol=eps**0.8)
3616
+