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