scipy 1.16.2__cp313-cp313-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.cp313-win_arm64.lib +0 -0
- scipy/_cyutility.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/_lib/_ccallback_c.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/_lib/_fpumode.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/_lib/_test_ccallback.cp313-win_arm64.pyd +0 -0
- scipy/_lib/_test_deprecation_call.cp313-win_arm64.lib +0 -0
- scipy/_lib/_test_deprecation_call.cp313-win_arm64.pyd +0 -0
- scipy/_lib/_test_deprecation_def.cp313-win_arm64.lib +0 -0
- scipy/_lib/_test_deprecation_def.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/_lib/_uarray/_uarray.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/_lib/messagestream.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/cluster/_hierarchy.cp313-win_arm64.pyd +0 -0
- scipy/cluster/_optimal_leaf_ordering.cp313-win_arm64.lib +0 -0
- scipy/cluster/_optimal_leaf_ordering.cp313-win_arm64.pyd +0 -0
- scipy/cluster/_vq.cp313-win_arm64.lib +0 -0
- scipy/cluster/_vq.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/fft/_pocketfft/pypocketfft.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/fftpack/convolve.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/integrate/_dop.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/integrate/_lsoda.cp313-win_arm64.pyd +0 -0
- scipy/integrate/_ode.py +1395 -0
- scipy/integrate/_odepack.cp313-win_arm64.lib +0 -0
- scipy/integrate/_odepack.cp313-win_arm64.pyd +0 -0
- scipy/integrate/_odepack_py.py +273 -0
- scipy/integrate/_quad_vec.py +674 -0
- scipy/integrate/_quadpack.cp313-win_arm64.lib +0 -0
- scipy/integrate/_quadpack.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/integrate/_test_multivariate.cp313-win_arm64.pyd +0 -0
- scipy/integrate/_test_odeint_banded.cp313-win_arm64.lib +0 -0
- scipy/integrate/_test_odeint_banded.cp313-win_arm64.pyd +0 -0
- scipy/integrate/_vode.cp313-win_arm64.lib +0 -0
- scipy/integrate/_vode.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/interpolate/_dfitpack.cp313-win_arm64.pyd +0 -0
- scipy/interpolate/_dierckx.cp313-win_arm64.lib +0 -0
- scipy/interpolate/_dierckx.cp313-win_arm64.pyd +0 -0
- scipy/interpolate/_fitpack.cp313-win_arm64.lib +0 -0
- scipy/interpolate/_fitpack.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/interpolate/_interpnd.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/interpolate/_ppoly.cp313-win_arm64.pyd +0 -0
- scipy/interpolate/_rbf.py +290 -0
- scipy/interpolate/_rbfinterp.py +550 -0
- scipy/interpolate/_rbfinterp_pythran.cp313-win_arm64.lib +0 -0
- scipy/interpolate/_rbfinterp_pythran.cp313-win_arm64.pyd +0 -0
- scipy/interpolate/_rgi.py +764 -0
- scipy/interpolate/_rgi_cython.cp313-win_arm64.lib +0 -0
- scipy/interpolate/_rgi_cython.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/io/_fast_matrix_market/_fmm_core.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/io/_test_fortran.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/io/matlab/_mio5_utils.cp313-win_arm64.pyd +0 -0
- scipy/io/matlab/_mio_utils.cp313-win_arm64.lib +0 -0
- scipy/io/matlab/_mio_utils.cp313-win_arm64.pyd +0 -0
- scipy/io/matlab/_miobase.py +435 -0
- scipy/io/matlab/_streams.cp313-win_arm64.lib +0 -0
- scipy/io/matlab/_streams.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/linalg/_cythonized_array_utils.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/linalg/_decomp_interpolative.cp313-win_arm64.pyd +0 -0
- scipy/linalg/_decomp_ldl.py +356 -0
- scipy/linalg/_decomp_lu.py +401 -0
- scipy/linalg/_decomp_lu_cython.cp313-win_arm64.lib +0 -0
- scipy/linalg/_decomp_lu_cython.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/linalg/_decomp_update.cp313-win_arm64.pyd +0 -0
- scipy/linalg/_expm_frechet.py +417 -0
- scipy/linalg/_fblas.cp313-win_arm64.lib +0 -0
- scipy/linalg/_fblas.cp313-win_arm64.pyd +0 -0
- scipy/linalg/_flapack.cp313-win_arm64.lib +0 -0
- scipy/linalg/_flapack.cp313-win_arm64.pyd +0 -0
- scipy/linalg/_lapack_subroutines.h +1521 -0
- scipy/linalg/_linalg_pythran.cp313-win_arm64.lib +0 -0
- scipy/linalg/_linalg_pythran.cp313-win_arm64.pyd +0 -0
- scipy/linalg/_matfuncs.py +1050 -0
- scipy/linalg/_matfuncs_expm.cp313-win_arm64.lib +0 -0
- scipy/linalg/_matfuncs_expm.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/linalg/_matfuncs_schur_sqrtm.cp313-win_arm64.pyd +0 -0
- scipy/linalg/_matfuncs_sqrtm.py +107 -0
- scipy/linalg/_matfuncs_sqrtm_triu.cp313-win_arm64.lib +0 -0
- scipy/linalg/_matfuncs_sqrtm_triu.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/linalg/_solve_toeplitz.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/linalg/cython_blas.cp313-win_arm64.pyd +0 -0
- scipy/linalg/cython_blas.pxd +169 -0
- scipy/linalg/cython_blas.pyx +1432 -0
- scipy/linalg/cython_lapack.cp313-win_arm64.lib +0 -0
- scipy/linalg/cython_lapack.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/ndimage/_ctest.cp313-win_arm64.pyd +0 -0
- scipy/ndimage/_cytest.cp313-win_arm64.lib +0 -0
- scipy/ndimage/_cytest.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/ndimage/_nd_image.cp313-win_arm64.pyd +0 -0
- scipy/ndimage/_ndimage_api.py +16 -0
- scipy/ndimage/_ni_docstrings.py +214 -0
- scipy/ndimage/_ni_label.cp313-win_arm64.lib +0 -0
- scipy/ndimage/_ni_label.cp313-win_arm64.pyd +0 -0
- scipy/ndimage/_ni_support.py +139 -0
- scipy/ndimage/_rank_filter_1d.cp313-win_arm64.lib +0 -0
- scipy/ndimage/_rank_filter_1d.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/odr/__odrpack.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/optimize/_bglu_dense.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/optimize/_direct.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/optimize/_group_columns.cp313-win_arm64.pyd +0 -0
- scipy/optimize/_hessian_update_strategy.py +479 -0
- scipy/optimize/_highspy/__init__.py +0 -0
- scipy/optimize/_highspy/_core.cp313-win_arm64.lib +0 -0
- scipy/optimize/_highspy/_core.cp313-win_arm64.pyd +0 -0
- scipy/optimize/_highspy/_highs_options.cp313-win_arm64.lib +0 -0
- scipy/optimize/_highspy/_highs_options.cp313-win_arm64.pyd +0 -0
- scipy/optimize/_highspy/_highs_wrapper.py +338 -0
- scipy/optimize/_isotonic.py +157 -0
- scipy/optimize/_lbfgsb.cp313-win_arm64.lib +0 -0
- scipy/optimize/_lbfgsb.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/optimize/_lsap.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/optimize/_lsq/givens_elimination.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/optimize/_minpack.cp313-win_arm64.pyd +0 -0
- scipy/optimize/_minpack_py.py +1178 -0
- scipy/optimize/_moduleTNC.cp313-win_arm64.lib +0 -0
- scipy/optimize/_moduleTNC.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/optimize/_pava_pybind.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/optimize/_slsqplib.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/optimize/_trlib/_trlib.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/optimize/_zeros.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/optimize/cython_optimize/_zeros.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/signal/_max_len_seq_inner.cp313-win_arm64.pyd +0 -0
- scipy/signal/_peak_finding.py +1310 -0
- scipy/signal/_peak_finding_utils.cp313-win_arm64.lib +0 -0
- scipy/signal/_peak_finding_utils.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/signal/_sigtools.cp313-win_arm64.pyd +0 -0
- scipy/signal/_sosfilt.cp313-win_arm64.lib +0 -0
- scipy/signal/_sosfilt.cp313-win_arm64.pyd +0 -0
- scipy/signal/_spectral_py.py +2471 -0
- scipy/signal/_spline.cp313-win_arm64.lib +0 -0
- scipy/signal/_spline.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/signal/_upfirdn_apply.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/sparse/_csparsetools.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/sparse/_sparsetools.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/sparse/csgraph/_flow.cp313-win_arm64.pyd +0 -0
- scipy/sparse/csgraph/_laplacian.py +563 -0
- scipy/sparse/csgraph/_matching.cp313-win_arm64.lib +0 -0
- scipy/sparse/csgraph/_matching.cp313-win_arm64.pyd +0 -0
- scipy/sparse/csgraph/_min_spanning_tree.cp313-win_arm64.lib +0 -0
- scipy/sparse/csgraph/_min_spanning_tree.cp313-win_arm64.pyd +0 -0
- scipy/sparse/csgraph/_reordering.cp313-win_arm64.lib +0 -0
- scipy/sparse/csgraph/_reordering.cp313-win_arm64.pyd +0 -0
- scipy/sparse/csgraph/_shortest_path.cp313-win_arm64.lib +0 -0
- scipy/sparse/csgraph/_shortest_path.cp313-win_arm64.pyd +0 -0
- scipy/sparse/csgraph/_tools.cp313-win_arm64.lib +0 -0
- scipy/sparse/csgraph/_tools.cp313-win_arm64.pyd +0 -0
- scipy/sparse/csgraph/_traversal.cp313-win_arm64.lib +0 -0
- scipy/sparse/csgraph/_traversal.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/sparse/linalg/_dsolve/_superlu.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/sparse/linalg/_eigen/arpack/_arpack.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/sparse/linalg/_propack/_cpropack.cp313-win_arm64.pyd +0 -0
- scipy/sparse/linalg/_propack/_dpropack.cp313-win_arm64.lib +0 -0
- scipy/sparse/linalg/_propack/_dpropack.cp313-win_arm64.pyd +0 -0
- scipy/sparse/linalg/_propack/_spropack.cp313-win_arm64.lib +0 -0
- scipy/sparse/linalg/_propack/_spropack.cp313-win_arm64.pyd +0 -0
- scipy/sparse/linalg/_propack/_zpropack.cp313-win_arm64.lib +0 -0
- scipy/sparse/linalg/_propack/_zpropack.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/spatial/_ckdtree.cp313-win_arm64.pyd +0 -0
- scipy/spatial/_distance_pybind.cp313-win_arm64.lib +0 -0
- scipy/spatial/_distance_pybind.cp313-win_arm64.pyd +0 -0
- scipy/spatial/_distance_wrap.cp313-win_arm64.lib +0 -0
- scipy/spatial/_distance_wrap.cp313-win_arm64.pyd +0 -0
- scipy/spatial/_geometric_slerp.py +238 -0
- scipy/spatial/_hausdorff.cp313-win_arm64.lib +0 -0
- scipy/spatial/_hausdorff.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/spatial/_qhull.cp313-win_arm64.pyd +0 -0
- scipy/spatial/_qhull.pyi +213 -0
- scipy/spatial/_spherical_voronoi.py +341 -0
- scipy/spatial/_voronoi.cp313-win_arm64.lib +0 -0
- scipy/spatial/_voronoi.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/spatial/transform/_rigid_transform.cp313-win_arm64.pyd +0 -0
- scipy/spatial/transform/_rotation.cp313-win_arm64.lib +0 -0
- scipy/spatial/transform/_rotation.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/special/_comb.cp313-win_arm64.pyd +0 -0
- scipy/special/_ellip_harm.py +214 -0
- scipy/special/_ellip_harm_2.cp313-win_arm64.lib +0 -0
- scipy/special/_ellip_harm_2.cp313-win_arm64.pyd +0 -0
- scipy/special/_gufuncs.cp313-win_arm64.lib +0 -0
- scipy/special/_gufuncs.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/special/_specfun.cp313-win_arm64.pyd +0 -0
- scipy/special/_special_ufuncs.cp313-win_arm64.lib +0 -0
- scipy/special/_special_ufuncs.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/special/_test_internal.cp313-win_arm64.pyd +0 -0
- scipy/special/_test_internal.pyi +9 -0
- scipy/special/_testutils.py +321 -0
- scipy/special/_ufuncs.cp313-win_arm64.lib +0 -0
- scipy/special/_ufuncs.cp313-win_arm64.pyd +0 -0
- scipy/special/_ufuncs.pyi +522 -0
- scipy/special/_ufuncs.pyx +13173 -0
- scipy/special/_ufuncs_cxx.cp313-win_arm64.lib +0 -0
- scipy/special/_ufuncs_cxx.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/special/cython_special.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/stats/_ansari_swilk_statistics.cp313-win_arm64.pyd +0 -0
- scipy/stats/_axis_nan_policy.py +692 -0
- scipy/stats/_biasedurn.cp313-win_arm64.lib +0 -0
- scipy/stats/_biasedurn.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/stats/_levy_stable/levyst.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/stats/_qmc_cy.cp313-win_arm64.pyd +0 -0
- scipy/stats/_qmc_cy.pyi +54 -0
- scipy/stats/_qmvnt.py +454 -0
- scipy/stats/_qmvnt_cy.cp313-win_arm64.lib +0 -0
- scipy/stats/_qmvnt_cy.cp313-win_arm64.pyd +0 -0
- scipy/stats/_quantile.py +335 -0
- scipy/stats/_rcont/__init__.py +4 -0
- scipy/stats/_rcont/rcont.cp313-win_arm64.lib +0 -0
- scipy/stats/_rcont/rcont.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/stats/_sobol.cp313-win_arm64.pyd +0 -0
- scipy/stats/_sobol.pyi +54 -0
- scipy/stats/_sobol_direction_numbers.npz +0 -0
- scipy/stats/_stats.cp313-win_arm64.lib +0 -0
- scipy/stats/_stats.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/stats/_stats_pythran.cp313-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.cp313-win_arm64.lib +0 -0
- scipy/stats/_unuran/unuran_wrapper.cp313-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,3189 @@
|
|
1
|
+
import itertools
|
2
|
+
import platform
|
3
|
+
import sys
|
4
|
+
|
5
|
+
import numpy as np
|
6
|
+
from numpy.testing import (assert_equal, assert_almost_equal,
|
7
|
+
assert_array_almost_equal, assert_array_equal,
|
8
|
+
assert_, assert_allclose)
|
9
|
+
|
10
|
+
import pytest
|
11
|
+
from pytest import raises as assert_raises
|
12
|
+
|
13
|
+
from scipy.linalg import (eig, eigvals, lu, svd, svdvals, cholesky, qr,
|
14
|
+
schur, rsf2csf, lu_solve, lu_factor, solve, diagsvd,
|
15
|
+
hessenberg, rq, eig_banded, eigvals_banded, eigh,
|
16
|
+
eigvalsh, qr_multiply, qz, orth, ordqz,
|
17
|
+
subspace_angles, hadamard, eigvalsh_tridiagonal,
|
18
|
+
eigh_tridiagonal, null_space, cdf2rdf, LinAlgError)
|
19
|
+
|
20
|
+
from scipy.linalg.lapack import (dgbtrf, dgbtrs, zgbtrf, zgbtrs, dsbev,
|
21
|
+
dsbevd, dsbevx, zhbevd, zhbevx)
|
22
|
+
|
23
|
+
from scipy.linalg._misc import norm
|
24
|
+
from scipy.linalg._decomp_qz import _select_function
|
25
|
+
from scipy.stats import ortho_group
|
26
|
+
|
27
|
+
from numpy import (array, diag, full, linalg, argsort, zeros, arange,
|
28
|
+
float32, complex64, ravel, sqrt, iscomplex, shape, sort,
|
29
|
+
sign, asarray, isfinite, ndarray, eye,)
|
30
|
+
|
31
|
+
from scipy.linalg._testutils import assert_no_overwrite
|
32
|
+
from scipy.sparse._sputils import matrix
|
33
|
+
|
34
|
+
from scipy._lib._testutils import check_free_memory
|
35
|
+
from scipy.linalg.blas import HAS_ILP64
|
36
|
+
try:
|
37
|
+
from scipy.__config__ import CONFIG
|
38
|
+
except ImportError:
|
39
|
+
CONFIG = None
|
40
|
+
|
41
|
+
IS_WASM = (sys.platform == "emscripten" or platform.machine() in ["wasm32", "wasm64"])
|
42
|
+
|
43
|
+
|
44
|
+
def _random_hermitian_matrix(n, posdef=False, dtype=float):
|
45
|
+
"Generate random sym/hermitian array of the given size n"
|
46
|
+
if dtype in COMPLEX_DTYPES:
|
47
|
+
A = np.random.rand(n, n) + np.random.rand(n, n)*1.0j
|
48
|
+
A = (A + A.conj().T)/2
|
49
|
+
else:
|
50
|
+
A = np.random.rand(n, n)
|
51
|
+
A = (A + A.T)/2
|
52
|
+
|
53
|
+
if posdef:
|
54
|
+
A += sqrt(2*n)*np.eye(n)
|
55
|
+
|
56
|
+
return A.astype(dtype)
|
57
|
+
|
58
|
+
|
59
|
+
REAL_DTYPES = [np.float32, np.float64]
|
60
|
+
COMPLEX_DTYPES = [np.complex64, np.complex128]
|
61
|
+
DTYPES = REAL_DTYPES + COMPLEX_DTYPES
|
62
|
+
|
63
|
+
|
64
|
+
# XXX: This function should not be defined here, but somewhere in
|
65
|
+
# scipy.linalg namespace
|
66
|
+
def symrand(dim_or_eigv, rng):
|
67
|
+
"""Return a random symmetric (Hermitian) matrix.
|
68
|
+
|
69
|
+
If 'dim_or_eigv' is an integer N, return a NxN matrix, with eigenvalues
|
70
|
+
uniformly distributed on (-1,1).
|
71
|
+
|
72
|
+
If 'dim_or_eigv' is 1-D real array 'a', return a matrix whose
|
73
|
+
eigenvalues are 'a'.
|
74
|
+
"""
|
75
|
+
if isinstance(dim_or_eigv, int):
|
76
|
+
dim = dim_or_eigv
|
77
|
+
d = rng.random(dim)*2 - 1
|
78
|
+
elif (isinstance(dim_or_eigv, ndarray) and
|
79
|
+
len(dim_or_eigv.shape) == 1):
|
80
|
+
dim = dim_or_eigv.shape[0]
|
81
|
+
d = dim_or_eigv
|
82
|
+
else:
|
83
|
+
raise TypeError("input type not supported.")
|
84
|
+
|
85
|
+
v = ortho_group.rvs(dim)
|
86
|
+
h = v.T.conj() @ diag(d) @ v
|
87
|
+
# to avoid roundoff errors, symmetrize the matrix (again)
|
88
|
+
h = 0.5*(h.T+h)
|
89
|
+
return h
|
90
|
+
|
91
|
+
|
92
|
+
class TestEigVals:
|
93
|
+
|
94
|
+
def test_simple(self):
|
95
|
+
a = [[1, 2, 3], [1, 2, 3], [2, 5, 6]]
|
96
|
+
w = eigvals(a)
|
97
|
+
exact_w = [(9+sqrt(93))/2, 0, (9-sqrt(93))/2]
|
98
|
+
assert_array_almost_equal(w, exact_w)
|
99
|
+
|
100
|
+
def test_simple_tr(self):
|
101
|
+
a = array([[1, 2, 3], [1, 2, 3], [2, 5, 6]], 'd').T
|
102
|
+
a = a.copy()
|
103
|
+
a = a.T
|
104
|
+
w = eigvals(a)
|
105
|
+
exact_w = [(9+sqrt(93))/2, 0, (9-sqrt(93))/2]
|
106
|
+
assert_array_almost_equal(w, exact_w)
|
107
|
+
|
108
|
+
def test_simple_complex(self):
|
109
|
+
a = [[1, 2, 3], [1, 2, 3], [2, 5, 6+1j]]
|
110
|
+
w = eigvals(a)
|
111
|
+
exact_w = [(9+1j+sqrt(92+6j))/2,
|
112
|
+
0,
|
113
|
+
(9+1j-sqrt(92+6j))/2]
|
114
|
+
assert_array_almost_equal(w, exact_w)
|
115
|
+
|
116
|
+
def test_finite(self):
|
117
|
+
a = [[1, 2, 3], [1, 2, 3], [2, 5, 6]]
|
118
|
+
w = eigvals(a, check_finite=False)
|
119
|
+
exact_w = [(9+sqrt(93))/2, 0, (9-sqrt(93))/2]
|
120
|
+
assert_array_almost_equal(w, exact_w)
|
121
|
+
|
122
|
+
@pytest.mark.parametrize('dt', [int, float, float32, complex, complex64])
|
123
|
+
def test_empty(self, dt):
|
124
|
+
a = np.empty((0, 0), dtype=dt)
|
125
|
+
w = eigvals(a)
|
126
|
+
assert w.shape == (0,)
|
127
|
+
assert w.dtype == eigvals(np.eye(2, dtype=dt)).dtype
|
128
|
+
|
129
|
+
w = eigvals(a, homogeneous_eigvals=True)
|
130
|
+
assert w.shape == (2, 0)
|
131
|
+
assert w.dtype == eigvals(np.eye(2, dtype=dt)).dtype
|
132
|
+
|
133
|
+
|
134
|
+
class TestEig:
|
135
|
+
|
136
|
+
def test_simple(self):
|
137
|
+
a = array([[1, 2, 3], [1, 2, 3], [2, 5, 6]])
|
138
|
+
w, v = eig(a)
|
139
|
+
exact_w = [(9+sqrt(93))/2, 0, (9-sqrt(93))/2]
|
140
|
+
v0 = array([1, 1, (1+sqrt(93)/3)/2])
|
141
|
+
v1 = array([3., 0, -1])
|
142
|
+
v2 = array([1, 1, (1-sqrt(93)/3)/2])
|
143
|
+
v0 = v0 / norm(v0)
|
144
|
+
v1 = v1 / norm(v1)
|
145
|
+
v2 = v2 / norm(v2)
|
146
|
+
assert_array_almost_equal(w, exact_w)
|
147
|
+
assert_array_almost_equal(v0, v[:, 0]*sign(v[0, 0]))
|
148
|
+
assert_array_almost_equal(v1, v[:, 1]*sign(v[0, 1]))
|
149
|
+
assert_array_almost_equal(v2, v[:, 2]*sign(v[0, 2]))
|
150
|
+
for i in range(3):
|
151
|
+
assert_array_almost_equal(a @ v[:, i], w[i]*v[:, i])
|
152
|
+
w, v = eig(a, left=1, right=0)
|
153
|
+
for i in range(3):
|
154
|
+
assert_array_almost_equal(a.T @ v[:, i], w[i]*v[:, i])
|
155
|
+
|
156
|
+
def test_simple_complex_eig(self):
|
157
|
+
a = array([[1, 2], [-2, 1]])
|
158
|
+
w, vl, vr = eig(a, left=1, right=1)
|
159
|
+
assert_array_almost_equal(w, array([1+2j, 1-2j]))
|
160
|
+
for i in range(2):
|
161
|
+
assert_array_almost_equal(a @ vr[:, i], w[i]*vr[:, i])
|
162
|
+
for i in range(2):
|
163
|
+
assert_array_almost_equal(a.conj().T @ vl[:, i],
|
164
|
+
w[i].conj()*vl[:, i])
|
165
|
+
|
166
|
+
def test_simple_complex(self):
|
167
|
+
a = array([[1, 2, 3], [1, 2, 3], [2, 5, 6+1j]])
|
168
|
+
w, vl, vr = eig(a, left=1, right=1)
|
169
|
+
for i in range(3):
|
170
|
+
assert_array_almost_equal(a @ vr[:, i], w[i]*vr[:, i])
|
171
|
+
for i in range(3):
|
172
|
+
assert_array_almost_equal(a.conj().T @ vl[:, i],
|
173
|
+
w[i].conj()*vl[:, i])
|
174
|
+
|
175
|
+
def test_gh_3054(self):
|
176
|
+
a = [[1]]
|
177
|
+
b = [[0]]
|
178
|
+
w, vr = eig(a, b, homogeneous_eigvals=True)
|
179
|
+
assert_allclose(w[1, 0], 0)
|
180
|
+
assert_(w[0, 0] != 0)
|
181
|
+
assert_allclose(vr, 1)
|
182
|
+
|
183
|
+
w, vr = eig(a, b)
|
184
|
+
assert_equal(w, np.inf)
|
185
|
+
assert_allclose(vr, 1)
|
186
|
+
|
187
|
+
def _check_gen_eig(self, A, B, atol_homog=1e-13, rtol_homog=1e-13,
|
188
|
+
atol=1e-13, rtol=1e-13):
|
189
|
+
if B is not None:
|
190
|
+
A, B = asarray(A), asarray(B)
|
191
|
+
B0 = B
|
192
|
+
else:
|
193
|
+
A = asarray(A)
|
194
|
+
B0 = B
|
195
|
+
B = np.eye(*A.shape)
|
196
|
+
msg = f"\n{A!r}\n{B!r}"
|
197
|
+
|
198
|
+
# Eigenvalues in homogeneous coordinates
|
199
|
+
w, vr = eig(A, B0, homogeneous_eigvals=True)
|
200
|
+
wt = eigvals(A, B0, homogeneous_eigvals=True)
|
201
|
+
val1 = A @ vr * w[1, :]
|
202
|
+
val2 = B @ vr * w[0, :]
|
203
|
+
for i in range(val1.shape[1]):
|
204
|
+
assert_allclose(val1[:, i], val2[:, i],
|
205
|
+
rtol=rtol_homog, atol=atol_homog, err_msg=msg)
|
206
|
+
|
207
|
+
if B0 is None:
|
208
|
+
assert_allclose(w[1, :], 1)
|
209
|
+
assert_allclose(wt[1, :], 1)
|
210
|
+
|
211
|
+
perm = np.lexsort(w)
|
212
|
+
permt = np.lexsort(wt)
|
213
|
+
assert_allclose(w[:, perm], wt[:, permt], atol=1e-7, rtol=1e-7,
|
214
|
+
err_msg=msg)
|
215
|
+
|
216
|
+
length = np.empty(len(vr))
|
217
|
+
|
218
|
+
for i in range(len(vr)):
|
219
|
+
length[i] = norm(vr[:, i])
|
220
|
+
|
221
|
+
assert_allclose(length, np.ones(length.size), err_msg=msg,
|
222
|
+
atol=1e-7, rtol=1e-7)
|
223
|
+
|
224
|
+
# Convert homogeneous coordinates
|
225
|
+
beta_nonzero = (w[1, :] != 0)
|
226
|
+
wh = w[0, beta_nonzero] / w[1, beta_nonzero]
|
227
|
+
|
228
|
+
# Eigenvalues in standard coordinates
|
229
|
+
w, vr = eig(A, B0)
|
230
|
+
wt = eigvals(A, B0)
|
231
|
+
val1 = A @ vr
|
232
|
+
val2 = B @ vr * w
|
233
|
+
res = val1 - val2
|
234
|
+
for i in range(res.shape[1]):
|
235
|
+
if np.all(isfinite(res[:, i])):
|
236
|
+
assert_allclose(res[:, i], 0,
|
237
|
+
rtol=rtol, atol=atol, err_msg=msg)
|
238
|
+
|
239
|
+
# try to consistently order eigenvalues, including complex conjugate pairs
|
240
|
+
w_fin = w[isfinite(w)]
|
241
|
+
wt_fin = wt[isfinite(wt)]
|
242
|
+
|
243
|
+
# prune noise in the real parts
|
244
|
+
w_fin = -1j * np.real_if_close(1j*w_fin, tol=1e-10)
|
245
|
+
wt_fin = -1j * np.real_if_close(1j*wt_fin, tol=1e-10)
|
246
|
+
|
247
|
+
perm = argsort(abs(w_fin) + w_fin.imag)
|
248
|
+
permt = argsort(abs(wt_fin) + wt_fin.imag)
|
249
|
+
|
250
|
+
assert_allclose(w_fin[perm], wt_fin[permt],
|
251
|
+
atol=1e-7, rtol=1e-7, err_msg=msg)
|
252
|
+
|
253
|
+
length = np.empty(len(vr))
|
254
|
+
for i in range(len(vr)):
|
255
|
+
length[i] = norm(vr[:, i])
|
256
|
+
assert_allclose(length, np.ones(length.size), err_msg=msg)
|
257
|
+
|
258
|
+
# Compare homogeneous and nonhomogeneous versions
|
259
|
+
assert_allclose(sort(wh), sort(w[np.isfinite(w)]))
|
260
|
+
|
261
|
+
def test_singular(self):
|
262
|
+
# Example taken from
|
263
|
+
# https://web.archive.org/web/20040903121217/http://www.cs.umu.se/research/nla/singular_pairs/guptri/matlab.html
|
264
|
+
A = array([[22, 34, 31, 31, 17],
|
265
|
+
[45, 45, 42, 19, 29],
|
266
|
+
[39, 47, 49, 26, 34],
|
267
|
+
[27, 31, 26, 21, 15],
|
268
|
+
[38, 44, 44, 24, 30]])
|
269
|
+
B = array([[13, 26, 25, 17, 24],
|
270
|
+
[31, 46, 40, 26, 37],
|
271
|
+
[26, 40, 19, 25, 25],
|
272
|
+
[16, 25, 27, 14, 23],
|
273
|
+
[24, 35, 18, 21, 22]])
|
274
|
+
|
275
|
+
with np.errstate(all='ignore'):
|
276
|
+
self._check_gen_eig(A, B, atol_homog=5e-13, atol=5e-13)
|
277
|
+
|
278
|
+
def test_falker(self):
|
279
|
+
# Test matrices giving some Nan generalized eigenvalues.
|
280
|
+
M = diag(array([1, 0, 3]))
|
281
|
+
K = array(([2, -1, -1], [-1, 2, -1], [-1, -1, 2]))
|
282
|
+
D = array(([1, -1, 0], [-1, 1, 0], [0, 0, 0]))
|
283
|
+
Z = zeros((3, 3))
|
284
|
+
I3 = eye(3)
|
285
|
+
A = np.block([[I3, Z], [Z, -K]])
|
286
|
+
B = np.block([[Z, I3], [M, D]])
|
287
|
+
|
288
|
+
with np.errstate(all='ignore'):
|
289
|
+
self._check_gen_eig(A, B)
|
290
|
+
|
291
|
+
def test_bad_geneig(self):
|
292
|
+
# Ticket #709 (strange return values from DGGEV)
|
293
|
+
|
294
|
+
def matrices(omega):
|
295
|
+
c1 = -9 + omega**2
|
296
|
+
c2 = 2*omega
|
297
|
+
A = [[1, 0, 0, 0],
|
298
|
+
[0, 1, 0, 0],
|
299
|
+
[0, 0, c1, 0],
|
300
|
+
[0, 0, 0, c1]]
|
301
|
+
B = [[0, 0, 1, 0],
|
302
|
+
[0, 0, 0, 1],
|
303
|
+
[1, 0, 0, -c2],
|
304
|
+
[0, 1, c2, 0]]
|
305
|
+
return A, B
|
306
|
+
|
307
|
+
# With a buggy LAPACK, this can fail for different omega on different
|
308
|
+
# machines -- so we need to test several values
|
309
|
+
with np.errstate(all='ignore'):
|
310
|
+
for k in range(100):
|
311
|
+
A, B = matrices(omega=k*5./100)
|
312
|
+
self._check_gen_eig(A, B)
|
313
|
+
|
314
|
+
def test_make_eigvals(self):
|
315
|
+
# Step through all paths in _make_eigvals
|
316
|
+
# Real eigenvalues
|
317
|
+
rng = np.random.RandomState(1234)
|
318
|
+
A = symrand(3, rng)
|
319
|
+
self._check_gen_eig(A, None)
|
320
|
+
B = symrand(3, rng)
|
321
|
+
self._check_gen_eig(A, B)
|
322
|
+
# Complex eigenvalues
|
323
|
+
A = rng.random((3, 3)) + 1j*rng.random((3, 3))
|
324
|
+
self._check_gen_eig(A, None)
|
325
|
+
B = rng.random((3, 3)) + 1j*rng.random((3, 3))
|
326
|
+
self._check_gen_eig(A, B)
|
327
|
+
|
328
|
+
def test_check_finite(self):
|
329
|
+
a = [[1, 2, 3], [1, 2, 3], [2, 5, 6]]
|
330
|
+
w, v = eig(a, check_finite=False)
|
331
|
+
exact_w = [(9+sqrt(93))/2, 0, (9-sqrt(93))/2]
|
332
|
+
v0 = array([1, 1, (1+sqrt(93)/3)/2])
|
333
|
+
v1 = array([3., 0, -1])
|
334
|
+
v2 = array([1, 1, (1-sqrt(93)/3)/2])
|
335
|
+
v0 = v0 / norm(v0)
|
336
|
+
v1 = v1 / norm(v1)
|
337
|
+
v2 = v2 / norm(v2)
|
338
|
+
assert_array_almost_equal(w, exact_w)
|
339
|
+
assert_array_almost_equal(v0, v[:, 0]*sign(v[0, 0]))
|
340
|
+
assert_array_almost_equal(v1, v[:, 1]*sign(v[0, 1]))
|
341
|
+
assert_array_almost_equal(v2, v[:, 2]*sign(v[0, 2]))
|
342
|
+
for i in range(3):
|
343
|
+
assert_array_almost_equal(a @ v[:, i], w[i]*v[:, i])
|
344
|
+
|
345
|
+
def test_not_square_error(self):
|
346
|
+
"""Check that passing a non-square array raises a ValueError."""
|
347
|
+
A = np.arange(6).reshape(3, 2)
|
348
|
+
assert_raises(ValueError, eig, A)
|
349
|
+
|
350
|
+
def test_shape_mismatch(self):
|
351
|
+
"""Check that passing arrays of with different shapes
|
352
|
+
raises a ValueError."""
|
353
|
+
A = eye(2)
|
354
|
+
B = np.arange(9.0).reshape(3, 3)
|
355
|
+
assert_raises(ValueError, eig, A, B)
|
356
|
+
assert_raises(ValueError, eig, B, A)
|
357
|
+
|
358
|
+
def test_gh_11577(self):
|
359
|
+
# https://github.com/scipy/scipy/issues/11577
|
360
|
+
# `A - lambda B` should have 4 and 8 among the eigenvalues, and this
|
361
|
+
# was apparently broken on some platforms
|
362
|
+
A = np.array([[12.0, 28.0, 76.0, 220.0],
|
363
|
+
[16.0, 32.0, 80.0, 224.0],
|
364
|
+
[24.0, 40.0, 88.0, 232.0],
|
365
|
+
[40.0, 56.0, 104.0, 248.0]], dtype='float64')
|
366
|
+
B = np.array([[2.0, 4.0, 10.0, 28.0],
|
367
|
+
[3.0, 5.0, 11.0, 29.0],
|
368
|
+
[5.0, 7.0, 13.0, 31.0],
|
369
|
+
[9.0, 11.0, 17.0, 35.0]], dtype='float64')
|
370
|
+
|
371
|
+
D, V = eig(A, B)
|
372
|
+
|
373
|
+
# The problem is ill-conditioned, and two other eigenvalues
|
374
|
+
# depend on ATLAS/OpenBLAS version, compiler version etc
|
375
|
+
# see gh-11577 for discussion
|
376
|
+
#
|
377
|
+
# NB: it is tempting to use `assert_allclose(D[:2], [4, 8])` instead but
|
378
|
+
# the ordering of eigenvalues also comes out different on different
|
379
|
+
# systems depending on who knows what.
|
380
|
+
with np.testing.suppress_warnings() as sup:
|
381
|
+
# isclose chokes on inf/nan values
|
382
|
+
sup.filter(RuntimeWarning, "invalid value encountered in multiply")
|
383
|
+
assert np.isclose(D, 4.0, atol=1e-14).any()
|
384
|
+
assert np.isclose(D, 8.0, atol=1e-14).any()
|
385
|
+
|
386
|
+
@pytest.mark.parametrize('dt', [int, float, np.float32, complex, np.complex64])
|
387
|
+
def test_empty(self, dt):
|
388
|
+
a = np.empty((0, 0), dtype=dt)
|
389
|
+
w, vr = eig(a)
|
390
|
+
|
391
|
+
w_n, vr_n = eig(np.eye(2, dtype=dt))
|
392
|
+
|
393
|
+
assert w.shape == (0,)
|
394
|
+
assert w.dtype == w_n.dtype #eigvals(np.eye(2, dtype=dt)).dtype
|
395
|
+
|
396
|
+
assert_allclose(vr, np.empty((0, 0)))
|
397
|
+
assert vr.shape == (0, 0)
|
398
|
+
assert vr.dtype == vr_n.dtype
|
399
|
+
|
400
|
+
w, vr = eig(a, homogeneous_eigvals=True)
|
401
|
+
assert w.shape == (2, 0)
|
402
|
+
assert w.dtype == w_n.dtype
|
403
|
+
|
404
|
+
assert vr.shape == (0, 0)
|
405
|
+
assert vr.dtype == vr_n.dtype
|
406
|
+
|
407
|
+
@pytest.mark.parametrize("include_B", [False, True])
|
408
|
+
@pytest.mark.parametrize("left", [False, True])
|
409
|
+
@pytest.mark.parametrize("right", [False, True])
|
410
|
+
@pytest.mark.parametrize("homogeneous_eigvals", [False, True])
|
411
|
+
@pytest.mark.parametrize("dtype", [np.float32, np.complex128])
|
412
|
+
def test_nd_input(self, include_B, left, right, homogeneous_eigvals, dtype):
|
413
|
+
batch_shape = (3, 2)
|
414
|
+
core_shape = (4, 4)
|
415
|
+
rng = np.random.default_rng(3249823598235)
|
416
|
+
A = rng.random(batch_shape + core_shape).astype(dtype)
|
417
|
+
B = rng.random(batch_shape + core_shape).astype(dtype)
|
418
|
+
kwargs = dict(right=right, homogeneous_eigvals=homogeneous_eigvals)
|
419
|
+
|
420
|
+
if include_B:
|
421
|
+
res = eig(A, b=B, left=left, **kwargs)
|
422
|
+
else:
|
423
|
+
res = eig(A, left=left, **kwargs)
|
424
|
+
|
425
|
+
for i in range(batch_shape[0]):
|
426
|
+
for j in range(batch_shape[1]):
|
427
|
+
if include_B:
|
428
|
+
ref = eig(A[i, j], b=B[i, j], left=left, **kwargs)
|
429
|
+
else:
|
430
|
+
ref = eig(A[i, j], left=left, **kwargs)
|
431
|
+
|
432
|
+
if left or right:
|
433
|
+
for k in range(len(ref)):
|
434
|
+
assert_allclose(res[k][i, j], ref[k])
|
435
|
+
else:
|
436
|
+
assert_allclose(res[i, j], ref)
|
437
|
+
|
438
|
+
|
439
|
+
class TestEigBanded:
|
440
|
+
def setup_method(self):
|
441
|
+
self.create_bandmat()
|
442
|
+
|
443
|
+
def create_bandmat(self):
|
444
|
+
"""Create the full matrix `self.fullmat` and
|
445
|
+
the corresponding band matrix `self.bandmat`."""
|
446
|
+
N = 10
|
447
|
+
self.KL = 2 # number of subdiagonals (below the diagonal)
|
448
|
+
self.KU = 2 # number of superdiagonals (above the diagonal)
|
449
|
+
|
450
|
+
# symmetric band matrix
|
451
|
+
self.sym_mat = (diag(full(N, 1.0))
|
452
|
+
+ diag(full(N-1, -1.0), -1) + diag(full(N-1, -1.0), 1)
|
453
|
+
+ diag(full(N-2, -2.0), -2) + diag(full(N-2, -2.0), 2))
|
454
|
+
|
455
|
+
# hermitian band matrix
|
456
|
+
self.herm_mat = (diag(full(N, -1.0))
|
457
|
+
+ 1j*diag(full(N-1, 1.0), -1)
|
458
|
+
- 1j*diag(full(N-1, 1.0), 1)
|
459
|
+
+ diag(full(N-2, -2.0), -2)
|
460
|
+
+ diag(full(N-2, -2.0), 2))
|
461
|
+
|
462
|
+
# general real band matrix
|
463
|
+
self.real_mat = (diag(full(N, 1.0))
|
464
|
+
+ diag(full(N-1, -1.0), -1) + diag(full(N-1, -3.0), 1)
|
465
|
+
+ diag(full(N-2, 2.0), -2) + diag(full(N-2, -2.0), 2))
|
466
|
+
|
467
|
+
# general complex band matrix
|
468
|
+
self.comp_mat = (1j*diag(full(N, 1.0))
|
469
|
+
+ diag(full(N-1, -1.0), -1)
|
470
|
+
+ 1j*diag(full(N-1, -3.0), 1)
|
471
|
+
+ diag(full(N-2, 2.0), -2)
|
472
|
+
+ diag(full(N-2, -2.0), 2))
|
473
|
+
|
474
|
+
# Eigenvalues and -vectors from linalg.eig
|
475
|
+
ew, ev = linalg.eig(self.sym_mat)
|
476
|
+
ew = ew.real
|
477
|
+
args = argsort(ew)
|
478
|
+
self.w_sym_lin = ew[args]
|
479
|
+
self.evec_sym_lin = ev[:, args]
|
480
|
+
|
481
|
+
ew, ev = linalg.eig(self.herm_mat)
|
482
|
+
ew = ew.real
|
483
|
+
args = argsort(ew)
|
484
|
+
self.w_herm_lin = ew[args]
|
485
|
+
self.evec_herm_lin = ev[:, args]
|
486
|
+
|
487
|
+
# Extract upper bands from symmetric and hermitian band matrices
|
488
|
+
# (for use in dsbevd, dsbevx, zhbevd, zhbevx
|
489
|
+
# and their single precision versions)
|
490
|
+
LDAB = self.KU + 1
|
491
|
+
self.bandmat_sym = zeros((LDAB, N), dtype=float)
|
492
|
+
self.bandmat_herm = zeros((LDAB, N), dtype=complex)
|
493
|
+
for i in range(LDAB):
|
494
|
+
self.bandmat_sym[LDAB-i-1, i:N] = diag(self.sym_mat, i)
|
495
|
+
self.bandmat_herm[LDAB-i-1, i:N] = diag(self.herm_mat, i)
|
496
|
+
|
497
|
+
# Extract bands from general real and complex band matrix
|
498
|
+
# (for use in dgbtrf, dgbtrs and their single precision versions)
|
499
|
+
LDAB = 2*self.KL + self.KU + 1
|
500
|
+
self.bandmat_real = zeros((LDAB, N), dtype=float)
|
501
|
+
self.bandmat_real[2*self.KL, :] = diag(self.real_mat) # diagonal
|
502
|
+
for i in range(self.KL):
|
503
|
+
# superdiagonals
|
504
|
+
self.bandmat_real[2*self.KL-1-i, i+1:N] = diag(self.real_mat, i+1)
|
505
|
+
# subdiagonals
|
506
|
+
self.bandmat_real[2*self.KL+1+i, 0:N-1-i] = diag(self.real_mat,
|
507
|
+
-i-1)
|
508
|
+
|
509
|
+
self.bandmat_comp = zeros((LDAB, N), dtype=complex)
|
510
|
+
self.bandmat_comp[2*self.KL, :] = diag(self.comp_mat) # diagonal
|
511
|
+
for i in range(self.KL):
|
512
|
+
# superdiagonals
|
513
|
+
self.bandmat_comp[2*self.KL-1-i, i+1:N] = diag(self.comp_mat, i+1)
|
514
|
+
# subdiagonals
|
515
|
+
self.bandmat_comp[2*self.KL+1+i, 0:N-1-i] = diag(self.comp_mat,
|
516
|
+
-i-1)
|
517
|
+
|
518
|
+
# absolute value for linear equation system A*x = b
|
519
|
+
self.b = 1.0*arange(N)
|
520
|
+
self.bc = self.b * (1 + 1j)
|
521
|
+
|
522
|
+
#####################################################################
|
523
|
+
|
524
|
+
def test_dsbev(self):
|
525
|
+
"""Compare dsbev eigenvalues and eigenvectors with
|
526
|
+
the result of linalg.eig."""
|
527
|
+
w, evec, info = dsbev(self.bandmat_sym, compute_v=1)
|
528
|
+
evec_ = evec[:, argsort(w)]
|
529
|
+
assert_array_almost_equal(sort(w), self.w_sym_lin)
|
530
|
+
assert_array_almost_equal(abs(evec_), abs(self.evec_sym_lin))
|
531
|
+
|
532
|
+
def test_dsbevd(self):
|
533
|
+
"""Compare dsbevd eigenvalues and eigenvectors with
|
534
|
+
the result of linalg.eig."""
|
535
|
+
w, evec, info = dsbevd(self.bandmat_sym, compute_v=1)
|
536
|
+
evec_ = evec[:, argsort(w)]
|
537
|
+
assert_array_almost_equal(sort(w), self.w_sym_lin)
|
538
|
+
assert_array_almost_equal(abs(evec_), abs(self.evec_sym_lin))
|
539
|
+
|
540
|
+
def test_dsbevx(self):
|
541
|
+
"""Compare dsbevx eigenvalues and eigenvectors
|
542
|
+
with the result of linalg.eig."""
|
543
|
+
N, N = shape(self.sym_mat)
|
544
|
+
# Achtung: Argumente 0.0,0.0,range?
|
545
|
+
w, evec, num, ifail, info = dsbevx(self.bandmat_sym, 0.0, 0.0, 1, N,
|
546
|
+
compute_v=1, range=2)
|
547
|
+
evec_ = evec[:, argsort(w)]
|
548
|
+
assert_array_almost_equal(sort(w), self.w_sym_lin)
|
549
|
+
assert_array_almost_equal(abs(evec_), abs(self.evec_sym_lin))
|
550
|
+
|
551
|
+
def test_zhbevd(self):
|
552
|
+
"""Compare zhbevd eigenvalues and eigenvectors
|
553
|
+
with the result of linalg.eig."""
|
554
|
+
w, evec, info = zhbevd(self.bandmat_herm, compute_v=1)
|
555
|
+
evec_ = evec[:, argsort(w)]
|
556
|
+
assert_array_almost_equal(sort(w), self.w_herm_lin)
|
557
|
+
assert_array_almost_equal(abs(evec_), abs(self.evec_herm_lin))
|
558
|
+
|
559
|
+
def test_zhbevx(self):
|
560
|
+
"""Compare zhbevx eigenvalues and eigenvectors
|
561
|
+
with the result of linalg.eig."""
|
562
|
+
N, N = shape(self.herm_mat)
|
563
|
+
# Achtung: Argumente 0.0,0.0,range?
|
564
|
+
w, evec, num, ifail, info = zhbevx(self.bandmat_herm, 0.0, 0.0, 1, N,
|
565
|
+
compute_v=1, range=2)
|
566
|
+
evec_ = evec[:, argsort(w)]
|
567
|
+
assert_array_almost_equal(sort(w), self.w_herm_lin)
|
568
|
+
assert_array_almost_equal(abs(evec_), abs(self.evec_herm_lin))
|
569
|
+
|
570
|
+
def test_eigvals_banded(self):
|
571
|
+
"""Compare eigenvalues of eigvals_banded with those of linalg.eig."""
|
572
|
+
w_sym = eigvals_banded(self.bandmat_sym)
|
573
|
+
w_sym = w_sym.real
|
574
|
+
assert_array_almost_equal(sort(w_sym), self.w_sym_lin)
|
575
|
+
|
576
|
+
w_herm = eigvals_banded(self.bandmat_herm)
|
577
|
+
w_herm = w_herm.real
|
578
|
+
assert_array_almost_equal(sort(w_herm), self.w_herm_lin)
|
579
|
+
|
580
|
+
# extracting eigenvalues with respect to an index range
|
581
|
+
ind1 = 2
|
582
|
+
ind2 = np.longlong(6)
|
583
|
+
w_sym_ind = eigvals_banded(self.bandmat_sym,
|
584
|
+
select='i', select_range=(ind1, ind2))
|
585
|
+
assert_array_almost_equal(sort(w_sym_ind),
|
586
|
+
self.w_sym_lin[ind1:ind2+1])
|
587
|
+
w_herm_ind = eigvals_banded(self.bandmat_herm,
|
588
|
+
select='i', select_range=(ind1, ind2))
|
589
|
+
assert_array_almost_equal(sort(w_herm_ind),
|
590
|
+
self.w_herm_lin[ind1:ind2+1])
|
591
|
+
|
592
|
+
# extracting eigenvalues with respect to a value range
|
593
|
+
v_lower = self.w_sym_lin[ind1] - 1.0e-5
|
594
|
+
v_upper = self.w_sym_lin[ind2] + 1.0e-5
|
595
|
+
w_sym_val = eigvals_banded(self.bandmat_sym,
|
596
|
+
select='v', select_range=(v_lower, v_upper))
|
597
|
+
assert_array_almost_equal(sort(w_sym_val),
|
598
|
+
self.w_sym_lin[ind1:ind2+1])
|
599
|
+
|
600
|
+
v_lower = self.w_herm_lin[ind1] - 1.0e-5
|
601
|
+
v_upper = self.w_herm_lin[ind2] + 1.0e-5
|
602
|
+
w_herm_val = eigvals_banded(self.bandmat_herm,
|
603
|
+
select='v',
|
604
|
+
select_range=(v_lower, v_upper))
|
605
|
+
assert_array_almost_equal(sort(w_herm_val),
|
606
|
+
self.w_herm_lin[ind1:ind2+1])
|
607
|
+
|
608
|
+
w_sym = eigvals_banded(self.bandmat_sym, check_finite=False)
|
609
|
+
w_sym = w_sym.real
|
610
|
+
assert_array_almost_equal(sort(w_sym), self.w_sym_lin)
|
611
|
+
|
612
|
+
def test_eig_banded(self):
|
613
|
+
"""Compare eigenvalues and eigenvectors of eig_banded
|
614
|
+
with those of linalg.eig. """
|
615
|
+
w_sym, evec_sym = eig_banded(self.bandmat_sym)
|
616
|
+
evec_sym_ = evec_sym[:, argsort(w_sym.real)]
|
617
|
+
assert_array_almost_equal(sort(w_sym), self.w_sym_lin)
|
618
|
+
assert_array_almost_equal(abs(evec_sym_), abs(self.evec_sym_lin))
|
619
|
+
|
620
|
+
w_herm, evec_herm = eig_banded(self.bandmat_herm)
|
621
|
+
evec_herm_ = evec_herm[:, argsort(w_herm.real)]
|
622
|
+
assert_array_almost_equal(sort(w_herm), self.w_herm_lin)
|
623
|
+
assert_array_almost_equal(abs(evec_herm_), abs(self.evec_herm_lin))
|
624
|
+
|
625
|
+
# extracting eigenvalues with respect to an index range
|
626
|
+
ind1 = 2
|
627
|
+
ind2 = 6
|
628
|
+
w_sym_ind, evec_sym_ind = eig_banded(self.bandmat_sym,
|
629
|
+
select='i',
|
630
|
+
select_range=(ind1, ind2))
|
631
|
+
assert_array_almost_equal(sort(w_sym_ind),
|
632
|
+
self.w_sym_lin[ind1:ind2+1])
|
633
|
+
assert_array_almost_equal(abs(evec_sym_ind),
|
634
|
+
abs(self.evec_sym_lin[:, ind1:ind2+1]))
|
635
|
+
|
636
|
+
w_herm_ind, evec_herm_ind = eig_banded(self.bandmat_herm,
|
637
|
+
select='i',
|
638
|
+
select_range=(ind1, ind2))
|
639
|
+
assert_array_almost_equal(sort(w_herm_ind),
|
640
|
+
self.w_herm_lin[ind1:ind2+1])
|
641
|
+
assert_array_almost_equal(abs(evec_herm_ind),
|
642
|
+
abs(self.evec_herm_lin[:, ind1:ind2+1]))
|
643
|
+
|
644
|
+
# extracting eigenvalues with respect to a value range
|
645
|
+
v_lower = self.w_sym_lin[ind1] - 1.0e-5
|
646
|
+
v_upper = self.w_sym_lin[ind2] + 1.0e-5
|
647
|
+
w_sym_val, evec_sym_val = eig_banded(self.bandmat_sym,
|
648
|
+
select='v',
|
649
|
+
select_range=(v_lower, v_upper))
|
650
|
+
assert_array_almost_equal(sort(w_sym_val),
|
651
|
+
self.w_sym_lin[ind1:ind2+1])
|
652
|
+
assert_array_almost_equal(abs(evec_sym_val),
|
653
|
+
abs(self.evec_sym_lin[:, ind1:ind2+1]))
|
654
|
+
|
655
|
+
v_lower = self.w_herm_lin[ind1] - 1.0e-5
|
656
|
+
v_upper = self.w_herm_lin[ind2] + 1.0e-5
|
657
|
+
w_herm_val, evec_herm_val = eig_banded(self.bandmat_herm,
|
658
|
+
select='v',
|
659
|
+
select_range=(v_lower, v_upper))
|
660
|
+
assert_array_almost_equal(sort(w_herm_val),
|
661
|
+
self.w_herm_lin[ind1:ind2+1])
|
662
|
+
assert_array_almost_equal(abs(evec_herm_val),
|
663
|
+
abs(self.evec_herm_lin[:, ind1:ind2+1]))
|
664
|
+
|
665
|
+
w_sym, evec_sym = eig_banded(self.bandmat_sym, check_finite=False)
|
666
|
+
evec_sym_ = evec_sym[:, argsort(w_sym.real)]
|
667
|
+
assert_array_almost_equal(sort(w_sym), self.w_sym_lin)
|
668
|
+
assert_array_almost_equal(abs(evec_sym_), abs(self.evec_sym_lin))
|
669
|
+
|
670
|
+
def test_dgbtrf(self):
|
671
|
+
"""Compare dgbtrf LU factorisation with the LU factorisation result
|
672
|
+
of linalg.lu."""
|
673
|
+
M, N = shape(self.real_mat)
|
674
|
+
lu_symm_band, ipiv, info = dgbtrf(self.bandmat_real, self.KL, self.KU)
|
675
|
+
|
676
|
+
# extract matrix u from lu_symm_band
|
677
|
+
u = diag(lu_symm_band[2*self.KL, :])
|
678
|
+
for i in range(self.KL + self.KU):
|
679
|
+
u += diag(lu_symm_band[2*self.KL-1-i, i+1:N], i+1)
|
680
|
+
|
681
|
+
p_lin, l_lin, u_lin = lu(self.real_mat, permute_l=0)
|
682
|
+
assert_array_almost_equal(u, u_lin)
|
683
|
+
|
684
|
+
def test_zgbtrf(self):
|
685
|
+
"""Compare zgbtrf LU factorisation with the LU factorisation result
|
686
|
+
of linalg.lu."""
|
687
|
+
M, N = shape(self.comp_mat)
|
688
|
+
lu_symm_band, ipiv, info = zgbtrf(self.bandmat_comp, self.KL, self.KU)
|
689
|
+
|
690
|
+
# extract matrix u from lu_symm_band
|
691
|
+
u = diag(lu_symm_band[2*self.KL, :])
|
692
|
+
for i in range(self.KL + self.KU):
|
693
|
+
u += diag(lu_symm_band[2*self.KL-1-i, i+1:N], i+1)
|
694
|
+
|
695
|
+
p_lin, l_lin, u_lin = lu(self.comp_mat, permute_l=0)
|
696
|
+
assert_array_almost_equal(u, u_lin)
|
697
|
+
|
698
|
+
def test_dgbtrs(self):
|
699
|
+
"""Compare dgbtrs solutions for linear equation system A*x = b
|
700
|
+
with solutions of linalg.solve."""
|
701
|
+
|
702
|
+
lu_symm_band, ipiv, info = dgbtrf(self.bandmat_real, self.KL, self.KU)
|
703
|
+
y, info = dgbtrs(lu_symm_band, self.KL, self.KU, self.b, ipiv)
|
704
|
+
|
705
|
+
y_lin = linalg.solve(self.real_mat, self.b)
|
706
|
+
assert_array_almost_equal(y, y_lin)
|
707
|
+
|
708
|
+
def test_zgbtrs(self):
|
709
|
+
"""Compare zgbtrs solutions for linear equation system A*x = b
|
710
|
+
with solutions of linalg.solve."""
|
711
|
+
|
712
|
+
lu_symm_band, ipiv, info = zgbtrf(self.bandmat_comp, self.KL, self.KU)
|
713
|
+
y, info = zgbtrs(lu_symm_band, self.KL, self.KU, self.bc, ipiv)
|
714
|
+
|
715
|
+
y_lin = linalg.solve(self.comp_mat, self.bc)
|
716
|
+
assert_array_almost_equal(y, y_lin)
|
717
|
+
|
718
|
+
@pytest.mark.parametrize('dt', [int, float, np.float32, complex, np.complex64])
|
719
|
+
def test_empty(self, dt):
|
720
|
+
a_band = np.empty((0, 0), dtype=dt)
|
721
|
+
w, v = eig_banded(a_band)
|
722
|
+
|
723
|
+
w_n, v_n = eig_banded(np.array([[0, 0], [1, 1]], dtype=dt))
|
724
|
+
|
725
|
+
assert w.shape == (0,)
|
726
|
+
assert w.dtype == w_n.dtype
|
727
|
+
|
728
|
+
assert v.shape == (0, 0)
|
729
|
+
assert v.dtype == v_n.dtype
|
730
|
+
|
731
|
+
w = eig_banded(a_band, eigvals_only=True)
|
732
|
+
assert w.shape == (0,)
|
733
|
+
assert w.dtype == w_n.dtype
|
734
|
+
|
735
|
+
class TestEigTridiagonal:
|
736
|
+
def setup_method(self):
|
737
|
+
self.create_trimat()
|
738
|
+
|
739
|
+
def create_trimat(self):
|
740
|
+
"""Create the full matrix `self.fullmat`, `self.d`, and `self.e`."""
|
741
|
+
N = 10
|
742
|
+
|
743
|
+
# symmetric band matrix
|
744
|
+
self.d = full(N, 1.0)
|
745
|
+
self.e = full(N-1, -1.0)
|
746
|
+
self.full_mat = (diag(self.d) + diag(self.e, -1) + diag(self.e, 1))
|
747
|
+
|
748
|
+
ew, ev = linalg.eig(self.full_mat)
|
749
|
+
ew = ew.real
|
750
|
+
args = argsort(ew)
|
751
|
+
self.w = ew[args]
|
752
|
+
self.evec = ev[:, args]
|
753
|
+
|
754
|
+
def test_degenerate(self):
|
755
|
+
"""Test error conditions."""
|
756
|
+
# Wrong sizes
|
757
|
+
assert_raises(ValueError, eigvalsh_tridiagonal, self.d, self.e[:-1])
|
758
|
+
# Must be real
|
759
|
+
assert_raises(TypeError, eigvalsh_tridiagonal, self.d, self.e * 1j)
|
760
|
+
# Bad driver
|
761
|
+
assert_raises(TypeError, eigvalsh_tridiagonal, self.d, self.e,
|
762
|
+
lapack_driver=1.)
|
763
|
+
assert_raises(ValueError, eigvalsh_tridiagonal, self.d, self.e,
|
764
|
+
lapack_driver='foo')
|
765
|
+
# Bad bounds
|
766
|
+
assert_raises(ValueError, eigvalsh_tridiagonal, self.d, self.e,
|
767
|
+
select='i', select_range=(0, -1))
|
768
|
+
|
769
|
+
def test_eigvalsh_tridiagonal(self):
|
770
|
+
"""Compare eigenvalues of eigvalsh_tridiagonal with those of eig."""
|
771
|
+
# can't use ?STERF with subselection
|
772
|
+
for driver in ('sterf', 'stev', 'stevd', 'stebz', 'stemr', 'auto'):
|
773
|
+
w = eigvalsh_tridiagonal(self.d, self.e, lapack_driver=driver)
|
774
|
+
assert_array_almost_equal(sort(w), self.w)
|
775
|
+
|
776
|
+
for driver in ('sterf', 'stev', 'stevd'):
|
777
|
+
assert_raises(ValueError, eigvalsh_tridiagonal, self.d, self.e,
|
778
|
+
lapack_driver=driver, select='i',
|
779
|
+
select_range=(0, 1))
|
780
|
+
for driver in ('stebz', 'stemr', 'auto'):
|
781
|
+
# extracting eigenvalues with respect to the full index range
|
782
|
+
w_ind = eigvalsh_tridiagonal(
|
783
|
+
self.d, self.e, select='i', select_range=(0, len(self.d)-1),
|
784
|
+
lapack_driver=driver)
|
785
|
+
assert_array_almost_equal(sort(w_ind), self.w)
|
786
|
+
|
787
|
+
# extracting eigenvalues with respect to an index range
|
788
|
+
ind1 = 2
|
789
|
+
ind2 = 6
|
790
|
+
w_ind = eigvalsh_tridiagonal(
|
791
|
+
self.d, self.e, select='i', select_range=(ind1, ind2),
|
792
|
+
lapack_driver=driver)
|
793
|
+
assert_array_almost_equal(sort(w_ind), self.w[ind1:ind2+1])
|
794
|
+
|
795
|
+
# extracting eigenvalues with respect to a value range
|
796
|
+
v_lower = self.w[ind1] - 1.0e-5
|
797
|
+
v_upper = self.w[ind2] + 1.0e-5
|
798
|
+
w_val = eigvalsh_tridiagonal(
|
799
|
+
self.d, self.e, select='v', select_range=(v_lower, v_upper),
|
800
|
+
lapack_driver=driver)
|
801
|
+
assert_array_almost_equal(sort(w_val), self.w[ind1:ind2+1])
|
802
|
+
|
803
|
+
def test_eigh_tridiagonal(self):
|
804
|
+
"""Compare eigenvalues and eigenvectors of eigh_tridiagonal
|
805
|
+
with those of eig. """
|
806
|
+
# can't use ?STERF when eigenvectors are requested
|
807
|
+
assert_raises(ValueError, eigh_tridiagonal, self.d, self.e,
|
808
|
+
lapack_driver='sterf')
|
809
|
+
for driver in ('stebz', 'stev', 'stevd', 'stemr', 'auto'):
|
810
|
+
w, evec = eigh_tridiagonal(self.d, self.e, lapack_driver=driver)
|
811
|
+
evec_ = evec[:, argsort(w)]
|
812
|
+
assert_array_almost_equal(sort(w), self.w)
|
813
|
+
assert_array_almost_equal(abs(evec_), abs(self.evec))
|
814
|
+
|
815
|
+
assert_raises(ValueError, eigh_tridiagonal, self.d, self.e,
|
816
|
+
lapack_driver='stev', select='i', select_range=(0, 1))
|
817
|
+
for driver in ('stebz', 'stemr', 'auto'):
|
818
|
+
# extracting eigenvalues with respect to an index range
|
819
|
+
ind1 = 0
|
820
|
+
ind2 = len(self.d)-1
|
821
|
+
w, evec = eigh_tridiagonal(
|
822
|
+
self.d, self.e, select='i', select_range=(ind1, ind2),
|
823
|
+
lapack_driver=driver)
|
824
|
+
assert_array_almost_equal(sort(w), self.w)
|
825
|
+
assert_array_almost_equal(abs(evec), abs(self.evec))
|
826
|
+
ind1 = 2
|
827
|
+
ind2 = 6
|
828
|
+
w, evec = eigh_tridiagonal(
|
829
|
+
self.d, self.e, select='i', select_range=(ind1, ind2),
|
830
|
+
lapack_driver=driver)
|
831
|
+
assert_array_almost_equal(sort(w), self.w[ind1:ind2+1])
|
832
|
+
assert_array_almost_equal(abs(evec),
|
833
|
+
abs(self.evec[:, ind1:ind2+1]))
|
834
|
+
|
835
|
+
# extracting eigenvalues with respect to a value range
|
836
|
+
v_lower = self.w[ind1] - 1.0e-5
|
837
|
+
v_upper = self.w[ind2] + 1.0e-5
|
838
|
+
w, evec = eigh_tridiagonal(
|
839
|
+
self.d, self.e, select='v', select_range=(v_lower, v_upper),
|
840
|
+
lapack_driver=driver)
|
841
|
+
assert_array_almost_equal(sort(w), self.w[ind1:ind2+1])
|
842
|
+
assert_array_almost_equal(abs(evec),
|
843
|
+
abs(self.evec[:, ind1:ind2+1]))
|
844
|
+
|
845
|
+
def test_eigh_tridiagonal_1x1(self):
|
846
|
+
"""See gh-20075"""
|
847
|
+
a = np.array([-2.0])
|
848
|
+
b = np.array([])
|
849
|
+
x = eigh_tridiagonal(a, b, eigvals_only=True)
|
850
|
+
assert x.ndim == 1
|
851
|
+
assert_allclose(x, a)
|
852
|
+
x, V = eigh_tridiagonal(a, b, select="i", select_range=(0, 0))
|
853
|
+
assert x.ndim == 1
|
854
|
+
assert V.ndim == 2
|
855
|
+
assert_allclose(x, a)
|
856
|
+
assert_allclose(V, array([[1.]]))
|
857
|
+
|
858
|
+
x, V = eigh_tridiagonal(a, b, select="v", select_range=(-2, 0))
|
859
|
+
assert x.size == 0
|
860
|
+
assert x.shape == (0,)
|
861
|
+
assert V.shape == (1, 0)
|
862
|
+
|
863
|
+
|
864
|
+
class TestEigh:
|
865
|
+
def setup_class(self):
|
866
|
+
np.random.seed(1234)
|
867
|
+
|
868
|
+
def test_wrong_inputs(self):
|
869
|
+
# Nonsquare a
|
870
|
+
assert_raises(ValueError, eigh, np.ones([1, 2]))
|
871
|
+
# Nonsquare b
|
872
|
+
assert_raises(ValueError, eigh, np.ones([2, 2]), np.ones([2, 1]))
|
873
|
+
# Incompatible a, b sizes
|
874
|
+
assert_raises(ValueError, eigh, np.ones([3, 3]), np.ones([2, 2]))
|
875
|
+
# Wrong type parameter for generalized problem
|
876
|
+
assert_raises(ValueError, eigh, np.ones([3, 3]), np.ones([3, 3]),
|
877
|
+
type=4)
|
878
|
+
# Both value and index subsets requested
|
879
|
+
assert_raises(ValueError, eigh, np.ones([3, 3]), np.ones([3, 3]),
|
880
|
+
subset_by_value=[1, 2], subset_by_index=[2, 4])
|
881
|
+
# Invalid upper index spec
|
882
|
+
assert_raises(ValueError, eigh, np.ones([3, 3]), np.ones([3, 3]),
|
883
|
+
subset_by_index=[0, 4])
|
884
|
+
# Invalid lower index
|
885
|
+
assert_raises(ValueError, eigh, np.ones([3, 3]), np.ones([3, 3]),
|
886
|
+
subset_by_index=[-2, 2])
|
887
|
+
# Invalid index spec #2
|
888
|
+
assert_raises(ValueError, eigh, np.ones([3, 3]), np.ones([3, 3]),
|
889
|
+
subset_by_index=[2, 0])
|
890
|
+
# Invalid value spec
|
891
|
+
assert_raises(ValueError, eigh, np.ones([3, 3]), np.ones([3, 3]),
|
892
|
+
subset_by_value=[2, 0])
|
893
|
+
# Invalid driver name
|
894
|
+
assert_raises(ValueError, eigh, np.ones([2, 2]), driver='wrong')
|
895
|
+
# Generalized driver selection without b
|
896
|
+
assert_raises(ValueError, eigh, np.ones([3, 3]), None, driver='gvx')
|
897
|
+
# Standard driver with b
|
898
|
+
assert_raises(ValueError, eigh, np.ones([3, 3]), np.ones([3, 3]),
|
899
|
+
driver='evr')
|
900
|
+
# Subset request from invalid driver
|
901
|
+
assert_raises(ValueError, eigh, np.ones([3, 3]), np.ones([3, 3]),
|
902
|
+
driver='gvd', subset_by_index=[1, 2])
|
903
|
+
assert_raises(ValueError, eigh, np.ones([3, 3]), np.ones([3, 3]),
|
904
|
+
driver='gvd', subset_by_index=[1, 2])
|
905
|
+
|
906
|
+
def test_nonpositive_b(self):
|
907
|
+
assert_raises(LinAlgError, eigh, np.ones([3, 3]), np.ones([3, 3]))
|
908
|
+
|
909
|
+
# index based subsets are done in the legacy test_eigh()
|
910
|
+
def test_value_subsets(self):
|
911
|
+
for ind, dt in enumerate(DTYPES):
|
912
|
+
|
913
|
+
a = _random_hermitian_matrix(20, dtype=dt)
|
914
|
+
w, v = eigh(a, subset_by_value=[-2, 2])
|
915
|
+
assert_equal(v.shape[1], len(w))
|
916
|
+
assert all((w > -2) & (w < 2))
|
917
|
+
|
918
|
+
b = _random_hermitian_matrix(20, posdef=True, dtype=dt)
|
919
|
+
w, v = eigh(a, b, subset_by_value=[-2, 2])
|
920
|
+
assert_equal(v.shape[1], len(w))
|
921
|
+
assert all((w > -2) & (w < 2))
|
922
|
+
|
923
|
+
def test_eigh_integer(self):
|
924
|
+
a = array([[1, 2], [2, 7]])
|
925
|
+
b = array([[3, 1], [1, 5]])
|
926
|
+
w, z = eigh(a)
|
927
|
+
w, z = eigh(a, b)
|
928
|
+
|
929
|
+
def test_eigh_of_sparse(self):
|
930
|
+
# This tests the rejection of inputs that eigh cannot currently handle.
|
931
|
+
import scipy.sparse
|
932
|
+
a = scipy.sparse.identity(2).tocsc()
|
933
|
+
b = np.atleast_2d(a)
|
934
|
+
assert_raises(ValueError, eigh, a)
|
935
|
+
assert_raises(ValueError, eigh, b)
|
936
|
+
|
937
|
+
@pytest.mark.parametrize('dtype_', DTYPES)
|
938
|
+
@pytest.mark.parametrize('driver', ("ev", "evd", "evr", "evx"))
|
939
|
+
def test_various_drivers_standard(self, driver, dtype_):
|
940
|
+
a = _random_hermitian_matrix(n=20, dtype=dtype_)
|
941
|
+
w, v = eigh(a, driver=driver)
|
942
|
+
assert_allclose(a @ v - (v * w), 0.,
|
943
|
+
atol=1000*np.finfo(dtype_).eps,
|
944
|
+
rtol=0.)
|
945
|
+
|
946
|
+
@pytest.mark.parametrize('driver', ("ev", "evd", "evr", "evx"))
|
947
|
+
def test_1x1_lwork(self, driver):
|
948
|
+
w, v = eigh([[1]], driver=driver)
|
949
|
+
assert_allclose(w, array([1.]), atol=1e-15)
|
950
|
+
assert_allclose(v, array([[1.]]), atol=1e-15)
|
951
|
+
|
952
|
+
# complex case now
|
953
|
+
w, v = eigh([[1j]], driver=driver)
|
954
|
+
assert_allclose(w, array([0]), atol=1e-15)
|
955
|
+
assert_allclose(v, array([[1.]]), atol=1e-15)
|
956
|
+
|
957
|
+
@pytest.mark.parametrize('type', (1, 2, 3))
|
958
|
+
@pytest.mark.parametrize('driver', ("gv", "gvd", "gvx"))
|
959
|
+
def test_various_drivers_generalized(self, driver, type):
|
960
|
+
atol = np.spacing(5000.)
|
961
|
+
a = _random_hermitian_matrix(20)
|
962
|
+
b = _random_hermitian_matrix(20, posdef=True)
|
963
|
+
w, v = eigh(a=a, b=b, driver=driver, type=type)
|
964
|
+
if type == 1:
|
965
|
+
assert_allclose(a @ v - w*(b @ v), 0., atol=atol, rtol=0.)
|
966
|
+
elif type == 2:
|
967
|
+
assert_allclose(a @ b @ v - v * w, 0., atol=atol, rtol=0.)
|
968
|
+
else:
|
969
|
+
assert_allclose(b @ a @ v - v * w, 0., atol=atol, rtol=0.)
|
970
|
+
|
971
|
+
def test_eigvalsh_new_args(self):
|
972
|
+
a = _random_hermitian_matrix(5)
|
973
|
+
w = eigvalsh(a, subset_by_index=[1, 2])
|
974
|
+
assert_equal(len(w), 2)
|
975
|
+
|
976
|
+
w2 = eigvalsh(a, subset_by_index=[1, 2])
|
977
|
+
assert_equal(len(w2), 2)
|
978
|
+
assert_allclose(w, w2)
|
979
|
+
|
980
|
+
b = np.diag([1, 1.2, 1.3, 1.5, 2])
|
981
|
+
w3 = eigvalsh(b, subset_by_value=[1, 1.4])
|
982
|
+
assert_equal(len(w3), 2)
|
983
|
+
assert_allclose(w3, np.array([1.2, 1.3]))
|
984
|
+
|
985
|
+
@pytest.mark.parametrize('dt', [int, float, np.float32, complex, np.complex64])
|
986
|
+
def test_empty(self, dt):
|
987
|
+
a = np.empty((0, 0), dtype=dt)
|
988
|
+
w, v = eigh(a)
|
989
|
+
|
990
|
+
w_n, v_n = eigh(np.eye(2, dtype=dt))
|
991
|
+
|
992
|
+
assert w.shape == (0,)
|
993
|
+
assert w.dtype == w_n.dtype
|
994
|
+
|
995
|
+
assert v.shape == (0, 0)
|
996
|
+
assert v.dtype == v_n.dtype
|
997
|
+
|
998
|
+
w = eigh(a, eigvals_only=True)
|
999
|
+
assert_allclose(w, np.empty((0,)))
|
1000
|
+
|
1001
|
+
assert w.shape == (0,)
|
1002
|
+
assert w.dtype == w_n.dtype
|
1003
|
+
|
1004
|
+
class TestSVD_GESDD:
|
1005
|
+
lapack_driver = 'gesdd'
|
1006
|
+
|
1007
|
+
def test_degenerate(self):
|
1008
|
+
assert_raises(TypeError, svd, [[1.]], lapack_driver=1.)
|
1009
|
+
assert_raises(ValueError, svd, [[1.]], lapack_driver='foo')
|
1010
|
+
|
1011
|
+
def test_simple(self):
|
1012
|
+
a = [[1, 2, 3], [1, 20, 3], [2, 5, 6]]
|
1013
|
+
for full_matrices in (True, False):
|
1014
|
+
u, s, vh = svd(a, full_matrices=full_matrices,
|
1015
|
+
lapack_driver=self.lapack_driver)
|
1016
|
+
assert_array_almost_equal(u.T @ u, eye(3))
|
1017
|
+
assert_array_almost_equal(vh.T @ vh, eye(3))
|
1018
|
+
sigma = zeros((u.shape[0], vh.shape[0]), s.dtype.char)
|
1019
|
+
for i in range(len(s)):
|
1020
|
+
sigma[i, i] = s[i]
|
1021
|
+
assert_array_almost_equal(u @ sigma @ vh, a)
|
1022
|
+
|
1023
|
+
def test_simple_singular(self):
|
1024
|
+
a = [[1, 2, 3], [1, 2, 3], [2, 5, 6]]
|
1025
|
+
for full_matrices in (True, False):
|
1026
|
+
u, s, vh = svd(a, full_matrices=full_matrices,
|
1027
|
+
lapack_driver=self.lapack_driver)
|
1028
|
+
assert_array_almost_equal(u.T @ u, eye(3))
|
1029
|
+
assert_array_almost_equal(vh.T @ vh, eye(3))
|
1030
|
+
sigma = zeros((u.shape[0], vh.shape[0]), s.dtype.char)
|
1031
|
+
for i in range(len(s)):
|
1032
|
+
sigma[i, i] = s[i]
|
1033
|
+
assert_array_almost_equal(u @ sigma @ vh, a)
|
1034
|
+
|
1035
|
+
def test_simple_underdet(self):
|
1036
|
+
a = [[1, 2, 3], [4, 5, 6]]
|
1037
|
+
for full_matrices in (True, False):
|
1038
|
+
u, s, vh = svd(a, full_matrices=full_matrices,
|
1039
|
+
lapack_driver=self.lapack_driver)
|
1040
|
+
assert_array_almost_equal(u.T @ u, eye(u.shape[0]))
|
1041
|
+
sigma = zeros((u.shape[0], vh.shape[0]), s.dtype.char)
|
1042
|
+
for i in range(len(s)):
|
1043
|
+
sigma[i, i] = s[i]
|
1044
|
+
assert_array_almost_equal(u @ sigma @ vh, a)
|
1045
|
+
|
1046
|
+
def test_simple_overdet(self):
|
1047
|
+
a = [[1, 2], [4, 5], [3, 4]]
|
1048
|
+
for full_matrices in (True, False):
|
1049
|
+
u, s, vh = svd(a, full_matrices=full_matrices,
|
1050
|
+
lapack_driver=self.lapack_driver)
|
1051
|
+
assert_array_almost_equal(u.T @ u, eye(u.shape[1]))
|
1052
|
+
assert_array_almost_equal(vh.T @ vh, eye(2))
|
1053
|
+
sigma = zeros((u.shape[1], vh.shape[0]), s.dtype.char)
|
1054
|
+
for i in range(len(s)):
|
1055
|
+
sigma[i, i] = s[i]
|
1056
|
+
assert_array_almost_equal(u @ sigma @ vh, a)
|
1057
|
+
|
1058
|
+
def test_random(self):
|
1059
|
+
rng = np.random.RandomState(1234)
|
1060
|
+
n = 20
|
1061
|
+
m = 15
|
1062
|
+
for i in range(3):
|
1063
|
+
for a in [rng.random([n, m]), rng.random([m, n])]:
|
1064
|
+
for full_matrices in (True, False):
|
1065
|
+
u, s, vh = svd(a, full_matrices=full_matrices,
|
1066
|
+
lapack_driver=self.lapack_driver)
|
1067
|
+
assert_array_almost_equal(u.T @ u, eye(u.shape[1]))
|
1068
|
+
assert_array_almost_equal(vh @ vh.T, eye(vh.shape[0]))
|
1069
|
+
sigma = zeros((u.shape[1], vh.shape[0]), s.dtype.char)
|
1070
|
+
for i in range(len(s)):
|
1071
|
+
sigma[i, i] = s[i]
|
1072
|
+
assert_array_almost_equal(u @ sigma @ vh, a)
|
1073
|
+
|
1074
|
+
def test_simple_complex(self):
|
1075
|
+
a = [[1, 2, 3], [1, 2j, 3], [2, 5, 6]]
|
1076
|
+
for full_matrices in (True, False):
|
1077
|
+
u, s, vh = svd(a, full_matrices=full_matrices,
|
1078
|
+
lapack_driver=self.lapack_driver)
|
1079
|
+
assert_array_almost_equal(u.conj().T @ u, eye(u.shape[1]))
|
1080
|
+
assert_array_almost_equal(vh.conj().T @ vh, eye(vh.shape[0]))
|
1081
|
+
sigma = zeros((u.shape[0], vh.shape[0]), s.dtype.char)
|
1082
|
+
for i in range(len(s)):
|
1083
|
+
sigma[i, i] = s[i]
|
1084
|
+
assert_array_almost_equal(u @ sigma @ vh, a)
|
1085
|
+
|
1086
|
+
def test_random_complex(self):
|
1087
|
+
rng = np.random.RandomState(1234)
|
1088
|
+
n = 20
|
1089
|
+
m = 15
|
1090
|
+
for i in range(3):
|
1091
|
+
for full_matrices in (True, False):
|
1092
|
+
for a in [rng.random([n, m]), rng.random([m, n])]:
|
1093
|
+
a = a + 1j*rng.random(list(a.shape))
|
1094
|
+
u, s, vh = svd(a, full_matrices=full_matrices,
|
1095
|
+
lapack_driver=self.lapack_driver)
|
1096
|
+
assert_array_almost_equal(u.conj().T @ u,
|
1097
|
+
eye(u.shape[1]))
|
1098
|
+
# This fails when [m,n]
|
1099
|
+
# assert_array_almost_equal(vh.conj().T @ vh,
|
1100
|
+
# eye(len(vh),dtype=vh.dtype.char))
|
1101
|
+
sigma = zeros((u.shape[1], vh.shape[0]), s.dtype.char)
|
1102
|
+
for i in range(len(s)):
|
1103
|
+
sigma[i, i] = s[i]
|
1104
|
+
assert_array_almost_equal(u @ sigma @ vh, a)
|
1105
|
+
|
1106
|
+
def test_crash_1580(self):
|
1107
|
+
rng = np.random.RandomState(1234)
|
1108
|
+
sizes = [(13, 23), (30, 50), (60, 100)]
|
1109
|
+
for sz in sizes:
|
1110
|
+
for dt in [np.float32, np.float64, np.complex64, np.complex128]:
|
1111
|
+
a = rng.rand(*sz).astype(dt)
|
1112
|
+
# should not crash
|
1113
|
+
svd(a, lapack_driver=self.lapack_driver)
|
1114
|
+
|
1115
|
+
def test_check_finite(self):
|
1116
|
+
a = [[1, 2, 3], [1, 20, 3], [2, 5, 6]]
|
1117
|
+
u, s, vh = svd(a, check_finite=False, lapack_driver=self.lapack_driver)
|
1118
|
+
assert_array_almost_equal(u.T @ u, eye(3))
|
1119
|
+
assert_array_almost_equal(vh.T @ vh, eye(3))
|
1120
|
+
sigma = zeros((u.shape[0], vh.shape[0]), s.dtype.char)
|
1121
|
+
for i in range(len(s)):
|
1122
|
+
sigma[i, i] = s[i]
|
1123
|
+
assert_array_almost_equal(u @ sigma @ vh, a)
|
1124
|
+
|
1125
|
+
def test_gh_5039(self):
|
1126
|
+
# This is a smoke test for https://github.com/scipy/scipy/issues/5039
|
1127
|
+
#
|
1128
|
+
# The following is reported to raise "ValueError: On entry to DGESDD
|
1129
|
+
# parameter number 12 had an illegal value".
|
1130
|
+
# `interp1d([1,2,3,4], [1,2,3,4], kind='cubic')`
|
1131
|
+
# This is reported to only show up on LAPACK 3.0.3.
|
1132
|
+
#
|
1133
|
+
# The matrix below is taken from the call to
|
1134
|
+
# `B = _fitpack._bsplmat(order, xk)` in interpolate._find_smoothest
|
1135
|
+
b = np.array(
|
1136
|
+
[[0.16666667, 0.66666667, 0.16666667, 0., 0., 0.],
|
1137
|
+
[0., 0.16666667, 0.66666667, 0.16666667, 0., 0.],
|
1138
|
+
[0., 0., 0.16666667, 0.66666667, 0.16666667, 0.],
|
1139
|
+
[0., 0., 0., 0.16666667, 0.66666667, 0.16666667]])
|
1140
|
+
svd(b, lapack_driver=self.lapack_driver)
|
1141
|
+
|
1142
|
+
@pytest.mark.skipif(not HAS_ILP64, reason="64-bit LAPACK required")
|
1143
|
+
@pytest.mark.slow
|
1144
|
+
def test_large_matrix(self):
|
1145
|
+
check_free_memory(free_mb=17000)
|
1146
|
+
A = np.zeros([1, 2**31], dtype=np.float32)
|
1147
|
+
A[0, -1] = 1
|
1148
|
+
u, s, vh = svd(A, full_matrices=False)
|
1149
|
+
assert_allclose(s[0], 1.0)
|
1150
|
+
assert_allclose(u[0, 0] * vh[0, -1], 1.0)
|
1151
|
+
|
1152
|
+
@pytest.mark.parametrize("m", [0, 1, 2])
|
1153
|
+
@pytest.mark.parametrize("n", [0, 1, 2])
|
1154
|
+
@pytest.mark.parametrize('dtype', DTYPES)
|
1155
|
+
def test_shape_dtype(self, m, n, dtype):
|
1156
|
+
a = np.zeros((m, n), dtype=dtype)
|
1157
|
+
k = min(m, n)
|
1158
|
+
dchar = a.dtype.char
|
1159
|
+
real_dchar = dchar.lower() if dchar in 'FD' else dchar
|
1160
|
+
|
1161
|
+
u, s, v = svd(a)
|
1162
|
+
assert_equal(u.shape, (m, m))
|
1163
|
+
assert_equal(u.dtype, dtype)
|
1164
|
+
assert_equal(s.shape, (k,))
|
1165
|
+
assert_equal(s.dtype, np.dtype(real_dchar))
|
1166
|
+
assert_equal(v.shape, (n, n))
|
1167
|
+
assert_equal(v.dtype, dtype)
|
1168
|
+
|
1169
|
+
u, s, v = svd(a, full_matrices=False)
|
1170
|
+
assert_equal(u.shape, (m, k))
|
1171
|
+
assert_equal(u.dtype, dtype)
|
1172
|
+
assert_equal(s.shape, (k,))
|
1173
|
+
assert_equal(s.dtype, np.dtype(real_dchar))
|
1174
|
+
assert_equal(v.shape, (k, n))
|
1175
|
+
assert_equal(v.dtype, dtype)
|
1176
|
+
|
1177
|
+
s = svd(a, compute_uv=False)
|
1178
|
+
assert_equal(s.shape, (k,))
|
1179
|
+
assert_equal(s.dtype, np.dtype(real_dchar))
|
1180
|
+
|
1181
|
+
@pytest.mark.parametrize('dt', [int, float, np.float32, complex, np.complex64])
|
1182
|
+
@pytest.mark.parametrize(("m", "n"), [(0, 0), (0, 2), (2, 0)])
|
1183
|
+
def test_empty(self, dt, m, n):
|
1184
|
+
a0 = np.eye(3, dtype=dt)
|
1185
|
+
u0, s0, v0 = svd(a0)
|
1186
|
+
|
1187
|
+
a = np.empty((m, n), dtype=dt)
|
1188
|
+
u, s, v = svd(a)
|
1189
|
+
assert_allclose(u, np.identity(m))
|
1190
|
+
assert_allclose(s, np.empty((0,)))
|
1191
|
+
assert_allclose(v, np.identity(n))
|
1192
|
+
|
1193
|
+
assert u.dtype == u0.dtype
|
1194
|
+
assert v.dtype == v0.dtype
|
1195
|
+
assert s.dtype == s0.dtype
|
1196
|
+
|
1197
|
+
u, s, v = svd(a, full_matrices=False)
|
1198
|
+
assert_allclose(u, np.empty((m, 0)))
|
1199
|
+
assert_allclose(s, np.empty((0,)))
|
1200
|
+
assert_allclose(v, np.empty((0, n)))
|
1201
|
+
|
1202
|
+
assert u.dtype == u0.dtype
|
1203
|
+
assert v.dtype == v0.dtype
|
1204
|
+
assert s.dtype == s0.dtype
|
1205
|
+
|
1206
|
+
s = svd(a, compute_uv=False)
|
1207
|
+
assert_allclose(s, np.empty((0,)))
|
1208
|
+
|
1209
|
+
assert s.dtype == s0.dtype
|
1210
|
+
|
1211
|
+
class TestSVD_GESVD(TestSVD_GESDD):
|
1212
|
+
lapack_driver = 'gesvd'
|
1213
|
+
|
1214
|
+
|
1215
|
+
# Allocating an array of such a size leads to _ArrayMemoryError(s)
|
1216
|
+
# since the maximum memory that can be in 32-bit (WASM) is 4GB
|
1217
|
+
@pytest.mark.skipif(IS_WASM, reason="out of memory in WASM")
|
1218
|
+
@pytest.mark.fail_slow(10)
|
1219
|
+
def test_svd_gesdd_nofegfault():
|
1220
|
+
# svd(a) with {U,VT}.size > INT_MAX does not segfault
|
1221
|
+
# cf https://github.com/scipy/scipy/issues/14001
|
1222
|
+
df=np.ones((4799, 53130), dtype=np.float64)
|
1223
|
+
with assert_raises(ValueError):
|
1224
|
+
svd(df)
|
1225
|
+
|
1226
|
+
|
1227
|
+
def test_gesdd_nan_error_message():
|
1228
|
+
A = np.eye(2)
|
1229
|
+
A[0, 0] = np.nan
|
1230
|
+
with pytest.raises(ValueError, match="NaN"):
|
1231
|
+
svd(A, check_finite=False)
|
1232
|
+
|
1233
|
+
|
1234
|
+
class TestSVDVals:
|
1235
|
+
|
1236
|
+
@pytest.mark.parametrize('dt', [int, float, np.float32, complex, np.complex64])
|
1237
|
+
def test_empty(self, dt):
|
1238
|
+
for a in [[]], np.empty((2, 0)), np.ones((0, 3)):
|
1239
|
+
a = np.array(a, dtype=dt)
|
1240
|
+
s = svdvals(a)
|
1241
|
+
assert_equal(s, np.empty(0))
|
1242
|
+
|
1243
|
+
s0 = svdvals(np.eye(2, dtype=dt))
|
1244
|
+
assert s.dtype == s0.dtype
|
1245
|
+
|
1246
|
+
def test_simple(self):
|
1247
|
+
a = [[1, 2, 3], [1, 2, 3], [2, 5, 6]]
|
1248
|
+
s = svdvals(a)
|
1249
|
+
assert_(len(s) == 3)
|
1250
|
+
assert_(s[0] >= s[1] >= s[2])
|
1251
|
+
|
1252
|
+
def test_simple_underdet(self):
|
1253
|
+
a = [[1, 2, 3], [4, 5, 6]]
|
1254
|
+
s = svdvals(a)
|
1255
|
+
assert_(len(s) == 2)
|
1256
|
+
assert_(s[0] >= s[1])
|
1257
|
+
|
1258
|
+
def test_simple_overdet(self):
|
1259
|
+
a = [[1, 2], [4, 5], [3, 4]]
|
1260
|
+
s = svdvals(a)
|
1261
|
+
assert_(len(s) == 2)
|
1262
|
+
assert_(s[0] >= s[1])
|
1263
|
+
|
1264
|
+
def test_simple_complex(self):
|
1265
|
+
a = [[1, 2, 3], [1, 20, 3j], [2, 5, 6]]
|
1266
|
+
s = svdvals(a)
|
1267
|
+
assert_(len(s) == 3)
|
1268
|
+
assert_(s[0] >= s[1] >= s[2])
|
1269
|
+
|
1270
|
+
def test_simple_underdet_complex(self):
|
1271
|
+
a = [[1, 2, 3], [4, 5j, 6]]
|
1272
|
+
s = svdvals(a)
|
1273
|
+
assert_(len(s) == 2)
|
1274
|
+
assert_(s[0] >= s[1])
|
1275
|
+
|
1276
|
+
def test_simple_overdet_complex(self):
|
1277
|
+
a = [[1, 2], [4, 5], [3j, 4]]
|
1278
|
+
s = svdvals(a)
|
1279
|
+
assert_(len(s) == 2)
|
1280
|
+
assert_(s[0] >= s[1])
|
1281
|
+
|
1282
|
+
def test_check_finite(self):
|
1283
|
+
a = [[1, 2, 3], [1, 2, 3], [2, 5, 6]]
|
1284
|
+
s = svdvals(a, check_finite=False)
|
1285
|
+
assert_(len(s) == 3)
|
1286
|
+
assert_(s[0] >= s[1] >= s[2])
|
1287
|
+
|
1288
|
+
@pytest.mark.slow
|
1289
|
+
def test_crash_2609(self):
|
1290
|
+
np.random.seed(1234)
|
1291
|
+
a = np.random.rand(1500, 2800)
|
1292
|
+
# Shouldn't crash:
|
1293
|
+
svdvals(a)
|
1294
|
+
|
1295
|
+
|
1296
|
+
class TestDiagSVD:
|
1297
|
+
|
1298
|
+
def test_simple(self):
|
1299
|
+
assert_array_almost_equal(diagsvd([1, 0, 0], 3, 3),
|
1300
|
+
[[1, 0, 0], [0, 0, 0], [0, 0, 0]])
|
1301
|
+
|
1302
|
+
|
1303
|
+
class TestQR:
|
1304
|
+
def test_simple(self):
|
1305
|
+
a = [[8, 2, 3], [2, 9, 3], [5, 3, 6]]
|
1306
|
+
q, r = qr(a)
|
1307
|
+
assert_array_almost_equal(q.T @ q, eye(3))
|
1308
|
+
assert_array_almost_equal(q @ r, a)
|
1309
|
+
|
1310
|
+
def test_simple_left(self):
|
1311
|
+
a = [[8, 2, 3], [2, 9, 3], [5, 3, 6]]
|
1312
|
+
q, r = qr(a)
|
1313
|
+
c = [1, 2, 3]
|
1314
|
+
qc, r2 = qr_multiply(a, c, "left")
|
1315
|
+
assert_array_almost_equal(q @ c, qc)
|
1316
|
+
assert_array_almost_equal(r, r2)
|
1317
|
+
qc, r2 = qr_multiply(a, eye(3), "left")
|
1318
|
+
assert_array_almost_equal(q, qc)
|
1319
|
+
|
1320
|
+
def test_simple_right(self):
|
1321
|
+
a = [[8, 2, 3], [2, 9, 3], [5, 3, 6]]
|
1322
|
+
q, r = qr(a)
|
1323
|
+
c = [1, 2, 3]
|
1324
|
+
qc, r2 = qr_multiply(a, c)
|
1325
|
+
assert_array_almost_equal(c @ q, qc)
|
1326
|
+
assert_array_almost_equal(r, r2)
|
1327
|
+
qc, r = qr_multiply(a, eye(3))
|
1328
|
+
assert_array_almost_equal(q, qc)
|
1329
|
+
|
1330
|
+
def test_simple_pivoting(self):
|
1331
|
+
a = np.asarray([[8, 2, 3], [2, 9, 3], [5, 3, 6]])
|
1332
|
+
q, r, p = qr(a, pivoting=True)
|
1333
|
+
d = abs(diag(r))
|
1334
|
+
assert_(np.all(d[1:] <= d[:-1]))
|
1335
|
+
assert_array_almost_equal(q.T @ q, eye(3))
|
1336
|
+
assert_array_almost_equal(q @ r, a[:, p])
|
1337
|
+
q2, r2 = qr(a[:, p])
|
1338
|
+
assert_array_almost_equal(q, q2)
|
1339
|
+
assert_array_almost_equal(r, r2)
|
1340
|
+
|
1341
|
+
def test_simple_left_pivoting(self):
|
1342
|
+
a = [[8, 2, 3], [2, 9, 3], [5, 3, 6]]
|
1343
|
+
q, r, jpvt = qr(a, pivoting=True)
|
1344
|
+
c = [1, 2, 3]
|
1345
|
+
qc, r, jpvt = qr_multiply(a, c, "left", True)
|
1346
|
+
assert_array_almost_equal(q @ c, qc)
|
1347
|
+
|
1348
|
+
def test_simple_right_pivoting(self):
|
1349
|
+
a = [[8, 2, 3], [2, 9, 3], [5, 3, 6]]
|
1350
|
+
q, r, jpvt = qr(a, pivoting=True)
|
1351
|
+
c = [1, 2, 3]
|
1352
|
+
qc, r, jpvt = qr_multiply(a, c, pivoting=True)
|
1353
|
+
assert_array_almost_equal(c @ q, qc)
|
1354
|
+
|
1355
|
+
def test_simple_trap(self):
|
1356
|
+
a = [[8, 2, 3], [2, 9, 3]]
|
1357
|
+
q, r = qr(a)
|
1358
|
+
assert_array_almost_equal(q.T @ q, eye(2))
|
1359
|
+
assert_array_almost_equal(q @ r, a)
|
1360
|
+
|
1361
|
+
def test_simple_trap_pivoting(self):
|
1362
|
+
a = np.asarray([[8, 2, 3], [2, 9, 3]])
|
1363
|
+
q, r, p = qr(a, pivoting=True)
|
1364
|
+
d = abs(diag(r))
|
1365
|
+
assert_(np.all(d[1:] <= d[:-1]))
|
1366
|
+
assert_array_almost_equal(q.T @ q, eye(2))
|
1367
|
+
assert_array_almost_equal(q @ r, a[:, p])
|
1368
|
+
q2, r2 = qr(a[:, p])
|
1369
|
+
assert_array_almost_equal(q, q2)
|
1370
|
+
assert_array_almost_equal(r, r2)
|
1371
|
+
|
1372
|
+
def test_simple_tall(self):
|
1373
|
+
# full version
|
1374
|
+
a = [[8, 2], [2, 9], [5, 3]]
|
1375
|
+
q, r = qr(a)
|
1376
|
+
assert_array_almost_equal(q.T @ q, eye(3))
|
1377
|
+
assert_array_almost_equal(q @ r, a)
|
1378
|
+
|
1379
|
+
def test_simple_tall_pivoting(self):
|
1380
|
+
# full version pivoting
|
1381
|
+
a = np.asarray([[8, 2], [2, 9], [5, 3]])
|
1382
|
+
q, r, p = qr(a, pivoting=True)
|
1383
|
+
d = abs(diag(r))
|
1384
|
+
assert_(np.all(d[1:] <= d[:-1]))
|
1385
|
+
assert_array_almost_equal(q.T @ q, eye(3))
|
1386
|
+
assert_array_almost_equal(q @ r, a[:, p])
|
1387
|
+
q2, r2 = qr(a[:, p])
|
1388
|
+
assert_array_almost_equal(q, q2)
|
1389
|
+
assert_array_almost_equal(r, r2)
|
1390
|
+
|
1391
|
+
def test_simple_tall_e(self):
|
1392
|
+
# economy version
|
1393
|
+
a = [[8, 2], [2, 9], [5, 3]]
|
1394
|
+
q, r = qr(a, mode='economic')
|
1395
|
+
assert_array_almost_equal(q.T @ q, eye(2))
|
1396
|
+
assert_array_almost_equal(q @ r, a)
|
1397
|
+
assert_equal(q.shape, (3, 2))
|
1398
|
+
assert_equal(r.shape, (2, 2))
|
1399
|
+
|
1400
|
+
def test_simple_tall_e_pivoting(self):
|
1401
|
+
# economy version pivoting
|
1402
|
+
a = np.asarray([[8, 2], [2, 9], [5, 3]])
|
1403
|
+
q, r, p = qr(a, pivoting=True, mode='economic')
|
1404
|
+
d = abs(diag(r))
|
1405
|
+
assert_(np.all(d[1:] <= d[:-1]))
|
1406
|
+
assert_array_almost_equal(q.T @ q, eye(2))
|
1407
|
+
assert_array_almost_equal(q @ r, a[:, p])
|
1408
|
+
q2, r2 = qr(a[:, p], mode='economic')
|
1409
|
+
assert_array_almost_equal(q, q2)
|
1410
|
+
assert_array_almost_equal(r, r2)
|
1411
|
+
|
1412
|
+
def test_simple_tall_left(self):
|
1413
|
+
a = [[8, 2], [2, 9], [5, 3]]
|
1414
|
+
q, r = qr(a, mode="economic")
|
1415
|
+
c = [1, 2]
|
1416
|
+
qc, r2 = qr_multiply(a, c, "left")
|
1417
|
+
assert_array_almost_equal(q @ c, qc)
|
1418
|
+
assert_array_almost_equal(r, r2)
|
1419
|
+
c = array([1, 2, 0])
|
1420
|
+
qc, r2 = qr_multiply(a, c, "left", overwrite_c=True)
|
1421
|
+
assert_array_almost_equal(q @ c[:2], qc)
|
1422
|
+
qc, r = qr_multiply(a, eye(2), "left")
|
1423
|
+
assert_array_almost_equal(qc, q)
|
1424
|
+
|
1425
|
+
def test_simple_tall_left_pivoting(self):
|
1426
|
+
a = [[8, 2], [2, 9], [5, 3]]
|
1427
|
+
q, r, jpvt = qr(a, mode="economic", pivoting=True)
|
1428
|
+
c = [1, 2]
|
1429
|
+
qc, r, kpvt = qr_multiply(a, c, "left", True)
|
1430
|
+
assert_array_equal(jpvt, kpvt)
|
1431
|
+
assert_array_almost_equal(q @ c, qc)
|
1432
|
+
qc, r, jpvt = qr_multiply(a, eye(2), "left", True)
|
1433
|
+
assert_array_almost_equal(qc, q)
|
1434
|
+
|
1435
|
+
def test_simple_tall_right(self):
|
1436
|
+
a = [[8, 2], [2, 9], [5, 3]]
|
1437
|
+
q, r = qr(a, mode="economic")
|
1438
|
+
c = [1, 2, 3]
|
1439
|
+
cq, r2 = qr_multiply(a, c)
|
1440
|
+
assert_array_almost_equal(c @ q, cq)
|
1441
|
+
assert_array_almost_equal(r, r2)
|
1442
|
+
cq, r = qr_multiply(a, eye(3))
|
1443
|
+
assert_array_almost_equal(cq, q)
|
1444
|
+
|
1445
|
+
def test_simple_tall_right_pivoting(self):
|
1446
|
+
a = [[8, 2], [2, 9], [5, 3]]
|
1447
|
+
q, r, jpvt = qr(a, pivoting=True, mode="economic")
|
1448
|
+
c = [1, 2, 3]
|
1449
|
+
cq, r, jpvt = qr_multiply(a, c, pivoting=True)
|
1450
|
+
assert_array_almost_equal(c @ q, cq)
|
1451
|
+
cq, r, jpvt = qr_multiply(a, eye(3), pivoting=True)
|
1452
|
+
assert_array_almost_equal(cq, q)
|
1453
|
+
|
1454
|
+
def test_simple_fat(self):
|
1455
|
+
# full version
|
1456
|
+
a = [[8, 2, 5], [2, 9, 3]]
|
1457
|
+
q, r = qr(a)
|
1458
|
+
assert_array_almost_equal(q.T @ q, eye(2))
|
1459
|
+
assert_array_almost_equal(q @ r, a)
|
1460
|
+
assert_equal(q.shape, (2, 2))
|
1461
|
+
assert_equal(r.shape, (2, 3))
|
1462
|
+
|
1463
|
+
def test_simple_fat_pivoting(self):
|
1464
|
+
# full version pivoting
|
1465
|
+
a = np.asarray([[8, 2, 5], [2, 9, 3]])
|
1466
|
+
q, r, p = qr(a, pivoting=True)
|
1467
|
+
d = abs(diag(r))
|
1468
|
+
assert_(np.all(d[1:] <= d[:-1]))
|
1469
|
+
assert_array_almost_equal(q.T @ q, eye(2))
|
1470
|
+
assert_array_almost_equal(q @ r, a[:, p])
|
1471
|
+
assert_equal(q.shape, (2, 2))
|
1472
|
+
assert_equal(r.shape, (2, 3))
|
1473
|
+
q2, r2 = qr(a[:, p])
|
1474
|
+
assert_array_almost_equal(q, q2)
|
1475
|
+
assert_array_almost_equal(r, r2)
|
1476
|
+
|
1477
|
+
def test_simple_fat_e(self):
|
1478
|
+
# economy version
|
1479
|
+
a = [[8, 2, 3], [2, 9, 5]]
|
1480
|
+
q, r = qr(a, mode='economic')
|
1481
|
+
assert_array_almost_equal(q.T @ q, eye(2))
|
1482
|
+
assert_array_almost_equal(q @ r, a)
|
1483
|
+
assert_equal(q.shape, (2, 2))
|
1484
|
+
assert_equal(r.shape, (2, 3))
|
1485
|
+
|
1486
|
+
def test_simple_fat_e_pivoting(self):
|
1487
|
+
# economy version pivoting
|
1488
|
+
a = np.asarray([[8, 2, 3], [2, 9, 5]])
|
1489
|
+
q, r, p = qr(a, pivoting=True, mode='economic')
|
1490
|
+
d = abs(diag(r))
|
1491
|
+
assert_(np.all(d[1:] <= d[:-1]))
|
1492
|
+
assert_array_almost_equal(q.T @ q, eye(2))
|
1493
|
+
assert_array_almost_equal(q @ r, a[:, p])
|
1494
|
+
assert_equal(q.shape, (2, 2))
|
1495
|
+
assert_equal(r.shape, (2, 3))
|
1496
|
+
q2, r2 = qr(a[:, p], mode='economic')
|
1497
|
+
assert_array_almost_equal(q, q2)
|
1498
|
+
assert_array_almost_equal(r, r2)
|
1499
|
+
|
1500
|
+
def test_simple_fat_left(self):
|
1501
|
+
a = [[8, 2, 3], [2, 9, 5]]
|
1502
|
+
q, r = qr(a, mode="economic")
|
1503
|
+
c = [1, 2]
|
1504
|
+
qc, r2 = qr_multiply(a, c, "left")
|
1505
|
+
assert_array_almost_equal(q @ c, qc)
|
1506
|
+
assert_array_almost_equal(r, r2)
|
1507
|
+
qc, r = qr_multiply(a, eye(2), "left")
|
1508
|
+
assert_array_almost_equal(qc, q)
|
1509
|
+
|
1510
|
+
def test_simple_fat_left_pivoting(self):
|
1511
|
+
a = [[8, 2, 3], [2, 9, 5]]
|
1512
|
+
q, r, jpvt = qr(a, mode="economic", pivoting=True)
|
1513
|
+
c = [1, 2]
|
1514
|
+
qc, r, jpvt = qr_multiply(a, c, "left", True)
|
1515
|
+
assert_array_almost_equal(q @ c, qc)
|
1516
|
+
qc, r, jpvt = qr_multiply(a, eye(2), "left", True)
|
1517
|
+
assert_array_almost_equal(qc, q)
|
1518
|
+
|
1519
|
+
def test_simple_fat_right(self):
|
1520
|
+
a = [[8, 2, 3], [2, 9, 5]]
|
1521
|
+
q, r = qr(a, mode="economic")
|
1522
|
+
c = [1, 2]
|
1523
|
+
cq, r2 = qr_multiply(a, c)
|
1524
|
+
assert_array_almost_equal(c @ q, cq)
|
1525
|
+
assert_array_almost_equal(r, r2)
|
1526
|
+
cq, r = qr_multiply(a, eye(2))
|
1527
|
+
assert_array_almost_equal(cq, q)
|
1528
|
+
|
1529
|
+
def test_simple_fat_right_pivoting(self):
|
1530
|
+
a = [[8, 2, 3], [2, 9, 5]]
|
1531
|
+
q, r, jpvt = qr(a, pivoting=True, mode="economic")
|
1532
|
+
c = [1, 2]
|
1533
|
+
cq, r, jpvt = qr_multiply(a, c, pivoting=True)
|
1534
|
+
assert_array_almost_equal(c @ q, cq)
|
1535
|
+
cq, r, jpvt = qr_multiply(a, eye(2), pivoting=True)
|
1536
|
+
assert_array_almost_equal(cq, q)
|
1537
|
+
|
1538
|
+
def test_simple_complex(self):
|
1539
|
+
a = [[3, 3+4j, 5], [5, 2, 2+7j], [3, 2, 7]]
|
1540
|
+
q, r = qr(a)
|
1541
|
+
assert_array_almost_equal(q.conj().T @ q, eye(3))
|
1542
|
+
assert_array_almost_equal(q @ r, a)
|
1543
|
+
|
1544
|
+
def test_simple_complex_left(self):
|
1545
|
+
a = [[3, 3+4j, 5], [5, 2, 2+7j], [3, 2, 7]]
|
1546
|
+
q, r = qr(a)
|
1547
|
+
c = [1, 2, 3+4j]
|
1548
|
+
qc, r = qr_multiply(a, c, "left")
|
1549
|
+
assert_array_almost_equal(q @ c, qc)
|
1550
|
+
qc, r = qr_multiply(a, eye(3), "left")
|
1551
|
+
assert_array_almost_equal(q, qc)
|
1552
|
+
|
1553
|
+
def test_simple_complex_right(self):
|
1554
|
+
a = [[3, 3+4j, 5], [5, 2, 2+7j], [3, 2, 7]]
|
1555
|
+
q, r = qr(a)
|
1556
|
+
c = [1, 2, 3+4j]
|
1557
|
+
qc, r = qr_multiply(a, c)
|
1558
|
+
assert_array_almost_equal(c @ q, qc)
|
1559
|
+
qc, r = qr_multiply(a, eye(3))
|
1560
|
+
assert_array_almost_equal(q, qc)
|
1561
|
+
|
1562
|
+
def test_simple_tall_complex_left(self):
|
1563
|
+
a = [[8, 2+3j], [2, 9], [5+7j, 3]]
|
1564
|
+
q, r = qr(a, mode="economic")
|
1565
|
+
c = [1, 2+2j]
|
1566
|
+
qc, r2 = qr_multiply(a, c, "left")
|
1567
|
+
assert_array_almost_equal(q @ c, qc)
|
1568
|
+
assert_array_almost_equal(r, r2)
|
1569
|
+
c = array([1, 2, 0])
|
1570
|
+
qc, r2 = qr_multiply(a, c, "left", overwrite_c=True)
|
1571
|
+
assert_array_almost_equal(q @ c[:2], qc)
|
1572
|
+
qc, r = qr_multiply(a, eye(2), "left")
|
1573
|
+
assert_array_almost_equal(qc, q)
|
1574
|
+
|
1575
|
+
def test_simple_complex_left_conjugate(self):
|
1576
|
+
a = [[3, 3+4j, 5], [5, 2, 2+7j], [3, 2, 7]]
|
1577
|
+
q, r = qr(a)
|
1578
|
+
c = [1, 2, 3+4j]
|
1579
|
+
qc, r = qr_multiply(a, c, "left", conjugate=True)
|
1580
|
+
assert_array_almost_equal(q.conj() @ c, qc)
|
1581
|
+
|
1582
|
+
def test_simple_complex_tall_left_conjugate(self):
|
1583
|
+
a = [[3, 3+4j], [5, 2+2j], [3, 2]]
|
1584
|
+
q, r = qr(a, mode='economic')
|
1585
|
+
c = [1, 3+4j]
|
1586
|
+
qc, r = qr_multiply(a, c, "left", conjugate=True)
|
1587
|
+
assert_array_almost_equal(q.conj() @ c, qc)
|
1588
|
+
|
1589
|
+
def test_simple_complex_right_conjugate(self):
|
1590
|
+
a = [[3, 3+4j, 5], [5, 2, 2+7j], [3, 2, 7]]
|
1591
|
+
q, r = qr(a)
|
1592
|
+
c = np.array([1, 2, 3+4j])
|
1593
|
+
qc, r = qr_multiply(a, c, conjugate=True)
|
1594
|
+
assert_array_almost_equal(c @ q.conj(), qc)
|
1595
|
+
|
1596
|
+
def test_simple_complex_pivoting(self):
|
1597
|
+
a = array([[3, 3+4j, 5], [5, 2, 2+7j], [3, 2, 7]])
|
1598
|
+
q, r, p = qr(a, pivoting=True)
|
1599
|
+
d = abs(diag(r))
|
1600
|
+
assert_(np.all(d[1:] <= d[:-1]))
|
1601
|
+
assert_array_almost_equal(q.conj().T @ q, eye(3))
|
1602
|
+
assert_array_almost_equal(q @ r, a[:, p])
|
1603
|
+
q2, r2 = qr(a[:, p])
|
1604
|
+
assert_array_almost_equal(q, q2)
|
1605
|
+
assert_array_almost_equal(r, r2)
|
1606
|
+
|
1607
|
+
def test_simple_complex_left_pivoting(self):
|
1608
|
+
a = array([[3, 3+4j, 5], [5, 2, 2+7j], [3, 2, 7]])
|
1609
|
+
q, r, jpvt = qr(a, pivoting=True)
|
1610
|
+
c = [1, 2, 3+4j]
|
1611
|
+
qc, r, jpvt = qr_multiply(a, c, "left", True)
|
1612
|
+
assert_array_almost_equal(q @ c, qc)
|
1613
|
+
|
1614
|
+
def test_simple_complex_right_pivoting(self):
|
1615
|
+
a = array([[3, 3+4j, 5], [5, 2, 2+7j], [3, 2, 7]])
|
1616
|
+
q, r, jpvt = qr(a, pivoting=True)
|
1617
|
+
c = [1, 2, 3+4j]
|
1618
|
+
qc, r, jpvt = qr_multiply(a, c, pivoting=True)
|
1619
|
+
assert_array_almost_equal(c @ q, qc)
|
1620
|
+
|
1621
|
+
def test_random(self):
|
1622
|
+
rng = np.random.RandomState(1234)
|
1623
|
+
n = 20
|
1624
|
+
for k in range(2):
|
1625
|
+
a = rng.random([n, n])
|
1626
|
+
q, r = qr(a)
|
1627
|
+
assert_array_almost_equal(q.T @ q, eye(n))
|
1628
|
+
assert_array_almost_equal(q @ r, a)
|
1629
|
+
|
1630
|
+
def test_random_left(self):
|
1631
|
+
rng = np.random.RandomState(1234)
|
1632
|
+
n = 20
|
1633
|
+
for k in range(2):
|
1634
|
+
a = rng.random([n, n])
|
1635
|
+
q, r = qr(a)
|
1636
|
+
c = rng.random([n])
|
1637
|
+
qc, r = qr_multiply(a, c, "left")
|
1638
|
+
assert_array_almost_equal(q @ c, qc)
|
1639
|
+
qc, r = qr_multiply(a, eye(n), "left")
|
1640
|
+
assert_array_almost_equal(q, qc)
|
1641
|
+
|
1642
|
+
def test_random_right(self):
|
1643
|
+
rng = np.random.RandomState(1234)
|
1644
|
+
n = 20
|
1645
|
+
for k in range(2):
|
1646
|
+
a = rng.random([n, n])
|
1647
|
+
q, r = qr(a)
|
1648
|
+
c = rng.random([n])
|
1649
|
+
cq, r = qr_multiply(a, c)
|
1650
|
+
assert_array_almost_equal(c @ q, cq)
|
1651
|
+
cq, r = qr_multiply(a, eye(n))
|
1652
|
+
assert_array_almost_equal(q, cq)
|
1653
|
+
|
1654
|
+
def test_random_pivoting(self):
|
1655
|
+
rng = np.random.RandomState(1234)
|
1656
|
+
n = 20
|
1657
|
+
for k in range(2):
|
1658
|
+
a = rng.random([n, n])
|
1659
|
+
q, r, p = qr(a, pivoting=True)
|
1660
|
+
d = abs(diag(r))
|
1661
|
+
assert_(np.all(d[1:] <= d[:-1]))
|
1662
|
+
assert_array_almost_equal(q.T @ q, eye(n))
|
1663
|
+
assert_array_almost_equal(q @ r, a[:, p])
|
1664
|
+
q2, r2 = qr(a[:, p])
|
1665
|
+
assert_array_almost_equal(q, q2)
|
1666
|
+
assert_array_almost_equal(r, r2)
|
1667
|
+
|
1668
|
+
def test_random_tall(self):
|
1669
|
+
rng = np.random.RandomState(1234)
|
1670
|
+
# full version
|
1671
|
+
m = 200
|
1672
|
+
n = 100
|
1673
|
+
for k in range(2):
|
1674
|
+
a = rng.random([m, n])
|
1675
|
+
q, r = qr(a)
|
1676
|
+
assert_array_almost_equal(q.T @ q, eye(m))
|
1677
|
+
assert_array_almost_equal(q @ r, a)
|
1678
|
+
|
1679
|
+
def test_random_tall_left(self):
|
1680
|
+
rng = np.random.RandomState(1234)
|
1681
|
+
# full version
|
1682
|
+
m = 200
|
1683
|
+
n = 100
|
1684
|
+
for k in range(2):
|
1685
|
+
a = rng.random([m, n])
|
1686
|
+
q, r = qr(a, mode="economic")
|
1687
|
+
c = rng.random([n])
|
1688
|
+
qc, r = qr_multiply(a, c, "left")
|
1689
|
+
assert_array_almost_equal(q @ c, qc)
|
1690
|
+
qc, r = qr_multiply(a, eye(n), "left")
|
1691
|
+
assert_array_almost_equal(qc, q)
|
1692
|
+
|
1693
|
+
def test_random_tall_right(self):
|
1694
|
+
rng = np.random.RandomState(1234)
|
1695
|
+
# full version
|
1696
|
+
m = 200
|
1697
|
+
n = 100
|
1698
|
+
for k in range(2):
|
1699
|
+
a = rng.random([m, n])
|
1700
|
+
q, r = qr(a, mode="economic")
|
1701
|
+
c = rng.random([m])
|
1702
|
+
cq, r = qr_multiply(a, c)
|
1703
|
+
assert_array_almost_equal(c @ q, cq)
|
1704
|
+
cq, r = qr_multiply(a, eye(m))
|
1705
|
+
assert_array_almost_equal(cq, q)
|
1706
|
+
|
1707
|
+
def test_random_tall_pivoting(self):
|
1708
|
+
rng = np.random.RandomState(1234)
|
1709
|
+
# full version pivoting
|
1710
|
+
m = 200
|
1711
|
+
n = 100
|
1712
|
+
for k in range(2):
|
1713
|
+
a = rng.random([m, n])
|
1714
|
+
q, r, p = qr(a, pivoting=True)
|
1715
|
+
d = abs(diag(r))
|
1716
|
+
assert_(np.all(d[1:] <= d[:-1]))
|
1717
|
+
assert_array_almost_equal(q.T @ q, eye(m))
|
1718
|
+
assert_array_almost_equal(q @ r, a[:, p])
|
1719
|
+
q2, r2 = qr(a[:, p])
|
1720
|
+
assert_array_almost_equal(q, q2)
|
1721
|
+
assert_array_almost_equal(r, r2)
|
1722
|
+
|
1723
|
+
def test_random_tall_e(self):
|
1724
|
+
rng = np.random.RandomState(1234)
|
1725
|
+
# economy version
|
1726
|
+
m = 200
|
1727
|
+
n = 100
|
1728
|
+
for k in range(2):
|
1729
|
+
a = rng.random([m, n])
|
1730
|
+
q, r = qr(a, mode='economic')
|
1731
|
+
assert_array_almost_equal(q.T @ q, eye(n))
|
1732
|
+
assert_array_almost_equal(q @ r, a)
|
1733
|
+
assert_equal(q.shape, (m, n))
|
1734
|
+
assert_equal(r.shape, (n, n))
|
1735
|
+
|
1736
|
+
def test_random_tall_e_pivoting(self):
|
1737
|
+
rng = np.random.RandomState(1234)
|
1738
|
+
# economy version pivoting
|
1739
|
+
m = 200
|
1740
|
+
n = 100
|
1741
|
+
for k in range(2):
|
1742
|
+
a = rng.random([m, n])
|
1743
|
+
q, r, p = qr(a, pivoting=True, mode='economic')
|
1744
|
+
d = abs(diag(r))
|
1745
|
+
assert_(np.all(d[1:] <= d[:-1]))
|
1746
|
+
assert_array_almost_equal(q.T @ q, eye(n))
|
1747
|
+
assert_array_almost_equal(q @ r, a[:, p])
|
1748
|
+
assert_equal(q.shape, (m, n))
|
1749
|
+
assert_equal(r.shape, (n, n))
|
1750
|
+
q2, r2 = qr(a[:, p], mode='economic')
|
1751
|
+
assert_array_almost_equal(q, q2)
|
1752
|
+
assert_array_almost_equal(r, r2)
|
1753
|
+
|
1754
|
+
def test_random_trap(self):
|
1755
|
+
rng = np.random.RandomState(1234)
|
1756
|
+
m = 100
|
1757
|
+
n = 200
|
1758
|
+
for k in range(2):
|
1759
|
+
a = rng.random([m, n])
|
1760
|
+
q, r = qr(a)
|
1761
|
+
assert_array_almost_equal(q.T @ q, eye(m))
|
1762
|
+
assert_array_almost_equal(q @ r, a)
|
1763
|
+
|
1764
|
+
def test_random_trap_pivoting(self):
|
1765
|
+
rng = np.random.RandomState(1234)
|
1766
|
+
m = 100
|
1767
|
+
n = 200
|
1768
|
+
for k in range(2):
|
1769
|
+
a = rng.random([m, n])
|
1770
|
+
q, r, p = qr(a, pivoting=True)
|
1771
|
+
d = abs(diag(r))
|
1772
|
+
assert_(np.all(d[1:] <= d[:-1]))
|
1773
|
+
assert_array_almost_equal(q.T @ q, eye(m))
|
1774
|
+
assert_array_almost_equal(q @ r, a[:, p])
|
1775
|
+
q2, r2 = qr(a[:, p])
|
1776
|
+
assert_array_almost_equal(q, q2)
|
1777
|
+
assert_array_almost_equal(r, r2)
|
1778
|
+
|
1779
|
+
def test_random_complex(self):
|
1780
|
+
rng = np.random.RandomState(1234)
|
1781
|
+
n = 20
|
1782
|
+
for k in range(2):
|
1783
|
+
a = rng.random([n, n]) + 1j*rng.random([n, n])
|
1784
|
+
q, r = qr(a)
|
1785
|
+
assert_array_almost_equal(q.conj().T @ q, eye(n))
|
1786
|
+
assert_array_almost_equal(q @ r, a)
|
1787
|
+
|
1788
|
+
def test_random_complex_left(self):
|
1789
|
+
rng = np.random.RandomState(1234)
|
1790
|
+
n = 20
|
1791
|
+
for k in range(2):
|
1792
|
+
a = rng.random([n, n]) + 1j*rng.random([n, n])
|
1793
|
+
q, r = qr(a)
|
1794
|
+
c = rng.random([n]) + 1j*rng.random([n])
|
1795
|
+
qc, r = qr_multiply(a, c, "left")
|
1796
|
+
assert_array_almost_equal(q @ c, qc)
|
1797
|
+
qc, r = qr_multiply(a, eye(n), "left")
|
1798
|
+
assert_array_almost_equal(q, qc)
|
1799
|
+
|
1800
|
+
def test_random_complex_right(self):
|
1801
|
+
rng = np.random.RandomState(1234)
|
1802
|
+
n = 20
|
1803
|
+
for k in range(2):
|
1804
|
+
a = rng.random([n, n]) + 1j*rng.random([n, n])
|
1805
|
+
q, r = qr(a)
|
1806
|
+
c = rng.random([n]) + 1j*rng.random([n])
|
1807
|
+
cq, r = qr_multiply(a, c)
|
1808
|
+
assert_array_almost_equal(c @ q, cq)
|
1809
|
+
cq, r = qr_multiply(a, eye(n))
|
1810
|
+
assert_array_almost_equal(q, cq)
|
1811
|
+
|
1812
|
+
def test_random_complex_pivoting(self):
|
1813
|
+
rng = np.random.RandomState(1234)
|
1814
|
+
n = 20
|
1815
|
+
for k in range(2):
|
1816
|
+
a = rng.random([n, n]) + 1j*rng.random([n, n])
|
1817
|
+
q, r, p = qr(a, pivoting=True)
|
1818
|
+
d = abs(diag(r))
|
1819
|
+
assert_(np.all(d[1:] <= d[:-1]))
|
1820
|
+
assert_array_almost_equal(q.conj().T @ q, eye(n))
|
1821
|
+
assert_array_almost_equal(q @ r, a[:, p])
|
1822
|
+
q2, r2 = qr(a[:, p])
|
1823
|
+
assert_array_almost_equal(q, q2)
|
1824
|
+
assert_array_almost_equal(r, r2)
|
1825
|
+
|
1826
|
+
def test_check_finite(self):
|
1827
|
+
a = [[8, 2, 3], [2, 9, 3], [5, 3, 6]]
|
1828
|
+
q, r = qr(a, check_finite=False)
|
1829
|
+
assert_array_almost_equal(q.T @ q, eye(3))
|
1830
|
+
assert_array_almost_equal(q @ r, a)
|
1831
|
+
|
1832
|
+
def test_lwork(self):
|
1833
|
+
a = [[8, 2, 3], [2, 9, 3], [5, 3, 6]]
|
1834
|
+
# Get comparison values
|
1835
|
+
q, r = qr(a, lwork=None)
|
1836
|
+
|
1837
|
+
# Test against minimum valid lwork
|
1838
|
+
q2, r2 = qr(a, lwork=3)
|
1839
|
+
assert_array_almost_equal(q2, q)
|
1840
|
+
assert_array_almost_equal(r2, r)
|
1841
|
+
|
1842
|
+
# Test against larger lwork
|
1843
|
+
q3, r3 = qr(a, lwork=10)
|
1844
|
+
assert_array_almost_equal(q3, q)
|
1845
|
+
assert_array_almost_equal(r3, r)
|
1846
|
+
|
1847
|
+
# Test against explicit lwork=-1
|
1848
|
+
q4, r4 = qr(a, lwork=-1)
|
1849
|
+
assert_array_almost_equal(q4, q)
|
1850
|
+
assert_array_almost_equal(r4, r)
|
1851
|
+
|
1852
|
+
# Test against invalid lwork
|
1853
|
+
assert_raises(Exception, qr, (a,), {'lwork': 0})
|
1854
|
+
assert_raises(Exception, qr, (a,), {'lwork': 2})
|
1855
|
+
|
1856
|
+
@pytest.mark.parametrize("m", [0, 1, 2])
|
1857
|
+
@pytest.mark.parametrize("n", [0, 1, 2])
|
1858
|
+
@pytest.mark.parametrize("pivoting", [False, True])
|
1859
|
+
@pytest.mark.parametrize('dtype', DTYPES)
|
1860
|
+
def test_shape_dtype(self, m, n, pivoting, dtype):
|
1861
|
+
k = min(m, n)
|
1862
|
+
|
1863
|
+
a = np.zeros((m, n), dtype=dtype)
|
1864
|
+
q, r, *other = qr(a, pivoting=pivoting)
|
1865
|
+
assert_equal(q.shape, (m, m))
|
1866
|
+
assert_equal(q.dtype, dtype)
|
1867
|
+
assert_equal(r.shape, (m, n))
|
1868
|
+
assert_equal(r.dtype, dtype)
|
1869
|
+
assert len(other) == (1 if pivoting else 0)
|
1870
|
+
if pivoting:
|
1871
|
+
p, = other
|
1872
|
+
assert_equal(p.shape, (n,))
|
1873
|
+
assert_equal(p.dtype, np.int32)
|
1874
|
+
|
1875
|
+
r, *other = qr(a, mode='r', pivoting=pivoting)
|
1876
|
+
assert_equal(r.shape, (m, n))
|
1877
|
+
assert_equal(r.dtype, dtype)
|
1878
|
+
assert len(other) == (1 if pivoting else 0)
|
1879
|
+
if pivoting:
|
1880
|
+
p, = other
|
1881
|
+
assert_equal(p.shape, (n,))
|
1882
|
+
assert_equal(p.dtype, np.int32)
|
1883
|
+
|
1884
|
+
q, r, *other = qr(a, mode='economic', pivoting=pivoting)
|
1885
|
+
assert_equal(q.shape, (m, k))
|
1886
|
+
assert_equal(q.dtype, dtype)
|
1887
|
+
assert_equal(r.shape, (k, n))
|
1888
|
+
assert_equal(r.dtype, dtype)
|
1889
|
+
assert len(other) == (1 if pivoting else 0)
|
1890
|
+
if pivoting:
|
1891
|
+
p, = other
|
1892
|
+
assert_equal(p.shape, (n,))
|
1893
|
+
assert_equal(p.dtype, np.int32)
|
1894
|
+
|
1895
|
+
(raw, tau), r, *other = qr(a, mode='raw', pivoting=pivoting)
|
1896
|
+
assert_equal(raw.shape, (m, n))
|
1897
|
+
assert_equal(raw.dtype, dtype)
|
1898
|
+
assert_equal(tau.shape, (k,))
|
1899
|
+
assert_equal(tau.dtype, dtype)
|
1900
|
+
assert_equal(r.shape, (k, n))
|
1901
|
+
assert_equal(r.dtype, dtype)
|
1902
|
+
assert len(other) == (1 if pivoting else 0)
|
1903
|
+
if pivoting:
|
1904
|
+
p, = other
|
1905
|
+
assert_equal(p.shape, (n,))
|
1906
|
+
assert_equal(p.dtype, np.int32)
|
1907
|
+
|
1908
|
+
@pytest.mark.parametrize(("m", "n"), [(0, 0), (0, 2), (2, 0)])
|
1909
|
+
def test_empty(self, m, n):
|
1910
|
+
k = min(m, n)
|
1911
|
+
|
1912
|
+
a = np.empty((m, n))
|
1913
|
+
q, r = qr(a)
|
1914
|
+
assert_allclose(q, np.identity(m))
|
1915
|
+
assert_allclose(r, np.empty((m, n)))
|
1916
|
+
|
1917
|
+
q, r, p = qr(a, pivoting=True)
|
1918
|
+
assert_allclose(q, np.identity(m))
|
1919
|
+
assert_allclose(r, np.empty((m, n)))
|
1920
|
+
assert_allclose(p, np.arange(n))
|
1921
|
+
|
1922
|
+
r, = qr(a, mode='r')
|
1923
|
+
assert_allclose(r, np.empty((m, n)))
|
1924
|
+
|
1925
|
+
q, r = qr(a, mode='economic')
|
1926
|
+
assert_allclose(q, np.empty((m, k)))
|
1927
|
+
assert_allclose(r, np.empty((k, n)))
|
1928
|
+
|
1929
|
+
(raw, tau), r = qr(a, mode='raw')
|
1930
|
+
assert_allclose(raw, np.empty((m, n)))
|
1931
|
+
assert_allclose(tau, np.empty((k,)))
|
1932
|
+
assert_allclose(r, np.empty((k, n)))
|
1933
|
+
|
1934
|
+
def test_multiply_empty(self):
|
1935
|
+
a = np.empty((0, 0))
|
1936
|
+
c = np.empty((0, 0))
|
1937
|
+
cq, r = qr_multiply(a, c)
|
1938
|
+
assert_allclose(cq, np.empty((0, 0)))
|
1939
|
+
|
1940
|
+
a = np.empty((0, 2))
|
1941
|
+
c = np.empty((2, 0))
|
1942
|
+
cq, r = qr_multiply(a, c)
|
1943
|
+
assert_allclose(cq, np.empty((2, 0)))
|
1944
|
+
|
1945
|
+
a = np.empty((2, 0))
|
1946
|
+
c = np.empty((0, 2))
|
1947
|
+
cq, r = qr_multiply(a, c)
|
1948
|
+
assert_allclose(cq, np.empty((0, 2)))
|
1949
|
+
|
1950
|
+
|
1951
|
+
class TestRQ:
|
1952
|
+
def test_simple(self):
|
1953
|
+
a = [[8, 2, 3], [2, 9, 3], [5, 3, 6]]
|
1954
|
+
r, q = rq(a)
|
1955
|
+
assert_array_almost_equal(q @ q.T, eye(3))
|
1956
|
+
assert_array_almost_equal(r @ q, a)
|
1957
|
+
|
1958
|
+
def test_r(self):
|
1959
|
+
a = [[8, 2, 3], [2, 9, 3], [5, 3, 6]]
|
1960
|
+
r, q = rq(a)
|
1961
|
+
r2 = rq(a, mode='r')
|
1962
|
+
assert_array_almost_equal(r, r2)
|
1963
|
+
|
1964
|
+
def test_random(self):
|
1965
|
+
rng = np.random.RandomState(1234)
|
1966
|
+
n = 20
|
1967
|
+
for k in range(2):
|
1968
|
+
a = rng.random([n, n])
|
1969
|
+
r, q = rq(a)
|
1970
|
+
assert_array_almost_equal(q @ q.T, eye(n))
|
1971
|
+
assert_array_almost_equal(r @ q, a)
|
1972
|
+
|
1973
|
+
def test_simple_trap(self):
|
1974
|
+
a = [[8, 2, 3], [2, 9, 3]]
|
1975
|
+
r, q = rq(a)
|
1976
|
+
assert_array_almost_equal(q.T @ q, eye(3))
|
1977
|
+
assert_array_almost_equal(r @ q, a)
|
1978
|
+
|
1979
|
+
def test_simple_tall(self):
|
1980
|
+
a = [[8, 2], [2, 9], [5, 3]]
|
1981
|
+
r, q = rq(a)
|
1982
|
+
assert_array_almost_equal(q.T @ q, eye(2))
|
1983
|
+
assert_array_almost_equal(r @ q, a)
|
1984
|
+
|
1985
|
+
def test_simple_fat(self):
|
1986
|
+
a = [[8, 2, 5], [2, 9, 3]]
|
1987
|
+
r, q = rq(a)
|
1988
|
+
assert_array_almost_equal(q @ q.T, eye(3))
|
1989
|
+
assert_array_almost_equal(r @ q, a)
|
1990
|
+
|
1991
|
+
def test_simple_complex(self):
|
1992
|
+
a = [[3, 3+4j, 5], [5, 2, 2+7j], [3, 2, 7]]
|
1993
|
+
r, q = rq(a)
|
1994
|
+
assert_array_almost_equal(q @ q.conj().T, eye(3))
|
1995
|
+
assert_array_almost_equal(r @ q, a)
|
1996
|
+
|
1997
|
+
def test_random_tall(self):
|
1998
|
+
rng = np.random.RandomState(1234)
|
1999
|
+
m = 200
|
2000
|
+
n = 100
|
2001
|
+
for k in range(2):
|
2002
|
+
a = rng.random([m, n])
|
2003
|
+
r, q = rq(a)
|
2004
|
+
assert_array_almost_equal(q @ q.T, eye(n))
|
2005
|
+
assert_array_almost_equal(r @ q, a)
|
2006
|
+
|
2007
|
+
def test_random_trap(self):
|
2008
|
+
rng = np.random.RandomState(1234)
|
2009
|
+
m = 100
|
2010
|
+
n = 200
|
2011
|
+
for k in range(2):
|
2012
|
+
a = rng.random([m, n])
|
2013
|
+
r, q = rq(a)
|
2014
|
+
assert_array_almost_equal(q @ q.T, eye(n))
|
2015
|
+
assert_array_almost_equal(r @ q, a)
|
2016
|
+
|
2017
|
+
def test_random_trap_economic(self):
|
2018
|
+
rng = np.random.RandomState(1234)
|
2019
|
+
m = 100
|
2020
|
+
n = 200
|
2021
|
+
for k in range(2):
|
2022
|
+
a = rng.random([m, n])
|
2023
|
+
r, q = rq(a, mode='economic')
|
2024
|
+
assert_array_almost_equal(q @ q.T, eye(m))
|
2025
|
+
assert_array_almost_equal(r @ q, a)
|
2026
|
+
assert_equal(q.shape, (m, n))
|
2027
|
+
assert_equal(r.shape, (m, m))
|
2028
|
+
|
2029
|
+
def test_random_complex(self):
|
2030
|
+
rng = np.random.RandomState(1234)
|
2031
|
+
n = 20
|
2032
|
+
for k in range(2):
|
2033
|
+
a = rng.random([n, n]) + 1j*rng.random([n, n])
|
2034
|
+
r, q = rq(a)
|
2035
|
+
assert_array_almost_equal(q @ q.conj().T, eye(n))
|
2036
|
+
assert_array_almost_equal(r @ q, a)
|
2037
|
+
|
2038
|
+
def test_random_complex_economic(self):
|
2039
|
+
rng = np.random.RandomState(1234)
|
2040
|
+
m = 100
|
2041
|
+
n = 200
|
2042
|
+
for k in range(2):
|
2043
|
+
a = rng.random([m, n]) + 1j*rng.random([m, n])
|
2044
|
+
r, q = rq(a, mode='economic')
|
2045
|
+
assert_array_almost_equal(q @ q.conj().T, eye(m))
|
2046
|
+
assert_array_almost_equal(r @ q, a)
|
2047
|
+
assert_equal(q.shape, (m, n))
|
2048
|
+
assert_equal(r.shape, (m, m))
|
2049
|
+
|
2050
|
+
def test_check_finite(self):
|
2051
|
+
a = [[8, 2, 3], [2, 9, 3], [5, 3, 6]]
|
2052
|
+
r, q = rq(a, check_finite=False)
|
2053
|
+
assert_array_almost_equal(q @ q.T, eye(3))
|
2054
|
+
assert_array_almost_equal(r @ q, a)
|
2055
|
+
|
2056
|
+
@pytest.mark.parametrize("m", [0, 1, 2])
|
2057
|
+
@pytest.mark.parametrize("n", [0, 1, 2])
|
2058
|
+
@pytest.mark.parametrize('dtype', DTYPES)
|
2059
|
+
def test_shape_dtype(self, m, n, dtype):
|
2060
|
+
k = min(m, n)
|
2061
|
+
|
2062
|
+
a = np.zeros((m, n), dtype=dtype)
|
2063
|
+
r, q = rq(a)
|
2064
|
+
assert_equal(q.shape, (n, n))
|
2065
|
+
assert_equal(r.shape, (m, n))
|
2066
|
+
assert_equal(r.dtype, dtype)
|
2067
|
+
assert_equal(q.dtype, dtype)
|
2068
|
+
|
2069
|
+
r = rq(a, mode='r')
|
2070
|
+
assert_equal(r.shape, (m, n))
|
2071
|
+
assert_equal(r.dtype, dtype)
|
2072
|
+
|
2073
|
+
r, q = rq(a, mode='economic')
|
2074
|
+
assert_equal(r.shape, (m, k))
|
2075
|
+
assert_equal(r.dtype, dtype)
|
2076
|
+
assert_equal(q.shape, (k, n))
|
2077
|
+
assert_equal(q.dtype, dtype)
|
2078
|
+
|
2079
|
+
@pytest.mark.parametrize(("m", "n"), [(0, 0), (0, 2), (2, 0)])
|
2080
|
+
def test_empty(self, m, n):
|
2081
|
+
k = min(m, n)
|
2082
|
+
|
2083
|
+
a = np.empty((m, n))
|
2084
|
+
r, q = rq(a)
|
2085
|
+
assert_allclose(r, np.empty((m, n)))
|
2086
|
+
assert_allclose(q, np.identity(n))
|
2087
|
+
|
2088
|
+
r = rq(a, mode='r')
|
2089
|
+
assert_allclose(r, np.empty((m, n)))
|
2090
|
+
|
2091
|
+
r, q = rq(a, mode='economic')
|
2092
|
+
assert_allclose(r, np.empty((m, k)))
|
2093
|
+
assert_allclose(q, np.empty((k, n)))
|
2094
|
+
|
2095
|
+
|
2096
|
+
class TestSchur:
|
2097
|
+
|
2098
|
+
def check_schur(self, a, t, u, rtol, atol):
|
2099
|
+
# Check that the Schur decomposition is correct.
|
2100
|
+
assert_allclose(u @ t @ u.conj().T, a, rtol=rtol, atol=atol,
|
2101
|
+
err_msg="Schur decomposition does not match 'a'")
|
2102
|
+
# The expected value of u @ u.H - I is all zeros, so test
|
2103
|
+
# with absolute tolerance only.
|
2104
|
+
assert_allclose(u @ u.conj().T - np.eye(len(u)), 0, rtol=0, atol=atol,
|
2105
|
+
err_msg="u is not unitary")
|
2106
|
+
|
2107
|
+
def test_simple(self):
|
2108
|
+
a = [[8, 12, 3], [2, 9, 3], [10, 3, 6]]
|
2109
|
+
t, z = schur(a)
|
2110
|
+
self.check_schur(a, t, z, rtol=1e-14, atol=5e-15)
|
2111
|
+
tc, zc = schur(a, 'complex')
|
2112
|
+
assert_(np.any(ravel(iscomplex(zc))) and np.any(ravel(iscomplex(tc))))
|
2113
|
+
self.check_schur(a, tc, zc, rtol=1e-14, atol=5e-15)
|
2114
|
+
tc2, zc2 = rsf2csf(tc, zc)
|
2115
|
+
self.check_schur(a, tc2, zc2, rtol=1e-14, atol=5e-15)
|
2116
|
+
|
2117
|
+
@pytest.mark.parametrize(
|
2118
|
+
'sort, expected_diag',
|
2119
|
+
[('lhp', [-np.sqrt(2), -0.5, np.sqrt(2), 0.5]),
|
2120
|
+
('rhp', [np.sqrt(2), 0.5, -np.sqrt(2), -0.5]),
|
2121
|
+
('iuc', [-0.5, 0.5, np.sqrt(2), -np.sqrt(2)]),
|
2122
|
+
('ouc', [np.sqrt(2), -np.sqrt(2), -0.5, 0.5]),
|
2123
|
+
(lambda x: x >= 0.0, [np.sqrt(2), 0.5, -np.sqrt(2), -0.5])]
|
2124
|
+
)
|
2125
|
+
def test_sort(self, sort, expected_diag):
|
2126
|
+
# The exact eigenvalues of this matrix are
|
2127
|
+
# -sqrt(2), sqrt(2), -1/2, 1/2.
|
2128
|
+
a = [[4., 3., 1., -1.],
|
2129
|
+
[-4.5, -3.5, -1., 1.],
|
2130
|
+
[9., 6., -4., 4.5],
|
2131
|
+
[6., 4., -3., 3.5]]
|
2132
|
+
t, u, sdim = schur(a, sort=sort)
|
2133
|
+
self.check_schur(a, t, u, rtol=1e-14, atol=5e-15)
|
2134
|
+
assert_allclose(np.diag(t), expected_diag, rtol=1e-12)
|
2135
|
+
assert_equal(2, sdim)
|
2136
|
+
|
2137
|
+
def test_sort_errors(self):
|
2138
|
+
a = [[4., 3., 1., -1.],
|
2139
|
+
[-4.5, -3.5, -1., 1.],
|
2140
|
+
[9., 6., -4., 4.5],
|
2141
|
+
[6., 4., -3., 3.5]]
|
2142
|
+
assert_raises(ValueError, schur, a, sort='unsupported')
|
2143
|
+
assert_raises(ValueError, schur, a, sort=1)
|
2144
|
+
|
2145
|
+
def test_check_finite(self):
|
2146
|
+
a = [[8, 12, 3], [2, 9, 3], [10, 3, 6]]
|
2147
|
+
t, z = schur(a, check_finite=False)
|
2148
|
+
assert_array_almost_equal(z @ t @ z.conj().T, a)
|
2149
|
+
|
2150
|
+
@pytest.mark.parametrize('dt', [int, float, np.float32, complex, np.complex64])
|
2151
|
+
def test_empty(self, dt):
|
2152
|
+
a = np.empty((0, 0), dtype=dt)
|
2153
|
+
t, z = schur(a)
|
2154
|
+
t0, z0 = schur(np.eye(2, dtype=dt))
|
2155
|
+
assert_allclose(t, np.empty((0, 0)))
|
2156
|
+
assert_allclose(z, np.empty((0, 0)))
|
2157
|
+
assert t.dtype == t0.dtype
|
2158
|
+
assert z.dtype == z0.dtype
|
2159
|
+
|
2160
|
+
t, z, sdim = schur(a, sort='lhp')
|
2161
|
+
assert_allclose(t, np.empty((0, 0)))
|
2162
|
+
assert_allclose(z, np.empty((0, 0)))
|
2163
|
+
assert_equal(sdim, 0)
|
2164
|
+
assert t.dtype == t0.dtype
|
2165
|
+
assert z.dtype == z0.dtype
|
2166
|
+
|
2167
|
+
@pytest.mark.parametrize('sort', ['iuc', 'ouc'])
|
2168
|
+
@pytest.mark.parametrize('output', ['real', 'complex'])
|
2169
|
+
@pytest.mark.parametrize('dtype', [np.float32, np.float64,
|
2170
|
+
np.complex64, np.complex128])
|
2171
|
+
def test_gh_13137_sort_str(self, sort, output, dtype):
|
2172
|
+
# gh-13137 reported that sort values 'iuc' and 'ouc' were not
|
2173
|
+
# correct because the callables assumed that the eigenvalues would
|
2174
|
+
# always be expressed as a single complex number.
|
2175
|
+
# In fact, when `output='real'` and the dtype is real, the
|
2176
|
+
# eigenvalues are passed as separate real and imaginary components
|
2177
|
+
# (yet no error is raised if the callable accepts only one argument).
|
2178
|
+
#
|
2179
|
+
# This tests these sort values by counting the number of eigenvalues
|
2180
|
+
# `schur` reports as being inside/outside the unit circle.
|
2181
|
+
|
2182
|
+
# Real matrix with eigenvalues 0.1 +- 2j
|
2183
|
+
A = np.asarray([[0.1, -2], [2, 0.1]])
|
2184
|
+
|
2185
|
+
# Previously, this would fail for `output='real'` with real dtypes
|
2186
|
+
sdim = schur(A.astype(dtype), sort=sort, output=output)[-1]
|
2187
|
+
assert sdim == 0 if sort == 'iuc' else sdim == 2
|
2188
|
+
|
2189
|
+
@pytest.mark.parametrize('output', ['real', 'complex'])
|
2190
|
+
@pytest.mark.parametrize('dtype', [np.float32, np.float64,
|
2191
|
+
np.complex64, np.complex128])
|
2192
|
+
def test_gh_13137_sort_custom(self, output, dtype):
|
2193
|
+
# This simply tests our understanding of how eigenvalues are
|
2194
|
+
# passed to a sort callable. If `output='real'` and the dtype is real,
|
2195
|
+
# real and imaginary parts are passed as separate real arguments;
|
2196
|
+
# otherwise, they are passed a single complex argument.
|
2197
|
+
# Also, if `output='real'` and the dtype is real, when either
|
2198
|
+
# eigenvalue in a complex conjugate pair satisfies the sort condition,
|
2199
|
+
# `sdim` is incremented by TWO.
|
2200
|
+
|
2201
|
+
# Real matrix with eigenvalues 0.1 +- 2j
|
2202
|
+
A = np.asarray([[0.1, -2], [2, 0.1]])
|
2203
|
+
|
2204
|
+
all_real = output=='real' and dtype in {np.float32, np.float64}
|
2205
|
+
|
2206
|
+
def sort(x, y=None):
|
2207
|
+
if all_real:
|
2208
|
+
assert not np.iscomplexobj(x)
|
2209
|
+
assert y is not None and np.isreal(y)
|
2210
|
+
z = x + y*1j
|
2211
|
+
else:
|
2212
|
+
assert np.iscomplexobj(x)
|
2213
|
+
assert y is None
|
2214
|
+
z = x
|
2215
|
+
return z.imag > 1e-15
|
2216
|
+
|
2217
|
+
# Only one complex eigenvalue satisfies the condition, but when
|
2218
|
+
# `all_real` applies, both eigenvalues in the complex conjugate pair
|
2219
|
+
# are counted.
|
2220
|
+
sdim = schur(A.astype(dtype), sort=sort, output=output)[-1]
|
2221
|
+
assert sdim == 2 if all_real else sdim == 1
|
2222
|
+
|
2223
|
+
|
2224
|
+
class TestHessenberg:
|
2225
|
+
|
2226
|
+
def test_simple(self):
|
2227
|
+
a = [[-149, -50, -154],
|
2228
|
+
[537, 180, 546],
|
2229
|
+
[-27, -9, -25]]
|
2230
|
+
h1 = [[-149.0000, 42.2037, -156.3165],
|
2231
|
+
[-537.6783, 152.5511, -554.9272],
|
2232
|
+
[0, 0.0728, 2.4489]]
|
2233
|
+
h, q = hessenberg(a, calc_q=1)
|
2234
|
+
assert_array_almost_equal(q.T @ a @ q, h)
|
2235
|
+
assert_array_almost_equal(h, h1, decimal=4)
|
2236
|
+
|
2237
|
+
def test_simple_complex(self):
|
2238
|
+
a = [[-149, -50, -154],
|
2239
|
+
[537, 180j, 546],
|
2240
|
+
[-27j, -9, -25]]
|
2241
|
+
h, q = hessenberg(a, calc_q=1)
|
2242
|
+
assert_array_almost_equal(q.conj().T @ a @ q, h)
|
2243
|
+
|
2244
|
+
def test_simple2(self):
|
2245
|
+
a = [[1, 2, 3, 4, 5, 6, 7],
|
2246
|
+
[0, 2, 3, 4, 6, 7, 2],
|
2247
|
+
[0, 2, 2, 3, 0, 3, 2],
|
2248
|
+
[0, 0, 2, 8, 0, 0, 2],
|
2249
|
+
[0, 3, 1, 2, 0, 1, 2],
|
2250
|
+
[0, 1, 2, 3, 0, 1, 0],
|
2251
|
+
[0, 0, 0, 0, 0, 1, 2]]
|
2252
|
+
h, q = hessenberg(a, calc_q=1)
|
2253
|
+
assert_array_almost_equal(q.T @ a @ q, h)
|
2254
|
+
|
2255
|
+
def test_simple3(self):
|
2256
|
+
a = np.eye(3)
|
2257
|
+
a[-1, 0] = 2
|
2258
|
+
h, q = hessenberg(a, calc_q=1)
|
2259
|
+
assert_array_almost_equal(q.T @ a @ q, h)
|
2260
|
+
|
2261
|
+
def test_random(self):
|
2262
|
+
rng = np.random.RandomState(1234)
|
2263
|
+
n = 20
|
2264
|
+
for k in range(2):
|
2265
|
+
a = rng.random([n, n])
|
2266
|
+
h, q = hessenberg(a, calc_q=1)
|
2267
|
+
assert_array_almost_equal(q.T @ a @ q, h)
|
2268
|
+
|
2269
|
+
def test_random_complex(self):
|
2270
|
+
rng = np.random.RandomState(1234)
|
2271
|
+
n = 20
|
2272
|
+
for k in range(2):
|
2273
|
+
a = rng.random([n, n]) + 1j*rng.random([n, n])
|
2274
|
+
h, q = hessenberg(a, calc_q=1)
|
2275
|
+
assert_array_almost_equal(q.conj().T @ a @ q, h)
|
2276
|
+
|
2277
|
+
def test_check_finite(self):
|
2278
|
+
a = [[-149, -50, -154],
|
2279
|
+
[537, 180, 546],
|
2280
|
+
[-27, -9, -25]]
|
2281
|
+
h1 = [[-149.0000, 42.2037, -156.3165],
|
2282
|
+
[-537.6783, 152.5511, -554.9272],
|
2283
|
+
[0, 0.0728, 2.4489]]
|
2284
|
+
h, q = hessenberg(a, calc_q=1, check_finite=False)
|
2285
|
+
assert_array_almost_equal(q.T @ a @ q, h)
|
2286
|
+
assert_array_almost_equal(h, h1, decimal=4)
|
2287
|
+
|
2288
|
+
def test_2x2(self):
|
2289
|
+
a = [[2, 1], [7, 12]]
|
2290
|
+
|
2291
|
+
h, q = hessenberg(a, calc_q=1)
|
2292
|
+
assert_array_almost_equal(q, np.eye(2))
|
2293
|
+
assert_array_almost_equal(h, a)
|
2294
|
+
|
2295
|
+
b = [[2-7j, 1+2j], [7+3j, 12-2j]]
|
2296
|
+
h2, q2 = hessenberg(b, calc_q=1)
|
2297
|
+
assert_array_almost_equal(q2, np.eye(2))
|
2298
|
+
assert_array_almost_equal(h2, b)
|
2299
|
+
|
2300
|
+
@pytest.mark.parametrize('dt', [int, float, float32, complex, complex64])
|
2301
|
+
def test_empty(self, dt):
|
2302
|
+
a = np.empty((0, 0), dtype=dt)
|
2303
|
+
h = hessenberg(a)
|
2304
|
+
assert h.shape == (0, 0)
|
2305
|
+
assert h.dtype == hessenberg(np.eye(3, dtype=dt)).dtype
|
2306
|
+
|
2307
|
+
h, q = hessenberg(a, calc_q=True)
|
2308
|
+
h3, q3 = hessenberg(a, calc_q=True)
|
2309
|
+
assert h.shape == (0, 0)
|
2310
|
+
assert h.dtype == h3.dtype
|
2311
|
+
|
2312
|
+
assert q.shape == (0, 0)
|
2313
|
+
assert q.dtype == q3.dtype
|
2314
|
+
|
2315
|
+
|
2316
|
+
blas_provider = blas_version = None
|
2317
|
+
if CONFIG is not None:
|
2318
|
+
blas_provider = CONFIG['Build Dependencies']['blas']['name']
|
2319
|
+
blas_version = CONFIG['Build Dependencies']['blas']['version']
|
2320
|
+
|
2321
|
+
|
2322
|
+
class TestQZ:
|
2323
|
+
def test_qz_single(self):
|
2324
|
+
rng = np.random.RandomState(12345)
|
2325
|
+
n = 5
|
2326
|
+
A = rng.random([n, n]).astype(float32)
|
2327
|
+
B = rng.random([n, n]).astype(float32)
|
2328
|
+
AA, BB, Q, Z = qz(A, B)
|
2329
|
+
assert_array_almost_equal(Q @ AA @ Z.T, A, decimal=5)
|
2330
|
+
assert_array_almost_equal(Q @ BB @ Z.T, B, decimal=5)
|
2331
|
+
assert_array_almost_equal(Q @ Q.T, eye(n), decimal=5)
|
2332
|
+
assert_array_almost_equal(Z @ Z.T, eye(n), decimal=5)
|
2333
|
+
assert_(np.all(diag(BB) >= 0))
|
2334
|
+
|
2335
|
+
def test_qz_double(self):
|
2336
|
+
rng = np.random.RandomState(12345)
|
2337
|
+
n = 5
|
2338
|
+
A = rng.random([n, n])
|
2339
|
+
B = rng.random([n, n])
|
2340
|
+
AA, BB, Q, Z = qz(A, B)
|
2341
|
+
assert_array_almost_equal(Q @ AA @ Z.T, A)
|
2342
|
+
assert_array_almost_equal(Q @ BB @ Z.T, B)
|
2343
|
+
assert_array_almost_equal(Q @ Q.T, eye(n))
|
2344
|
+
assert_array_almost_equal(Z @ Z.T, eye(n))
|
2345
|
+
assert_(np.all(diag(BB) >= 0))
|
2346
|
+
|
2347
|
+
def test_qz_complex(self):
|
2348
|
+
rng = np.random.RandomState(12345)
|
2349
|
+
n = 5
|
2350
|
+
A = rng.random([n, n]) + 1j*rng.random([n, n])
|
2351
|
+
B = rng.random([n, n]) + 1j*rng.random([n, n])
|
2352
|
+
AA, BB, Q, Z = qz(A, B)
|
2353
|
+
assert_array_almost_equal(Q @ AA @ Z.conj().T, A)
|
2354
|
+
assert_array_almost_equal(Q @ BB @ Z.conj().T, B)
|
2355
|
+
assert_array_almost_equal(Q @ Q.conj().T, eye(n))
|
2356
|
+
assert_array_almost_equal(Z @ Z.conj().T, eye(n))
|
2357
|
+
assert_(np.all(diag(BB) >= 0))
|
2358
|
+
assert_(np.all(diag(BB).imag == 0))
|
2359
|
+
|
2360
|
+
def test_qz_complex64(self):
|
2361
|
+
rng = np.random.RandomState(12345)
|
2362
|
+
n = 5
|
2363
|
+
A = (rng.random([n, n]) + 1j*rng.random([n, n])).astype(complex64)
|
2364
|
+
B = (rng.random([n, n]) + 1j*rng.random([n, n])).astype(complex64)
|
2365
|
+
AA, BB, Q, Z = qz(A, B)
|
2366
|
+
assert_array_almost_equal(Q @ AA @ Z.conj().T, A, decimal=5)
|
2367
|
+
assert_array_almost_equal(Q @ BB @ Z.conj().T, B, decimal=5)
|
2368
|
+
assert_array_almost_equal(Q @ Q.conj().T, eye(n), decimal=5)
|
2369
|
+
assert_array_almost_equal(Z @ Z.conj().T, eye(n), decimal=5)
|
2370
|
+
assert_(np.all(diag(BB) >= 0))
|
2371
|
+
assert_(np.all(diag(BB).imag == 0))
|
2372
|
+
|
2373
|
+
def test_qz_double_complex(self):
|
2374
|
+
rng = np.random.RandomState(12345)
|
2375
|
+
n = 5
|
2376
|
+
A = rng.random([n, n])
|
2377
|
+
B = rng.random([n, n])
|
2378
|
+
AA, BB, Q, Z = qz(A, B, output='complex')
|
2379
|
+
aa = Q @ AA @ Z.conj().T
|
2380
|
+
assert_array_almost_equal(aa.real, A)
|
2381
|
+
assert_array_almost_equal(aa.imag, 0)
|
2382
|
+
bb = Q @ BB @ Z.conj().T
|
2383
|
+
assert_array_almost_equal(bb.real, B)
|
2384
|
+
assert_array_almost_equal(bb.imag, 0)
|
2385
|
+
assert_array_almost_equal(Q @ Q.conj().T, eye(n))
|
2386
|
+
assert_array_almost_equal(Z @ Z.conj().T, eye(n))
|
2387
|
+
assert_(np.all(diag(BB) >= 0))
|
2388
|
+
|
2389
|
+
def test_qz_double_sort(self):
|
2390
|
+
# from https://www.nag.com/lapack-ex/node119.html
|
2391
|
+
# NOTE: These matrices may be ill-conditioned and lead to a
|
2392
|
+
# seg fault on certain python versions when compiled with
|
2393
|
+
# sse2 or sse3 older ATLAS/LAPACK binaries for windows
|
2394
|
+
# A = np.array([[3.9, 12.5, -34.5, -0.5],
|
2395
|
+
# [ 4.3, 21.5, -47.5, 7.5],
|
2396
|
+
# [ 4.3, 21.5, -43.5, 3.5],
|
2397
|
+
# [ 4.4, 26.0, -46.0, 6.0 ]])
|
2398
|
+
|
2399
|
+
# B = np.array([[ 1.0, 2.0, -3.0, 1.0],
|
2400
|
+
# [1.0, 3.0, -5.0, 4.0],
|
2401
|
+
# [1.0, 3.0, -4.0, 3.0],
|
2402
|
+
# [1.0, 3.0, -4.0, 4.0]])
|
2403
|
+
A = np.array([[3.9, 12.5, -34.5, 2.5],
|
2404
|
+
[4.3, 21.5, -47.5, 7.5],
|
2405
|
+
[4.3, 1.5, -43.5, 3.5],
|
2406
|
+
[4.4, 6.0, -46.0, 6.0]])
|
2407
|
+
|
2408
|
+
B = np.array([[1.0, 1.0, -3.0, 1.0],
|
2409
|
+
[1.0, 3.0, -5.0, 4.4],
|
2410
|
+
[1.0, 2.0, -4.0, 1.0],
|
2411
|
+
[1.2, 3.0, -4.0, 4.0]])
|
2412
|
+
|
2413
|
+
assert_raises(ValueError, qz, A, B, sort=lambda ar, ai, beta: ai == 0)
|
2414
|
+
if False:
|
2415
|
+
AA, BB, Q, Z, sdim = qz(A, B, sort=lambda ar, ai, beta: ai == 0)
|
2416
|
+
# assert_(sdim == 2)
|
2417
|
+
assert_(sdim == 4)
|
2418
|
+
assert_array_almost_equal(Q @ AA @ Z.T, A)
|
2419
|
+
assert_array_almost_equal(Q @ BB @ Z.T, B)
|
2420
|
+
|
2421
|
+
# test absolute values bc the sign is ambiguous and
|
2422
|
+
# might be platform dependent
|
2423
|
+
assert_array_almost_equal(np.abs(AA), np.abs(np.array(
|
2424
|
+
[[35.7864, -80.9061, -12.0629, -9.498],
|
2425
|
+
[0., 2.7638, -2.3505, 7.3256],
|
2426
|
+
[0., 0., 0.6258, -0.0398],
|
2427
|
+
[0., 0., 0., -12.8217]])), 4)
|
2428
|
+
assert_array_almost_equal(np.abs(BB), np.abs(np.array(
|
2429
|
+
[[4.5324, -8.7878, 3.2357, -3.5526],
|
2430
|
+
[0., 1.4314, -2.1894, 0.9709],
|
2431
|
+
[0., 0., 1.3126, -0.3468],
|
2432
|
+
[0., 0., 0., 0.559]])), 4)
|
2433
|
+
assert_array_almost_equal(np.abs(Q), np.abs(np.array(
|
2434
|
+
[[-0.4193, -0.605, -0.1894, -0.6498],
|
2435
|
+
[-0.5495, 0.6987, 0.2654, -0.3734],
|
2436
|
+
[-0.4973, -0.3682, 0.6194, 0.4832],
|
2437
|
+
[-0.5243, 0.1008, -0.7142, 0.4526]])), 4)
|
2438
|
+
assert_array_almost_equal(np.abs(Z), np.abs(np.array(
|
2439
|
+
[[-0.9471, -0.2971, -0.1217, 0.0055],
|
2440
|
+
[-0.0367, 0.1209, 0.0358, 0.9913],
|
2441
|
+
[0.3171, -0.9041, -0.2547, 0.1312],
|
2442
|
+
[0.0346, 0.2824, -0.9587, 0.0014]])), 4)
|
2443
|
+
|
2444
|
+
# test absolute values bc the sign is ambiguous and might be platform
|
2445
|
+
# dependent
|
2446
|
+
# assert_array_almost_equal(abs(AA), abs(np.array([
|
2447
|
+
# [3.8009, -69.4505, 50.3135, -43.2884],
|
2448
|
+
# [0.0000, 9.2033, -0.2001, 5.9881],
|
2449
|
+
# [0.0000, 0.0000, 1.4279, 4.4453],
|
2450
|
+
# [0.0000, 0.0000, 0.9019, -1.1962]])), 4)
|
2451
|
+
# assert_array_almost_equal(abs(BB), abs(np.array([
|
2452
|
+
# [1.9005, -10.2285, 0.8658, -5.2134],
|
2453
|
+
# [0.0000, 2.3008, 0.7915, 0.4262],
|
2454
|
+
# [0.0000, 0.0000, 0.8101, 0.0000],
|
2455
|
+
# [0.0000, 0.0000, 0.0000, -0.2823]])), 4)
|
2456
|
+
# assert_array_almost_equal(abs(Q), abs(np.array([
|
2457
|
+
# [0.4642, 0.7886, 0.2915, -0.2786],
|
2458
|
+
# [0.5002, -0.5986, 0.5638, -0.2713],
|
2459
|
+
# [0.5002, 0.0154, -0.0107, 0.8657],
|
2460
|
+
# [0.5331, -0.1395, -0.7727, -0.3151]])), 4)
|
2461
|
+
# assert_array_almost_equal(dot(Q,Q.T), eye(4))
|
2462
|
+
# assert_array_almost_equal(abs(Z), abs(np.array([
|
2463
|
+
# [0.9961, -0.0014, 0.0887, -0.0026],
|
2464
|
+
# [0.0057, -0.0404, -0.0938, -0.9948],
|
2465
|
+
# [0.0626, 0.7194, -0.6908, 0.0363],
|
2466
|
+
# [0.0626, -0.6934, -0.7114, 0.0956]])), 4)
|
2467
|
+
# assert_array_almost_equal(dot(Z,Z.T), eye(4))
|
2468
|
+
|
2469
|
+
# def test_qz_complex_sort(self):
|
2470
|
+
# cA = np.array([
|
2471
|
+
# [-21.10+22.50*1j, 53.50+-50.50*1j, -34.50+127.50*1j, 7.50+ 0.50*1j],
|
2472
|
+
# [-0.46+ -7.78*1j, -3.50+-37.50*1j, -15.50+ 58.50*1j,-10.50+ -1.50*1j],
|
2473
|
+
# [ 4.30+ -5.50*1j, 39.70+-17.10*1j, -68.50+ 12.50*1j, -7.50+ -3.50*1j],
|
2474
|
+
# [ 5.50+ 4.40*1j, 14.40+ 43.30*1j, -32.50+-46.00*1j,-19.00+-32.50*1j]])
|
2475
|
+
|
2476
|
+
# cB = np.array([
|
2477
|
+
# [1.00+ -5.00*1j, 1.60+ 1.20*1j,-3.00+ 0.00*1j, 0.00+ -1.00*1j],
|
2478
|
+
# [0.80+ -0.60*1j, 3.00+ -5.00*1j,-4.00+ 3.00*1j,-2.40+ -3.20*1j],
|
2479
|
+
# [1.00+ 0.00*1j, 2.40+ 1.80*1j,-4.00+ -5.00*1j, 0.00+ -3.00*1j],
|
2480
|
+
# [0.00+ 1.00*1j,-1.80+ 2.40*1j, 0.00+ -4.00*1j, 4.00+ -5.00*1j]])
|
2481
|
+
|
2482
|
+
# AAS,BBS,QS,ZS,sdim = qz(cA,cB,sort='lhp')
|
2483
|
+
|
2484
|
+
# eigenvalues = diag(AAS)/diag(BBS)
|
2485
|
+
# assert_(np.all(np.real(eigenvalues[:sdim] < 0)))
|
2486
|
+
# assert_(np.all(np.real(eigenvalues[sdim:] > 0)))
|
2487
|
+
|
2488
|
+
def test_check_finite(self):
|
2489
|
+
rng = np.random.RandomState(12345)
|
2490
|
+
n = 5
|
2491
|
+
A = rng.random([n, n])
|
2492
|
+
B = rng.random([n, n])
|
2493
|
+
AA, BB, Q, Z = qz(A, B, check_finite=False)
|
2494
|
+
assert_array_almost_equal(Q @ AA @ Z.T, A)
|
2495
|
+
assert_array_almost_equal(Q @ BB @ Z.T, B)
|
2496
|
+
assert_array_almost_equal(Q @ Q.T, eye(n))
|
2497
|
+
assert_array_almost_equal(Z @ Z.T, eye(n))
|
2498
|
+
assert_(np.all(diag(BB) >= 0))
|
2499
|
+
|
2500
|
+
|
2501
|
+
class TestOrdQZ:
|
2502
|
+
@classmethod
|
2503
|
+
def setup_class(cls):
|
2504
|
+
# https://www.nag.com/lapack-ex/node119.html
|
2505
|
+
A1 = np.array([[-21.10 - 22.50j, 53.5 - 50.5j, -34.5 + 127.5j,
|
2506
|
+
7.5 + 0.5j],
|
2507
|
+
[-0.46 - 7.78j, -3.5 - 37.5j, -15.5 + 58.5j,
|
2508
|
+
-10.5 - 1.5j],
|
2509
|
+
[4.30 - 5.50j, 39.7 - 17.1j, -68.5 + 12.5j,
|
2510
|
+
-7.5 - 3.5j],
|
2511
|
+
[5.50 + 4.40j, 14.4 + 43.3j, -32.5 - 46.0j,
|
2512
|
+
-19.0 - 32.5j]])
|
2513
|
+
|
2514
|
+
B1 = np.array([[1.0 - 5.0j, 1.6 + 1.2j, -3 + 0j, 0.0 - 1.0j],
|
2515
|
+
[0.8 - 0.6j, .0 - 5.0j, -4 + 3j, -2.4 - 3.2j],
|
2516
|
+
[1.0 + 0.0j, 2.4 + 1.8j, -4 - 5j, 0.0 - 3.0j],
|
2517
|
+
[0.0 + 1.0j, -1.8 + 2.4j, 0 - 4j, 4.0 - 5.0j]])
|
2518
|
+
|
2519
|
+
# https://www.nag.com/numeric/fl/nagdoc_fl23/xhtml/F08/f08yuf.xml
|
2520
|
+
A2 = np.array([[3.9, 12.5, -34.5, -0.5],
|
2521
|
+
[4.3, 21.5, -47.5, 7.5],
|
2522
|
+
[4.3, 21.5, -43.5, 3.5],
|
2523
|
+
[4.4, 26.0, -46.0, 6.0]])
|
2524
|
+
|
2525
|
+
B2 = np.array([[1, 2, -3, 1],
|
2526
|
+
[1, 3, -5, 4],
|
2527
|
+
[1, 3, -4, 3],
|
2528
|
+
[1, 3, -4, 4]])
|
2529
|
+
|
2530
|
+
# example with the eigenvalues
|
2531
|
+
# -0.33891648, 1.61217396+0.74013521j, 1.61217396-0.74013521j,
|
2532
|
+
# 0.61244091
|
2533
|
+
# thus featuring:
|
2534
|
+
# * one complex conjugate eigenvalue pair,
|
2535
|
+
# * one eigenvalue in the lhp
|
2536
|
+
# * 2 eigenvalues in the unit circle
|
2537
|
+
# * 2 non-real eigenvalues
|
2538
|
+
A3 = np.array([[5., 1., 3., 3.],
|
2539
|
+
[4., 4., 2., 7.],
|
2540
|
+
[7., 4., 1., 3.],
|
2541
|
+
[0., 4., 8., 7.]])
|
2542
|
+
B3 = np.array([[8., 10., 6., 10.],
|
2543
|
+
[7., 7., 2., 9.],
|
2544
|
+
[9., 1., 6., 6.],
|
2545
|
+
[5., 1., 4., 7.]])
|
2546
|
+
|
2547
|
+
# example with infinite eigenvalues
|
2548
|
+
A4 = np.eye(2)
|
2549
|
+
B4 = np.diag([0, 1])
|
2550
|
+
|
2551
|
+
# example with (alpha, beta) = (0, 0)
|
2552
|
+
A5 = np.diag([1, 0])
|
2553
|
+
|
2554
|
+
cls.A = [A1, A2, A3, A4, A5]
|
2555
|
+
cls.B = [B1, B2, B3, B4, A5]
|
2556
|
+
|
2557
|
+
def qz_decomp(self, sort):
|
2558
|
+
with np.errstate(all='raise'):
|
2559
|
+
ret = [ordqz(Ai, Bi, sort=sort) for Ai, Bi in zip(self.A, self.B)]
|
2560
|
+
return tuple(ret)
|
2561
|
+
|
2562
|
+
def check(self, A, B, sort, AA, BB, alpha, beta, Q, Z):
|
2563
|
+
Id = np.eye(*A.shape)
|
2564
|
+
# make sure Q and Z are orthogonal
|
2565
|
+
assert_array_almost_equal(Q @ Q.T.conj(), Id)
|
2566
|
+
assert_array_almost_equal(Z @ Z.T.conj(), Id)
|
2567
|
+
# check factorization
|
2568
|
+
assert_array_almost_equal(Q @ AA, A @ Z)
|
2569
|
+
assert_array_almost_equal(Q @ BB, B @ Z)
|
2570
|
+
# check shape of AA and BB
|
2571
|
+
assert_array_equal(np.tril(AA, -2), np.zeros(AA.shape))
|
2572
|
+
assert_array_equal(np.tril(BB, -1), np.zeros(BB.shape))
|
2573
|
+
# check eigenvalues
|
2574
|
+
for i in range(A.shape[0]):
|
2575
|
+
# does the current diagonal element belong to a 2-by-2 block
|
2576
|
+
# that was already checked?
|
2577
|
+
if i > 0 and A[i, i - 1] != 0:
|
2578
|
+
continue
|
2579
|
+
# take care of 2-by-2 blocks
|
2580
|
+
if i < AA.shape[0] - 1 and AA[i + 1, i] != 0:
|
2581
|
+
evals, _ = eig(AA[i:i + 2, i:i + 2], BB[i:i + 2, i:i + 2])
|
2582
|
+
# make sure the pair of complex conjugate eigenvalues
|
2583
|
+
# is ordered consistently (positive imaginary part first)
|
2584
|
+
if evals[0].imag < 0:
|
2585
|
+
evals = evals[[1, 0]]
|
2586
|
+
tmp = alpha[i:i + 2]/beta[i:i + 2]
|
2587
|
+
if tmp[0].imag < 0:
|
2588
|
+
tmp = tmp[[1, 0]]
|
2589
|
+
assert_array_almost_equal(evals, tmp)
|
2590
|
+
else:
|
2591
|
+
if alpha[i] == 0 and beta[i] == 0:
|
2592
|
+
assert_equal(AA[i, i], 0)
|
2593
|
+
assert_equal(BB[i, i], 0)
|
2594
|
+
elif beta[i] == 0:
|
2595
|
+
assert_equal(BB[i, i], 0)
|
2596
|
+
else:
|
2597
|
+
assert_almost_equal(AA[i, i]/BB[i, i], alpha[i]/beta[i])
|
2598
|
+
sortfun = _select_function(sort)
|
2599
|
+
lastsort = True
|
2600
|
+
for i in range(A.shape[0]):
|
2601
|
+
cursort = sortfun(np.array([alpha[i]]), np.array([beta[i]]))
|
2602
|
+
# once the sorting criterion was not matched all subsequent
|
2603
|
+
# eigenvalues also shouldn't match
|
2604
|
+
if not lastsort:
|
2605
|
+
assert not cursort
|
2606
|
+
lastsort = cursort
|
2607
|
+
|
2608
|
+
def check_all(self, sort):
|
2609
|
+
ret = self.qz_decomp(sort)
|
2610
|
+
|
2611
|
+
for reti, Ai, Bi in zip(ret, self.A, self.B):
|
2612
|
+
self.check(Ai, Bi, sort, *reti)
|
2613
|
+
|
2614
|
+
def test_lhp(self):
|
2615
|
+
self.check_all('lhp')
|
2616
|
+
|
2617
|
+
def test_rhp(self):
|
2618
|
+
self.check_all('rhp')
|
2619
|
+
|
2620
|
+
def test_iuc(self):
|
2621
|
+
self.check_all('iuc')
|
2622
|
+
|
2623
|
+
def test_ouc(self):
|
2624
|
+
self.check_all('ouc')
|
2625
|
+
|
2626
|
+
def test_ref(self):
|
2627
|
+
# real eigenvalues first (top-left corner)
|
2628
|
+
def sort(x, y):
|
2629
|
+
out = np.empty_like(x, dtype=bool)
|
2630
|
+
nonzero = (y != 0)
|
2631
|
+
out[~nonzero] = False
|
2632
|
+
out[nonzero] = (x[nonzero]/y[nonzero]).imag == 0
|
2633
|
+
return out
|
2634
|
+
|
2635
|
+
self.check_all(sort)
|
2636
|
+
|
2637
|
+
def test_cef(self):
|
2638
|
+
# complex eigenvalues first (top-left corner)
|
2639
|
+
def sort(x, y):
|
2640
|
+
out = np.empty_like(x, dtype=bool)
|
2641
|
+
nonzero = (y != 0)
|
2642
|
+
out[~nonzero] = False
|
2643
|
+
out[nonzero] = (x[nonzero]/y[nonzero]).imag != 0
|
2644
|
+
return out
|
2645
|
+
|
2646
|
+
self.check_all(sort)
|
2647
|
+
|
2648
|
+
def test_diff_input_types(self):
|
2649
|
+
ret = ordqz(self.A[1], self.B[2], sort='lhp')
|
2650
|
+
self.check(self.A[1], self.B[2], 'lhp', *ret)
|
2651
|
+
|
2652
|
+
ret = ordqz(self.B[2], self.A[1], sort='lhp')
|
2653
|
+
self.check(self.B[2], self.A[1], 'lhp', *ret)
|
2654
|
+
|
2655
|
+
def test_sort_explicit(self):
|
2656
|
+
# Test order of the eigenvalues in the 2 x 2 case where we can
|
2657
|
+
# explicitly compute the solution
|
2658
|
+
A1 = np.eye(2)
|
2659
|
+
B1 = np.diag([-2, 0.5])
|
2660
|
+
expected1 = [('lhp', [-0.5, 2]),
|
2661
|
+
('rhp', [2, -0.5]),
|
2662
|
+
('iuc', [-0.5, 2]),
|
2663
|
+
('ouc', [2, -0.5])]
|
2664
|
+
A2 = np.eye(2)
|
2665
|
+
B2 = np.diag([-2 + 1j, 0.5 + 0.5j])
|
2666
|
+
expected2 = [('lhp', [1/(-2 + 1j), 1/(0.5 + 0.5j)]),
|
2667
|
+
('rhp', [1/(0.5 + 0.5j), 1/(-2 + 1j)]),
|
2668
|
+
('iuc', [1/(-2 + 1j), 1/(0.5 + 0.5j)]),
|
2669
|
+
('ouc', [1/(0.5 + 0.5j), 1/(-2 + 1j)])]
|
2670
|
+
# 'lhp' is ambiguous so don't test it
|
2671
|
+
A3 = np.eye(2)
|
2672
|
+
B3 = np.diag([2, 0])
|
2673
|
+
expected3 = [('rhp', [0.5, np.inf]),
|
2674
|
+
('iuc', [0.5, np.inf]),
|
2675
|
+
('ouc', [np.inf, 0.5])]
|
2676
|
+
# 'rhp' is ambiguous so don't test it
|
2677
|
+
A4 = np.eye(2)
|
2678
|
+
B4 = np.diag([-2, 0])
|
2679
|
+
expected4 = [('lhp', [-0.5, np.inf]),
|
2680
|
+
('iuc', [-0.5, np.inf]),
|
2681
|
+
('ouc', [np.inf, -0.5])]
|
2682
|
+
A5 = np.diag([0, 1])
|
2683
|
+
B5 = np.diag([0, 0.5])
|
2684
|
+
# 'lhp' and 'iuc' are ambiguous so don't test them
|
2685
|
+
expected5 = [('rhp', [2, np.nan]),
|
2686
|
+
('ouc', [2, np.nan])]
|
2687
|
+
|
2688
|
+
A = [A1, A2, A3, A4, A5]
|
2689
|
+
B = [B1, B2, B3, B4, B5]
|
2690
|
+
expected = [expected1, expected2, expected3, expected4, expected5]
|
2691
|
+
for Ai, Bi, expectedi in zip(A, B, expected):
|
2692
|
+
for sortstr, expected_eigvals in expectedi:
|
2693
|
+
_, _, alpha, beta, _, _ = ordqz(Ai, Bi, sort=sortstr)
|
2694
|
+
azero = (alpha == 0)
|
2695
|
+
bzero = (beta == 0)
|
2696
|
+
x = np.empty_like(alpha)
|
2697
|
+
x[azero & bzero] = np.nan
|
2698
|
+
x[~azero & bzero] = np.inf
|
2699
|
+
x[~bzero] = alpha[~bzero]/beta[~bzero]
|
2700
|
+
assert_allclose(expected_eigvals, x)
|
2701
|
+
|
2702
|
+
|
2703
|
+
class TestOrdQZWorkspaceSize:
|
2704
|
+
@pytest.mark.fail_slow(5)
|
2705
|
+
def test_decompose(self):
|
2706
|
+
rng = np.random.RandomState(12345)
|
2707
|
+
N = 202
|
2708
|
+
# raises error if lwork parameter to dtrsen is too small
|
2709
|
+
for ddtype in [np.float32, np.float64]:
|
2710
|
+
A = rng.random((N, N)).astype(ddtype)
|
2711
|
+
B = rng.random((N, N)).astype(ddtype)
|
2712
|
+
# sort = lambda ar, ai, b: ar**2 + ai**2 < b**2
|
2713
|
+
_ = ordqz(A, B, sort=lambda alpha, beta: alpha < beta,
|
2714
|
+
output='real')
|
2715
|
+
|
2716
|
+
for ddtype in [np.complex128, np.complex64]:
|
2717
|
+
A = rng.random((N, N)).astype(ddtype)
|
2718
|
+
B = rng.random((N, N)).astype(ddtype)
|
2719
|
+
_ = ordqz(A, B, sort=lambda alpha, beta: alpha < beta,
|
2720
|
+
output='complex')
|
2721
|
+
|
2722
|
+
@pytest.mark.slow
|
2723
|
+
def test_decompose_ouc(self):
|
2724
|
+
rng = np.random.RandomState(12345)
|
2725
|
+
N = 202
|
2726
|
+
# segfaults if lwork parameter to dtrsen is too small
|
2727
|
+
for ddtype in [np.float32, np.float64, np.complex128, np.complex64]:
|
2728
|
+
A = rng.random((N, N)).astype(ddtype)
|
2729
|
+
B = rng.random((N, N)).astype(ddtype)
|
2730
|
+
S, T, alpha, beta, U, V = ordqz(A, B, sort='ouc')
|
2731
|
+
|
2732
|
+
|
2733
|
+
class TestDatacopied:
|
2734
|
+
|
2735
|
+
def test_datacopied(self):
|
2736
|
+
from scipy.linalg._decomp import _datacopied
|
2737
|
+
|
2738
|
+
M = matrix([[0, 1], [2, 3]])
|
2739
|
+
A = asarray(M)
|
2740
|
+
L = M.tolist()
|
2741
|
+
M2 = M.copy()
|
2742
|
+
|
2743
|
+
class Fake1:
|
2744
|
+
def __array__(self, dtype=None, copy=None):
|
2745
|
+
return A
|
2746
|
+
|
2747
|
+
class Fake2:
|
2748
|
+
__array_interface__ = A.__array_interface__
|
2749
|
+
|
2750
|
+
F1 = Fake1()
|
2751
|
+
F2 = Fake2()
|
2752
|
+
|
2753
|
+
for item, status in [(M, False), (A, False), (L, True),
|
2754
|
+
(M2, False), (F1, False), (F2, False)]:
|
2755
|
+
arr = asarray(item)
|
2756
|
+
assert_equal(_datacopied(arr, item), status,
|
2757
|
+
err_msg=repr(item))
|
2758
|
+
|
2759
|
+
|
2760
|
+
def test_aligned_mem_float():
|
2761
|
+
"""Check linalg works with non-aligned memory (float32)"""
|
2762
|
+
# Allocate 402 bytes of memory (allocated on boundary)
|
2763
|
+
a = arange(402, dtype=np.uint8)
|
2764
|
+
|
2765
|
+
# Create an array with boundary offset 4
|
2766
|
+
z = np.frombuffer(a.data, offset=2, count=100, dtype=float32)
|
2767
|
+
z.shape = 10, 10
|
2768
|
+
|
2769
|
+
eig(z, overwrite_a=True)
|
2770
|
+
eig(z.T, overwrite_a=True)
|
2771
|
+
|
2772
|
+
|
2773
|
+
@pytest.mark.skipif(platform.machine() == 'ppc64le',
|
2774
|
+
reason="crashes on ppc64le")
|
2775
|
+
def test_aligned_mem():
|
2776
|
+
"""Check linalg works with non-aligned memory (float64)"""
|
2777
|
+
# Allocate 804 bytes of memory (allocated on boundary)
|
2778
|
+
a = arange(804, dtype=np.uint8)
|
2779
|
+
|
2780
|
+
# Create an array with boundary offset 4
|
2781
|
+
z = np.frombuffer(a.data, offset=4, count=100, dtype=float)
|
2782
|
+
z.shape = 10, 10
|
2783
|
+
|
2784
|
+
eig(z, overwrite_a=True)
|
2785
|
+
eig(z.T, overwrite_a=True)
|
2786
|
+
|
2787
|
+
|
2788
|
+
def test_aligned_mem_complex():
|
2789
|
+
"""Check that complex objects don't need to be completely aligned"""
|
2790
|
+
# Allocate 1608 bytes of memory (allocated on boundary)
|
2791
|
+
a = zeros(1608, dtype=np.uint8)
|
2792
|
+
|
2793
|
+
# Create an array with boundary offset 8
|
2794
|
+
z = np.frombuffer(a.data, offset=8, count=100, dtype=complex)
|
2795
|
+
z.shape = 10, 10
|
2796
|
+
|
2797
|
+
eig(z, overwrite_a=True)
|
2798
|
+
# This does not need special handling
|
2799
|
+
eig(z.T, overwrite_a=True)
|
2800
|
+
|
2801
|
+
|
2802
|
+
def check_lapack_misaligned(func, args, kwargs):
|
2803
|
+
args = list(args)
|
2804
|
+
for i in range(len(args)):
|
2805
|
+
a = args[:]
|
2806
|
+
if isinstance(a[i], np.ndarray):
|
2807
|
+
# Try misaligning a[i]
|
2808
|
+
aa = np.zeros(a[i].size*a[i].dtype.itemsize+8, dtype=np.uint8)
|
2809
|
+
aa = np.frombuffer(aa.data, offset=4, count=a[i].size,
|
2810
|
+
dtype=a[i].dtype)
|
2811
|
+
aa.shape = a[i].shape
|
2812
|
+
aa[...] = a[i]
|
2813
|
+
a[i] = aa
|
2814
|
+
func(*a, **kwargs)
|
2815
|
+
if len(a[i].shape) > 1:
|
2816
|
+
a[i] = a[i].T
|
2817
|
+
func(*a, **kwargs)
|
2818
|
+
|
2819
|
+
|
2820
|
+
@pytest.mark.xfail(run=False,
|
2821
|
+
reason="Ticket #1152, triggers a segfault in rare cases.")
|
2822
|
+
def test_lapack_misaligned():
|
2823
|
+
M = np.eye(10, dtype=float)
|
2824
|
+
R = np.arange(100)
|
2825
|
+
R.shape = 10, 10
|
2826
|
+
S = np.arange(20000, dtype=np.uint8)
|
2827
|
+
S = np.frombuffer(S.data, offset=4, count=100, dtype=float)
|
2828
|
+
S.shape = 10, 10
|
2829
|
+
b = np.ones(10)
|
2830
|
+
LU, piv = lu_factor(S)
|
2831
|
+
for (func, args, kwargs) in [
|
2832
|
+
(eig, (S,), dict(overwrite_a=True)), # crash
|
2833
|
+
(eigvals, (S,), dict(overwrite_a=True)), # no crash
|
2834
|
+
(lu, (S,), dict(overwrite_a=True)), # no crash
|
2835
|
+
(lu_factor, (S,), dict(overwrite_a=True)), # no crash
|
2836
|
+
(lu_solve, ((LU, piv), b), dict(overwrite_b=True)),
|
2837
|
+
(solve, (S, b), dict(overwrite_a=True, overwrite_b=True)),
|
2838
|
+
(svd, (M,), dict(overwrite_a=True)), # no crash
|
2839
|
+
(svd, (R,), dict(overwrite_a=True)), # no crash
|
2840
|
+
(svd, (S,), dict(overwrite_a=True)), # crash
|
2841
|
+
(svdvals, (S,), dict()), # no crash
|
2842
|
+
(svdvals, (S,), dict(overwrite_a=True)), # crash
|
2843
|
+
(cholesky, (M,), dict(overwrite_a=True)), # no crash
|
2844
|
+
(qr, (S,), dict(overwrite_a=True)), # crash
|
2845
|
+
(rq, (S,), dict(overwrite_a=True)), # crash
|
2846
|
+
(hessenberg, (S,), dict(overwrite_a=True)), # crash
|
2847
|
+
(schur, (S,), dict(overwrite_a=True)), # crash
|
2848
|
+
]:
|
2849
|
+
check_lapack_misaligned(func, args, kwargs)
|
2850
|
+
# not properly tested
|
2851
|
+
# cholesky, rsf2csf, lu_solve, solve, eig_banded, eigvals_banded, eigh, diagsvd
|
2852
|
+
|
2853
|
+
|
2854
|
+
class TestOverwrite:
|
2855
|
+
def test_eig(self):
|
2856
|
+
assert_no_overwrite(eig, [(3, 3)])
|
2857
|
+
assert_no_overwrite(eig, [(3, 3), (3, 3)])
|
2858
|
+
|
2859
|
+
def test_eigh(self):
|
2860
|
+
assert_no_overwrite(eigh, [(3, 3)])
|
2861
|
+
assert_no_overwrite(eigh, [(3, 3), (3, 3)])
|
2862
|
+
|
2863
|
+
def test_eig_banded(self):
|
2864
|
+
assert_no_overwrite(eig_banded, [(3, 2)])
|
2865
|
+
|
2866
|
+
def test_eigvals(self):
|
2867
|
+
assert_no_overwrite(eigvals, [(3, 3)])
|
2868
|
+
|
2869
|
+
def test_eigvalsh(self):
|
2870
|
+
assert_no_overwrite(eigvalsh, [(3, 3)])
|
2871
|
+
|
2872
|
+
def test_eigvals_banded(self):
|
2873
|
+
assert_no_overwrite(eigvals_banded, [(3, 2)])
|
2874
|
+
|
2875
|
+
def test_hessenberg(self):
|
2876
|
+
assert_no_overwrite(hessenberg, [(3, 3)])
|
2877
|
+
|
2878
|
+
def test_lu_factor(self):
|
2879
|
+
assert_no_overwrite(lu_factor, [(3, 3)])
|
2880
|
+
|
2881
|
+
def test_lu_solve(self):
|
2882
|
+
x = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 8]])
|
2883
|
+
xlu = lu_factor(x)
|
2884
|
+
assert_no_overwrite(lambda b: lu_solve(xlu, b), [(3,)])
|
2885
|
+
|
2886
|
+
def test_lu(self):
|
2887
|
+
assert_no_overwrite(lu, [(3, 3)])
|
2888
|
+
|
2889
|
+
def test_qr(self):
|
2890
|
+
assert_no_overwrite(qr, [(3, 3)])
|
2891
|
+
|
2892
|
+
def test_rq(self):
|
2893
|
+
assert_no_overwrite(rq, [(3, 3)])
|
2894
|
+
|
2895
|
+
def test_schur(self):
|
2896
|
+
assert_no_overwrite(schur, [(3, 3)])
|
2897
|
+
|
2898
|
+
def test_schur_complex(self):
|
2899
|
+
assert_no_overwrite(lambda a: schur(a, 'complex'), [(3, 3)],
|
2900
|
+
dtypes=[np.float32, np.float64])
|
2901
|
+
|
2902
|
+
def test_svd(self):
|
2903
|
+
assert_no_overwrite(svd, [(3, 3)])
|
2904
|
+
assert_no_overwrite(lambda a: svd(a, lapack_driver='gesvd'), [(3, 3)])
|
2905
|
+
|
2906
|
+
def test_svdvals(self):
|
2907
|
+
assert_no_overwrite(svdvals, [(3, 3)])
|
2908
|
+
|
2909
|
+
|
2910
|
+
def _check_orth(n, dtype, skip_big=False):
|
2911
|
+
X = np.ones((n, 2), dtype=float).astype(dtype)
|
2912
|
+
|
2913
|
+
eps = np.finfo(dtype).eps
|
2914
|
+
tol = 1000 * eps
|
2915
|
+
|
2916
|
+
Y = orth(X)
|
2917
|
+
assert_equal(Y.shape, (n, 1))
|
2918
|
+
assert_allclose(Y, Y.mean(), atol=tol)
|
2919
|
+
|
2920
|
+
Y = orth(X.T)
|
2921
|
+
assert_equal(Y.shape, (2, 1))
|
2922
|
+
assert_allclose(Y, Y.mean(), atol=tol)
|
2923
|
+
|
2924
|
+
if n > 5 and not skip_big:
|
2925
|
+
rng = np.random.RandomState(1)
|
2926
|
+
X = rng.rand(n, 5) @ rng.rand(5, n)
|
2927
|
+
X = X + 1e-4 * rng.rand(n, 1) @ rng.rand(1, n)
|
2928
|
+
X = X.astype(dtype)
|
2929
|
+
|
2930
|
+
Y = orth(X, rcond=1e-3)
|
2931
|
+
assert_equal(Y.shape, (n, 5))
|
2932
|
+
|
2933
|
+
Y = orth(X, rcond=1e-6)
|
2934
|
+
assert_equal(Y.shape, (n, 5 + 1))
|
2935
|
+
|
2936
|
+
|
2937
|
+
@pytest.mark.slow
|
2938
|
+
@pytest.mark.skipif(np.dtype(np.intp).itemsize < 8,
|
2939
|
+
reason="test only on 64-bit, else too slow")
|
2940
|
+
def test_orth_memory_efficiency():
|
2941
|
+
# Pick n so that 16*n bytes is reasonable but 8*n*n bytes is unreasonable.
|
2942
|
+
# Keep in mind that @pytest.mark.slow tests are likely to be running
|
2943
|
+
# under configurations that support 4Gb+ memory for tests related to
|
2944
|
+
# 32 bit overflow.
|
2945
|
+
n = 10*1000*1000
|
2946
|
+
try:
|
2947
|
+
_check_orth(n, np.float64, skip_big=True)
|
2948
|
+
except MemoryError as e:
|
2949
|
+
raise AssertionError(
|
2950
|
+
'memory error perhaps caused by orth regression'
|
2951
|
+
) from e
|
2952
|
+
|
2953
|
+
|
2954
|
+
def test_orth():
|
2955
|
+
dtypes = [np.float32, np.float64, np.complex64, np.complex128]
|
2956
|
+
sizes = [1, 2, 3, 10, 100]
|
2957
|
+
for dt, n in itertools.product(dtypes, sizes):
|
2958
|
+
_check_orth(n, dt)
|
2959
|
+
|
2960
|
+
@pytest.mark.parametrize('dt', [int, float, np.float32, complex, np.complex64])
|
2961
|
+
def test_orth_empty(dt):
|
2962
|
+
a = np.empty((0, 0), dtype=dt)
|
2963
|
+
a0 = np.eye(2, dtype=dt)
|
2964
|
+
|
2965
|
+
oa = orth(a)
|
2966
|
+
assert oa.dtype == orth(a0).dtype
|
2967
|
+
assert oa.shape == (0, 0)
|
2968
|
+
|
2969
|
+
|
2970
|
+
class TestNullSpace:
|
2971
|
+
def test_null_space(self):
|
2972
|
+
rng = np.random.RandomState(1)
|
2973
|
+
|
2974
|
+
dtypes = [np.float32, np.float64, np.complex64, np.complex128]
|
2975
|
+
sizes = [1, 2, 3, 10, 100]
|
2976
|
+
|
2977
|
+
for dt, n in itertools.product(dtypes, sizes):
|
2978
|
+
X = np.ones((2, n), dtype=dt)
|
2979
|
+
|
2980
|
+
eps = np.finfo(dt).eps
|
2981
|
+
tol = 1000 * eps
|
2982
|
+
|
2983
|
+
Y = null_space(X)
|
2984
|
+
assert_equal(Y.shape, (n, n-1))
|
2985
|
+
assert_allclose(X @ Y, 0, atol=tol)
|
2986
|
+
|
2987
|
+
Y = null_space(X.T)
|
2988
|
+
assert_equal(Y.shape, (2, 1))
|
2989
|
+
assert_allclose(X.T @ Y, 0, atol=tol)
|
2990
|
+
|
2991
|
+
X = rng.randn(1 + n//2, n)
|
2992
|
+
Y = null_space(X)
|
2993
|
+
assert_equal(Y.shape, (n, n - 1 - n//2))
|
2994
|
+
assert_allclose(X @ Y, 0, atol=tol)
|
2995
|
+
|
2996
|
+
if n > 5:
|
2997
|
+
rng = np.random.RandomState(1)
|
2998
|
+
X = rng.rand(n, 5) @ rng.rand(5, n)
|
2999
|
+
X = X + 1e-4 * rng.rand(n, 1) @ rng.rand(1, n)
|
3000
|
+
X = X.astype(dt)
|
3001
|
+
|
3002
|
+
Y = null_space(X, rcond=1e-3)
|
3003
|
+
assert_equal(Y.shape, (n, n - 5))
|
3004
|
+
|
3005
|
+
Y = null_space(X, rcond=1e-6)
|
3006
|
+
assert_equal(Y.shape, (n, n - 6))
|
3007
|
+
|
3008
|
+
@pytest.mark.parametrize('dt', [int, float, np.float32, complex, np.complex64])
|
3009
|
+
def test_null_space_empty(self, dt):
|
3010
|
+
a = np.empty((0, 0), dtype=dt)
|
3011
|
+
a0 = np.eye(2, dtype=dt)
|
3012
|
+
nsa = null_space(a)
|
3013
|
+
|
3014
|
+
assert nsa.shape == (0, 0)
|
3015
|
+
assert nsa.dtype == null_space(a0).dtype
|
3016
|
+
|
3017
|
+
@pytest.mark.parametrize("overwrite_a", [True, False])
|
3018
|
+
@pytest.mark.parametrize("check_finite", [True, False])
|
3019
|
+
@pytest.mark.parametrize("lapack_driver", ["gesdd", "gesvd"])
|
3020
|
+
def test_null_space_options(self, overwrite_a, check_finite, lapack_driver):
|
3021
|
+
rng = np.random.default_rng(42887289350573064398746)
|
3022
|
+
n = 10
|
3023
|
+
X = rng.standard_normal((1 + n//2, n))
|
3024
|
+
Y = null_space(X.copy(), overwrite_a=overwrite_a, check_finite=check_finite,
|
3025
|
+
lapack_driver=lapack_driver)
|
3026
|
+
assert_allclose(X @ Y, 0, atol=np.finfo(X.dtype).eps*100)
|
3027
|
+
|
3028
|
+
|
3029
|
+
def test_subspace_angles():
|
3030
|
+
H = hadamard(8, float)
|
3031
|
+
A = H[:, :3]
|
3032
|
+
B = H[:, 3:]
|
3033
|
+
assert_allclose(subspace_angles(A, B), [np.pi / 2.] * 3, atol=1e-14)
|
3034
|
+
assert_allclose(subspace_angles(B, A), [np.pi / 2.] * 3, atol=1e-14)
|
3035
|
+
for x in (A, B):
|
3036
|
+
assert_allclose(subspace_angles(x, x), np.zeros(x.shape[1]),
|
3037
|
+
atol=1e-14)
|
3038
|
+
# From MATLAB function "subspace", which effectively only returns the
|
3039
|
+
# last value that we calculate
|
3040
|
+
x = np.array(
|
3041
|
+
[[0.537667139546100, 0.318765239858981, 3.578396939725760, 0.725404224946106], # noqa: E501
|
3042
|
+
[1.833885014595086, -1.307688296305273, 2.769437029884877, -0.063054873189656], # noqa: E501
|
3043
|
+
[-2.258846861003648, -0.433592022305684, -1.349886940156521, 0.714742903826096], # noqa: E501
|
3044
|
+
[0.862173320368121, 0.342624466538650, 3.034923466331855, -0.204966058299775]]) # noqa: E501
|
3045
|
+
expected = 1.481454682101605
|
3046
|
+
assert_allclose(subspace_angles(x[:, :2], x[:, 2:])[0], expected,
|
3047
|
+
rtol=1e-12)
|
3048
|
+
assert_allclose(subspace_angles(x[:, 2:], x[:, :2])[0], expected,
|
3049
|
+
rtol=1e-12)
|
3050
|
+
expected = 0.746361174247302
|
3051
|
+
assert_allclose(subspace_angles(x[:, :2], x[:, [2]]), expected, rtol=1e-12)
|
3052
|
+
assert_allclose(subspace_angles(x[:, [2]], x[:, :2]), expected, rtol=1e-12)
|
3053
|
+
expected = 0.487163718534313
|
3054
|
+
assert_allclose(subspace_angles(x[:, :3], x[:, [3]]), expected, rtol=1e-12)
|
3055
|
+
assert_allclose(subspace_angles(x[:, [3]], x[:, :3]), expected, rtol=1e-12)
|
3056
|
+
expected = 0.328950515907756
|
3057
|
+
assert_allclose(subspace_angles(x[:, :2], x[:, 1:]), [expected, 0],
|
3058
|
+
atol=1e-12)
|
3059
|
+
# Degenerate conditions
|
3060
|
+
assert_raises(ValueError, subspace_angles, x[0], x)
|
3061
|
+
assert_raises(ValueError, subspace_angles, x, x[0])
|
3062
|
+
assert_raises(ValueError, subspace_angles, x[:-1], x)
|
3063
|
+
|
3064
|
+
# Test branch if mask.any is True:
|
3065
|
+
A = np.array([[1, 0, 0],
|
3066
|
+
[0, 1, 0],
|
3067
|
+
[0, 0, 1],
|
3068
|
+
[0, 0, 0],
|
3069
|
+
[0, 0, 0]])
|
3070
|
+
B = np.array([[1, 0, 0],
|
3071
|
+
[0, 1, 0],
|
3072
|
+
[0, 0, 0],
|
3073
|
+
[0, 0, 0],
|
3074
|
+
[0, 0, 1]])
|
3075
|
+
expected = np.array([np.pi/2, 0, 0])
|
3076
|
+
assert_allclose(subspace_angles(A, B), expected, rtol=1e-12)
|
3077
|
+
|
3078
|
+
# Complex
|
3079
|
+
# second column in "b" does not affect result, just there so that
|
3080
|
+
# b can have more cols than a, and vice-versa (both conditional code paths)
|
3081
|
+
a = [[1 + 1j], [0]]
|
3082
|
+
b = [[1 - 1j, 0], [0, 1]]
|
3083
|
+
assert_allclose(subspace_angles(a, b), 0., atol=1e-14)
|
3084
|
+
assert_allclose(subspace_angles(b, a), 0., atol=1e-14)
|
3085
|
+
|
3086
|
+
# Empty
|
3087
|
+
a = np.empty((0, 0))
|
3088
|
+
b = np.empty((0, 0))
|
3089
|
+
assert_allclose(subspace_angles(a, b), np.empty((0,)))
|
3090
|
+
a = np.empty((2, 0))
|
3091
|
+
b = np.empty((2, 0))
|
3092
|
+
assert_allclose(subspace_angles(a, b), np.empty((0,)))
|
3093
|
+
a = np.empty((0, 2))
|
3094
|
+
b = np.empty((0, 3))
|
3095
|
+
assert_allclose(subspace_angles(a, b), np.empty((0,)))
|
3096
|
+
|
3097
|
+
|
3098
|
+
class TestCDF2RDF:
|
3099
|
+
|
3100
|
+
def matmul(self, a, b):
|
3101
|
+
return np.einsum('...ij,...jk->...ik', a, b)
|
3102
|
+
|
3103
|
+
def assert_eig_valid(self, w, v, x):
|
3104
|
+
assert_array_almost_equal(
|
3105
|
+
self.matmul(v, w),
|
3106
|
+
self.matmul(x, v)
|
3107
|
+
)
|
3108
|
+
|
3109
|
+
def test_single_array0x0real(self):
|
3110
|
+
# eig doesn't support 0x0 in old versions of numpy
|
3111
|
+
X = np.empty((0, 0))
|
3112
|
+
w, v = np.empty(0), np.empty((0, 0))
|
3113
|
+
wr, vr = cdf2rdf(w, v)
|
3114
|
+
self.assert_eig_valid(wr, vr, X)
|
3115
|
+
|
3116
|
+
def test_single_array2x2_real(self):
|
3117
|
+
X = np.array([[1, 2], [3, -1]])
|
3118
|
+
w, v = np.linalg.eig(X)
|
3119
|
+
wr, vr = cdf2rdf(w, v)
|
3120
|
+
self.assert_eig_valid(wr, vr, X)
|
3121
|
+
|
3122
|
+
def test_single_array2x2_complex(self):
|
3123
|
+
X = np.array([[1, 2], [-2, 1]])
|
3124
|
+
w, v = np.linalg.eig(X)
|
3125
|
+
wr, vr = cdf2rdf(w, v)
|
3126
|
+
self.assert_eig_valid(wr, vr, X)
|
3127
|
+
|
3128
|
+
def test_single_array3x3_real(self):
|
3129
|
+
X = np.array([[1, 2, 3], [1, 2, 3], [2, 5, 6]])
|
3130
|
+
w, v = np.linalg.eig(X)
|
3131
|
+
wr, vr = cdf2rdf(w, v)
|
3132
|
+
self.assert_eig_valid(wr, vr, X)
|
3133
|
+
|
3134
|
+
def test_single_array3x3_complex(self):
|
3135
|
+
X = np.array([[1, 2, 3], [0, 4, 5], [0, -5, 4]])
|
3136
|
+
w, v = np.linalg.eig(X)
|
3137
|
+
wr, vr = cdf2rdf(w, v)
|
3138
|
+
self.assert_eig_valid(wr, vr, X)
|
3139
|
+
|
3140
|
+
def test_random_1d_stacked_arrays(self):
|
3141
|
+
# cannot test M == 0 due to bug in old numpy
|
3142
|
+
for M in range(1, 7):
|
3143
|
+
np.random.seed(999999999)
|
3144
|
+
X = np.random.rand(100, M, M)
|
3145
|
+
w, v = np.linalg.eig(X)
|
3146
|
+
wr, vr = cdf2rdf(w, v)
|
3147
|
+
self.assert_eig_valid(wr, vr, X)
|
3148
|
+
|
3149
|
+
def test_random_2d_stacked_arrays(self):
|
3150
|
+
# cannot test M == 0 due to bug in old numpy
|
3151
|
+
for M in range(1, 7):
|
3152
|
+
X = np.random.rand(10, 10, M, M)
|
3153
|
+
w, v = np.linalg.eig(X)
|
3154
|
+
wr, vr = cdf2rdf(w, v)
|
3155
|
+
self.assert_eig_valid(wr, vr, X)
|
3156
|
+
|
3157
|
+
def test_low_dimensionality_error(self):
|
3158
|
+
w, v = np.empty(()), np.array((2,))
|
3159
|
+
assert_raises(ValueError, cdf2rdf, w, v)
|
3160
|
+
|
3161
|
+
def test_not_square_error(self):
|
3162
|
+
# Check that passing a non-square array raises a ValueError.
|
3163
|
+
w, v = np.arange(3), np.arange(6).reshape(3, 2)
|
3164
|
+
assert_raises(ValueError, cdf2rdf, w, v)
|
3165
|
+
|
3166
|
+
def test_swapped_v_w_error(self):
|
3167
|
+
# Check that exchanging places of w and v raises ValueError.
|
3168
|
+
X = np.array([[1, 2, 3], [0, 4, 5], [0, -5, 4]])
|
3169
|
+
w, v = np.linalg.eig(X)
|
3170
|
+
assert_raises(ValueError, cdf2rdf, v, w)
|
3171
|
+
|
3172
|
+
def test_non_associated_error(self):
|
3173
|
+
# Check that passing non-associated eigenvectors raises a ValueError.
|
3174
|
+
w, v = np.arange(3), np.arange(16).reshape(4, 4)
|
3175
|
+
assert_raises(ValueError, cdf2rdf, w, v)
|
3176
|
+
|
3177
|
+
def test_not_conjugate_pairs(self):
|
3178
|
+
# Check that passing non-conjugate pairs raises a ValueError.
|
3179
|
+
X = np.array([[1, 2, 3], [1, 2, 3], [2, 5, 6+1j]])
|
3180
|
+
w, v = np.linalg.eig(X)
|
3181
|
+
assert_raises(ValueError, cdf2rdf, w, v)
|
3182
|
+
|
3183
|
+
# different arrays in the stack, so not conjugate
|
3184
|
+
X = np.array([
|
3185
|
+
[[1, 2, 3], [1, 2, 3], [2, 5, 6+1j]],
|
3186
|
+
[[1, 2, 3], [1, 2, 3], [2, 5, 6-1j]],
|
3187
|
+
])
|
3188
|
+
w, v = np.linalg.eig(X)
|
3189
|
+
assert_raises(ValueError, cdf2rdf, w, v)
|