scipy 1.16.2__cp314-cp314t-win_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- scipy/__config__.py +161 -0
- scipy/__init__.py +150 -0
- scipy/_cyutility.cp314t-win_arm64.lib +0 -0
- scipy/_cyutility.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/_lib/_ccallback_c.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/_lib/_fpumode.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/_lib/_test_ccallback.cp314t-win_arm64.pyd +0 -0
- scipy/_lib/_test_deprecation_call.cp314t-win_arm64.lib +0 -0
- scipy/_lib/_test_deprecation_call.cp314t-win_arm64.pyd +0 -0
- scipy/_lib/_test_deprecation_def.cp314t-win_arm64.lib +0 -0
- scipy/_lib/_test_deprecation_def.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/_lib/_uarray/_uarray.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/_lib/messagestream.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/cluster/_hierarchy.cp314t-win_arm64.pyd +0 -0
- scipy/cluster/_optimal_leaf_ordering.cp314t-win_arm64.lib +0 -0
- scipy/cluster/_optimal_leaf_ordering.cp314t-win_arm64.pyd +0 -0
- scipy/cluster/_vq.cp314t-win_arm64.lib +0 -0
- scipy/cluster/_vq.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/fft/_pocketfft/pypocketfft.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/fftpack/convolve.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/integrate/_dop.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/integrate/_lsoda.cp314t-win_arm64.pyd +0 -0
- scipy/integrate/_ode.py +1395 -0
- scipy/integrate/_odepack.cp314t-win_arm64.lib +0 -0
- scipy/integrate/_odepack.cp314t-win_arm64.pyd +0 -0
- scipy/integrate/_odepack_py.py +273 -0
- scipy/integrate/_quad_vec.py +674 -0
- scipy/integrate/_quadpack.cp314t-win_arm64.lib +0 -0
- scipy/integrate/_quadpack.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/integrate/_test_multivariate.cp314t-win_arm64.pyd +0 -0
- scipy/integrate/_test_odeint_banded.cp314t-win_arm64.lib +0 -0
- scipy/integrate/_test_odeint_banded.cp314t-win_arm64.pyd +0 -0
- scipy/integrate/_vode.cp314t-win_arm64.lib +0 -0
- scipy/integrate/_vode.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/interpolate/_dfitpack.cp314t-win_arm64.pyd +0 -0
- scipy/interpolate/_dierckx.cp314t-win_arm64.lib +0 -0
- scipy/interpolate/_dierckx.cp314t-win_arm64.pyd +0 -0
- scipy/interpolate/_fitpack.cp314t-win_arm64.lib +0 -0
- scipy/interpolate/_fitpack.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/interpolate/_interpnd.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/interpolate/_ppoly.cp314t-win_arm64.pyd +0 -0
- scipy/interpolate/_rbf.py +290 -0
- scipy/interpolate/_rbfinterp.py +550 -0
- scipy/interpolate/_rbfinterp_pythran.cp314t-win_arm64.lib +0 -0
- scipy/interpolate/_rbfinterp_pythran.cp314t-win_arm64.pyd +0 -0
- scipy/interpolate/_rgi.py +764 -0
- scipy/interpolate/_rgi_cython.cp314t-win_arm64.lib +0 -0
- scipy/interpolate/_rgi_cython.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/io/_fast_matrix_market/_fmm_core.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/io/_test_fortran.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/io/matlab/_mio5_utils.cp314t-win_arm64.pyd +0 -0
- scipy/io/matlab/_mio_utils.cp314t-win_arm64.lib +0 -0
- scipy/io/matlab/_mio_utils.cp314t-win_arm64.pyd +0 -0
- scipy/io/matlab/_miobase.py +435 -0
- scipy/io/matlab/_streams.cp314t-win_arm64.lib +0 -0
- scipy/io/matlab/_streams.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/linalg/_cythonized_array_utils.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/linalg/_decomp_interpolative.cp314t-win_arm64.pyd +0 -0
- scipy/linalg/_decomp_ldl.py +356 -0
- scipy/linalg/_decomp_lu.py +401 -0
- scipy/linalg/_decomp_lu_cython.cp314t-win_arm64.lib +0 -0
- scipy/linalg/_decomp_lu_cython.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/linalg/_decomp_update.cp314t-win_arm64.pyd +0 -0
- scipy/linalg/_expm_frechet.py +417 -0
- scipy/linalg/_fblas.cp314t-win_arm64.lib +0 -0
- scipy/linalg/_fblas.cp314t-win_arm64.pyd +0 -0
- scipy/linalg/_flapack.cp314t-win_arm64.lib +0 -0
- scipy/linalg/_flapack.cp314t-win_arm64.pyd +0 -0
- scipy/linalg/_lapack_subroutines.h +1521 -0
- scipy/linalg/_linalg_pythran.cp314t-win_arm64.lib +0 -0
- scipy/linalg/_linalg_pythran.cp314t-win_arm64.pyd +0 -0
- scipy/linalg/_matfuncs.py +1050 -0
- scipy/linalg/_matfuncs_expm.cp314t-win_arm64.lib +0 -0
- scipy/linalg/_matfuncs_expm.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/linalg/_matfuncs_schur_sqrtm.cp314t-win_arm64.pyd +0 -0
- scipy/linalg/_matfuncs_sqrtm.py +107 -0
- scipy/linalg/_matfuncs_sqrtm_triu.cp314t-win_arm64.lib +0 -0
- scipy/linalg/_matfuncs_sqrtm_triu.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/linalg/_solve_toeplitz.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/linalg/cython_blas.cp314t-win_arm64.pyd +0 -0
- scipy/linalg/cython_blas.pxd +169 -0
- scipy/linalg/cython_blas.pyx +1432 -0
- scipy/linalg/cython_lapack.cp314t-win_arm64.lib +0 -0
- scipy/linalg/cython_lapack.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/ndimage/_ctest.cp314t-win_arm64.pyd +0 -0
- scipy/ndimage/_cytest.cp314t-win_arm64.lib +0 -0
- scipy/ndimage/_cytest.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/ndimage/_nd_image.cp314t-win_arm64.pyd +0 -0
- scipy/ndimage/_ndimage_api.py +16 -0
- scipy/ndimage/_ni_docstrings.py +214 -0
- scipy/ndimage/_ni_label.cp314t-win_arm64.lib +0 -0
- scipy/ndimage/_ni_label.cp314t-win_arm64.pyd +0 -0
- scipy/ndimage/_ni_support.py +139 -0
- scipy/ndimage/_rank_filter_1d.cp314t-win_arm64.lib +0 -0
- scipy/ndimage/_rank_filter_1d.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/odr/__odrpack.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/optimize/_bglu_dense.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/optimize/_direct.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/optimize/_group_columns.cp314t-win_arm64.pyd +0 -0
- scipy/optimize/_hessian_update_strategy.py +479 -0
- scipy/optimize/_highspy/__init__.py +0 -0
- scipy/optimize/_highspy/_core.cp314t-win_arm64.lib +0 -0
- scipy/optimize/_highspy/_core.cp314t-win_arm64.pyd +0 -0
- scipy/optimize/_highspy/_highs_options.cp314t-win_arm64.lib +0 -0
- scipy/optimize/_highspy/_highs_options.cp314t-win_arm64.pyd +0 -0
- scipy/optimize/_highspy/_highs_wrapper.py +338 -0
- scipy/optimize/_isotonic.py +157 -0
- scipy/optimize/_lbfgsb.cp314t-win_arm64.lib +0 -0
- scipy/optimize/_lbfgsb.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/optimize/_lsap.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/optimize/_lsq/givens_elimination.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/optimize/_minpack.cp314t-win_arm64.pyd +0 -0
- scipy/optimize/_minpack_py.py +1178 -0
- scipy/optimize/_moduleTNC.cp314t-win_arm64.lib +0 -0
- scipy/optimize/_moduleTNC.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/optimize/_pava_pybind.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/optimize/_slsqplib.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/optimize/_trlib/_trlib.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/optimize/_zeros.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/optimize/cython_optimize/_zeros.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/signal/_max_len_seq_inner.cp314t-win_arm64.pyd +0 -0
- scipy/signal/_peak_finding.py +1310 -0
- scipy/signal/_peak_finding_utils.cp314t-win_arm64.lib +0 -0
- scipy/signal/_peak_finding_utils.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/signal/_sigtools.cp314t-win_arm64.pyd +0 -0
- scipy/signal/_sosfilt.cp314t-win_arm64.lib +0 -0
- scipy/signal/_sosfilt.cp314t-win_arm64.pyd +0 -0
- scipy/signal/_spectral_py.py +2471 -0
- scipy/signal/_spline.cp314t-win_arm64.lib +0 -0
- scipy/signal/_spline.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/signal/_upfirdn_apply.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/sparse/_csparsetools.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/sparse/_sparsetools.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/sparse/csgraph/_flow.cp314t-win_arm64.pyd +0 -0
- scipy/sparse/csgraph/_laplacian.py +563 -0
- scipy/sparse/csgraph/_matching.cp314t-win_arm64.lib +0 -0
- scipy/sparse/csgraph/_matching.cp314t-win_arm64.pyd +0 -0
- scipy/sparse/csgraph/_min_spanning_tree.cp314t-win_arm64.lib +0 -0
- scipy/sparse/csgraph/_min_spanning_tree.cp314t-win_arm64.pyd +0 -0
- scipy/sparse/csgraph/_reordering.cp314t-win_arm64.lib +0 -0
- scipy/sparse/csgraph/_reordering.cp314t-win_arm64.pyd +0 -0
- scipy/sparse/csgraph/_shortest_path.cp314t-win_arm64.lib +0 -0
- scipy/sparse/csgraph/_shortest_path.cp314t-win_arm64.pyd +0 -0
- scipy/sparse/csgraph/_tools.cp314t-win_arm64.lib +0 -0
- scipy/sparse/csgraph/_tools.cp314t-win_arm64.pyd +0 -0
- scipy/sparse/csgraph/_traversal.cp314t-win_arm64.lib +0 -0
- scipy/sparse/csgraph/_traversal.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/sparse/linalg/_dsolve/_superlu.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/sparse/linalg/_eigen/arpack/_arpack.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/sparse/linalg/_propack/_cpropack.cp314t-win_arm64.pyd +0 -0
- scipy/sparse/linalg/_propack/_dpropack.cp314t-win_arm64.lib +0 -0
- scipy/sparse/linalg/_propack/_dpropack.cp314t-win_arm64.pyd +0 -0
- scipy/sparse/linalg/_propack/_spropack.cp314t-win_arm64.lib +0 -0
- scipy/sparse/linalg/_propack/_spropack.cp314t-win_arm64.pyd +0 -0
- scipy/sparse/linalg/_propack/_zpropack.cp314t-win_arm64.lib +0 -0
- scipy/sparse/linalg/_propack/_zpropack.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/spatial/_ckdtree.cp314t-win_arm64.pyd +0 -0
- scipy/spatial/_distance_pybind.cp314t-win_arm64.lib +0 -0
- scipy/spatial/_distance_pybind.cp314t-win_arm64.pyd +0 -0
- scipy/spatial/_distance_wrap.cp314t-win_arm64.lib +0 -0
- scipy/spatial/_distance_wrap.cp314t-win_arm64.pyd +0 -0
- scipy/spatial/_geometric_slerp.py +238 -0
- scipy/spatial/_hausdorff.cp314t-win_arm64.lib +0 -0
- scipy/spatial/_hausdorff.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/spatial/_qhull.cp314t-win_arm64.pyd +0 -0
- scipy/spatial/_qhull.pyi +213 -0
- scipy/spatial/_spherical_voronoi.py +341 -0
- scipy/spatial/_voronoi.cp314t-win_arm64.lib +0 -0
- scipy/spatial/_voronoi.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/spatial/transform/_rigid_transform.cp314t-win_arm64.pyd +0 -0
- scipy/spatial/transform/_rotation.cp314t-win_arm64.lib +0 -0
- scipy/spatial/transform/_rotation.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/special/_comb.cp314t-win_arm64.pyd +0 -0
- scipy/special/_ellip_harm.py +214 -0
- scipy/special/_ellip_harm_2.cp314t-win_arm64.lib +0 -0
- scipy/special/_ellip_harm_2.cp314t-win_arm64.pyd +0 -0
- scipy/special/_gufuncs.cp314t-win_arm64.lib +0 -0
- scipy/special/_gufuncs.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/special/_specfun.cp314t-win_arm64.pyd +0 -0
- scipy/special/_special_ufuncs.cp314t-win_arm64.lib +0 -0
- scipy/special/_special_ufuncs.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/special/_test_internal.cp314t-win_arm64.pyd +0 -0
- scipy/special/_test_internal.pyi +9 -0
- scipy/special/_testutils.py +321 -0
- scipy/special/_ufuncs.cp314t-win_arm64.lib +0 -0
- scipy/special/_ufuncs.cp314t-win_arm64.pyd +0 -0
- scipy/special/_ufuncs.pyi +522 -0
- scipy/special/_ufuncs.pyx +13173 -0
- scipy/special/_ufuncs_cxx.cp314t-win_arm64.lib +0 -0
- scipy/special/_ufuncs_cxx.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/special/cython_special.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/stats/_ansari_swilk_statistics.cp314t-win_arm64.pyd +0 -0
- scipy/stats/_axis_nan_policy.py +692 -0
- scipy/stats/_biasedurn.cp314t-win_arm64.lib +0 -0
- scipy/stats/_biasedurn.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/stats/_levy_stable/levyst.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/stats/_qmc_cy.cp314t-win_arm64.pyd +0 -0
- scipy/stats/_qmc_cy.pyi +54 -0
- scipy/stats/_qmvnt.py +454 -0
- scipy/stats/_qmvnt_cy.cp314t-win_arm64.lib +0 -0
- scipy/stats/_qmvnt_cy.cp314t-win_arm64.pyd +0 -0
- scipy/stats/_quantile.py +335 -0
- scipy/stats/_rcont/__init__.py +4 -0
- scipy/stats/_rcont/rcont.cp314t-win_arm64.lib +0 -0
- scipy/stats/_rcont/rcont.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/stats/_sobol.cp314t-win_arm64.pyd +0 -0
- scipy/stats/_sobol.pyi +54 -0
- scipy/stats/_sobol_direction_numbers.npz +0 -0
- scipy/stats/_stats.cp314t-win_arm64.lib +0 -0
- scipy/stats/_stats.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/stats/_stats_pythran.cp314t-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.cp314t-win_arm64.lib +0 -0
- scipy/stats/_unuran/unuran_wrapper.cp314t-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,3083 @@
|
|
1
|
+
''' Some tests for filters '''
|
2
|
+
import functools
|
3
|
+
import itertools
|
4
|
+
import re
|
5
|
+
import contextlib
|
6
|
+
|
7
|
+
import numpy as np
|
8
|
+
import pytest
|
9
|
+
from numpy.testing import suppress_warnings, assert_allclose, assert_array_equal
|
10
|
+
from hypothesis import strategies as st
|
11
|
+
from hypothesis import given
|
12
|
+
import hypothesis.extra.numpy as npst
|
13
|
+
from pytest import raises as assert_raises
|
14
|
+
from scipy import ndimage
|
15
|
+
from scipy._lib._array_api import (
|
16
|
+
assert_almost_equal,
|
17
|
+
assert_array_almost_equal,
|
18
|
+
xp_assert_close,
|
19
|
+
xp_assert_equal,
|
20
|
+
)
|
21
|
+
from scipy._lib._array_api import (is_cupy, is_torch, is_dask, is_jax, array_namespace,
|
22
|
+
is_array_api_strict, xp_copy)
|
23
|
+
from scipy.ndimage._filters import _gaussian_kernel1d
|
24
|
+
|
25
|
+
from . import types, float_types, complex_types
|
26
|
+
|
27
|
+
|
28
|
+
skip_xp_backends = pytest.mark.skip_xp_backends
|
29
|
+
xfail_xp_backends = pytest.mark.xfail_xp_backends
|
30
|
+
pytestmark = [skip_xp_backends(cpu_only=True, exceptions=['cupy', 'jax.numpy'])]
|
31
|
+
|
32
|
+
uses_output_dtype = skip_xp_backends(
|
33
|
+
np_only=True, exceptions=["cupy"],
|
34
|
+
reason="output=dtype is numpy-specific"
|
35
|
+
)
|
36
|
+
|
37
|
+
|
38
|
+
def uses_output_array(f):
|
39
|
+
return skip_xp_backends("dask.array", reason="output=array requires buffer view")(
|
40
|
+
skip_xp_backends("jax.numpy", reason="output=array requires buffer view")(f))
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
def sumsq(a, b, xp=None):
|
45
|
+
xp = array_namespace(a, b) if xp is None else xp
|
46
|
+
return xp.sqrt(xp.sum((a - b)**2))
|
47
|
+
|
48
|
+
|
49
|
+
def _complex_correlate(xp, array, kernel, real_dtype, convolve=False,
|
50
|
+
mode="reflect", cval=0, ):
|
51
|
+
"""Utility to perform a reference complex-valued convolutions.
|
52
|
+
|
53
|
+
When convolve==False, correlation is performed instead
|
54
|
+
"""
|
55
|
+
array = xp.asarray(array)
|
56
|
+
kernel = xp.asarray(kernel)
|
57
|
+
complex_array = xp.isdtype(array.dtype, 'complex floating')
|
58
|
+
complex_kernel = xp.isdtype(kernel.dtype, 'complex floating')
|
59
|
+
if array.ndim == 1:
|
60
|
+
func = ndimage.convolve1d if convolve else ndimage.correlate1d
|
61
|
+
else:
|
62
|
+
func = ndimage.convolve if convolve else ndimage.correlate
|
63
|
+
if not convolve:
|
64
|
+
kernel = xp.conj(kernel)
|
65
|
+
if complex_array and complex_kernel:
|
66
|
+
# use: real(cval) for array.real component
|
67
|
+
# imag(cval) for array.imag component
|
68
|
+
re_cval = cval.real if isinstance(cval, complex) else xp.real(cval)
|
69
|
+
im_cval = cval.imag if isinstance(cval, complex) else xp.imag(cval)
|
70
|
+
|
71
|
+
output = (
|
72
|
+
func(xp.real(array), xp.real(kernel), output=real_dtype,
|
73
|
+
mode=mode, cval=re_cval) -
|
74
|
+
func(xp.imag(array), xp.imag(kernel), output=real_dtype,
|
75
|
+
mode=mode, cval=im_cval) +
|
76
|
+
1j * func(xp.imag(array), xp.real(kernel), output=real_dtype,
|
77
|
+
mode=mode, cval=im_cval) +
|
78
|
+
1j * func(xp.real(array), xp.imag(kernel), output=real_dtype,
|
79
|
+
mode=mode, cval=re_cval)
|
80
|
+
)
|
81
|
+
elif complex_array:
|
82
|
+
re_cval = xp.real(cval)
|
83
|
+
re_cval = re_cval.item() if isinstance(re_cval, xp.ndarray) else re_cval
|
84
|
+
im_cval = xp.imag(cval)
|
85
|
+
im_cval = im_cval.item() if isinstance(im_cval, xp.ndarray) else im_cval
|
86
|
+
|
87
|
+
output = (
|
88
|
+
func(xp.real(array), kernel, output=real_dtype, mode=mode,
|
89
|
+
cval=re_cval) +
|
90
|
+
1j * func(xp.imag(array), kernel, output=real_dtype, mode=mode,
|
91
|
+
cval=im_cval)
|
92
|
+
)
|
93
|
+
elif complex_kernel:
|
94
|
+
# real array so cval is real too
|
95
|
+
output = (
|
96
|
+
func(array, xp.real(kernel), output=real_dtype, mode=mode, cval=cval) +
|
97
|
+
1j * func(array, xp.imag(kernel), output=real_dtype, mode=mode,
|
98
|
+
cval=cval)
|
99
|
+
)
|
100
|
+
return output
|
101
|
+
|
102
|
+
|
103
|
+
def _cases_axes_tuple_length_mismatch():
|
104
|
+
# Generate combinations of filter function, valid kwargs, and
|
105
|
+
# keyword-value pairs for which the value will become with mismatched
|
106
|
+
# (invalid) size
|
107
|
+
filter_func = ndimage.gaussian_filter
|
108
|
+
kwargs = dict(radius=3, mode='constant', sigma=1.0, order=0)
|
109
|
+
for key, val in kwargs.items():
|
110
|
+
yield filter_func, kwargs, key, val
|
111
|
+
|
112
|
+
filter_funcs = [ndimage.uniform_filter, ndimage.minimum_filter,
|
113
|
+
ndimage.maximum_filter]
|
114
|
+
kwargs = dict(size=3, mode='constant', origin=0)
|
115
|
+
for filter_func in filter_funcs:
|
116
|
+
for key, val in kwargs.items():
|
117
|
+
yield filter_func, kwargs, key, val
|
118
|
+
|
119
|
+
filter_funcs = [ndimage.correlate, ndimage.convolve]
|
120
|
+
# sequence of mode not supported for correlate or convolve
|
121
|
+
kwargs = dict(origin=0)
|
122
|
+
for filter_func in filter_funcs:
|
123
|
+
for key, val in kwargs.items():
|
124
|
+
yield filter_func, kwargs, key, val
|
125
|
+
|
126
|
+
|
127
|
+
class TestNdimageFilters:
|
128
|
+
|
129
|
+
def _validate_complex(self, xp, array, kernel, type2, mode='reflect',
|
130
|
+
cval=0, check_warnings=True):
|
131
|
+
# utility for validating complex-valued correlations
|
132
|
+
real_dtype = xp.real(xp.asarray([], dtype=type2)).dtype
|
133
|
+
expected = _complex_correlate(
|
134
|
+
xp, array, kernel, real_dtype, convolve=False, mode=mode, cval=cval
|
135
|
+
)
|
136
|
+
|
137
|
+
if array.ndim == 1:
|
138
|
+
correlate = functools.partial(ndimage.correlate1d, axis=-1,
|
139
|
+
mode=mode, cval=cval)
|
140
|
+
convolve = functools.partial(ndimage.convolve1d, axis=-1,
|
141
|
+
mode=mode, cval=cval)
|
142
|
+
else:
|
143
|
+
correlate = functools.partial(ndimage.correlate, mode=mode,
|
144
|
+
cval=cval)
|
145
|
+
convolve = functools.partial(ndimage.convolve, mode=mode,
|
146
|
+
cval=cval)
|
147
|
+
|
148
|
+
# test correlate output dtype
|
149
|
+
output = correlate(array, kernel, output=type2)
|
150
|
+
assert_array_almost_equal(expected, output)
|
151
|
+
assert output.dtype.type == type2
|
152
|
+
|
153
|
+
# test correlate with pre-allocated output
|
154
|
+
output = xp.zeros_like(array, dtype=type2)
|
155
|
+
correlate(array, kernel, output=output)
|
156
|
+
assert_array_almost_equal(expected, output)
|
157
|
+
|
158
|
+
# test convolve output dtype
|
159
|
+
output = convolve(array, kernel, output=type2)
|
160
|
+
expected = _complex_correlate(
|
161
|
+
xp, array, kernel, real_dtype, convolve=True, mode=mode, cval=cval,
|
162
|
+
)
|
163
|
+
assert_array_almost_equal(expected, output)
|
164
|
+
assert output.dtype.type == type2
|
165
|
+
|
166
|
+
# convolve with pre-allocated output
|
167
|
+
convolve(array, kernel, output=output)
|
168
|
+
assert_array_almost_equal(expected, output)
|
169
|
+
assert output.dtype.type == type2
|
170
|
+
|
171
|
+
if check_warnings:
|
172
|
+
# warns if the output is not a complex dtype
|
173
|
+
with pytest.warns(UserWarning,
|
174
|
+
match="promoting specified output dtype to "
|
175
|
+
"complex"):
|
176
|
+
correlate(array, kernel, output=real_dtype)
|
177
|
+
|
178
|
+
with pytest.warns(UserWarning,
|
179
|
+
match="promoting specified output dtype to "
|
180
|
+
"complex"):
|
181
|
+
convolve(array, kernel, output=real_dtype)
|
182
|
+
|
183
|
+
# raises if output array is provided, but is not complex-valued
|
184
|
+
output_real = xp.zeros_like(array, dtype=real_dtype)
|
185
|
+
with assert_raises(RuntimeError):
|
186
|
+
correlate(array, kernel, output=output_real)
|
187
|
+
|
188
|
+
with assert_raises(RuntimeError):
|
189
|
+
convolve(array, kernel, output=output_real)
|
190
|
+
|
191
|
+
def test_correlate01(self, xp):
|
192
|
+
array = xp.asarray([1, 2])
|
193
|
+
weights = xp.asarray([2])
|
194
|
+
expected = xp.asarray([2, 4])
|
195
|
+
|
196
|
+
output = ndimage.correlate(array, weights)
|
197
|
+
assert_array_almost_equal(output, expected)
|
198
|
+
|
199
|
+
output = ndimage.convolve(array, weights)
|
200
|
+
assert_array_almost_equal(output, expected)
|
201
|
+
|
202
|
+
output = ndimage.correlate1d(array, weights)
|
203
|
+
assert_array_almost_equal(output, expected)
|
204
|
+
|
205
|
+
output = ndimage.convolve1d(array, weights)
|
206
|
+
assert_array_almost_equal(output, expected)
|
207
|
+
|
208
|
+
@xfail_xp_backends('cupy', reason="Differs by a factor of two?")
|
209
|
+
@uses_output_array
|
210
|
+
def test_correlate01_overlap(self, xp):
|
211
|
+
array = xp.reshape(xp.arange(256), (16, 16))
|
212
|
+
weights = xp.asarray([2])
|
213
|
+
expected = 2 * array
|
214
|
+
|
215
|
+
ndimage.correlate1d(array, weights, output=array)
|
216
|
+
assert_array_almost_equal(array, expected)
|
217
|
+
|
218
|
+
def test_correlate02(self, xp):
|
219
|
+
array = xp.asarray([1, 2, 3])
|
220
|
+
kernel = xp.asarray([1])
|
221
|
+
|
222
|
+
output = ndimage.correlate(array, kernel)
|
223
|
+
assert_array_almost_equal(array, output)
|
224
|
+
|
225
|
+
output = ndimage.convolve(array, kernel)
|
226
|
+
assert_array_almost_equal(array, output)
|
227
|
+
|
228
|
+
output = ndimage.correlate1d(array, kernel)
|
229
|
+
assert_array_almost_equal(array, output)
|
230
|
+
|
231
|
+
output = ndimage.convolve1d(array, kernel)
|
232
|
+
assert_array_almost_equal(array, output)
|
233
|
+
|
234
|
+
def test_correlate03(self, xp):
|
235
|
+
array = xp.asarray([1])
|
236
|
+
weights = xp.asarray([1, 1])
|
237
|
+
expected = xp.asarray([2])
|
238
|
+
|
239
|
+
output = ndimage.correlate(array, weights)
|
240
|
+
assert_array_almost_equal(output, expected)
|
241
|
+
|
242
|
+
output = ndimage.convolve(array, weights)
|
243
|
+
assert_array_almost_equal(output, expected)
|
244
|
+
|
245
|
+
output = ndimage.correlate1d(array, weights)
|
246
|
+
assert_array_almost_equal(output, expected)
|
247
|
+
|
248
|
+
output = ndimage.convolve1d(array, weights)
|
249
|
+
assert_array_almost_equal(output, expected)
|
250
|
+
|
251
|
+
def test_correlate04(self, xp):
|
252
|
+
array = xp.asarray([1, 2])
|
253
|
+
tcor = xp.asarray([2, 3])
|
254
|
+
tcov = xp.asarray([3, 4])
|
255
|
+
weights = xp.asarray([1, 1])
|
256
|
+
output = ndimage.correlate(array, weights)
|
257
|
+
assert_array_almost_equal(output, tcor)
|
258
|
+
output = ndimage.convolve(array, weights)
|
259
|
+
assert_array_almost_equal(output, tcov)
|
260
|
+
output = ndimage.correlate1d(array, weights)
|
261
|
+
assert_array_almost_equal(output, tcor)
|
262
|
+
output = ndimage.convolve1d(array, weights)
|
263
|
+
assert_array_almost_equal(output, tcov)
|
264
|
+
|
265
|
+
def test_correlate05(self, xp):
|
266
|
+
array = xp.asarray([1, 2, 3])
|
267
|
+
tcor = xp.asarray([2, 3, 5])
|
268
|
+
tcov = xp.asarray([3, 5, 6])
|
269
|
+
kernel = xp.asarray([1, 1])
|
270
|
+
output = ndimage.correlate(array, kernel)
|
271
|
+
assert_array_almost_equal(tcor, output)
|
272
|
+
output = ndimage.convolve(array, kernel)
|
273
|
+
assert_array_almost_equal(tcov, output)
|
274
|
+
output = ndimage.correlate1d(array, kernel)
|
275
|
+
assert_array_almost_equal(tcor, output)
|
276
|
+
output = ndimage.convolve1d(array, kernel)
|
277
|
+
assert_array_almost_equal(tcov, output)
|
278
|
+
|
279
|
+
def test_correlate06(self, xp):
|
280
|
+
array = xp.asarray([1, 2, 3])
|
281
|
+
tcor = xp.asarray([9, 14, 17])
|
282
|
+
tcov = xp.asarray([7, 10, 15])
|
283
|
+
weights = xp.asarray([1, 2, 3])
|
284
|
+
output = ndimage.correlate(array, weights)
|
285
|
+
assert_array_almost_equal(output, tcor)
|
286
|
+
output = ndimage.convolve(array, weights)
|
287
|
+
assert_array_almost_equal(output, tcov)
|
288
|
+
output = ndimage.correlate1d(array, weights)
|
289
|
+
assert_array_almost_equal(output, tcor)
|
290
|
+
output = ndimage.convolve1d(array, weights)
|
291
|
+
assert_array_almost_equal(output, tcov)
|
292
|
+
|
293
|
+
def test_correlate07(self, xp):
|
294
|
+
array = xp.asarray([1, 2, 3])
|
295
|
+
expected = xp.asarray([5, 8, 11])
|
296
|
+
weights = xp.asarray([1, 2, 1])
|
297
|
+
output = ndimage.correlate(array, weights)
|
298
|
+
assert_array_almost_equal(output, expected)
|
299
|
+
output = ndimage.convolve(array, weights)
|
300
|
+
assert_array_almost_equal(output, expected)
|
301
|
+
output = ndimage.correlate1d(array, weights)
|
302
|
+
assert_array_almost_equal(output, expected)
|
303
|
+
output = ndimage.convolve1d(array, weights)
|
304
|
+
assert_array_almost_equal(output, expected)
|
305
|
+
|
306
|
+
def test_correlate08(self, xp):
|
307
|
+
array = xp.asarray([1, 2, 3])
|
308
|
+
tcor = xp.asarray([1, 2, 5])
|
309
|
+
tcov = xp.asarray([3, 6, 7])
|
310
|
+
weights = xp.asarray([1, 2, -1])
|
311
|
+
output = ndimage.correlate(array, weights)
|
312
|
+
assert_array_almost_equal(output, tcor)
|
313
|
+
output = ndimage.convolve(array, weights)
|
314
|
+
assert_array_almost_equal(output, tcov)
|
315
|
+
output = ndimage.correlate1d(array, weights)
|
316
|
+
assert_array_almost_equal(output, tcor)
|
317
|
+
output = ndimage.convolve1d(array, weights)
|
318
|
+
assert_array_almost_equal(output, tcov)
|
319
|
+
|
320
|
+
def test_correlate09(self, xp):
|
321
|
+
array = xp.asarray([])
|
322
|
+
kernel = xp.asarray([1, 1])
|
323
|
+
output = ndimage.correlate(array, kernel)
|
324
|
+
assert_array_almost_equal(array, output)
|
325
|
+
output = ndimage.convolve(array, kernel)
|
326
|
+
assert_array_almost_equal(array, output)
|
327
|
+
output = ndimage.correlate1d(array, kernel)
|
328
|
+
assert_array_almost_equal(array, output)
|
329
|
+
output = ndimage.convolve1d(array, kernel)
|
330
|
+
assert_array_almost_equal(array, output)
|
331
|
+
|
332
|
+
def test_correlate10(self, xp):
|
333
|
+
array = xp.asarray([[]])
|
334
|
+
kernel = xp.asarray([[1, 1]])
|
335
|
+
output = ndimage.correlate(array, kernel)
|
336
|
+
assert_array_almost_equal(array, output)
|
337
|
+
output = ndimage.convolve(array, kernel)
|
338
|
+
assert_array_almost_equal(array, output)
|
339
|
+
|
340
|
+
def test_correlate11(self, xp):
|
341
|
+
array = xp.asarray([[1, 2, 3],
|
342
|
+
[4, 5, 6]])
|
343
|
+
kernel = xp.asarray([[1, 1],
|
344
|
+
[1, 1]])
|
345
|
+
output = ndimage.correlate(array, kernel)
|
346
|
+
assert_array_almost_equal(xp.asarray([[4, 6, 10], [10, 12, 16]]), output)
|
347
|
+
output = ndimage.convolve(array, kernel)
|
348
|
+
assert_array_almost_equal(xp.asarray([[12, 16, 18], [18, 22, 24]]), output)
|
349
|
+
|
350
|
+
def test_correlate12(self, xp):
|
351
|
+
array = xp.asarray([[1, 2, 3],
|
352
|
+
[4, 5, 6]])
|
353
|
+
kernel = xp.asarray([[1, 0],
|
354
|
+
[0, 1]])
|
355
|
+
output = ndimage.correlate(array, kernel)
|
356
|
+
assert_array_almost_equal(xp.asarray([[2, 3, 5], [5, 6, 8]]), output)
|
357
|
+
output = ndimage.convolve(array, kernel)
|
358
|
+
assert_array_almost_equal(xp.asarray([[6, 8, 9], [9, 11, 12]]), output)
|
359
|
+
|
360
|
+
@uses_output_dtype
|
361
|
+
@pytest.mark.parametrize('dtype_array', types)
|
362
|
+
@pytest.mark.parametrize('dtype_kernel', types)
|
363
|
+
def test_correlate13(self, dtype_array, dtype_kernel, xp):
|
364
|
+
dtype_array = getattr(xp, dtype_array)
|
365
|
+
dtype_kernel = getattr(xp, dtype_kernel)
|
366
|
+
|
367
|
+
kernel = xp.asarray([[1, 0],
|
368
|
+
[0, 1]])
|
369
|
+
array = xp.asarray([[1, 2, 3],
|
370
|
+
[4, 5, 6]], dtype=dtype_array)
|
371
|
+
output = ndimage.correlate(array, kernel, output=dtype_kernel)
|
372
|
+
assert_array_almost_equal(xp.asarray([[2, 3, 5], [5, 6, 8]]), output)
|
373
|
+
assert output.dtype.type == dtype_kernel
|
374
|
+
|
375
|
+
output = ndimage.convolve(array, kernel,
|
376
|
+
output=dtype_kernel)
|
377
|
+
assert_array_almost_equal(xp.asarray([[6, 8, 9], [9, 11, 12]]), output)
|
378
|
+
assert output.dtype.type == dtype_kernel
|
379
|
+
|
380
|
+
@uses_output_array
|
381
|
+
@pytest.mark.parametrize('dtype_array', types)
|
382
|
+
@pytest.mark.parametrize('dtype_output', types)
|
383
|
+
def test_correlate14(self, dtype_array, dtype_output, xp):
|
384
|
+
dtype_array = getattr(xp, dtype_array)
|
385
|
+
dtype_output = getattr(xp, dtype_output)
|
386
|
+
|
387
|
+
kernel = xp.asarray([[1, 0],
|
388
|
+
[0, 1]])
|
389
|
+
array = xp.asarray([[1, 2, 3],
|
390
|
+
[4, 5, 6]], dtype=dtype_array)
|
391
|
+
output = xp.zeros(array.shape, dtype=dtype_output)
|
392
|
+
ndimage.correlate(array, kernel, output=output)
|
393
|
+
assert_array_almost_equal(xp.asarray([[2, 3, 5], [5, 6, 8]]), output)
|
394
|
+
assert output.dtype == dtype_output
|
395
|
+
|
396
|
+
ndimage.convolve(array, kernel, output=output)
|
397
|
+
assert_array_almost_equal(xp.asarray([[6, 8, 9], [9, 11, 12]]), output)
|
398
|
+
assert output.dtype == dtype_output
|
399
|
+
|
400
|
+
@uses_output_dtype
|
401
|
+
@pytest.mark.parametrize('dtype_array', types)
|
402
|
+
def test_correlate15(self, dtype_array, xp):
|
403
|
+
dtype_array = getattr(xp, dtype_array)
|
404
|
+
|
405
|
+
kernel = xp.asarray([[1, 0],
|
406
|
+
[0, 1]])
|
407
|
+
array = xp.asarray([[1, 2, 3],
|
408
|
+
[4, 5, 6]], dtype=dtype_array)
|
409
|
+
output = ndimage.correlate(array, kernel, output=xp.float32)
|
410
|
+
assert_array_almost_equal(xp.asarray([[2, 3, 5], [5, 6, 8]]), output)
|
411
|
+
assert output.dtype.type == xp.float32
|
412
|
+
|
413
|
+
output = ndimage.convolve(array, kernel, output=xp.float32)
|
414
|
+
assert_array_almost_equal(xp.asarray([[6, 8, 9], [9, 11, 12]]), output)
|
415
|
+
assert output.dtype.type == xp.float32
|
416
|
+
|
417
|
+
@uses_output_dtype
|
418
|
+
@pytest.mark.parametrize('dtype_array', types)
|
419
|
+
def test_correlate16(self, dtype_array, xp):
|
420
|
+
dtype_array = getattr(xp, dtype_array)
|
421
|
+
|
422
|
+
kernel = xp.asarray([[0.5, 0],
|
423
|
+
[0, 0.5]])
|
424
|
+
array = xp.asarray([[1, 2, 3], [4, 5, 6]], dtype=dtype_array)
|
425
|
+
output = ndimage.correlate(array, kernel, output=xp.float32)
|
426
|
+
assert_array_almost_equal(xp.asarray([[1, 1.5, 2.5], [2.5, 3, 4]]), output)
|
427
|
+
assert output.dtype.type == xp.float32
|
428
|
+
|
429
|
+
output = ndimage.convolve(array, kernel, output=xp.float32)
|
430
|
+
assert_array_almost_equal(xp.asarray([[3, 4, 4.5], [4.5, 5.5, 6]]), output)
|
431
|
+
assert output.dtype.type == xp.float32
|
432
|
+
|
433
|
+
def test_correlate17(self, xp):
|
434
|
+
array = xp.asarray([1, 2, 3])
|
435
|
+
tcor = xp.asarray([3, 5, 6])
|
436
|
+
tcov = xp.asarray([2, 3, 5])
|
437
|
+
kernel = xp.asarray([1, 1])
|
438
|
+
output = ndimage.correlate(array, kernel, origin=-1)
|
439
|
+
assert_array_almost_equal(tcor, output)
|
440
|
+
output = ndimage.convolve(array, kernel, origin=-1)
|
441
|
+
assert_array_almost_equal(tcov, output)
|
442
|
+
output = ndimage.correlate1d(array, kernel, origin=-1)
|
443
|
+
assert_array_almost_equal(tcor, output)
|
444
|
+
output = ndimage.convolve1d(array, kernel, origin=-1)
|
445
|
+
assert_array_almost_equal(tcov, output)
|
446
|
+
|
447
|
+
@uses_output_dtype
|
448
|
+
@pytest.mark.parametrize('dtype_array', types)
|
449
|
+
def test_correlate18(self, dtype_array, xp):
|
450
|
+
dtype_array = getattr(xp, dtype_array)
|
451
|
+
|
452
|
+
kernel = xp.asarray([[1, 0],
|
453
|
+
[0, 1]])
|
454
|
+
array = xp.asarray([[1, 2, 3],
|
455
|
+
[4, 5, 6]], dtype=dtype_array)
|
456
|
+
output = ndimage.correlate(array, kernel,
|
457
|
+
output=xp.float32,
|
458
|
+
mode='nearest', origin=-1)
|
459
|
+
assert_array_almost_equal(xp.asarray([[6, 8, 9], [9, 11, 12]]), output)
|
460
|
+
assert output.dtype.type == xp.float32
|
461
|
+
|
462
|
+
output = ndimage.convolve(array, kernel,
|
463
|
+
output=xp.float32,
|
464
|
+
mode='nearest', origin=-1)
|
465
|
+
assert_array_almost_equal(xp.asarray([[2, 3, 5], [5, 6, 8]]), output)
|
466
|
+
assert output.dtype.type == xp.float32
|
467
|
+
|
468
|
+
def test_correlate_mode_sequence(self, xp):
|
469
|
+
kernel = xp.ones((2, 2))
|
470
|
+
array = xp.ones((3, 3), dtype=xp.float64)
|
471
|
+
with assert_raises(RuntimeError):
|
472
|
+
ndimage.correlate(array, kernel, mode=['nearest', 'reflect'])
|
473
|
+
with assert_raises(RuntimeError):
|
474
|
+
ndimage.convolve(array, kernel, mode=['nearest', 'reflect'])
|
475
|
+
|
476
|
+
@uses_output_dtype
|
477
|
+
@pytest.mark.parametrize('dtype_array', types)
|
478
|
+
def test_correlate19(self, dtype_array, xp):
|
479
|
+
dtype_array = getattr(xp, dtype_array)
|
480
|
+
|
481
|
+
kernel = xp.asarray([[1, 0],
|
482
|
+
[0, 1]])
|
483
|
+
array = xp.asarray([[1, 2, 3],
|
484
|
+
[4, 5, 6]], dtype=dtype_array)
|
485
|
+
output = ndimage.correlate(array, kernel,
|
486
|
+
output=xp.float32,
|
487
|
+
mode='nearest', origin=[-1, 0])
|
488
|
+
assert_array_almost_equal(xp.asarray([[5, 6, 8], [8, 9, 11]]), output)
|
489
|
+
assert output.dtype.type == xp.float32
|
490
|
+
|
491
|
+
output = ndimage.convolve(array, kernel,
|
492
|
+
output=xp.float32,
|
493
|
+
mode='nearest', origin=[-1, 0])
|
494
|
+
assert_array_almost_equal(xp.asarray([[3, 5, 6], [6, 8, 9]]), output)
|
495
|
+
assert output.dtype.type == xp.float32
|
496
|
+
|
497
|
+
@uses_output_array
|
498
|
+
@pytest.mark.parametrize('dtype_array', types)
|
499
|
+
@pytest.mark.parametrize('dtype_output', types)
|
500
|
+
def test_correlate20(self, dtype_array, dtype_output, xp):
|
501
|
+
dtype_array = getattr(xp, dtype_array)
|
502
|
+
dtype_output = getattr(xp, dtype_output)
|
503
|
+
|
504
|
+
weights = xp.asarray([1, 2, 1])
|
505
|
+
expected = xp.asarray([[5, 10, 15], [7, 14, 21]])
|
506
|
+
array = xp.asarray([[1, 2, 3],
|
507
|
+
[2, 4, 6]], dtype=dtype_array)
|
508
|
+
output = xp.zeros((2, 3), dtype=dtype_output)
|
509
|
+
ndimage.correlate1d(array, weights, axis=0, output=output)
|
510
|
+
assert_array_almost_equal(output, expected)
|
511
|
+
ndimage.convolve1d(array, weights, axis=0, output=output)
|
512
|
+
assert_array_almost_equal(output, expected)
|
513
|
+
|
514
|
+
def test_correlate21(self, xp):
|
515
|
+
array = xp.asarray([[1, 2, 3],
|
516
|
+
[2, 4, 6]])
|
517
|
+
expected = xp.asarray([[5, 10, 15], [7, 14, 21]])
|
518
|
+
weights = xp.asarray([1, 2, 1])
|
519
|
+
output = ndimage.correlate1d(array, weights, axis=0)
|
520
|
+
assert_array_almost_equal(output, expected)
|
521
|
+
output = ndimage.convolve1d(array, weights, axis=0)
|
522
|
+
assert_array_almost_equal(output, expected)
|
523
|
+
|
524
|
+
@uses_output_array
|
525
|
+
@pytest.mark.parametrize('dtype_array', types)
|
526
|
+
@pytest.mark.parametrize('dtype_output', types)
|
527
|
+
def test_correlate22(self, dtype_array, dtype_output, xp):
|
528
|
+
dtype_array = getattr(xp, dtype_array)
|
529
|
+
dtype_output = getattr(xp, dtype_output)
|
530
|
+
|
531
|
+
weights = xp.asarray([1, 2, 1])
|
532
|
+
expected = xp.asarray([[6, 12, 18], [6, 12, 18]])
|
533
|
+
array = xp.asarray([[1, 2, 3],
|
534
|
+
[2, 4, 6]], dtype=dtype_array)
|
535
|
+
output = xp.zeros((2, 3), dtype=dtype_output)
|
536
|
+
ndimage.correlate1d(array, weights, axis=0,
|
537
|
+
mode='wrap', output=output)
|
538
|
+
assert_array_almost_equal(output, expected)
|
539
|
+
ndimage.convolve1d(array, weights, axis=0,
|
540
|
+
mode='wrap', output=output)
|
541
|
+
assert_array_almost_equal(output, expected)
|
542
|
+
|
543
|
+
@uses_output_array
|
544
|
+
@pytest.mark.parametrize('dtype_array', types)
|
545
|
+
@pytest.mark.parametrize('dtype_output', types)
|
546
|
+
def test_correlate23(self, dtype_array, dtype_output, xp):
|
547
|
+
dtype_array = getattr(xp, dtype_array)
|
548
|
+
dtype_output = getattr(xp, dtype_output)
|
549
|
+
|
550
|
+
weights = xp.asarray([1, 2, 1])
|
551
|
+
expected = xp.asarray([[5, 10, 15], [7, 14, 21]])
|
552
|
+
array = xp.asarray([[1, 2, 3],
|
553
|
+
[2, 4, 6]], dtype=dtype_array)
|
554
|
+
output = xp.zeros((2, 3), dtype=dtype_output)
|
555
|
+
ndimage.correlate1d(array, weights, axis=0,
|
556
|
+
mode='nearest', output=output)
|
557
|
+
assert_array_almost_equal(output, expected)
|
558
|
+
ndimage.convolve1d(array, weights, axis=0,
|
559
|
+
mode='nearest', output=output)
|
560
|
+
assert_array_almost_equal(output, expected)
|
561
|
+
|
562
|
+
@uses_output_array
|
563
|
+
@pytest.mark.parametrize('dtype_array', types)
|
564
|
+
@pytest.mark.parametrize('dtype_output', types)
|
565
|
+
def test_correlate24(self, dtype_array, dtype_output, xp):
|
566
|
+
dtype_array = getattr(xp, dtype_array)
|
567
|
+
dtype_output = getattr(xp, dtype_output)
|
568
|
+
|
569
|
+
weights = xp.asarray([1, 2, 1])
|
570
|
+
tcor = xp.asarray([[7, 14, 21], [8, 16, 24]])
|
571
|
+
tcov = xp.asarray([[4, 8, 12], [5, 10, 15]])
|
572
|
+
array = xp.asarray([[1, 2, 3],
|
573
|
+
[2, 4, 6]], dtype=dtype_array)
|
574
|
+
output = xp.zeros((2, 3), dtype=dtype_output)
|
575
|
+
ndimage.correlate1d(array, weights, axis=0,
|
576
|
+
mode='nearest', output=output, origin=-1)
|
577
|
+
assert_array_almost_equal(output, tcor)
|
578
|
+
ndimage.convolve1d(array, weights, axis=0,
|
579
|
+
mode='nearest', output=output, origin=-1)
|
580
|
+
assert_array_almost_equal(output, tcov)
|
581
|
+
|
582
|
+
@uses_output_array
|
583
|
+
@pytest.mark.parametrize('dtype_array', types)
|
584
|
+
@pytest.mark.parametrize('dtype_output', types)
|
585
|
+
def test_correlate25(self, dtype_array, dtype_output, xp):
|
586
|
+
dtype_array = getattr(xp, dtype_array)
|
587
|
+
dtype_output = getattr(xp, dtype_output)
|
588
|
+
|
589
|
+
weights = xp.asarray([1, 2, 1])
|
590
|
+
tcor = xp.asarray([[4, 8, 12], [5, 10, 15]])
|
591
|
+
tcov = xp.asarray([[7, 14, 21], [8, 16, 24]])
|
592
|
+
array = xp.asarray([[1, 2, 3],
|
593
|
+
[2, 4, 6]], dtype=dtype_array)
|
594
|
+
output = xp.zeros((2, 3), dtype=dtype_output)
|
595
|
+
ndimage.correlate1d(array, weights, axis=0,
|
596
|
+
mode='nearest', output=output, origin=1)
|
597
|
+
assert_array_almost_equal(output, tcor)
|
598
|
+
ndimage.convolve1d(array, weights, axis=0,
|
599
|
+
mode='nearest', output=output, origin=1)
|
600
|
+
assert_array_almost_equal(output, tcov)
|
601
|
+
|
602
|
+
def test_correlate26(self, xp):
|
603
|
+
# test fix for gh-11661 (mirror extension of a length 1 signal)
|
604
|
+
y = ndimage.convolve1d(xp.ones(1), xp.ones(5), mode='mirror')
|
605
|
+
xp_assert_equal(y, xp.asarray([5.]))
|
606
|
+
|
607
|
+
y = ndimage.correlate1d(xp.ones(1), xp.ones(5), mode='mirror')
|
608
|
+
xp_assert_equal(y, xp.asarray([5.]))
|
609
|
+
|
610
|
+
@uses_output_dtype
|
611
|
+
@pytest.mark.parametrize('dtype_kernel', complex_types)
|
612
|
+
@pytest.mark.parametrize('dtype_input', types)
|
613
|
+
@pytest.mark.parametrize('dtype_output', complex_types)
|
614
|
+
def test_correlate_complex_kernel(self, dtype_input, dtype_kernel,
|
615
|
+
dtype_output, xp, num_parallel_threads):
|
616
|
+
dtype_input = getattr(xp, dtype_input)
|
617
|
+
dtype_kernel = getattr(xp, dtype_kernel)
|
618
|
+
dtype_output = getattr(xp, dtype_output)
|
619
|
+
|
620
|
+
kernel = xp.asarray([[1, 0],
|
621
|
+
[0, 1 + 1j]], dtype=dtype_kernel)
|
622
|
+
array = xp.asarray([[1, 2, 3],
|
623
|
+
[4, 5, 6]], dtype=dtype_input)
|
624
|
+
self._validate_complex(xp, array, kernel, dtype_output,
|
625
|
+
check_warnings=num_parallel_threads == 1)
|
626
|
+
|
627
|
+
@uses_output_dtype
|
628
|
+
@pytest.mark.parametrize('dtype_kernel', complex_types)
|
629
|
+
@pytest.mark.parametrize('dtype_input', types)
|
630
|
+
@pytest.mark.parametrize('dtype_output', complex_types)
|
631
|
+
@pytest.mark.parametrize('mode', ['grid-constant', 'constant'])
|
632
|
+
def test_correlate_complex_kernel_cval(self, dtype_input, dtype_kernel,
|
633
|
+
dtype_output, mode, xp,
|
634
|
+
num_parallel_threads):
|
635
|
+
dtype_input = getattr(xp, dtype_input)
|
636
|
+
dtype_kernel = getattr(xp, dtype_kernel)
|
637
|
+
dtype_output = getattr(xp, dtype_output)
|
638
|
+
|
639
|
+
if is_cupy(xp) and mode == 'grid-constant':
|
640
|
+
pytest.xfail('cupy/cupy#8404')
|
641
|
+
|
642
|
+
# test use of non-zero cval with complex inputs
|
643
|
+
# also verifies that mode 'grid-constant' does not segfault
|
644
|
+
kernel = xp.asarray([[1, 0],
|
645
|
+
[0, 1 + 1j]], dtype=dtype_kernel)
|
646
|
+
array = xp.asarray([[1, 2, 3],
|
647
|
+
[4, 5, 6]], dtype=dtype_input)
|
648
|
+
self._validate_complex(xp, array, kernel, dtype_output, mode=mode,
|
649
|
+
cval=5.0,
|
650
|
+
check_warnings=num_parallel_threads == 1)
|
651
|
+
|
652
|
+
@xfail_xp_backends('cupy', reason="cupy/cupy#8405")
|
653
|
+
@pytest.mark.parametrize('dtype_kernel', complex_types)
|
654
|
+
@pytest.mark.parametrize('dtype_input', types)
|
655
|
+
@pytest.mark.thread_unsafe
|
656
|
+
def test_correlate_complex_kernel_invalid_cval(self, dtype_input,
|
657
|
+
dtype_kernel, xp):
|
658
|
+
dtype_input = getattr(xp, dtype_input)
|
659
|
+
dtype_kernel = getattr(xp, dtype_kernel)
|
660
|
+
|
661
|
+
# cannot give complex cval with a real image
|
662
|
+
kernel = xp.asarray([[1, 0],
|
663
|
+
[0, 1 + 1j]], dtype=dtype_kernel)
|
664
|
+
array = xp.asarray([[1, 2, 3],
|
665
|
+
[4, 5, 6]], dtype=dtype_input)
|
666
|
+
for func in [ndimage.convolve, ndimage.correlate, ndimage.convolve1d,
|
667
|
+
ndimage.correlate1d]:
|
668
|
+
with pytest.raises((ValueError, TypeError)):
|
669
|
+
func(array, kernel, mode='constant', cval=5.0 + 1.0j,
|
670
|
+
output=xp.complex64)
|
671
|
+
|
672
|
+
@uses_output_dtype
|
673
|
+
@pytest.mark.parametrize('dtype_kernel', complex_types)
|
674
|
+
@pytest.mark.parametrize('dtype_input', types)
|
675
|
+
@pytest.mark.parametrize('dtype_output', complex_types)
|
676
|
+
def test_correlate1d_complex_kernel(self, dtype_input, dtype_kernel,
|
677
|
+
dtype_output, xp, num_parallel_threads):
|
678
|
+
dtype_input = getattr(xp, dtype_input)
|
679
|
+
dtype_kernel = getattr(xp, dtype_kernel)
|
680
|
+
dtype_output = getattr(xp, dtype_output)
|
681
|
+
|
682
|
+
kernel = xp.asarray([1, 1 + 1j], dtype=dtype_kernel)
|
683
|
+
array = xp.asarray([1, 2, 3, 4, 5, 6], dtype=dtype_input)
|
684
|
+
self._validate_complex(xp, array, kernel, dtype_output,
|
685
|
+
check_warnings=num_parallel_threads == 1)
|
686
|
+
|
687
|
+
@uses_output_dtype
|
688
|
+
@pytest.mark.parametrize('dtype_kernel', complex_types)
|
689
|
+
@pytest.mark.parametrize('dtype_input', types)
|
690
|
+
@pytest.mark.parametrize('dtype_output', complex_types)
|
691
|
+
def test_correlate1d_complex_kernel_cval(self, dtype_input, dtype_kernel,
|
692
|
+
dtype_output, xp,
|
693
|
+
num_parallel_threads):
|
694
|
+
dtype_input = getattr(xp, dtype_input)
|
695
|
+
dtype_kernel = getattr(xp, dtype_kernel)
|
696
|
+
dtype_output = getattr(xp, dtype_output)
|
697
|
+
|
698
|
+
kernel = xp.asarray([1, 1 + 1j], dtype=dtype_kernel)
|
699
|
+
array = xp.asarray([1, 2, 3, 4, 5, 6], dtype=dtype_input)
|
700
|
+
self._validate_complex(xp, array, kernel, dtype_output, mode='constant',
|
701
|
+
cval=5.0,
|
702
|
+
check_warnings=num_parallel_threads == 1)
|
703
|
+
|
704
|
+
@uses_output_dtype
|
705
|
+
@pytest.mark.parametrize('dtype_kernel', types)
|
706
|
+
@pytest.mark.parametrize('dtype_input', complex_types)
|
707
|
+
@pytest.mark.parametrize('dtype_output', complex_types)
|
708
|
+
def test_correlate_complex_input(self, dtype_input, dtype_kernel,
|
709
|
+
dtype_output, xp, num_parallel_threads):
|
710
|
+
dtype_input = getattr(xp, dtype_input)
|
711
|
+
dtype_kernel = getattr(xp, dtype_kernel)
|
712
|
+
dtype_output = getattr(xp, dtype_output)
|
713
|
+
|
714
|
+
kernel = xp.asarray([[1, 0],
|
715
|
+
[0, 1]], dtype=dtype_kernel)
|
716
|
+
array = xp.asarray([[1, 2j, 3],
|
717
|
+
[1 + 4j, 5, 6j]], dtype=dtype_input)
|
718
|
+
self._validate_complex(xp, array, kernel, dtype_output,
|
719
|
+
check_warnings=num_parallel_threads == 1)
|
720
|
+
|
721
|
+
@uses_output_dtype
|
722
|
+
@pytest.mark.parametrize('dtype_kernel', types)
|
723
|
+
@pytest.mark.parametrize('dtype_input', complex_types)
|
724
|
+
@pytest.mark.parametrize('dtype_output', complex_types)
|
725
|
+
def test_correlate1d_complex_input(self, dtype_input, dtype_kernel,
|
726
|
+
dtype_output, xp, num_parallel_threads):
|
727
|
+
dtype_input = getattr(xp, dtype_input)
|
728
|
+
dtype_kernel = getattr(xp, dtype_kernel)
|
729
|
+
dtype_output = getattr(xp, dtype_output)
|
730
|
+
|
731
|
+
kernel = xp.asarray([1, 0, 1], dtype=dtype_kernel)
|
732
|
+
array = xp.asarray([1, 2j, 3, 1 + 4j, 5, 6j], dtype=dtype_input)
|
733
|
+
self._validate_complex(xp, array, kernel, dtype_output,
|
734
|
+
check_warnings=num_parallel_threads == 1)
|
735
|
+
|
736
|
+
@uses_output_dtype
|
737
|
+
@xfail_xp_backends("cupy", reason="cupy/cupy#8405")
|
738
|
+
@pytest.mark.parametrize('dtype_kernel', types)
|
739
|
+
@pytest.mark.parametrize('dtype_input', complex_types)
|
740
|
+
@pytest.mark.parametrize('dtype_output', complex_types)
|
741
|
+
def test_correlate1d_complex_input_cval(self, dtype_input, dtype_kernel,
|
742
|
+
dtype_output, xp,
|
743
|
+
num_parallel_threads):
|
744
|
+
dtype_input = getattr(xp, dtype_input)
|
745
|
+
dtype_kernel = getattr(xp, dtype_kernel)
|
746
|
+
dtype_output = getattr(xp, dtype_output)
|
747
|
+
|
748
|
+
kernel = xp.asarray([1, 0, 1], dtype=dtype_kernel)
|
749
|
+
array = xp.asarray([1, 2j, 3, 1 + 4j, 5, 6j], dtype=dtype_input)
|
750
|
+
self._validate_complex(xp, array, kernel, dtype_output, mode='constant',
|
751
|
+
cval=5 - 3j,
|
752
|
+
check_warnings=num_parallel_threads == 1)
|
753
|
+
|
754
|
+
@uses_output_dtype
|
755
|
+
@xfail_xp_backends("cupy", reason="unhashable type: 'ndarray'")
|
756
|
+
@pytest.mark.parametrize('dtype', complex_types)
|
757
|
+
@pytest.mark.parametrize('dtype_output', complex_types)
|
758
|
+
def test_correlate_complex_input_and_kernel(self, dtype, dtype_output, xp,
|
759
|
+
num_parallel_threads):
|
760
|
+
dtype = getattr(xp, dtype)
|
761
|
+
dtype_output = getattr(xp, dtype_output)
|
762
|
+
|
763
|
+
kernel = xp.asarray([[1, 0],
|
764
|
+
[0, 1 + 1j]], dtype=dtype)
|
765
|
+
array = xp.asarray([[1, 2j, 3],
|
766
|
+
[1 + 4j, 5, 6j]], dtype=dtype)
|
767
|
+
self._validate_complex(xp, array, kernel, dtype_output,
|
768
|
+
check_warnings=num_parallel_threads == 1)
|
769
|
+
|
770
|
+
@uses_output_dtype
|
771
|
+
@xfail_xp_backends("cupy", reason="cupy/cupy#8405")
|
772
|
+
@pytest.mark.parametrize('dtype', complex_types)
|
773
|
+
@pytest.mark.parametrize('dtype_output', complex_types)
|
774
|
+
def test_correlate_complex_input_and_kernel_cval(self, dtype,
|
775
|
+
dtype_output, xp,
|
776
|
+
num_parallel_threads):
|
777
|
+
dtype = getattr(xp, dtype)
|
778
|
+
dtype_output = getattr(xp, dtype_output)
|
779
|
+
|
780
|
+
kernel = xp.asarray([[1, 0],
|
781
|
+
[0, 1 + 1j]], dtype=dtype)
|
782
|
+
array = xp.asarray([[1, 2, 3],
|
783
|
+
[4, 5, 6]], dtype=dtype)
|
784
|
+
self._validate_complex(xp, array, kernel, dtype_output, mode='constant',
|
785
|
+
cval=5.0 + 2.0j,
|
786
|
+
check_warnings=num_parallel_threads == 1)
|
787
|
+
|
788
|
+
@uses_output_dtype
|
789
|
+
@xfail_xp_backends("cupy", reason="unhashable type: 'ndarray'")
|
790
|
+
@pytest.mark.parametrize('dtype', complex_types)
|
791
|
+
@pytest.mark.parametrize('dtype_output', complex_types)
|
792
|
+
@pytest.mark.thread_unsafe
|
793
|
+
def test_correlate1d_complex_input_and_kernel(self, dtype, dtype_output, xp,
|
794
|
+
num_parallel_threads):
|
795
|
+
dtype = getattr(xp, dtype)
|
796
|
+
dtype_output = getattr(xp, dtype_output)
|
797
|
+
|
798
|
+
kernel = xp.asarray([1, 1 + 1j], dtype=dtype)
|
799
|
+
array = xp.asarray([1, 2j, 3, 1 + 4j, 5, 6j], dtype=dtype)
|
800
|
+
self._validate_complex(xp, array, kernel, dtype_output,
|
801
|
+
check_warnings=num_parallel_threads == 1)
|
802
|
+
|
803
|
+
@uses_output_dtype
|
804
|
+
@xfail_xp_backends("cupy", reason="cupy/cupy#8405")
|
805
|
+
@pytest.mark.parametrize('dtype', complex_types)
|
806
|
+
@pytest.mark.parametrize('dtype_output', complex_types)
|
807
|
+
def test_correlate1d_complex_input_and_kernel_cval(self, dtype,
|
808
|
+
dtype_output, xp,
|
809
|
+
num_parallel_threads):
|
810
|
+
|
811
|
+
dtype = getattr(xp, dtype)
|
812
|
+
dtype_output = getattr(xp, dtype_output)
|
813
|
+
|
814
|
+
kernel = xp.asarray([1, 1 + 1j], dtype=dtype)
|
815
|
+
array = xp.asarray([1, 2j, 3, 1 + 4j, 5, 6j], dtype=dtype)
|
816
|
+
self._validate_complex(xp, array, kernel, dtype_output, mode='constant',
|
817
|
+
cval=5.0 + 2.0j,
|
818
|
+
check_warnings=num_parallel_threads == 1)
|
819
|
+
|
820
|
+
def test_gauss01(self, xp):
|
821
|
+
input = xp.asarray([[1, 2, 3],
|
822
|
+
[2, 4, 6]], dtype=xp.float32)
|
823
|
+
output = ndimage.gaussian_filter(input, 0)
|
824
|
+
assert_array_almost_equal(output, input)
|
825
|
+
|
826
|
+
def test_gauss02(self, xp):
|
827
|
+
input = xp.asarray([[1, 2, 3],
|
828
|
+
[2, 4, 6]], dtype=xp.float32)
|
829
|
+
output = ndimage.gaussian_filter(input, 1.0)
|
830
|
+
assert input.dtype == output.dtype
|
831
|
+
assert input.shape == output.shape
|
832
|
+
|
833
|
+
@xfail_xp_backends("cupy", reason="cupy/cupy#8403")
|
834
|
+
def test_gauss03(self, xp):
|
835
|
+
# single precision data
|
836
|
+
input = xp.arange(100 * 100, dtype=xp.float32)
|
837
|
+
input = xp.reshape(input, (100, 100))
|
838
|
+
output = ndimage.gaussian_filter(input, [1.0, 1.0])
|
839
|
+
|
840
|
+
assert input.dtype == output.dtype
|
841
|
+
assert input.shape == output.shape
|
842
|
+
|
843
|
+
# input.sum() is 49995000.0. With single precision floats, we can't
|
844
|
+
# expect more than 8 digits of accuracy, so use decimal=0 in this test.
|
845
|
+
o_sum = xp.sum(output, dtype=xp.float64)
|
846
|
+
i_sum = xp.sum(input, dtype=xp.float64)
|
847
|
+
assert_almost_equal(o_sum, i_sum, decimal=0)
|
848
|
+
assert sumsq(input, output) > 1.0
|
849
|
+
|
850
|
+
@uses_output_dtype
|
851
|
+
def test_gauss04(self, xp):
|
852
|
+
input = xp.arange(100 * 100, dtype=xp.float32)
|
853
|
+
input = xp.reshape(input, (100, 100))
|
854
|
+
otype = xp.float64
|
855
|
+
output = ndimage.gaussian_filter(input, [1.0, 1.0], output=otype)
|
856
|
+
assert output.dtype.type == xp.float64
|
857
|
+
assert input.shape == output.shape
|
858
|
+
assert sumsq(input, output) > 1.0
|
859
|
+
|
860
|
+
@uses_output_dtype
|
861
|
+
def test_gauss05(self, xp):
|
862
|
+
input = xp.arange(100 * 100, dtype=xp.float32)
|
863
|
+
input = xp.reshape(input, (100, 100))
|
864
|
+
otype = xp.float64
|
865
|
+
output = ndimage.gaussian_filter(input, [1.0, 1.0],
|
866
|
+
order=1, output=otype)
|
867
|
+
assert output.dtype.type == xp.float64
|
868
|
+
assert input.shape == output.shape
|
869
|
+
assert sumsq(input, output) > 1.0
|
870
|
+
|
871
|
+
@uses_output_dtype
|
872
|
+
def test_gauss06(self, xp):
|
873
|
+
input = xp.arange(100 * 100, dtype=xp.float32)
|
874
|
+
input = xp.reshape(input, (100, 100))
|
875
|
+
otype = xp.float64
|
876
|
+
output1 = ndimage.gaussian_filter(input, [1.0, 1.0], output=otype)
|
877
|
+
output2 = ndimage.gaussian_filter(input, 1.0, output=otype)
|
878
|
+
assert_array_almost_equal(output1, output2)
|
879
|
+
|
880
|
+
@uses_output_array
|
881
|
+
def test_gauss_memory_overlap(self, xp):
|
882
|
+
input = xp.arange(100 * 100, dtype=xp.float32)
|
883
|
+
input = xp.reshape(input, (100, 100))
|
884
|
+
output1 = ndimage.gaussian_filter(input, 1.0)
|
885
|
+
ndimage.gaussian_filter(input, 1.0, output=input)
|
886
|
+
assert_array_almost_equal(output1, input)
|
887
|
+
|
888
|
+
@xfail_xp_backends("cupy", reason="https://github.com/cupy/cupy/pull/8339")
|
889
|
+
@pytest.mark.parametrize(('filter_func', 'extra_args', 'size0', 'size'),
|
890
|
+
[(ndimage.gaussian_filter, (), 0, 1.0),
|
891
|
+
(ndimage.uniform_filter, (), 1, 3),
|
892
|
+
(ndimage.minimum_filter, (), 1, 3),
|
893
|
+
(ndimage.maximum_filter, (), 1, 3),
|
894
|
+
(ndimage.median_filter, (), 1, 3),
|
895
|
+
(ndimage.rank_filter, (1,), 1, 3),
|
896
|
+
(ndimage.percentile_filter, (40,), 1, 3)])
|
897
|
+
@pytest.mark.parametrize(
|
898
|
+
'axes',
|
899
|
+
tuple(itertools.combinations(range(-3, 3), 1))
|
900
|
+
+ tuple(itertools.combinations(range(-3, 3), 2))
|
901
|
+
+ ((0, 1, 2),))
|
902
|
+
def test_filter_axes(self, filter_func, extra_args, size0, size, axes, xp):
|
903
|
+
# Note: `size` is called `sigma` in `gaussian_filter`
|
904
|
+
array = xp.arange(6 * 8 * 12, dtype=xp.float64)
|
905
|
+
array = xp.reshape(array, (6, 8, 12))
|
906
|
+
|
907
|
+
if len(set(ax % array.ndim for ax in axes)) != len(axes):
|
908
|
+
# parametrized cases with duplicate axes raise an error
|
909
|
+
with pytest.raises(ValueError, match="axes must be unique"):
|
910
|
+
filter_func(array, *extra_args, size, axes=axes)
|
911
|
+
return
|
912
|
+
output = filter_func(array, *extra_args, size, axes=axes)
|
913
|
+
|
914
|
+
# result should be equivalent to sigma=0.0/size=1 on unfiltered axes
|
915
|
+
axes = xp.asarray(axes)
|
916
|
+
all_sizes = tuple(size if ax in (axes % array.ndim) else size0
|
917
|
+
for ax in range(array.ndim))
|
918
|
+
expected = filter_func(array, *extra_args, all_sizes)
|
919
|
+
xp_assert_close(output, expected)
|
920
|
+
|
921
|
+
@skip_xp_backends("cupy",
|
922
|
+
reason="these filters do not yet have axes support")
|
923
|
+
@pytest.mark.parametrize(('filter_func', 'kwargs'),
|
924
|
+
[(ndimage.laplace, {}),
|
925
|
+
(ndimage.gaussian_gradient_magnitude,
|
926
|
+
{"sigma": 1.0}),
|
927
|
+
(ndimage.gaussian_laplace, {"sigma": 0.5})])
|
928
|
+
def test_derivative_filter_axes(self, xp, filter_func, kwargs):
|
929
|
+
array = xp.arange(6 * 8 * 12, dtype=xp.float64)
|
930
|
+
array = xp.reshape(array, (6, 8, 12))
|
931
|
+
|
932
|
+
# duplicate axes raises an error
|
933
|
+
with pytest.raises(ValueError, match="axes must be unique"):
|
934
|
+
filter_func(array, axes=(1, 1), **kwargs)
|
935
|
+
|
936
|
+
# compare results to manually looping over the non-filtered axes
|
937
|
+
output = filter_func(array, axes=(1, 2), **kwargs)
|
938
|
+
expected = xp.empty_like(output)
|
939
|
+
expected = []
|
940
|
+
for i in range(array.shape[0]):
|
941
|
+
expected.append(filter_func(array[i, ...], **kwargs))
|
942
|
+
expected = xp.stack(expected, axis=0)
|
943
|
+
xp_assert_close(output, expected)
|
944
|
+
|
945
|
+
output = filter_func(array, axes=(0, -1), **kwargs)
|
946
|
+
expected = []
|
947
|
+
for i in range(array.shape[1]):
|
948
|
+
expected.append(filter_func(array[:, i, :], **kwargs))
|
949
|
+
expected = xp.stack(expected, axis=1)
|
950
|
+
xp_assert_close(output, expected)
|
951
|
+
|
952
|
+
output = filter_func(array, axes=(1), **kwargs)
|
953
|
+
expected = []
|
954
|
+
for i in range(array.shape[0]):
|
955
|
+
exp_inner = []
|
956
|
+
for j in range(array.shape[2]):
|
957
|
+
exp_inner.append(filter_func(array[i, :, j], **kwargs))
|
958
|
+
expected.append(xp.stack(exp_inner, axis=-1))
|
959
|
+
expected = xp.stack(expected, axis=0)
|
960
|
+
xp_assert_close(output, expected)
|
961
|
+
|
962
|
+
@skip_xp_backends("cupy",
|
963
|
+
reason="generic_filter does not yet have axes support")
|
964
|
+
@pytest.mark.parametrize(
|
965
|
+
'axes',
|
966
|
+
tuple(itertools.combinations(range(-3, 3), 1))
|
967
|
+
+ tuple(itertools.combinations(range(-3, 3), 2))
|
968
|
+
+ ((0, 1, 2),))
|
969
|
+
def test_generic_filter_axes(self, xp, axes):
|
970
|
+
array = xp.arange(6 * 8 * 12, dtype=xp.float64)
|
971
|
+
array = xp.reshape(array, (6, 8, 12))
|
972
|
+
size = 3
|
973
|
+
if len(set(ax % array.ndim for ax in axes)) != len(axes):
|
974
|
+
# parametrized cases with duplicate axes raise an error
|
975
|
+
with pytest.raises(ValueError, match="axes must be unique"):
|
976
|
+
ndimage.generic_filter(array, np.amax, size=size, axes=axes)
|
977
|
+
return
|
978
|
+
|
979
|
+
# choose np.amax as the function so we can compare to maximum_filter
|
980
|
+
output = ndimage.generic_filter(array, np.amax, size=size, axes=axes)
|
981
|
+
expected = ndimage.maximum_filter(array, size=size, axes=axes)
|
982
|
+
xp_assert_close(output, expected)
|
983
|
+
|
984
|
+
@skip_xp_backends("cupy",
|
985
|
+
reason="https://github.com/cupy/cupy/pull/8339")
|
986
|
+
@pytest.mark.parametrize('func', [ndimage.correlate, ndimage.convolve])
|
987
|
+
@pytest.mark.parametrize(
|
988
|
+
'dtype', [np.float32, np.float64, np.complex64, np.complex128]
|
989
|
+
)
|
990
|
+
@pytest.mark.parametrize(
|
991
|
+
'axes', tuple(itertools.combinations(range(-3, 3), 2))
|
992
|
+
)
|
993
|
+
@pytest.mark.parametrize('origin', [(0, 0), (-1, 1)])
|
994
|
+
def test_correlate_convolve_axes(self, xp, func, dtype, axes, origin):
|
995
|
+
array = xp.asarray(np.arange(6 * 8 * 12, dtype=dtype).reshape(6, 8, 12))
|
996
|
+
weights = xp.arange(3 * 5)
|
997
|
+
weights = xp.reshape(weights, (3, 5))
|
998
|
+
axes = tuple(ax % array.ndim for ax in axes)
|
999
|
+
if len(tuple(set(axes))) != len(axes):
|
1000
|
+
# parametrized cases with duplicate axes raise an error
|
1001
|
+
with pytest.raises(ValueError):
|
1002
|
+
func(array, weights=weights, axes=axes, origin=origin)
|
1003
|
+
return
|
1004
|
+
output = func(array, weights=weights, axes=axes, origin=origin)
|
1005
|
+
|
1006
|
+
missing_axis = tuple(set(range(3)) - set(axes))[0]
|
1007
|
+
# module 'torch' has no attribute 'expand_dims' so use reshape instead
|
1008
|
+
# weights_3d = xp.expand_dims(weights, axis=missing_axis)
|
1009
|
+
shape_3d = (
|
1010
|
+
weights.shape[:missing_axis] + (1,) + weights.shape[missing_axis:]
|
1011
|
+
)
|
1012
|
+
weights_3d = xp.reshape(weights, shape_3d)
|
1013
|
+
origin_3d = [0, 0, 0]
|
1014
|
+
for i, ax in enumerate(axes):
|
1015
|
+
origin_3d[ax] = origin[i]
|
1016
|
+
expected = func(array, weights=weights_3d, origin=origin_3d)
|
1017
|
+
xp_assert_close(output, expected)
|
1018
|
+
|
1019
|
+
kwargs_gauss = dict(radius=[4, 2, 3], order=[0, 1, 2],
|
1020
|
+
mode=['reflect', 'nearest', 'constant'])
|
1021
|
+
kwargs_other = dict(origin=(-1, 0, 1),
|
1022
|
+
mode=['reflect', 'nearest', 'constant'])
|
1023
|
+
kwargs_rank = dict(origin=(-1, 0, 1))
|
1024
|
+
|
1025
|
+
@xfail_xp_backends("cupy", reason="https://github.com/cupy/cupy/pull/8339")
|
1026
|
+
@pytest.mark.parametrize("filter_func, size0, size, kwargs",
|
1027
|
+
[(ndimage.gaussian_filter, 0, 1.0, kwargs_gauss),
|
1028
|
+
(ndimage.uniform_filter, 1, 3, kwargs_other),
|
1029
|
+
(ndimage.maximum_filter, 1, 3, kwargs_other),
|
1030
|
+
(ndimage.minimum_filter, 1, 3, kwargs_other),
|
1031
|
+
(ndimage.median_filter, 1, 3, kwargs_rank),
|
1032
|
+
(ndimage.rank_filter, 1, 3, kwargs_rank),
|
1033
|
+
(ndimage.percentile_filter, 1, 3, kwargs_rank)])
|
1034
|
+
@pytest.mark.parametrize('axes', itertools.combinations(range(-3, 3), 2))
|
1035
|
+
def test_filter_axes_kwargs(self, filter_func, size0, size, kwargs, axes, xp):
|
1036
|
+
array = xp.arange(6 * 8 * 12, dtype=xp.float64)
|
1037
|
+
array = xp.reshape(array, (6, 8, 12))
|
1038
|
+
|
1039
|
+
kwargs = {key: np.array(val) for key, val in kwargs.items()}
|
1040
|
+
axes = np.array(axes)
|
1041
|
+
n_axes = axes.size
|
1042
|
+
|
1043
|
+
if filter_func == ndimage.rank_filter:
|
1044
|
+
args = (2,) # (rank,)
|
1045
|
+
elif filter_func == ndimage.percentile_filter:
|
1046
|
+
args = (30,) # (percentile,)
|
1047
|
+
else:
|
1048
|
+
args = ()
|
1049
|
+
|
1050
|
+
# form kwargs that specify only the axes in `axes`
|
1051
|
+
reduced_kwargs = {key: val[axes] for key, val in kwargs.items()}
|
1052
|
+
if len(set(axes % array.ndim)) != len(axes):
|
1053
|
+
# parametrized cases with duplicate axes raise an error
|
1054
|
+
with pytest.raises(ValueError, match="axes must be unique"):
|
1055
|
+
filter_func(array, *args, [size]*n_axes, axes=axes,
|
1056
|
+
**reduced_kwargs)
|
1057
|
+
return
|
1058
|
+
|
1059
|
+
output = filter_func(array, *args, [size]*n_axes, axes=axes,
|
1060
|
+
**reduced_kwargs)
|
1061
|
+
|
1062
|
+
# result should be equivalent to sigma=0.0/size=1 on unfiltered axes
|
1063
|
+
size_3d = np.full(array.ndim, fill_value=size0)
|
1064
|
+
size_3d[axes] = size
|
1065
|
+
size_3d = [size_3d[i] for i in range(size_3d.shape[0])]
|
1066
|
+
if 'origin' in kwargs:
|
1067
|
+
# origin should be zero on the axis that has size 0
|
1068
|
+
origin = np.asarray([0, 0, 0])
|
1069
|
+
origin[axes] = reduced_kwargs['origin']
|
1070
|
+
origin = xp.asarray(origin)
|
1071
|
+
kwargs['origin'] = origin
|
1072
|
+
expected = filter_func(array, *args, size_3d, **kwargs)
|
1073
|
+
xp_assert_close(output, expected)
|
1074
|
+
|
1075
|
+
|
1076
|
+
@xfail_xp_backends("cupy", reason="https://github.com/cupy/cupy/pull/8339")
|
1077
|
+
@pytest.mark.parametrize("filter_func, kwargs",
|
1078
|
+
[(ndimage.convolve, {}),
|
1079
|
+
(ndimage.correlate, {}),
|
1080
|
+
(ndimage.minimum_filter, {}),
|
1081
|
+
(ndimage.maximum_filter, {}),
|
1082
|
+
(ndimage.median_filter, {}),
|
1083
|
+
(ndimage.rank_filter, {"rank": 1}),
|
1084
|
+
(ndimage.percentile_filter, {"percentile": 30})])
|
1085
|
+
def test_filter_weights_subset_axes_origins(self, filter_func, kwargs, xp):
|
1086
|
+
axes = (-2, -1)
|
1087
|
+
origins = (0, 1)
|
1088
|
+
array = xp.arange(6 * 8 * 12, dtype=xp.float64)
|
1089
|
+
array = xp.reshape(array, (6, 8, 12))
|
1090
|
+
|
1091
|
+
# weights with ndim matching len(axes)
|
1092
|
+
footprint = np.ones((3, 5), dtype=bool)
|
1093
|
+
footprint[0, 1] = 0 # make non-separable
|
1094
|
+
footprint = xp.asarray(footprint)
|
1095
|
+
|
1096
|
+
if filter_func in (ndimage.convolve, ndimage.correlate):
|
1097
|
+
kwargs["weights"] = footprint
|
1098
|
+
else:
|
1099
|
+
kwargs["footprint"] = footprint
|
1100
|
+
kwargs["axes"] = axes
|
1101
|
+
|
1102
|
+
output = filter_func(array, origin=origins, **kwargs)
|
1103
|
+
|
1104
|
+
output0 = filter_func(array, origin=0, **kwargs)
|
1105
|
+
|
1106
|
+
# output has origin shift on last axis relative to output0, so
|
1107
|
+
# expect shifted arrays to be equal.
|
1108
|
+
if filter_func == ndimage.convolve:
|
1109
|
+
# shift is in the opposite direction for convolve because it
|
1110
|
+
# flips the weights array and negates the origin values.
|
1111
|
+
xp_assert_equal(
|
1112
|
+
output[:, :, :-origins[1]], output0[:, :, origins[1]:])
|
1113
|
+
else:
|
1114
|
+
xp_assert_equal(
|
1115
|
+
output[:, :, origins[1]:], output0[:, :, :-origins[1]])
|
1116
|
+
|
1117
|
+
|
1118
|
+
@xfail_xp_backends("cupy", reason="https://github.com/cupy/cupy/pull/8339")
|
1119
|
+
@pytest.mark.parametrize(
|
1120
|
+
'filter_func, args',
|
1121
|
+
[(ndimage.convolve, (np.ones((3, 3, 3)),)), # args = (weights,)
|
1122
|
+
(ndimage.correlate,(np.ones((3, 3, 3)),)), # args = (weights,)
|
1123
|
+
(ndimage.gaussian_filter, (1.0,)), # args = (sigma,)
|
1124
|
+
(ndimage.uniform_filter, (3,)), # args = (size,)
|
1125
|
+
(ndimage.minimum_filter, (3,)), # args = (size,)
|
1126
|
+
(ndimage.maximum_filter, (3,)), # args = (size,)
|
1127
|
+
(ndimage.median_filter, (3,)), # args = (size,)
|
1128
|
+
(ndimage.rank_filter, (2, 3)), # args = (rank, size)
|
1129
|
+
(ndimage.percentile_filter, (30, 3))]) # args = (percentile, size)
|
1130
|
+
@pytest.mark.parametrize(
|
1131
|
+
'axes', [(1.5,), (0, 1, 2, 3), (3,), (-4,)]
|
1132
|
+
)
|
1133
|
+
def test_filter_invalid_axes(self, filter_func, args, axes, xp):
|
1134
|
+
array = xp.arange(6 * 8 * 12, dtype=xp.float64)
|
1135
|
+
array = xp.reshape(array, (6, 8, 12))
|
1136
|
+
args = [
|
1137
|
+
xp.asarray(arg) if isinstance(arg, np.ndarray) else arg
|
1138
|
+
for arg in args
|
1139
|
+
]
|
1140
|
+
if any(isinstance(ax, float) for ax in axes):
|
1141
|
+
error_class = TypeError
|
1142
|
+
match = "cannot be interpreted as an integer"
|
1143
|
+
else:
|
1144
|
+
error_class = ValueError
|
1145
|
+
match = "out of range"
|
1146
|
+
with pytest.raises(error_class, match=match):
|
1147
|
+
filter_func(array, *args, axes=axes)
|
1148
|
+
|
1149
|
+
@xfail_xp_backends("cupy", reason="https://github.com/cupy/cupy/pull/8339")
|
1150
|
+
@pytest.mark.parametrize(
|
1151
|
+
'filter_func, kwargs',
|
1152
|
+
[(ndimage.convolve, {}),
|
1153
|
+
(ndimage.correlate, {}),
|
1154
|
+
(ndimage.minimum_filter, {}),
|
1155
|
+
(ndimage.maximum_filter, {}),
|
1156
|
+
(ndimage.median_filter, {}),
|
1157
|
+
(ndimage.rank_filter, dict(rank=3)),
|
1158
|
+
(ndimage.percentile_filter, dict(percentile=30))])
|
1159
|
+
@pytest.mark.parametrize(
|
1160
|
+
'axes', [(0, ), (1, 2), (0, 1, 2)]
|
1161
|
+
)
|
1162
|
+
@pytest.mark.parametrize('separable_footprint', [False, True])
|
1163
|
+
def test_filter_invalid_footprint_ndim(self, filter_func, kwargs, axes,
|
1164
|
+
separable_footprint, xp):
|
1165
|
+
array = xp.arange(6 * 8 * 12, dtype=xp.float64)
|
1166
|
+
array = xp.reshape(array, (6, 8, 12))
|
1167
|
+
# create a footprint with one too many dimensions
|
1168
|
+
footprint = np.ones((3,) * (len(axes) + 1))
|
1169
|
+
if not separable_footprint:
|
1170
|
+
footprint[(0,) * footprint.ndim] = 0
|
1171
|
+
footprint = xp.asarray(footprint)
|
1172
|
+
if (filter_func in [ndimage.minimum_filter, ndimage.maximum_filter]
|
1173
|
+
and separable_footprint):
|
1174
|
+
match = "sequence argument must have length equal to input rank"
|
1175
|
+
elif filter_func in [ndimage.convolve, ndimage.correlate]:
|
1176
|
+
match = re.escape(f"weights.ndim ({footprint.ndim}) must match "
|
1177
|
+
f"len(axes) ({len(axes)})")
|
1178
|
+
else:
|
1179
|
+
match = re.escape(f"footprint.ndim ({footprint.ndim}) must match "
|
1180
|
+
f"len(axes) ({len(axes)})")
|
1181
|
+
if filter_func in [ndimage.convolve, ndimage.correlate]:
|
1182
|
+
kwargs["weights"] = footprint
|
1183
|
+
else:
|
1184
|
+
kwargs["footprint"] = footprint
|
1185
|
+
with pytest.raises(RuntimeError, match=match):
|
1186
|
+
filter_func(array, axes=axes, **kwargs)
|
1187
|
+
|
1188
|
+
@xfail_xp_backends("cupy", reason="https://github.com/cupy/cupy/pull/8339")
|
1189
|
+
@pytest.mark.parametrize('n_mismatch', [1, 3])
|
1190
|
+
@pytest.mark.parametrize('filter_func, kwargs, key, val',
|
1191
|
+
_cases_axes_tuple_length_mismatch())
|
1192
|
+
def test_filter_tuple_length_mismatch(self, n_mismatch, filter_func,
|
1193
|
+
kwargs, key, val, xp):
|
1194
|
+
# Test for the intended RuntimeError when a kwargs has an invalid size
|
1195
|
+
array = xp.arange(6 * 8 * 12, dtype=xp.float64)
|
1196
|
+
array = xp.reshape(array, (6, 8, 12))
|
1197
|
+
axes = (0, 1)
|
1198
|
+
kwargs = dict(**kwargs, axes=axes)
|
1199
|
+
kwargs[key] = (val,) * n_mismatch
|
1200
|
+
if filter_func in [ndimage.convolve, ndimage.correlate]:
|
1201
|
+
kwargs["weights"] = xp.ones((5,) * len(axes))
|
1202
|
+
err_msg = "sequence argument must have length equal to input rank"
|
1203
|
+
with pytest.raises(RuntimeError, match=err_msg):
|
1204
|
+
filter_func(array, **kwargs)
|
1205
|
+
|
1206
|
+
@pytest.mark.parametrize('dtype', types + complex_types)
|
1207
|
+
def test_prewitt01(self, dtype, xp):
|
1208
|
+
dtype = getattr(xp, dtype)
|
1209
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1210
|
+
[5, 8, 3, 7, 1],
|
1211
|
+
[5, 6, 9, 3, 5]], dtype=dtype)
|
1212
|
+
t = ndimage.correlate1d(array, xp.asarray([-1.0, 0.0, 1.0]), 0)
|
1213
|
+
t = ndimage.correlate1d(t, xp.asarray([1.0, 1.0, 1.0]), 1)
|
1214
|
+
output = ndimage.prewitt(array, 0)
|
1215
|
+
assert_array_almost_equal(t, output)
|
1216
|
+
|
1217
|
+
@uses_output_array
|
1218
|
+
@pytest.mark.parametrize('dtype', types + complex_types)
|
1219
|
+
def test_prewitt02(self, dtype, xp):
|
1220
|
+
dtype = getattr(xp, dtype)
|
1221
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1222
|
+
[5, 8, 3, 7, 1],
|
1223
|
+
[5, 6, 9, 3, 5]], dtype=dtype)
|
1224
|
+
t = ndimage.correlate1d(array, xp.asarray([-1.0, 0.0, 1.0]), 0)
|
1225
|
+
t = ndimage.correlate1d(t, xp.asarray([1.0, 1.0, 1.0]), 1)
|
1226
|
+
output = xp.zeros(array.shape, dtype=dtype)
|
1227
|
+
ndimage.prewitt(array, 0, output)
|
1228
|
+
assert_array_almost_equal(t, output)
|
1229
|
+
|
1230
|
+
@pytest.mark.parametrize('dtype', types + complex_types)
|
1231
|
+
def test_prewitt03(self, dtype, xp):
|
1232
|
+
dtype = getattr(xp, dtype)
|
1233
|
+
if is_cupy(xp) and dtype in [xp.uint32, xp.uint64]:
|
1234
|
+
pytest.xfail("uint UB? XXX")
|
1235
|
+
|
1236
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1237
|
+
[5, 8, 3, 7, 1],
|
1238
|
+
[5, 6, 9, 3, 5]], dtype=dtype)
|
1239
|
+
t = ndimage.correlate1d(array, xp.asarray([-1.0, 0.0, 1.0]), 1)
|
1240
|
+
t = ndimage.correlate1d(t, xp.asarray([1.0, 1.0, 1.0]), 0)
|
1241
|
+
output = ndimage.prewitt(array, 1)
|
1242
|
+
assert_array_almost_equal(t, output)
|
1243
|
+
|
1244
|
+
@pytest.mark.parametrize('dtype', types + complex_types)
|
1245
|
+
def test_prewitt04(self, dtype, xp):
|
1246
|
+
dtype = getattr(xp, dtype)
|
1247
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1248
|
+
[5, 8, 3, 7, 1],
|
1249
|
+
[5, 6, 9, 3, 5]], dtype=dtype)
|
1250
|
+
t = ndimage.prewitt(array, -1)
|
1251
|
+
output = ndimage.prewitt(array, 1)
|
1252
|
+
assert_array_almost_equal(t, output)
|
1253
|
+
|
1254
|
+
@pytest.mark.parametrize('dtype', types + complex_types)
|
1255
|
+
def test_sobel01(self, dtype, xp):
|
1256
|
+
dtype = getattr(xp, dtype)
|
1257
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1258
|
+
[5, 8, 3, 7, 1],
|
1259
|
+
[5, 6, 9, 3, 5]], dtype=dtype)
|
1260
|
+
t = ndimage.correlate1d(array, xp.asarray([-1.0, 0.0, 1.0]), 0)
|
1261
|
+
t = ndimage.correlate1d(t, xp.asarray([1.0, 2.0, 1.0]), 1)
|
1262
|
+
output = ndimage.sobel(array, 0)
|
1263
|
+
assert_array_almost_equal(t, output)
|
1264
|
+
|
1265
|
+
@uses_output_array
|
1266
|
+
@pytest.mark.parametrize('dtype', types + complex_types)
|
1267
|
+
def test_sobel02(self, dtype, xp):
|
1268
|
+
dtype = getattr(xp, dtype)
|
1269
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1270
|
+
[5, 8, 3, 7, 1],
|
1271
|
+
[5, 6, 9, 3, 5]], dtype=dtype)
|
1272
|
+
t = ndimage.correlate1d(array, xp.asarray([-1.0, 0.0, 1.0]), 0)
|
1273
|
+
t = ndimage.correlate1d(t, xp.asarray([1.0, 2.0, 1.0]), 1)
|
1274
|
+
output = xp.zeros(array.shape, dtype=dtype)
|
1275
|
+
ndimage.sobel(array, 0, output)
|
1276
|
+
assert_array_almost_equal(t, output)
|
1277
|
+
|
1278
|
+
@pytest.mark.parametrize('dtype', types + complex_types)
|
1279
|
+
def test_sobel03(self, dtype, xp):
|
1280
|
+
if is_cupy(xp) and dtype in ["uint32", "uint64"]:
|
1281
|
+
pytest.xfail("uint UB? XXX")
|
1282
|
+
|
1283
|
+
dtype = getattr(xp, dtype)
|
1284
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1285
|
+
[5, 8, 3, 7, 1],
|
1286
|
+
[5, 6, 9, 3, 5]], dtype=dtype)
|
1287
|
+
t = ndimage.correlate1d(array, xp.asarray([-1.0, 0.0, 1.0]), 1)
|
1288
|
+
t = ndimage.correlate1d(t, xp.asarray([1.0, 2.0, 1.0]), 0)
|
1289
|
+
output = xp.zeros(array.shape, dtype=dtype)
|
1290
|
+
output = ndimage.sobel(array, 1)
|
1291
|
+
assert_array_almost_equal(t, output)
|
1292
|
+
|
1293
|
+
@pytest.mark.parametrize('dtype', types + complex_types)
|
1294
|
+
def test_sobel04(self, dtype, xp):
|
1295
|
+
dtype = getattr(xp, dtype)
|
1296
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1297
|
+
[5, 8, 3, 7, 1],
|
1298
|
+
[5, 6, 9, 3, 5]], dtype=dtype)
|
1299
|
+
t = ndimage.sobel(array, -1)
|
1300
|
+
output = ndimage.sobel(array, 1)
|
1301
|
+
assert_array_almost_equal(t, output)
|
1302
|
+
|
1303
|
+
@pytest.mark.parametrize('dtype',
|
1304
|
+
["int32", "float32", "float64",
|
1305
|
+
"complex64", "complex128"])
|
1306
|
+
def test_laplace01(self, dtype, xp):
|
1307
|
+
dtype = getattr(xp, dtype)
|
1308
|
+
|
1309
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1310
|
+
[5, 8, 3, 7, 1],
|
1311
|
+
[5, 6, 9, 3, 5]], dtype=dtype) * 100
|
1312
|
+
tmp1 = ndimage.correlate1d(array, xp.asarray([1, -2, 1]), 0)
|
1313
|
+
tmp2 = ndimage.correlate1d(array, xp.asarray([1, -2, 1]), 1)
|
1314
|
+
output = ndimage.laplace(array)
|
1315
|
+
assert_array_almost_equal(tmp1 + tmp2, output)
|
1316
|
+
|
1317
|
+
@uses_output_array
|
1318
|
+
@pytest.mark.parametrize('dtype',
|
1319
|
+
["int32", "float32", "float64",
|
1320
|
+
"complex64", "complex128"])
|
1321
|
+
def test_laplace02(self, dtype, xp):
|
1322
|
+
dtype = getattr(xp, dtype)
|
1323
|
+
|
1324
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1325
|
+
[5, 8, 3, 7, 1],
|
1326
|
+
[5, 6, 9, 3, 5]], dtype=dtype) * 100
|
1327
|
+
tmp1 = ndimage.correlate1d(array, xp.asarray([1, -2, 1]), 0)
|
1328
|
+
tmp2 = ndimage.correlate1d(array, xp.asarray([1, -2, 1]), 1)
|
1329
|
+
output = xp.zeros(array.shape, dtype=dtype)
|
1330
|
+
ndimage.laplace(array, output=output)
|
1331
|
+
assert_array_almost_equal(tmp1 + tmp2, output)
|
1332
|
+
|
1333
|
+
@pytest.mark.parametrize('dtype',
|
1334
|
+
["int32", "float32", "float64",
|
1335
|
+
"complex64", "complex128"])
|
1336
|
+
def test_gaussian_laplace01(self, dtype, xp):
|
1337
|
+
dtype = getattr(xp, dtype)
|
1338
|
+
|
1339
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1340
|
+
[5, 8, 3, 7, 1],
|
1341
|
+
[5, 6, 9, 3, 5]], dtype=dtype) * 100
|
1342
|
+
tmp1 = ndimage.gaussian_filter(array, 1.0, [2, 0])
|
1343
|
+
tmp2 = ndimage.gaussian_filter(array, 1.0, [0, 2])
|
1344
|
+
output = ndimage.gaussian_laplace(array, 1.0)
|
1345
|
+
assert_array_almost_equal(tmp1 + tmp2, output)
|
1346
|
+
|
1347
|
+
@uses_output_array
|
1348
|
+
@pytest.mark.parametrize('dtype',
|
1349
|
+
["int32", "float32", "float64",
|
1350
|
+
"complex64", "complex128"])
|
1351
|
+
def test_gaussian_laplace02(self, dtype, xp):
|
1352
|
+
dtype = getattr(xp, dtype)
|
1353
|
+
|
1354
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1355
|
+
[5, 8, 3, 7, 1],
|
1356
|
+
[5, 6, 9, 3, 5]], dtype=dtype) * 100
|
1357
|
+
tmp1 = ndimage.gaussian_filter(array, 1.0, [2, 0])
|
1358
|
+
tmp2 = ndimage.gaussian_filter(array, 1.0, [0, 2])
|
1359
|
+
output = xp.zeros(array.shape, dtype=dtype)
|
1360
|
+
ndimage.gaussian_laplace(array, 1.0, output)
|
1361
|
+
assert_array_almost_equal(tmp1 + tmp2, output)
|
1362
|
+
|
1363
|
+
@uses_output_array
|
1364
|
+
@pytest.mark.parametrize('dtype', types + complex_types)
|
1365
|
+
def test_generic_laplace01(self, dtype, xp):
|
1366
|
+
def derivative2(input, axis, output, mode, cval, a, b):
|
1367
|
+
sigma = np.asarray([a, b / 2.0])
|
1368
|
+
order = [0] * input.ndim
|
1369
|
+
order[axis] = 2
|
1370
|
+
return ndimage.gaussian_filter(input, sigma, order,
|
1371
|
+
output, mode, cval)
|
1372
|
+
|
1373
|
+
dtype = getattr(xp, dtype)
|
1374
|
+
|
1375
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1376
|
+
[5, 8, 3, 7, 1],
|
1377
|
+
[5, 6, 9, 3, 5]], dtype=dtype)
|
1378
|
+
output = xp.zeros(array.shape, dtype=dtype)
|
1379
|
+
tmp = ndimage.generic_laplace(array, derivative2,
|
1380
|
+
extra_arguments=(1.0,),
|
1381
|
+
extra_keywords={'b': 2.0})
|
1382
|
+
ndimage.gaussian_laplace(array, 1.0, output)
|
1383
|
+
assert_array_almost_equal(tmp, output)
|
1384
|
+
|
1385
|
+
@pytest.mark.parametrize('dtype',
|
1386
|
+
["int32", "float32", "float64",
|
1387
|
+
"complex64", "complex128"])
|
1388
|
+
def test_gaussian_gradient_magnitude01(self, dtype, xp):
|
1389
|
+
is_int_dtype = dtype == "int32"
|
1390
|
+
dtype = getattr(xp, dtype)
|
1391
|
+
|
1392
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1393
|
+
[5, 8, 3, 7, 1],
|
1394
|
+
[5, 6, 9, 3, 5]], dtype=dtype) * 100
|
1395
|
+
tmp1 = ndimage.gaussian_filter(array, 1.0, [1, 0])
|
1396
|
+
tmp2 = ndimage.gaussian_filter(array, 1.0, [0, 1])
|
1397
|
+
output = ndimage.gaussian_gradient_magnitude(array, 1.0)
|
1398
|
+
expected = tmp1 * tmp1 + tmp2 * tmp2
|
1399
|
+
|
1400
|
+
expected_float = xp.astype(expected, xp.float64) if is_int_dtype else expected
|
1401
|
+
expected = xp.astype(xp.sqrt(expected_float), dtype)
|
1402
|
+
xp_assert_close(output, expected, rtol=1e-6, atol=1e-6)
|
1403
|
+
|
1404
|
+
@uses_output_array
|
1405
|
+
@pytest.mark.parametrize('dtype',
|
1406
|
+
["int32", "float32", "float64",
|
1407
|
+
"complex64", "complex128"])
|
1408
|
+
def test_gaussian_gradient_magnitude02(self, dtype, xp):
|
1409
|
+
is_int_dtype = dtype == 'int32'
|
1410
|
+
dtype = getattr(xp, dtype)
|
1411
|
+
|
1412
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1413
|
+
[5, 8, 3, 7, 1],
|
1414
|
+
[5, 6, 9, 3, 5]], dtype=dtype) * 100
|
1415
|
+
tmp1 = ndimage.gaussian_filter(array, 1.0, [1, 0])
|
1416
|
+
tmp2 = ndimage.gaussian_filter(array, 1.0, [0, 1])
|
1417
|
+
output = xp.zeros(array.shape, dtype=dtype)
|
1418
|
+
ndimage.gaussian_gradient_magnitude(array, 1.0, output)
|
1419
|
+
expected = tmp1 * tmp1 + tmp2 * tmp2
|
1420
|
+
|
1421
|
+
fl_expected = xp.astype(expected, xp.float64) if is_int_dtype else expected
|
1422
|
+
|
1423
|
+
expected = xp.astype(xp.sqrt(fl_expected), dtype)
|
1424
|
+
xp_assert_close(output, expected, rtol=1e-6, atol=1e-6)
|
1425
|
+
|
1426
|
+
def test_generic_gradient_magnitude01(self, xp):
|
1427
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1428
|
+
[5, 8, 3, 7, 1],
|
1429
|
+
[5, 6, 9, 3, 5]], dtype=xp.float64)
|
1430
|
+
|
1431
|
+
def derivative(input, axis, output, mode, cval, a, b):
|
1432
|
+
sigma = [a, b / 2.0]
|
1433
|
+
order = [0] * input.ndim
|
1434
|
+
order[axis] = 1
|
1435
|
+
return ndimage.gaussian_filter(input, sigma, order, output, mode, cval)
|
1436
|
+
|
1437
|
+
tmp1 = ndimage.gaussian_gradient_magnitude(array, 1.0)
|
1438
|
+
tmp2 = ndimage.generic_gradient_magnitude(
|
1439
|
+
array, derivative, extra_arguments=(1.0,),
|
1440
|
+
extra_keywords={'b': 2.0})
|
1441
|
+
assert_array_almost_equal(tmp1, tmp2)
|
1442
|
+
|
1443
|
+
def test_uniform01(self, xp):
|
1444
|
+
array = xp.asarray([2, 4, 6])
|
1445
|
+
size = 2
|
1446
|
+
output = ndimage.uniform_filter1d(array, size, origin=-1)
|
1447
|
+
assert_array_almost_equal(xp.asarray([3, 5, 6]), output)
|
1448
|
+
|
1449
|
+
def test_uniform01_complex(self, xp):
|
1450
|
+
array = xp.asarray([2 + 1j, 4 + 2j, 6 + 3j], dtype=xp.complex128)
|
1451
|
+
size = 2
|
1452
|
+
output = ndimage.uniform_filter1d(array, size, origin=-1)
|
1453
|
+
assert_array_almost_equal(xp.real(output), xp.asarray([3., 5, 6]))
|
1454
|
+
assert_array_almost_equal(xp.imag(output), xp.asarray([1.5, 2.5, 3]))
|
1455
|
+
|
1456
|
+
def test_uniform02(self, xp):
|
1457
|
+
array = xp.asarray([1, 2, 3])
|
1458
|
+
filter_shape = [0]
|
1459
|
+
output = ndimage.uniform_filter(array, filter_shape)
|
1460
|
+
assert_array_almost_equal(array, output)
|
1461
|
+
|
1462
|
+
def test_uniform03(self, xp):
|
1463
|
+
array = xp.asarray([1, 2, 3])
|
1464
|
+
filter_shape = [1]
|
1465
|
+
output = ndimage.uniform_filter(array, filter_shape)
|
1466
|
+
assert_array_almost_equal(array, output)
|
1467
|
+
|
1468
|
+
def test_uniform04(self, xp):
|
1469
|
+
array = xp.asarray([2, 4, 6])
|
1470
|
+
filter_shape = [2]
|
1471
|
+
output = ndimage.uniform_filter(array, filter_shape)
|
1472
|
+
assert_array_almost_equal(xp.asarray([2, 3, 5]), output)
|
1473
|
+
|
1474
|
+
def test_uniform05(self, xp):
|
1475
|
+
array = xp.asarray([])
|
1476
|
+
filter_shape = [1]
|
1477
|
+
output = ndimage.uniform_filter(array, filter_shape)
|
1478
|
+
assert_array_almost_equal(xp.asarray([]), output)
|
1479
|
+
|
1480
|
+
@uses_output_dtype
|
1481
|
+
@pytest.mark.parametrize('dtype_array', types)
|
1482
|
+
@pytest.mark.parametrize('dtype_output', types)
|
1483
|
+
def test_uniform06(self, dtype_array, dtype_output, xp):
|
1484
|
+
dtype_array = getattr(xp, dtype_array)
|
1485
|
+
dtype_output = getattr(xp, dtype_output)
|
1486
|
+
|
1487
|
+
filter_shape = [2, 2]
|
1488
|
+
array = xp.asarray([[4, 8, 12],
|
1489
|
+
[16, 20, 24]], dtype=dtype_array)
|
1490
|
+
output = ndimage.uniform_filter(
|
1491
|
+
array, filter_shape, output=dtype_output)
|
1492
|
+
assert_array_almost_equal(xp.asarray([[4, 6, 10], [10, 12, 16]]), output)
|
1493
|
+
assert output.dtype.type == dtype_output
|
1494
|
+
|
1495
|
+
@uses_output_dtype
|
1496
|
+
@pytest.mark.parametrize('dtype_array', complex_types)
|
1497
|
+
@pytest.mark.parametrize('dtype_output', complex_types)
|
1498
|
+
def test_uniform06_complex(self, dtype_array, dtype_output, xp):
|
1499
|
+
dtype_array = getattr(xp, dtype_array)
|
1500
|
+
dtype_output = getattr(xp, dtype_output)
|
1501
|
+
|
1502
|
+
filter_shape = [2, 2]
|
1503
|
+
array = xp.asarray([[4, 8 + 5j, 12],
|
1504
|
+
[16, 20, 24]], dtype=dtype_array)
|
1505
|
+
output = ndimage.uniform_filter(
|
1506
|
+
array, filter_shape, output=dtype_output)
|
1507
|
+
assert_array_almost_equal(xp.asarray([[4, 6, 10], [10, 12, 16]]), output.real)
|
1508
|
+
assert output.dtype.type == dtype_output
|
1509
|
+
|
1510
|
+
def test_minimum_filter01(self, xp):
|
1511
|
+
array = xp.asarray([1, 2, 3, 4, 5])
|
1512
|
+
filter_shape = xp.asarray([2])
|
1513
|
+
output = ndimage.minimum_filter(array, filter_shape)
|
1514
|
+
assert_array_almost_equal(xp.asarray([1, 1, 2, 3, 4]), output)
|
1515
|
+
|
1516
|
+
def test_minimum_filter02(self, xp):
|
1517
|
+
array = xp.asarray([1, 2, 3, 4, 5])
|
1518
|
+
filter_shape = xp.asarray([3])
|
1519
|
+
output = ndimage.minimum_filter(array, filter_shape)
|
1520
|
+
assert_array_almost_equal(xp.asarray([1, 1, 2, 3, 4]), output)
|
1521
|
+
|
1522
|
+
def test_minimum_filter03(self, xp):
|
1523
|
+
array = xp.asarray([3, 2, 5, 1, 4])
|
1524
|
+
filter_shape = xp.asarray([2])
|
1525
|
+
output = ndimage.minimum_filter(array, filter_shape)
|
1526
|
+
assert_array_almost_equal(xp.asarray([3, 2, 2, 1, 1]), output)
|
1527
|
+
|
1528
|
+
def test_minimum_filter04(self, xp):
|
1529
|
+
array = xp.asarray([3, 2, 5, 1, 4])
|
1530
|
+
filter_shape = xp.asarray([3])
|
1531
|
+
output = ndimage.minimum_filter(array, filter_shape)
|
1532
|
+
assert_array_almost_equal(xp.asarray([2, 2, 1, 1, 1]), output)
|
1533
|
+
|
1534
|
+
def test_minimum_filter05(self, xp):
|
1535
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1536
|
+
[7, 6, 9, 3, 5],
|
1537
|
+
[5, 8, 3, 7, 1]])
|
1538
|
+
filter_shape = xp.asarray([2, 3])
|
1539
|
+
output = ndimage.minimum_filter(array, filter_shape)
|
1540
|
+
assert_array_almost_equal(xp.asarray([[2, 2, 1, 1, 1],
|
1541
|
+
[2, 2, 1, 1, 1],
|
1542
|
+
[5, 3, 3, 1, 1]]), output)
|
1543
|
+
|
1544
|
+
@uses_output_array
|
1545
|
+
def test_minimum_filter05_overlap(self, xp):
|
1546
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1547
|
+
[7, 6, 9, 3, 5],
|
1548
|
+
[5, 8, 3, 7, 1]])
|
1549
|
+
filter_shape = xp.asarray([2, 3])
|
1550
|
+
ndimage.minimum_filter(array, filter_shape, output=array)
|
1551
|
+
assert_array_almost_equal(xp.asarray([[2, 2, 1, 1, 1],
|
1552
|
+
[2, 2, 1, 1, 1],
|
1553
|
+
[5, 3, 3, 1, 1]]), array)
|
1554
|
+
|
1555
|
+
def test_minimum_filter06(self, xp):
|
1556
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1557
|
+
[7, 6, 9, 3, 5],
|
1558
|
+
[5, 8, 3, 7, 1]])
|
1559
|
+
footprint = xp.asarray([[1, 1, 1], [1, 1, 1]])
|
1560
|
+
output = ndimage.minimum_filter(array, footprint=footprint)
|
1561
|
+
assert_array_almost_equal(xp.asarray([[2, 2, 1, 1, 1],
|
1562
|
+
[2, 2, 1, 1, 1],
|
1563
|
+
[5, 3, 3, 1, 1]]), output)
|
1564
|
+
# separable footprint should allow mode sequence
|
1565
|
+
output2 = ndimage.minimum_filter(array, footprint=footprint,
|
1566
|
+
mode=['reflect', 'reflect'])
|
1567
|
+
assert_array_almost_equal(output2, output)
|
1568
|
+
|
1569
|
+
def test_minimum_filter07(self, xp):
|
1570
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1571
|
+
[7, 6, 9, 3, 5],
|
1572
|
+
[5, 8, 3, 7, 1]])
|
1573
|
+
footprint = xp.asarray([[1, 0, 1], [1, 1, 0]])
|
1574
|
+
output = ndimage.minimum_filter(array, footprint=footprint)
|
1575
|
+
assert_array_almost_equal(xp.asarray([[2, 2, 1, 1, 1],
|
1576
|
+
[2, 3, 1, 3, 1],
|
1577
|
+
[5, 5, 3, 3, 1]]), output)
|
1578
|
+
with assert_raises(RuntimeError):
|
1579
|
+
ndimage.minimum_filter(array, footprint=footprint,
|
1580
|
+
mode=['reflect', 'constant'])
|
1581
|
+
|
1582
|
+
def test_minimum_filter08(self, xp):
|
1583
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1584
|
+
[7, 6, 9, 3, 5],
|
1585
|
+
[5, 8, 3, 7, 1]])
|
1586
|
+
footprint = xp.asarray([[1, 0, 1], [1, 1, 0]])
|
1587
|
+
output = ndimage.minimum_filter(array, footprint=footprint, origin=-1)
|
1588
|
+
assert_array_almost_equal(xp.asarray([[3, 1, 3, 1, 1],
|
1589
|
+
[5, 3, 3, 1, 1],
|
1590
|
+
[3, 3, 1, 1, 1]]), output)
|
1591
|
+
|
1592
|
+
def test_minimum_filter09(self, xp):
|
1593
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1594
|
+
[7, 6, 9, 3, 5],
|
1595
|
+
[5, 8, 3, 7, 1]])
|
1596
|
+
footprint = xp.asarray([[1, 0, 1], [1, 1, 0]])
|
1597
|
+
output = ndimage.minimum_filter(array, footprint=footprint,
|
1598
|
+
origin=[-1, 0])
|
1599
|
+
assert_array_almost_equal(xp.asarray([[2, 3, 1, 3, 1],
|
1600
|
+
[5, 5, 3, 3, 1],
|
1601
|
+
[5, 3, 3, 1, 1]]), output)
|
1602
|
+
|
1603
|
+
def test_maximum_filter01(self, xp):
|
1604
|
+
array = xp.asarray([1, 2, 3, 4, 5])
|
1605
|
+
filter_shape = xp.asarray([2])
|
1606
|
+
output = ndimage.maximum_filter(array, filter_shape)
|
1607
|
+
assert_array_almost_equal(xp.asarray([1, 2, 3, 4, 5]), output)
|
1608
|
+
|
1609
|
+
def test_maximum_filter02(self, xp):
|
1610
|
+
array = xp.asarray([1, 2, 3, 4, 5])
|
1611
|
+
filter_shape = xp.asarray([3])
|
1612
|
+
output = ndimage.maximum_filter(array, filter_shape)
|
1613
|
+
assert_array_almost_equal(xp.asarray([2, 3, 4, 5, 5]), output)
|
1614
|
+
|
1615
|
+
def test_maximum_filter03(self, xp):
|
1616
|
+
array = xp.asarray([3, 2, 5, 1, 4])
|
1617
|
+
filter_shape = xp.asarray([2])
|
1618
|
+
output = ndimage.maximum_filter(array, filter_shape)
|
1619
|
+
assert_array_almost_equal(xp.asarray([3, 3, 5, 5, 4]), output)
|
1620
|
+
|
1621
|
+
def test_maximum_filter04(self, xp):
|
1622
|
+
array = xp.asarray([3, 2, 5, 1, 4])
|
1623
|
+
filter_shape = xp.asarray([3])
|
1624
|
+
output = ndimage.maximum_filter(array, filter_shape)
|
1625
|
+
assert_array_almost_equal(xp.asarray([3, 5, 5, 5, 4]), output)
|
1626
|
+
|
1627
|
+
def test_maximum_filter05(self, xp):
|
1628
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1629
|
+
[7, 6, 9, 3, 5],
|
1630
|
+
[5, 8, 3, 7, 1]])
|
1631
|
+
filter_shape = xp.asarray([2, 3])
|
1632
|
+
output = ndimage.maximum_filter(array, filter_shape)
|
1633
|
+
assert_array_almost_equal(xp.asarray([[3, 5, 5, 5, 4],
|
1634
|
+
[7, 9, 9, 9, 5],
|
1635
|
+
[8, 9, 9, 9, 7]]), output)
|
1636
|
+
|
1637
|
+
def test_maximum_filter06(self, xp):
|
1638
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1639
|
+
[7, 6, 9, 3, 5],
|
1640
|
+
[5, 8, 3, 7, 1]])
|
1641
|
+
footprint = xp.asarray([[1, 1, 1], [1, 1, 1]])
|
1642
|
+
output = ndimage.maximum_filter(array, footprint=footprint)
|
1643
|
+
assert_array_almost_equal(xp.asarray([[3, 5, 5, 5, 4],
|
1644
|
+
[7, 9, 9, 9, 5],
|
1645
|
+
[8, 9, 9, 9, 7]]), output)
|
1646
|
+
# separable footprint should allow mode sequence
|
1647
|
+
output2 = ndimage.maximum_filter(array, footprint=footprint,
|
1648
|
+
mode=['reflect', 'reflect'])
|
1649
|
+
assert_array_almost_equal(output2, output)
|
1650
|
+
|
1651
|
+
def test_maximum_filter07(self, xp):
|
1652
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1653
|
+
[7, 6, 9, 3, 5],
|
1654
|
+
[5, 8, 3, 7, 1]])
|
1655
|
+
footprint = xp.asarray([[1, 0, 1], [1, 1, 0]])
|
1656
|
+
output = ndimage.maximum_filter(array, footprint=footprint)
|
1657
|
+
assert_array_almost_equal(xp.asarray([[3, 5, 5, 5, 4],
|
1658
|
+
[7, 7, 9, 9, 5],
|
1659
|
+
[7, 9, 8, 9, 7]]), output)
|
1660
|
+
# non-separable footprint should not allow mode sequence
|
1661
|
+
with assert_raises(RuntimeError):
|
1662
|
+
ndimage.maximum_filter(array, footprint=footprint,
|
1663
|
+
mode=['reflect', 'reflect'])
|
1664
|
+
|
1665
|
+
def test_maximum_filter08(self, xp):
|
1666
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1667
|
+
[7, 6, 9, 3, 5],
|
1668
|
+
[5, 8, 3, 7, 1]])
|
1669
|
+
footprint = xp.asarray([[1, 0, 1], [1, 1, 0]])
|
1670
|
+
output = ndimage.maximum_filter(array, footprint=footprint, origin=-1)
|
1671
|
+
assert_array_almost_equal(xp.asarray([[7, 9, 9, 5, 5],
|
1672
|
+
[9, 8, 9, 7, 5],
|
1673
|
+
[8, 8, 7, 7, 7]]), output)
|
1674
|
+
|
1675
|
+
def test_maximum_filter09(self, xp):
|
1676
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1677
|
+
[7, 6, 9, 3, 5],
|
1678
|
+
[5, 8, 3, 7, 1]])
|
1679
|
+
footprint = xp.asarray([[1, 0, 1], [1, 1, 0]])
|
1680
|
+
output = ndimage.maximum_filter(array, footprint=footprint,
|
1681
|
+
origin=[-1, 0])
|
1682
|
+
assert_array_almost_equal(xp.asarray([[7, 7, 9, 9, 5],
|
1683
|
+
[7, 9, 8, 9, 7],
|
1684
|
+
[8, 8, 8, 7, 7]]), output)
|
1685
|
+
|
1686
|
+
@xfail_xp_backends("cupy", reason="https://github.com/cupy/cupy/pull/8339")
|
1687
|
+
@pytest.mark.parametrize(
|
1688
|
+
'axes', tuple(itertools.combinations(range(-3, 3), 2))
|
1689
|
+
)
|
1690
|
+
@pytest.mark.parametrize(
|
1691
|
+
'filter_func, kwargs',
|
1692
|
+
[(ndimage.minimum_filter, {}),
|
1693
|
+
(ndimage.maximum_filter, {}),
|
1694
|
+
(ndimage.median_filter, {}),
|
1695
|
+
(ndimage.rank_filter, dict(rank=3)),
|
1696
|
+
(ndimage.percentile_filter, dict(percentile=60))]
|
1697
|
+
)
|
1698
|
+
def test_minmax_nonseparable_axes(self, filter_func, axes, kwargs, xp):
|
1699
|
+
array = xp.arange(6 * 8 * 12, dtype=xp.float32)
|
1700
|
+
array = xp.reshape(array, (6, 8, 12))
|
1701
|
+
# use 2D triangular footprint because it is non-separable
|
1702
|
+
footprint = xp.asarray(np.tri(5))
|
1703
|
+
axes = np.asarray(axes)
|
1704
|
+
|
1705
|
+
if len(set(axes % array.ndim)) != len(axes):
|
1706
|
+
# parametrized cases with duplicate axes raise an error
|
1707
|
+
with pytest.raises(ValueError):
|
1708
|
+
filter_func(array, footprint=footprint, axes=axes, **kwargs)
|
1709
|
+
return
|
1710
|
+
output = filter_func(array, footprint=footprint, axes=axes, **kwargs)
|
1711
|
+
|
1712
|
+
missing_axis = tuple(set(range(3)) - set(axes % array.ndim))[0]
|
1713
|
+
|
1714
|
+
footprint_3d = xp.expand_dims(footprint, axis=missing_axis)
|
1715
|
+
expected = filter_func(array, footprint=footprint_3d, **kwargs)
|
1716
|
+
xp_assert_close(output, expected)
|
1717
|
+
|
1718
|
+
def test_rank01(self, xp):
|
1719
|
+
array = xp.asarray([1, 2, 3, 4, 5])
|
1720
|
+
output = ndimage.rank_filter(array, 1, size=2)
|
1721
|
+
xp_assert_equal(array, output)
|
1722
|
+
output = ndimage.percentile_filter(array, 100, size=2)
|
1723
|
+
xp_assert_equal(array, output)
|
1724
|
+
output = ndimage.median_filter(array, 2)
|
1725
|
+
xp_assert_equal(array, output)
|
1726
|
+
|
1727
|
+
def test_rank02(self, xp):
|
1728
|
+
array = xp.asarray([1, 2, 3, 4, 5])
|
1729
|
+
output = ndimage.rank_filter(array, 1, size=[3])
|
1730
|
+
xp_assert_equal(array, output)
|
1731
|
+
output = ndimage.percentile_filter(array, 50, size=3)
|
1732
|
+
xp_assert_equal(array, output)
|
1733
|
+
output = ndimage.median_filter(array, (3,))
|
1734
|
+
xp_assert_equal(array, output)
|
1735
|
+
|
1736
|
+
def test_rank03(self, xp):
|
1737
|
+
array = xp.asarray([3, 2, 5, 1, 4])
|
1738
|
+
output = ndimage.rank_filter(array, 1, size=[2])
|
1739
|
+
xp_assert_equal(xp.asarray([3, 3, 5, 5, 4]), output)
|
1740
|
+
output = ndimage.percentile_filter(array, 100, size=2)
|
1741
|
+
xp_assert_equal(xp.asarray([3, 3, 5, 5, 4]), output)
|
1742
|
+
|
1743
|
+
def test_rank04(self, xp):
|
1744
|
+
array = xp.asarray([3, 2, 5, 1, 4])
|
1745
|
+
expected = xp.asarray([3, 3, 2, 4, 4])
|
1746
|
+
output = ndimage.rank_filter(array, 1, size=3)
|
1747
|
+
xp_assert_equal(expected, output)
|
1748
|
+
output = ndimage.percentile_filter(array, 50, size=3)
|
1749
|
+
xp_assert_equal(expected, output)
|
1750
|
+
output = ndimage.median_filter(array, size=3)
|
1751
|
+
xp_assert_equal(expected, output)
|
1752
|
+
|
1753
|
+
def test_rank05(self, xp):
|
1754
|
+
array = xp.asarray([3, 2, 5, 1, 4])
|
1755
|
+
expected = xp.asarray([3, 3, 2, 4, 4])
|
1756
|
+
output = ndimage.rank_filter(array, -2, size=3)
|
1757
|
+
xp_assert_equal(expected, output)
|
1758
|
+
|
1759
|
+
def test_rank06(self, xp):
|
1760
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1761
|
+
[5, 8, 3, 7, 1],
|
1762
|
+
[5, 6, 9, 3, 5]])
|
1763
|
+
expected = [[2, 2, 1, 1, 1],
|
1764
|
+
[3, 3, 2, 1, 1],
|
1765
|
+
[5, 5, 3, 3, 1]]
|
1766
|
+
expected = xp.asarray(expected)
|
1767
|
+
output = ndimage.rank_filter(array, 1, size=[2, 3])
|
1768
|
+
xp_assert_equal(expected, output)
|
1769
|
+
output = ndimage.percentile_filter(array, 17, size=(2, 3))
|
1770
|
+
xp_assert_equal(expected, output)
|
1771
|
+
|
1772
|
+
@xfail_xp_backends("cupy", reason="cupy/cupy#8406")
|
1773
|
+
@uses_output_array
|
1774
|
+
def test_rank06_overlap(self, xp):
|
1775
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1776
|
+
[5, 8, 3, 7, 1],
|
1777
|
+
[5, 6, 9, 3, 5]])
|
1778
|
+
|
1779
|
+
array_copy = xp.asarray(array, copy=True)
|
1780
|
+
expected = [[2, 2, 1, 1, 1],
|
1781
|
+
[3, 3, 2, 1, 1],
|
1782
|
+
[5, 5, 3, 3, 1]]
|
1783
|
+
expected = xp.asarray(expected)
|
1784
|
+
ndimage.rank_filter(array, 1, size=[2, 3], output=array)
|
1785
|
+
xp_assert_equal(expected, array)
|
1786
|
+
|
1787
|
+
ndimage.percentile_filter(array_copy, 17, size=(2, 3),
|
1788
|
+
output=array_copy)
|
1789
|
+
xp_assert_equal(expected, array_copy)
|
1790
|
+
|
1791
|
+
def test_rank07(self, xp):
|
1792
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1793
|
+
[5, 8, 3, 7, 1],
|
1794
|
+
[5, 6, 9, 3, 5]])
|
1795
|
+
expected = [[3, 5, 5, 5, 4],
|
1796
|
+
[5, 5, 7, 5, 4],
|
1797
|
+
[6, 8, 8, 7, 5]]
|
1798
|
+
expected = xp.asarray(expected)
|
1799
|
+
output = ndimage.rank_filter(array, -2, size=[2, 3])
|
1800
|
+
xp_assert_equal(expected, output)
|
1801
|
+
|
1802
|
+
def test_rank08(self, xp):
|
1803
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1804
|
+
[5, 8, 3, 7, 1],
|
1805
|
+
[5, 6, 9, 3, 5]])
|
1806
|
+
expected = [[3, 3, 2, 4, 4],
|
1807
|
+
[5, 5, 5, 4, 4],
|
1808
|
+
[5, 6, 7, 5, 5]]
|
1809
|
+
expected = xp.asarray(expected)
|
1810
|
+
output = ndimage.percentile_filter(array, 50.0, size=(2, 3))
|
1811
|
+
xp_assert_equal(expected, output)
|
1812
|
+
output = ndimage.rank_filter(array, 3, size=(2, 3))
|
1813
|
+
xp_assert_equal(expected, output)
|
1814
|
+
output = ndimage.median_filter(array, size=(2, 3))
|
1815
|
+
xp_assert_equal(expected, output)
|
1816
|
+
|
1817
|
+
# non-separable: does not allow mode sequence
|
1818
|
+
with assert_raises(RuntimeError):
|
1819
|
+
ndimage.percentile_filter(array, 50.0, size=(2, 3),
|
1820
|
+
mode=['reflect', 'constant'])
|
1821
|
+
with assert_raises(RuntimeError):
|
1822
|
+
ndimage.rank_filter(array, 3, size=(2, 3), mode=['reflect']*2)
|
1823
|
+
with assert_raises(RuntimeError):
|
1824
|
+
ndimage.median_filter(array, size=(2, 3), mode=['reflect']*2)
|
1825
|
+
|
1826
|
+
@pytest.mark.parametrize('dtype', types)
|
1827
|
+
def test_rank09(self, dtype, xp):
|
1828
|
+
dtype = getattr(xp, dtype)
|
1829
|
+
expected = [[3, 3, 2, 4, 4],
|
1830
|
+
[3, 5, 2, 5, 1],
|
1831
|
+
[5, 5, 8, 3, 5]]
|
1832
|
+
expected = xp.asarray(expected)
|
1833
|
+
footprint = xp.asarray([[1, 0, 1], [0, 1, 0]])
|
1834
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1835
|
+
[5, 8, 3, 7, 1],
|
1836
|
+
[5, 6, 9, 3, 5]], dtype=dtype)
|
1837
|
+
output = ndimage.rank_filter(array, 1, footprint=footprint)
|
1838
|
+
assert_array_almost_equal(expected, output)
|
1839
|
+
output = ndimage.percentile_filter(array, 35, footprint=footprint)
|
1840
|
+
assert_array_almost_equal(expected, output)
|
1841
|
+
|
1842
|
+
def test_rank10(self, xp):
|
1843
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1844
|
+
[7, 6, 9, 3, 5],
|
1845
|
+
[5, 8, 3, 7, 1]])
|
1846
|
+
expected = [[2, 2, 1, 1, 1],
|
1847
|
+
[2, 3, 1, 3, 1],
|
1848
|
+
[5, 5, 3, 3, 1]]
|
1849
|
+
expected = xp.asarray(expected)
|
1850
|
+
footprint = xp.asarray([[1, 0, 1], [1, 1, 0]])
|
1851
|
+
output = ndimage.rank_filter(array, 0, footprint=footprint)
|
1852
|
+
xp_assert_equal(expected, output)
|
1853
|
+
output = ndimage.percentile_filter(array, 0.0, footprint=footprint)
|
1854
|
+
xp_assert_equal(expected, output)
|
1855
|
+
|
1856
|
+
def test_rank11(self, xp):
|
1857
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1858
|
+
[7, 6, 9, 3, 5],
|
1859
|
+
[5, 8, 3, 7, 1]])
|
1860
|
+
expected = [[3, 5, 5, 5, 4],
|
1861
|
+
[7, 7, 9, 9, 5],
|
1862
|
+
[7, 9, 8, 9, 7]]
|
1863
|
+
expected = xp.asarray(expected)
|
1864
|
+
footprint = xp.asarray([[1, 0, 1], [1, 1, 0]])
|
1865
|
+
output = ndimage.rank_filter(array, -1, footprint=footprint)
|
1866
|
+
xp_assert_equal(expected, output)
|
1867
|
+
output = ndimage.percentile_filter(array, 100.0, footprint=footprint)
|
1868
|
+
xp_assert_equal(expected, output)
|
1869
|
+
|
1870
|
+
@pytest.mark.parametrize('dtype', types)
|
1871
|
+
def test_rank12(self, dtype, xp):
|
1872
|
+
dtype = getattr(xp, dtype)
|
1873
|
+
expected = [[3, 3, 2, 4, 4],
|
1874
|
+
[3, 5, 2, 5, 1],
|
1875
|
+
[5, 5, 8, 3, 5]]
|
1876
|
+
expected = xp.asarray(expected, dtype=dtype)
|
1877
|
+
footprint = xp.asarray([[1, 0, 1], [0, 1, 0]])
|
1878
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1879
|
+
[5, 8, 3, 7, 1],
|
1880
|
+
[5, 6, 9, 3, 5]], dtype=dtype)
|
1881
|
+
output = ndimage.rank_filter(array, 1, footprint=footprint)
|
1882
|
+
assert_array_almost_equal(expected, output)
|
1883
|
+
output = ndimage.percentile_filter(array, 50.0,
|
1884
|
+
footprint=footprint)
|
1885
|
+
xp_assert_equal(expected, output)
|
1886
|
+
output = ndimage.median_filter(array, footprint=footprint)
|
1887
|
+
xp_assert_equal(expected, output)
|
1888
|
+
|
1889
|
+
@pytest.mark.parametrize('dtype', types)
|
1890
|
+
def test_rank13(self, dtype, xp):
|
1891
|
+
dtype = getattr(xp, dtype)
|
1892
|
+
expected = [[5, 2, 5, 1, 1],
|
1893
|
+
[5, 8, 3, 5, 5],
|
1894
|
+
[6, 6, 5, 5, 5]]
|
1895
|
+
expected = xp.asarray(expected, dtype=dtype)
|
1896
|
+
footprint = xp.asarray([[1, 0, 1], [0, 1, 0]])
|
1897
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1898
|
+
[5, 8, 3, 7, 1],
|
1899
|
+
[5, 6, 9, 3, 5]], dtype=dtype)
|
1900
|
+
output = ndimage.rank_filter(array, 1, footprint=footprint,
|
1901
|
+
origin=-1)
|
1902
|
+
xp_assert_equal(expected, output)
|
1903
|
+
|
1904
|
+
@pytest.mark.parametrize('dtype', types)
|
1905
|
+
def test_rank14(self, dtype, xp):
|
1906
|
+
dtype = getattr(xp, dtype)
|
1907
|
+
expected = [[3, 5, 2, 5, 1],
|
1908
|
+
[5, 5, 8, 3, 5],
|
1909
|
+
[5, 6, 6, 5, 5]]
|
1910
|
+
expected = xp.asarray(expected, dtype=dtype)
|
1911
|
+
footprint = xp.asarray([[1, 0, 1], [0, 1, 0]])
|
1912
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1913
|
+
[5, 8, 3, 7, 1],
|
1914
|
+
[5, 6, 9, 3, 5]], dtype=dtype)
|
1915
|
+
output = ndimage.rank_filter(array, 1, footprint=footprint,
|
1916
|
+
origin=[-1, 0])
|
1917
|
+
xp_assert_equal(expected, output)
|
1918
|
+
|
1919
|
+
@pytest.mark.parametrize('dtype', types)
|
1920
|
+
def test_rank15(self, dtype, xp):
|
1921
|
+
dtype = getattr(xp, dtype)
|
1922
|
+
expected = [[2, 3, 1, 4, 1],
|
1923
|
+
[5, 3, 7, 1, 1],
|
1924
|
+
[5, 5, 3, 3, 3]]
|
1925
|
+
expected = xp.asarray(expected, dtype=dtype)
|
1926
|
+
footprint = xp.asarray([[1, 0, 1], [0, 1, 0]])
|
1927
|
+
array = xp.asarray([[3, 2, 5, 1, 4],
|
1928
|
+
[5, 8, 3, 7, 1],
|
1929
|
+
[5, 6, 9, 3, 5]], dtype=dtype)
|
1930
|
+
output = ndimage.rank_filter(array, 0, footprint=footprint,
|
1931
|
+
origin=[-1, 0])
|
1932
|
+
xp_assert_equal(expected, output)
|
1933
|
+
|
1934
|
+
# NumPy-only because test is for list input
|
1935
|
+
def test_rank16(self):
|
1936
|
+
# test that lists are accepted and interpreted as numpy arrays
|
1937
|
+
array = [3, 2, 5, 1, 4]
|
1938
|
+
# expected values are: median(3, 2, 5) = 3, median(2, 5, 1) = 2, etc
|
1939
|
+
expected = np.asarray([3, 3, 2, 4, 4])
|
1940
|
+
output = ndimage.rank_filter(array, -2, size=3)
|
1941
|
+
xp_assert_equal(expected, output)
|
1942
|
+
|
1943
|
+
def test_rank17(self, xp):
|
1944
|
+
array = xp.asarray([3, 2, 5, 1, 4])
|
1945
|
+
if not hasattr(array, 'flags'):
|
1946
|
+
return
|
1947
|
+
array.flags.writeable = False
|
1948
|
+
expected = xp.asarray([3, 3, 2, 4, 4])
|
1949
|
+
output = ndimage.rank_filter(array, -2, size=3)
|
1950
|
+
xp_assert_equal(expected, output)
|
1951
|
+
|
1952
|
+
def test_rank18(self, xp):
|
1953
|
+
# module 'array_api_strict' has no attribute 'float16'
|
1954
|
+
tested_dtypes = ['int8', 'int16', 'int32', 'int64', 'float32', 'float64',
|
1955
|
+
'uint8', 'uint16', 'uint32', 'uint64']
|
1956
|
+
for dtype_str in tested_dtypes:
|
1957
|
+
dtype = getattr(xp, dtype_str)
|
1958
|
+
x = xp.asarray([3, 2, 5, 1, 4], dtype=dtype)
|
1959
|
+
y = ndimage.rank_filter(x, -2, size=3)
|
1960
|
+
assert y.dtype == x.dtype
|
1961
|
+
|
1962
|
+
def test_rank19(self, xp):
|
1963
|
+
# module 'array_api_strict' has no attribute 'float16'
|
1964
|
+
tested_dtypes = ['int8', 'int16', 'int32', 'int64', 'float32', 'float64',
|
1965
|
+
'uint8', 'uint16', 'uint32', 'uint64']
|
1966
|
+
for dtype_str in tested_dtypes:
|
1967
|
+
dtype = getattr(xp, dtype_str)
|
1968
|
+
x = xp.asarray([[3, 2, 5, 1, 4], [3, 2, 5, 1, 4]], dtype=dtype)
|
1969
|
+
y = ndimage.rank_filter(x, -2, size=3)
|
1970
|
+
assert y.dtype == x.dtype
|
1971
|
+
|
1972
|
+
@skip_xp_backends(np_only=True, exceptions=["cupy"],
|
1973
|
+
reason="off-by-ones on alt backends")
|
1974
|
+
@xfail_xp_backends("cupy", reason="does not support extra_arguments")
|
1975
|
+
@pytest.mark.parametrize('dtype', types)
|
1976
|
+
def test_generic_filter1d01(self, dtype, xp):
|
1977
|
+
weights = xp.asarray([1.1, 2.2, 3.3])
|
1978
|
+
|
1979
|
+
def _filter_func(input, output, fltr, total):
|
1980
|
+
fltr = fltr / total
|
1981
|
+
for ii in range(input.shape[0] - 2):
|
1982
|
+
output[ii] = input[ii] * fltr[0]
|
1983
|
+
output[ii] += input[ii + 1] * fltr[1]
|
1984
|
+
output[ii] += input[ii + 2] * fltr[2]
|
1985
|
+
|
1986
|
+
a = np.arange(12, dtype=dtype).reshape(3, 4)
|
1987
|
+
a = xp.asarray(a)
|
1988
|
+
dtype = getattr(xp, dtype)
|
1989
|
+
|
1990
|
+
r1 = ndimage.correlate1d(a, weights / xp.sum(weights), 0, origin=-1)
|
1991
|
+
r2 = ndimage.generic_filter1d(
|
1992
|
+
a, _filter_func, 3, axis=0, origin=-1,
|
1993
|
+
extra_arguments=(weights,),
|
1994
|
+
extra_keywords={'total': xp.sum(weights)})
|
1995
|
+
assert_array_almost_equal(r1, r2)
|
1996
|
+
|
1997
|
+
@xfail_xp_backends("cupy", reason="does not support extra_arguments")
|
1998
|
+
@pytest.mark.parametrize('dtype', types)
|
1999
|
+
def test_generic_filter01(self, dtype, xp):
|
2000
|
+
if is_torch(xp) and dtype in ("uint16", "uint32", "uint64"):
|
2001
|
+
pytest.xfail("https://github.com/pytorch/pytorch/issues/58734")
|
2002
|
+
|
2003
|
+
dtype_str = dtype
|
2004
|
+
dtype = getattr(xp, dtype_str)
|
2005
|
+
|
2006
|
+
filter_ = xp.asarray([[1.0, 2.0], [3.0, 4.0]])
|
2007
|
+
footprint = xp.asarray([[1.0, 0.0], [0.0, 1.0]])
|
2008
|
+
cf = xp.asarray([1., 4.])
|
2009
|
+
|
2010
|
+
def _filter_func(buffer, weights, total=1.0):
|
2011
|
+
weights = np.asarray(cf) / np.asarray(total)
|
2012
|
+
return np.sum(buffer * weights)
|
2013
|
+
|
2014
|
+
a = np.arange(12, dtype=dtype_str).reshape(3, 4)
|
2015
|
+
a = xp.asarray(a)
|
2016
|
+
r1 = ndimage.correlate(a, filter_ * footprint)
|
2017
|
+
if dtype_str in float_types:
|
2018
|
+
r1 /= 5
|
2019
|
+
else:
|
2020
|
+
r1 //= 5
|
2021
|
+
r2 = ndimage.generic_filter(
|
2022
|
+
a, _filter_func, footprint=footprint, extra_arguments=(cf,),
|
2023
|
+
extra_keywords={'total': xp.sum(cf)})
|
2024
|
+
assert_array_almost_equal(r1, r2)
|
2025
|
+
|
2026
|
+
# generic_filter doesn't allow mode sequence
|
2027
|
+
with assert_raises(RuntimeError):
|
2028
|
+
r2 = ndimage.generic_filter(
|
2029
|
+
a, _filter_func, mode=['reflect', 'reflect'],
|
2030
|
+
footprint=footprint, extra_arguments=(cf,),
|
2031
|
+
extra_keywords={'total': xp.sum(cf)})
|
2032
|
+
|
2033
|
+
@pytest.mark.parametrize(
|
2034
|
+
'mode, expected_value',
|
2035
|
+
[('nearest', [1, 1, 2]),
|
2036
|
+
('wrap', [3, 1, 2]),
|
2037
|
+
('reflect', [1, 1, 2]),
|
2038
|
+
('mirror', [2, 1, 2]),
|
2039
|
+
('constant', [0, 1, 2])]
|
2040
|
+
)
|
2041
|
+
def test_extend01(self, mode, expected_value, xp):
|
2042
|
+
array = xp.asarray([1, 2, 3])
|
2043
|
+
weights = xp.asarray([1, 0])
|
2044
|
+
output = ndimage.correlate1d(array, weights, 0, mode=mode, cval=0)
|
2045
|
+
expected_value = xp.asarray(expected_value)
|
2046
|
+
xp_assert_equal(output, expected_value)
|
2047
|
+
|
2048
|
+
@pytest.mark.parametrize(
|
2049
|
+
'mode, expected_value',
|
2050
|
+
[('nearest', [1, 1, 1]),
|
2051
|
+
('wrap', [3, 1, 2]),
|
2052
|
+
('reflect', [3, 3, 2]),
|
2053
|
+
('mirror', [1, 2, 3]),
|
2054
|
+
('constant', [0, 0, 0])]
|
2055
|
+
)
|
2056
|
+
def test_extend02(self, mode, expected_value, xp):
|
2057
|
+
array = xp.asarray([1, 2, 3])
|
2058
|
+
weights = xp.asarray([1, 0, 0, 0, 0, 0, 0, 0])
|
2059
|
+
output = ndimage.correlate1d(array, weights, 0, mode=mode, cval=0)
|
2060
|
+
expected_value = xp.asarray(expected_value)
|
2061
|
+
xp_assert_equal(output, expected_value)
|
2062
|
+
|
2063
|
+
@pytest.mark.parametrize(
|
2064
|
+
'mode, expected_value',
|
2065
|
+
[('nearest', [2, 3, 3]),
|
2066
|
+
('wrap', [2, 3, 1]),
|
2067
|
+
('reflect', [2, 3, 3]),
|
2068
|
+
('mirror', [2, 3, 2]),
|
2069
|
+
('constant', [2, 3, 0])]
|
2070
|
+
)
|
2071
|
+
def test_extend03(self, mode, expected_value, xp):
|
2072
|
+
array = xp.asarray([1, 2, 3])
|
2073
|
+
weights = xp.asarray([0, 0, 1])
|
2074
|
+
output = ndimage.correlate1d(array, weights, 0, mode=mode, cval=0)
|
2075
|
+
expected_value = xp.asarray(expected_value)
|
2076
|
+
xp_assert_equal(output, expected_value)
|
2077
|
+
|
2078
|
+
@pytest.mark.parametrize(
|
2079
|
+
'mode, expected_value',
|
2080
|
+
[('nearest', [3, 3, 3]),
|
2081
|
+
('wrap', [2, 3, 1]),
|
2082
|
+
('reflect', [2, 1, 1]),
|
2083
|
+
('mirror', [1, 2, 3]),
|
2084
|
+
('constant', [0, 0, 0])]
|
2085
|
+
)
|
2086
|
+
def test_extend04(self, mode, expected_value, xp):
|
2087
|
+
array = xp.asarray([1, 2, 3])
|
2088
|
+
weights = xp.asarray([0, 0, 0, 0, 0, 0, 0, 0, 1])
|
2089
|
+
output = ndimage.correlate1d(array, weights, 0, mode=mode, cval=0)
|
2090
|
+
expected_value = xp.asarray(expected_value)
|
2091
|
+
xp_assert_equal(output, expected_value)
|
2092
|
+
|
2093
|
+
@pytest.mark.parametrize(
|
2094
|
+
'mode, expected_value',
|
2095
|
+
[('nearest', [[1, 1, 2], [1, 1, 2], [4, 4, 5]]),
|
2096
|
+
('wrap', [[9, 7, 8], [3, 1, 2], [6, 4, 5]]),
|
2097
|
+
('reflect', [[1, 1, 2], [1, 1, 2], [4, 4, 5]]),
|
2098
|
+
('mirror', [[5, 4, 5], [2, 1, 2], [5, 4, 5]]),
|
2099
|
+
('constant', [[0, 0, 0], [0, 1, 2], [0, 4, 5]])]
|
2100
|
+
)
|
2101
|
+
def test_extend05(self, mode, expected_value, xp):
|
2102
|
+
array = xp.asarray([[1, 2, 3],
|
2103
|
+
[4, 5, 6],
|
2104
|
+
[7, 8, 9]])
|
2105
|
+
weights = xp.asarray([[1, 0], [0, 0]])
|
2106
|
+
output = ndimage.correlate(array, weights, mode=mode, cval=0)
|
2107
|
+
expected_value = xp.asarray(expected_value)
|
2108
|
+
xp_assert_equal(output, expected_value)
|
2109
|
+
|
2110
|
+
@pytest.mark.parametrize(
|
2111
|
+
'mode, expected_value',
|
2112
|
+
[('nearest', [[5, 6, 6], [8, 9, 9], [8, 9, 9]]),
|
2113
|
+
('wrap', [[5, 6, 4], [8, 9, 7], [2, 3, 1]]),
|
2114
|
+
('reflect', [[5, 6, 6], [8, 9, 9], [8, 9, 9]]),
|
2115
|
+
('mirror', [[5, 6, 5], [8, 9, 8], [5, 6, 5]]),
|
2116
|
+
('constant', [[5, 6, 0], [8, 9, 0], [0, 0, 0]])]
|
2117
|
+
)
|
2118
|
+
def test_extend06(self, mode, expected_value, xp):
|
2119
|
+
array = xp.asarray([[1, 2, 3],
|
2120
|
+
[4, 5, 6],
|
2121
|
+
[7, 8, 9]])
|
2122
|
+
weights = xp.asarray([[0, 0, 0], [0, 0, 0], [0, 0, 1]])
|
2123
|
+
output = ndimage.correlate(array, weights, mode=mode, cval=0)
|
2124
|
+
expected_value = xp.asarray(expected_value)
|
2125
|
+
xp_assert_equal(output, expected_value)
|
2126
|
+
|
2127
|
+
@pytest.mark.parametrize(
|
2128
|
+
'mode, expected_value',
|
2129
|
+
[('nearest', [3, 3, 3]),
|
2130
|
+
('wrap', [2, 3, 1]),
|
2131
|
+
('reflect', [2, 1, 1]),
|
2132
|
+
('mirror', [1, 2, 3]),
|
2133
|
+
('constant', [0, 0, 0])]
|
2134
|
+
)
|
2135
|
+
def test_extend07(self, mode, expected_value, xp):
|
2136
|
+
array = xp.asarray([1, 2, 3])
|
2137
|
+
weights = xp.asarray([0, 0, 0, 0, 0, 0, 0, 0, 1])
|
2138
|
+
output = ndimage.correlate(array, weights, mode=mode, cval=0)
|
2139
|
+
expected_value = xp.asarray(expected_value)
|
2140
|
+
xp_assert_equal(output, expected_value)
|
2141
|
+
|
2142
|
+
@pytest.mark.parametrize(
|
2143
|
+
'mode, expected_value',
|
2144
|
+
[('nearest', [[3], [3], [3]]),
|
2145
|
+
('wrap', [[2], [3], [1]]),
|
2146
|
+
('reflect', [[2], [1], [1]]),
|
2147
|
+
('mirror', [[1], [2], [3]]),
|
2148
|
+
('constant', [[0], [0], [0]])]
|
2149
|
+
)
|
2150
|
+
def test_extend08(self, mode, expected_value, xp):
|
2151
|
+
array = xp.asarray([[1], [2], [3]])
|
2152
|
+
weights = xp.asarray([[0], [0], [0], [0], [0], [0], [0], [0], [1]])
|
2153
|
+
output = ndimage.correlate(array, weights, mode=mode, cval=0)
|
2154
|
+
expected_value = xp.asarray(expected_value)
|
2155
|
+
xp_assert_equal(output, expected_value)
|
2156
|
+
|
2157
|
+
@pytest.mark.parametrize(
|
2158
|
+
'mode, expected_value',
|
2159
|
+
[('nearest', [3, 3, 3]),
|
2160
|
+
('wrap', [2, 3, 1]),
|
2161
|
+
('reflect', [2, 1, 1]),
|
2162
|
+
('mirror', [1, 2, 3]),
|
2163
|
+
('constant', [0, 0, 0])]
|
2164
|
+
)
|
2165
|
+
def test_extend09(self, mode, expected_value, xp):
|
2166
|
+
array = xp.asarray([1, 2, 3])
|
2167
|
+
weights = xp.asarray([0, 0, 0, 0, 0, 0, 0, 0, 1])
|
2168
|
+
output = ndimage.correlate(array, weights, mode=mode, cval=0)
|
2169
|
+
expected_value = xp.asarray(expected_value)
|
2170
|
+
xp_assert_equal(output, expected_value)
|
2171
|
+
|
2172
|
+
@pytest.mark.parametrize(
|
2173
|
+
'mode, expected_value',
|
2174
|
+
[('nearest', [[3], [3], [3]]),
|
2175
|
+
('wrap', [[2], [3], [1]]),
|
2176
|
+
('reflect', [[2], [1], [1]]),
|
2177
|
+
('mirror', [[1], [2], [3]]),
|
2178
|
+
('constant', [[0], [0], [0]])]
|
2179
|
+
)
|
2180
|
+
def test_extend10(self, mode, expected_value, xp):
|
2181
|
+
array = xp.asarray([[1], [2], [3]])
|
2182
|
+
weights = xp.asarray([[0], [0], [0], [0], [0], [0], [0], [0], [1]])
|
2183
|
+
output = ndimage.correlate(array, weights, mode=mode, cval=0)
|
2184
|
+
expected_value = xp.asarray(expected_value)
|
2185
|
+
xp_assert_equal(output, expected_value)
|
2186
|
+
|
2187
|
+
|
2188
|
+
@xfail_xp_backends("cupy", reason="TypeError")
|
2189
|
+
def test_ticket_701(xp):
|
2190
|
+
# Test generic filter sizes
|
2191
|
+
arr = xp.asarray(np.arange(4).reshape(2, 2))
|
2192
|
+
def func(x):
|
2193
|
+
return np.min(x) # NB: np.min not xp.min for callables
|
2194
|
+
res = ndimage.generic_filter(arr, func, size=(1, 1))
|
2195
|
+
# The following raises an error unless ticket 701 is fixed
|
2196
|
+
res2 = ndimage.generic_filter(arr, func, size=1)
|
2197
|
+
xp_assert_equal(res, res2)
|
2198
|
+
|
2199
|
+
|
2200
|
+
def test_gh_5430():
|
2201
|
+
# At least one of these raises an error unless gh-5430 is
|
2202
|
+
# fixed. In py2k an int is implemented using a C long, so
|
2203
|
+
# which one fails depends on your system. In py3k there is only
|
2204
|
+
# one arbitrary precision integer type, so both should fail.
|
2205
|
+
sigma = np.int32(1)
|
2206
|
+
out = ndimage._ni_support._normalize_sequence(sigma, 1)
|
2207
|
+
assert out == [sigma]
|
2208
|
+
sigma = np.int64(1)
|
2209
|
+
out = ndimage._ni_support._normalize_sequence(sigma, 1)
|
2210
|
+
assert out == [sigma]
|
2211
|
+
# This worked before; make sure it still works
|
2212
|
+
sigma = 1
|
2213
|
+
out = ndimage._ni_support._normalize_sequence(sigma, 1)
|
2214
|
+
assert out == [sigma]
|
2215
|
+
# This worked before; make sure it still works
|
2216
|
+
sigma = [1, 1]
|
2217
|
+
out = ndimage._ni_support._normalize_sequence(sigma, 2)
|
2218
|
+
assert out == sigma
|
2219
|
+
# Also include the OPs original example to make sure we fixed the issue
|
2220
|
+
x = np.random.normal(size=(256, 256))
|
2221
|
+
perlin = np.zeros_like(x)
|
2222
|
+
for i in 2**np.arange(6):
|
2223
|
+
perlin += ndimage.gaussian_filter(x, i, mode="wrap") * i**2
|
2224
|
+
# This also fixes gh-4106, show that the OPs example now runs.
|
2225
|
+
x = np.int64(21)
|
2226
|
+
ndimage._ni_support._normalize_sequence(x, 0)
|
2227
|
+
|
2228
|
+
|
2229
|
+
@skip_xp_backends("cupy", reason="tests a private scipy utility")
|
2230
|
+
def test_gaussian_kernel1d(xp):
|
2231
|
+
radius = 10
|
2232
|
+
sigma = 2
|
2233
|
+
sigma2 = sigma * sigma
|
2234
|
+
x = np.arange(-radius, radius + 1, dtype=np.float64)
|
2235
|
+
x = xp.asarray(x)
|
2236
|
+
phi_x = xp.exp(-0.5 * x * x / sigma2)
|
2237
|
+
phi_x /= xp.sum(phi_x)
|
2238
|
+
xp_assert_close(phi_x,
|
2239
|
+
xp.asarray(_gaussian_kernel1d(sigma, 0, radius)))
|
2240
|
+
xp_assert_close(-phi_x * x / sigma2,
|
2241
|
+
xp.asarray(_gaussian_kernel1d(sigma, 1, radius)))
|
2242
|
+
xp_assert_close(phi_x * (x * x / sigma2 - 1) / sigma2,
|
2243
|
+
xp.asarray(_gaussian_kernel1d(sigma, 2, radius)))
|
2244
|
+
xp_assert_close(phi_x * (3 - x * x / sigma2) * x / (sigma2 * sigma2),
|
2245
|
+
xp.asarray(_gaussian_kernel1d(sigma, 3, radius)))
|
2246
|
+
|
2247
|
+
|
2248
|
+
def test_orders_gauss(xp):
|
2249
|
+
# Check order inputs to Gaussians
|
2250
|
+
arr = xp.zeros((1,))
|
2251
|
+
xp_assert_equal(ndimage.gaussian_filter(arr, 1, order=0), xp.asarray([0.]))
|
2252
|
+
xp_assert_equal(ndimage.gaussian_filter(arr, 1, order=3), xp.asarray([0.]))
|
2253
|
+
assert_raises(ValueError, ndimage.gaussian_filter, arr, 1, -1)
|
2254
|
+
xp_assert_equal(ndimage.gaussian_filter1d(arr, 1, axis=-1, order=0),
|
2255
|
+
xp.asarray([0.]))
|
2256
|
+
xp_assert_equal(ndimage.gaussian_filter1d(arr, 1, axis=-1, order=3),
|
2257
|
+
xp.asarray([0.]))
|
2258
|
+
assert_raises(ValueError, ndimage.gaussian_filter1d, arr, 1, -1, -1)
|
2259
|
+
|
2260
|
+
|
2261
|
+
@xfail_xp_backends("cupy", reason="TypeError")
|
2262
|
+
def test_valid_origins(xp):
|
2263
|
+
"""Regression test for #1311."""
|
2264
|
+
def func(x):
|
2265
|
+
return xp.mean(x)
|
2266
|
+
|
2267
|
+
data = xp.asarray([1, 2, 3, 4, 5], dtype=xp.float64)
|
2268
|
+
assert_raises(ValueError, ndimage.generic_filter, data, func, size=3,
|
2269
|
+
origin=2)
|
2270
|
+
assert_raises(ValueError, ndimage.generic_filter1d, data, func,
|
2271
|
+
filter_size=3, origin=2)
|
2272
|
+
assert_raises(ValueError, ndimage.percentile_filter, data, 0.2, size=3,
|
2273
|
+
origin=2)
|
2274
|
+
|
2275
|
+
for filter in [ndimage.uniform_filter, ndimage.minimum_filter,
|
2276
|
+
ndimage.maximum_filter, ndimage.maximum_filter1d,
|
2277
|
+
ndimage.median_filter, ndimage.minimum_filter1d]:
|
2278
|
+
# This should work, since for size == 3, the valid range for origin is
|
2279
|
+
# -1 to 1.
|
2280
|
+
list(filter(data, 3, origin=-1))
|
2281
|
+
list(filter(data, 3, origin=1))
|
2282
|
+
# Just check this raises an error instead of silently accepting or
|
2283
|
+
# segfaulting.
|
2284
|
+
assert_raises(ValueError, filter, data, 3, origin=2)
|
2285
|
+
|
2286
|
+
|
2287
|
+
def test_bad_convolve_and_correlate_origins(xp):
|
2288
|
+
"""Regression test for gh-822."""
|
2289
|
+
# Before gh-822 was fixed, these would generate seg. faults or
|
2290
|
+
# other crashes on many system.
|
2291
|
+
assert_raises(ValueError, ndimage.correlate1d,
|
2292
|
+
[0, 1, 2, 3, 4, 5], [1, 1, 2, 0], origin=2)
|
2293
|
+
assert_raises(ValueError, ndimage.correlate,
|
2294
|
+
[0, 1, 2, 3, 4, 5], [0, 1, 2], origin=[2])
|
2295
|
+
assert_raises(ValueError, ndimage.correlate,
|
2296
|
+
xp.ones((3, 5)), xp.ones((2, 2)), origin=[0, 1])
|
2297
|
+
|
2298
|
+
assert_raises(ValueError, ndimage.convolve1d,
|
2299
|
+
xp.arange(10), xp.ones(3), origin=-2)
|
2300
|
+
assert_raises(ValueError, ndimage.convolve,
|
2301
|
+
xp.arange(10), xp.ones(3), origin=[-2])
|
2302
|
+
assert_raises(ValueError, ndimage.convolve,
|
2303
|
+
xp.ones((3, 5)), xp.ones((2, 2)), origin=[0, -2])
|
2304
|
+
|
2305
|
+
@skip_xp_backends("cupy", reason="https://github.com/cupy/cupy/pull/8430")
|
2306
|
+
def test_multiple_modes(xp):
|
2307
|
+
# Test that the filters with multiple mode capabilities for different
|
2308
|
+
# dimensions give the same result as applying a single mode.
|
2309
|
+
arr = xp.asarray([[1., 0., 0.],
|
2310
|
+
[1., 1., 0.],
|
2311
|
+
[0., 0., 0.]])
|
2312
|
+
|
2313
|
+
mode1 = 'reflect'
|
2314
|
+
mode2 = ['reflect', 'reflect']
|
2315
|
+
|
2316
|
+
xp_assert_equal(ndimage.gaussian_filter(arr, 1, mode=mode1),
|
2317
|
+
ndimage.gaussian_filter(arr, 1, mode=mode2))
|
2318
|
+
xp_assert_equal(ndimage.prewitt(arr, mode=mode1),
|
2319
|
+
ndimage.prewitt(arr, mode=mode2))
|
2320
|
+
xp_assert_equal(ndimage.sobel(arr, mode=mode1),
|
2321
|
+
ndimage.sobel(arr, mode=mode2))
|
2322
|
+
xp_assert_equal(ndimage.laplace(arr, mode=mode1),
|
2323
|
+
ndimage.laplace(arr, mode=mode2))
|
2324
|
+
xp_assert_equal(ndimage.gaussian_laplace(arr, 1, mode=mode1),
|
2325
|
+
ndimage.gaussian_laplace(arr, 1, mode=mode2))
|
2326
|
+
xp_assert_equal(ndimage.maximum_filter(arr, size=5, mode=mode1),
|
2327
|
+
ndimage.maximum_filter(arr, size=5, mode=mode2))
|
2328
|
+
xp_assert_equal(ndimage.minimum_filter(arr, size=5, mode=mode1),
|
2329
|
+
ndimage.minimum_filter(arr, size=5, mode=mode2))
|
2330
|
+
xp_assert_equal(ndimage.gaussian_gradient_magnitude(arr, 1, mode=mode1),
|
2331
|
+
ndimage.gaussian_gradient_magnitude(arr, 1, mode=mode2))
|
2332
|
+
xp_assert_equal(ndimage.uniform_filter(arr, 5, mode=mode1),
|
2333
|
+
ndimage.uniform_filter(arr, 5, mode=mode2))
|
2334
|
+
|
2335
|
+
|
2336
|
+
@skip_xp_backends("cupy", reason="https://github.com/cupy/cupy/pull/8430")
|
2337
|
+
def test_multiple_modes_sequentially(xp):
|
2338
|
+
# Test that the filters with multiple mode capabilities for different
|
2339
|
+
# dimensions give the same result as applying the filters with
|
2340
|
+
# different modes sequentially
|
2341
|
+
arr = xp.asarray([[1., 0., 0.],
|
2342
|
+
[1., 1., 0.],
|
2343
|
+
[0., 0., 0.]])
|
2344
|
+
|
2345
|
+
modes = ['reflect', 'wrap']
|
2346
|
+
|
2347
|
+
expected = ndimage.gaussian_filter1d(arr, 1, axis=0, mode=modes[0])
|
2348
|
+
expected = ndimage.gaussian_filter1d(expected, 1, axis=1, mode=modes[1])
|
2349
|
+
xp_assert_equal(expected,
|
2350
|
+
ndimage.gaussian_filter(arr, 1, mode=modes))
|
2351
|
+
|
2352
|
+
expected = ndimage.uniform_filter1d(arr, 5, axis=0, mode=modes[0])
|
2353
|
+
expected = ndimage.uniform_filter1d(expected, 5, axis=1, mode=modes[1])
|
2354
|
+
xp_assert_equal(expected,
|
2355
|
+
ndimage.uniform_filter(arr, 5, mode=modes))
|
2356
|
+
|
2357
|
+
expected = ndimage.maximum_filter1d(arr, size=5, axis=0, mode=modes[0])
|
2358
|
+
expected = ndimage.maximum_filter1d(expected, size=5, axis=1,
|
2359
|
+
mode=modes[1])
|
2360
|
+
xp_assert_equal(expected,
|
2361
|
+
ndimage.maximum_filter(arr, size=5, mode=modes))
|
2362
|
+
|
2363
|
+
expected = ndimage.minimum_filter1d(arr, size=5, axis=0, mode=modes[0])
|
2364
|
+
expected = ndimage.minimum_filter1d(expected, size=5, axis=1,
|
2365
|
+
mode=modes[1])
|
2366
|
+
xp_assert_equal(expected,
|
2367
|
+
ndimage.minimum_filter(arr, size=5, mode=modes))
|
2368
|
+
|
2369
|
+
|
2370
|
+
def test_multiple_modes_prewitt(xp):
|
2371
|
+
# Test prewitt filter for multiple extrapolation modes
|
2372
|
+
arr = xp.asarray([[1., 0., 0.],
|
2373
|
+
[1., 1., 0.],
|
2374
|
+
[0., 0., 0.]])
|
2375
|
+
|
2376
|
+
expected = xp.asarray([[1., -3., 2.],
|
2377
|
+
[1., -2., 1.],
|
2378
|
+
[1., -1., 0.]])
|
2379
|
+
|
2380
|
+
modes = ['reflect', 'wrap']
|
2381
|
+
|
2382
|
+
xp_assert_equal(expected,
|
2383
|
+
ndimage.prewitt(arr, mode=modes))
|
2384
|
+
|
2385
|
+
|
2386
|
+
def test_multiple_modes_sobel(xp):
|
2387
|
+
# Test sobel filter for multiple extrapolation modes
|
2388
|
+
arr = xp.asarray([[1., 0., 0.],
|
2389
|
+
[1., 1., 0.],
|
2390
|
+
[0., 0., 0.]])
|
2391
|
+
|
2392
|
+
expected = xp.asarray([[1., -4., 3.],
|
2393
|
+
[2., -3., 1.],
|
2394
|
+
[1., -1., 0.]])
|
2395
|
+
|
2396
|
+
modes = ['reflect', 'wrap']
|
2397
|
+
|
2398
|
+
xp_assert_equal(expected,
|
2399
|
+
ndimage.sobel(arr, mode=modes))
|
2400
|
+
|
2401
|
+
|
2402
|
+
def test_multiple_modes_laplace(xp):
|
2403
|
+
# Test laplace filter for multiple extrapolation modes
|
2404
|
+
arr = xp.asarray([[1., 0., 0.],
|
2405
|
+
[1., 1., 0.],
|
2406
|
+
[0., 0., 0.]])
|
2407
|
+
|
2408
|
+
expected = xp.asarray([[-2., 2., 1.],
|
2409
|
+
[-2., -3., 2.],
|
2410
|
+
[1., 1., 0.]])
|
2411
|
+
|
2412
|
+
modes = ['reflect', 'wrap']
|
2413
|
+
|
2414
|
+
xp_assert_equal(expected,
|
2415
|
+
ndimage.laplace(arr, mode=modes))
|
2416
|
+
|
2417
|
+
|
2418
|
+
def test_multiple_modes_gaussian_laplace(xp):
|
2419
|
+
# Test gaussian_laplace filter for multiple extrapolation modes
|
2420
|
+
arr = xp.asarray([[1., 0., 0.],
|
2421
|
+
[1., 1., 0.],
|
2422
|
+
[0., 0., 0.]])
|
2423
|
+
|
2424
|
+
expected = xp.asarray([[-0.28438687, 0.01559809, 0.19773499],
|
2425
|
+
[-0.36630503, -0.20069774, 0.07483620],
|
2426
|
+
[0.15849176, 0.18495566, 0.21934094]])
|
2427
|
+
|
2428
|
+
modes = ['reflect', 'wrap']
|
2429
|
+
|
2430
|
+
assert_almost_equal(expected,
|
2431
|
+
ndimage.gaussian_laplace(arr, 1, mode=modes))
|
2432
|
+
|
2433
|
+
|
2434
|
+
def test_multiple_modes_gaussian_gradient_magnitude(xp):
|
2435
|
+
# Test gaussian_gradient_magnitude filter for multiple
|
2436
|
+
# extrapolation modes
|
2437
|
+
arr = xp.asarray([[1., 0., 0.],
|
2438
|
+
[1., 1., 0.],
|
2439
|
+
[0., 0., 0.]])
|
2440
|
+
|
2441
|
+
expected = xp.asarray([[0.04928965, 0.09745625, 0.06405368],
|
2442
|
+
[0.23056905, 0.14025305, 0.04550846],
|
2443
|
+
[0.19894369, 0.14950060, 0.06796850]])
|
2444
|
+
|
2445
|
+
modes = ['reflect', 'wrap']
|
2446
|
+
|
2447
|
+
calculated = ndimage.gaussian_gradient_magnitude(arr, 1, mode=modes)
|
2448
|
+
|
2449
|
+
assert_almost_equal(expected, calculated)
|
2450
|
+
|
2451
|
+
@skip_xp_backends("cupy", reason="https://github.com/cupy/cupy/pull/8430")
|
2452
|
+
def test_multiple_modes_uniform(xp):
|
2453
|
+
# Test uniform filter for multiple extrapolation modes
|
2454
|
+
arr = xp.asarray([[1., 0., 0.],
|
2455
|
+
[1., 1., 0.],
|
2456
|
+
[0., 0., 0.]])
|
2457
|
+
|
2458
|
+
expected = xp.asarray([[0.32, 0.40, 0.48],
|
2459
|
+
[0.20, 0.28, 0.32],
|
2460
|
+
[0.28, 0.32, 0.40]])
|
2461
|
+
|
2462
|
+
modes = ['reflect', 'wrap']
|
2463
|
+
|
2464
|
+
assert_almost_equal(expected,
|
2465
|
+
ndimage.uniform_filter(arr, 5, mode=modes))
|
2466
|
+
|
2467
|
+
|
2468
|
+
def _count_nonzero(arr):
|
2469
|
+
# XXX: a simplified count_nonzero replacement; replace once
|
2470
|
+
# https://github.com/data-apis/array-api/pull/803/ is in
|
2471
|
+
|
2472
|
+
# this assumes arr.dtype == xp.bool
|
2473
|
+
xp = array_namespace(arr)
|
2474
|
+
return xp.sum(xp.astype(arr, xp.int8))
|
2475
|
+
|
2476
|
+
|
2477
|
+
def test_gaussian_truncate(xp):
|
2478
|
+
# Test that Gaussian filters can be truncated at different widths.
|
2479
|
+
# These tests only check that the result has the expected number
|
2480
|
+
# of nonzero elements.
|
2481
|
+
arr = np.zeros((100, 100), dtype=np.float64)
|
2482
|
+
arr[50, 50] = 1
|
2483
|
+
arr = xp.asarray(arr)
|
2484
|
+
num_nonzeros_2 = _count_nonzero(ndimage.gaussian_filter(arr, 5, truncate=2) > 0)
|
2485
|
+
assert num_nonzeros_2 == 21**2
|
2486
|
+
|
2487
|
+
num_nonzeros_5 = _count_nonzero(
|
2488
|
+
ndimage.gaussian_filter(arr, 5, truncate=5) > 0
|
2489
|
+
)
|
2490
|
+
assert num_nonzeros_5 == 51**2
|
2491
|
+
|
2492
|
+
# Test truncate when sigma is a sequence.
|
2493
|
+
f = ndimage.gaussian_filter(arr, [0.5, 2.5], truncate=3.5)
|
2494
|
+
fpos = f > 0
|
2495
|
+
n0 = _count_nonzero(xp.any(fpos, axis=0))
|
2496
|
+
assert n0 == 19
|
2497
|
+
n1 = _count_nonzero(xp.any(fpos, axis=1))
|
2498
|
+
assert n1 == 5
|
2499
|
+
|
2500
|
+
# Test gaussian_filter1d.
|
2501
|
+
x = np.zeros(51)
|
2502
|
+
x[25] = 1
|
2503
|
+
x = xp.asarray(x)
|
2504
|
+
f = ndimage.gaussian_filter1d(x, sigma=2, truncate=3.5)
|
2505
|
+
n = _count_nonzero(f > 0)
|
2506
|
+
assert n == 15
|
2507
|
+
|
2508
|
+
# Test gaussian_laplace
|
2509
|
+
y = ndimage.gaussian_laplace(x, sigma=2, truncate=3.5)
|
2510
|
+
nonzero_indices = xp.nonzero(y != 0)[0]
|
2511
|
+
|
2512
|
+
n = xp.max(nonzero_indices) - xp.min(nonzero_indices) + 1
|
2513
|
+
assert n == 15
|
2514
|
+
|
2515
|
+
# Test gaussian_gradient_magnitude
|
2516
|
+
y = ndimage.gaussian_gradient_magnitude(x, sigma=2, truncate=3.5)
|
2517
|
+
nonzero_indices = xp.nonzero(y != 0)[0]
|
2518
|
+
n = xp.max(nonzero_indices) - xp.min(nonzero_indices) + 1
|
2519
|
+
assert n == 15
|
2520
|
+
|
2521
|
+
|
2522
|
+
@xfail_xp_backends("cupy", reason="cupy/cupy#8402")
|
2523
|
+
def test_gaussian_radius(xp):
|
2524
|
+
# Test that Gaussian filters with radius argument produce the same
|
2525
|
+
# results as the filters with corresponding truncate argument.
|
2526
|
+
# radius = int(truncate * sigma + 0.5)
|
2527
|
+
# Test gaussian_filter1d
|
2528
|
+
x = np.zeros(7)
|
2529
|
+
x[3] = 1
|
2530
|
+
x = xp.asarray(x)
|
2531
|
+
f1 = ndimage.gaussian_filter1d(x, sigma=2, truncate=1.5)
|
2532
|
+
f2 = ndimage.gaussian_filter1d(x, sigma=2, radius=3)
|
2533
|
+
xp_assert_equal(f1, f2)
|
2534
|
+
|
2535
|
+
# Test gaussian_filter when sigma is a number.
|
2536
|
+
a = np.zeros((9, 9))
|
2537
|
+
a[4, 4] = 1
|
2538
|
+
a = xp.asarray(a)
|
2539
|
+
f1 = ndimage.gaussian_filter(a, sigma=0.5, truncate=3.5)
|
2540
|
+
f2 = ndimage.gaussian_filter(a, sigma=0.5, radius=2)
|
2541
|
+
xp_assert_equal(f1, f2)
|
2542
|
+
|
2543
|
+
# Test gaussian_filter when sigma is a sequence.
|
2544
|
+
a = np.zeros((50, 50))
|
2545
|
+
a[25, 25] = 1
|
2546
|
+
a = xp.asarray(a)
|
2547
|
+
f1 = ndimage.gaussian_filter(a, sigma=[0.5, 2.5], truncate=3.5)
|
2548
|
+
f2 = ndimage.gaussian_filter(a, sigma=[0.5, 2.5], radius=[2, 9])
|
2549
|
+
xp_assert_equal(f1, f2)
|
2550
|
+
|
2551
|
+
|
2552
|
+
@xfail_xp_backends("cupy", reason="cupy/cupy#8402")
|
2553
|
+
def test_gaussian_radius_invalid(xp):
|
2554
|
+
# radius must be a nonnegative integer
|
2555
|
+
with assert_raises(ValueError):
|
2556
|
+
ndimage.gaussian_filter1d(xp.zeros(8), sigma=1, radius=-1)
|
2557
|
+
with assert_raises(ValueError):
|
2558
|
+
ndimage.gaussian_filter1d(xp.zeros(8), sigma=1, radius=1.1)
|
2559
|
+
|
2560
|
+
|
2561
|
+
@uses_output_array
|
2562
|
+
class TestThreading:
|
2563
|
+
def check_func_thread(self, n, fun, args, out):
|
2564
|
+
from threading import Thread
|
2565
|
+
thrds = [Thread(target=fun, args=args, kwargs={'output': out[x, ...]})
|
2566
|
+
for x in range(n)]
|
2567
|
+
[t.start() for t in thrds]
|
2568
|
+
[t.join() for t in thrds]
|
2569
|
+
|
2570
|
+
def check_func_serial(self, n, fun, args, out):
|
2571
|
+
for i in range(n):
|
2572
|
+
fun(*args, output=out[i, ...])
|
2573
|
+
|
2574
|
+
@xfail_xp_backends("cupy",
|
2575
|
+
reason="XXX thread exception; cannot repro outside of pytest")
|
2576
|
+
def test_correlate1d(self, xp):
|
2577
|
+
d = np.random.randn(5000)
|
2578
|
+
os = np.empty((4, d.size))
|
2579
|
+
ot = np.empty_like(os)
|
2580
|
+
d = xp.asarray(d)
|
2581
|
+
os = xp.asarray(os)
|
2582
|
+
ot = xp.asarray(ot)
|
2583
|
+
k = xp.arange(5)
|
2584
|
+
self.check_func_serial(4, ndimage.correlate1d, (d, k), os)
|
2585
|
+
self.check_func_thread(4, ndimage.correlate1d, (d, k), ot)
|
2586
|
+
xp_assert_equal(os, ot)
|
2587
|
+
|
2588
|
+
@xfail_xp_backends("cupy",
|
2589
|
+
reason="XXX thread exception; cannot repro outside of pytest")
|
2590
|
+
def test_correlate(self, xp):
|
2591
|
+
d = xp.asarray(np.random.randn(500, 500))
|
2592
|
+
k = xp.asarray(np.random.randn(10, 10))
|
2593
|
+
os = xp.empty([4] + list(d.shape))
|
2594
|
+
ot = xp.empty_like(os)
|
2595
|
+
self.check_func_serial(4, ndimage.correlate, (d, k), os)
|
2596
|
+
self.check_func_thread(4, ndimage.correlate, (d, k), ot)
|
2597
|
+
xp_assert_equal(os, ot)
|
2598
|
+
|
2599
|
+
@xfail_xp_backends("cupy",
|
2600
|
+
reason="XXX thread exception; cannot repro outside of pytest")
|
2601
|
+
def test_median_filter(self, xp):
|
2602
|
+
d = xp.asarray(np.random.randn(500, 500))
|
2603
|
+
os = xp.empty([4] + list(d.shape))
|
2604
|
+
ot = xp.empty_like(os)
|
2605
|
+
self.check_func_serial(4, ndimage.median_filter, (d, 3), os)
|
2606
|
+
self.check_func_thread(4, ndimage.median_filter, (d, 3), ot)
|
2607
|
+
xp_assert_equal(os, ot)
|
2608
|
+
|
2609
|
+
@xfail_xp_backends("cupy",
|
2610
|
+
reason="XXX thread exception; cannot repro outside of pytest")
|
2611
|
+
def test_uniform_filter1d(self, xp):
|
2612
|
+
d = np.random.randn(5000)
|
2613
|
+
os = np.empty((4, d.size))
|
2614
|
+
ot = np.empty_like(os)
|
2615
|
+
d = xp.asarray(d)
|
2616
|
+
os = xp.asarray(os)
|
2617
|
+
ot = xp.asarray(ot)
|
2618
|
+
self.check_func_serial(4, ndimage.uniform_filter1d, (d, 5), os)
|
2619
|
+
self.check_func_thread(4, ndimage.uniform_filter1d, (d, 5), ot)
|
2620
|
+
xp_assert_equal(os, ot)
|
2621
|
+
|
2622
|
+
@xfail_xp_backends("cupy",
|
2623
|
+
reason="XXX thread exception; cannot repro outside of pytest")
|
2624
|
+
def test_minmax_filter(self, xp):
|
2625
|
+
d = xp.asarray(np.random.randn(500, 500))
|
2626
|
+
os = xp.empty([4] + list(d.shape))
|
2627
|
+
ot = xp.empty_like(os)
|
2628
|
+
self.check_func_serial(4, ndimage.maximum_filter, (d, 3), os)
|
2629
|
+
self.check_func_thread(4, ndimage.maximum_filter, (d, 3), ot)
|
2630
|
+
xp_assert_equal(os, ot)
|
2631
|
+
self.check_func_serial(4, ndimage.minimum_filter, (d, 3), os)
|
2632
|
+
self.check_func_thread(4, ndimage.minimum_filter, (d, 3), ot)
|
2633
|
+
xp_assert_equal(os, ot)
|
2634
|
+
|
2635
|
+
|
2636
|
+
def test_minmaximum_filter1d(xp):
|
2637
|
+
# Regression gh-3898
|
2638
|
+
in_ = xp.arange(10)
|
2639
|
+
out = ndimage.minimum_filter1d(in_, 1)
|
2640
|
+
xp_assert_equal(in_, out)
|
2641
|
+
out = ndimage.maximum_filter1d(in_, 1)
|
2642
|
+
xp_assert_equal(in_, out)
|
2643
|
+
# Test reflect
|
2644
|
+
out = ndimage.minimum_filter1d(in_, 5, mode='reflect')
|
2645
|
+
xp_assert_equal(xp.asarray([0, 0, 0, 1, 2, 3, 4, 5, 6, 7]), out)
|
2646
|
+
out = ndimage.maximum_filter1d(in_, 5, mode='reflect')
|
2647
|
+
xp_assert_equal(xp.asarray([2, 3, 4, 5, 6, 7, 8, 9, 9, 9]), out)
|
2648
|
+
# Test constant
|
2649
|
+
out = ndimage.minimum_filter1d(in_, 5, mode='constant', cval=-1)
|
2650
|
+
xp_assert_equal(xp.asarray([-1, -1, 0, 1, 2, 3, 4, 5, -1, -1]), out)
|
2651
|
+
out = ndimage.maximum_filter1d(in_, 5, mode='constant', cval=10)
|
2652
|
+
xp_assert_equal(xp.asarray([10, 10, 4, 5, 6, 7, 8, 9, 10, 10]), out)
|
2653
|
+
# Test nearest
|
2654
|
+
out = ndimage.minimum_filter1d(in_, 5, mode='nearest')
|
2655
|
+
xp_assert_equal(xp.asarray([0, 0, 0, 1, 2, 3, 4, 5, 6, 7]), out)
|
2656
|
+
out = ndimage.maximum_filter1d(in_, 5, mode='nearest')
|
2657
|
+
xp_assert_equal(xp.asarray([2, 3, 4, 5, 6, 7, 8, 9, 9, 9]), out)
|
2658
|
+
# Test wrap
|
2659
|
+
out = ndimage.minimum_filter1d(in_, 5, mode='wrap')
|
2660
|
+
xp_assert_equal(xp.asarray([0, 0, 0, 1, 2, 3, 4, 5, 0, 0]), out)
|
2661
|
+
out = ndimage.maximum_filter1d(in_, 5, mode='wrap')
|
2662
|
+
xp_assert_equal(xp.asarray([9, 9, 4, 5, 6, 7, 8, 9, 9, 9]), out)
|
2663
|
+
|
2664
|
+
|
2665
|
+
@xfail_xp_backends("cupy", reason="cupy/cupy#8401")
|
2666
|
+
def test_uniform_filter1d_roundoff_errors(xp):
|
2667
|
+
# gh-6930
|
2668
|
+
in_ = np.repeat([0, 1, 0], [9, 9, 9])
|
2669
|
+
in_ = xp.asarray(in_)
|
2670
|
+
|
2671
|
+
for filter_size in range(3, 10):
|
2672
|
+
out = ndimage.uniform_filter1d(in_, filter_size)
|
2673
|
+
xp_assert_equal(xp.sum(out), xp.asarray(10 - filter_size), check_0d=False)
|
2674
|
+
|
2675
|
+
|
2676
|
+
def test_footprint_all_zeros(xp):
|
2677
|
+
# regression test for gh-6876: footprint of all zeros segfaults
|
2678
|
+
arr = xp.asarray(np.random.randint(0, 100, (100, 100)))
|
2679
|
+
kernel = xp.asarray(np.zeros((3, 3), dtype=bool))
|
2680
|
+
with assert_raises(ValueError):
|
2681
|
+
ndimage.maximum_filter(arr, footprint=kernel)
|
2682
|
+
|
2683
|
+
|
2684
|
+
@xfail_xp_backends("cupy", reason="does not raise")
|
2685
|
+
@skip_xp_backends("array_api_strict", reason="no float16")
|
2686
|
+
@skip_xp_backends("dask.array", reason="no float16")
|
2687
|
+
def test_gaussian_filter_float16(xp):
|
2688
|
+
# gh-8207
|
2689
|
+
data = xp.asarray([1], dtype=xp.float16)
|
2690
|
+
sigma = 1.0
|
2691
|
+
with assert_raises(RuntimeError):
|
2692
|
+
ndimage.gaussian_filter(data, sigma)
|
2693
|
+
|
2694
|
+
|
2695
|
+
@xfail_xp_backends("cupy", reason="does not raise")
|
2696
|
+
def test_rank_filter_noninteger_rank(xp):
|
2697
|
+
# regression test for issue 9388: ValueError for
|
2698
|
+
# non integer rank when performing rank_filter
|
2699
|
+
arr = xp.asarray(np.random.random((10, 20, 30)))
|
2700
|
+
footprint = xp.asarray(np.ones((1, 1, 10), dtype=bool))
|
2701
|
+
assert_raises(TypeError, ndimage.rank_filter, arr, 0.5,
|
2702
|
+
footprint=footprint)
|
2703
|
+
|
2704
|
+
|
2705
|
+
def test_size_footprint_both_set(xp):
|
2706
|
+
# test for input validation, expect user warning when
|
2707
|
+
# size and footprint is set
|
2708
|
+
with suppress_warnings() as sup:
|
2709
|
+
sup.filter(UserWarning,
|
2710
|
+
"ignoring size because footprint is set")
|
2711
|
+
arr = xp.asarray(np.random.random((10, 20, 30)))
|
2712
|
+
footprint = xp.asarray(np.ones((1, 1, 10), dtype=bool))
|
2713
|
+
ndimage.rank_filter(
|
2714
|
+
arr, 5, size=2, footprint=footprint
|
2715
|
+
)
|
2716
|
+
|
2717
|
+
|
2718
|
+
# NumPy-only because 'byteorder is numpy-specific'
|
2719
|
+
def test_byte_order_median():
|
2720
|
+
"""Regression test for #413: median_filter does not handle bytes orders."""
|
2721
|
+
a = np.arange(9, dtype='<f4').reshape(3, 3)
|
2722
|
+
ref = ndimage.median_filter(a, (3, 3))
|
2723
|
+
b = np.arange(9, dtype='>f4').reshape(3, 3)
|
2724
|
+
t = ndimage.median_filter(b, (3, 3))
|
2725
|
+
assert_array_almost_equal(ref, t)
|
2726
|
+
|
2727
|
+
|
2728
|
+
@pytest.mark.parametrize("filter_size, exp", [
|
2729
|
+
# expected results from SciPy 1.14.1
|
2730
|
+
(20, 0.25754605),
|
2731
|
+
(10,
|
2732
|
+
np.array([0.25266576, 0.27894721, 0.30445588, 0.30958242, 0.30445588, 0.30445588,
|
2733
|
+
0.27894721, 0.30445588, 0.27894721, 0.30445588, 0.30445588, 0.25754605,
|
2734
|
+
0.22183391, 0.18015438, 0.22183391, 0.25266576, 0.25754605, 0.25266576,
|
2735
|
+
0.25266576, 0.25266576]),
|
2736
|
+
),
|
2737
|
+
# a median filter size of 1 is just an identity operation
|
2738
|
+
(1,
|
2739
|
+
np.array([0.30958242, 0.17555138, 0.34343917, 0.27894721, 0.03767094, 0.39024894,
|
2740
|
+
0.30445588, 0.31442572, 0.05124545, 0.18015438, 0.14831921, 0.370706,
|
2741
|
+
0.25754605, 0.32910465, 0.17736568, 0.09089549, 0.22183391, 0.0255269,
|
2742
|
+
0.33105247, 0.25266576]),
|
2743
|
+
),
|
2744
|
+
# testing odd-sized filters >1 makes sense too
|
2745
|
+
(3,
|
2746
|
+
np.array([0.25266576, 0.30958242, 0.27894721, 0.27894721, 0.27894721, 0.30445588,
|
2747
|
+
0.31442572, 0.30445588, 0.18015438, 0.14831921, 0.18015438, 0.25754605,
|
2748
|
+
0.32910465, 0.25754605, 0.17736568, 0.17736568, 0.09089549, 0.22183391,
|
2749
|
+
0.25266576, 0.30958242]),
|
2750
|
+
),
|
2751
|
+
(15,
|
2752
|
+
np.array([0.27894721, 0.25266576, 0.25266576, 0.25266576, 0.27894721, 0.27894721,
|
2753
|
+
0.27894721, 0.27894721, 0.25754605, 0.25754605, 0.22183391, 0.22183391,
|
2754
|
+
0.25266576, 0.25266576, 0.22183391, 0.22183391, 0.25266576, 0.25266576,
|
2755
|
+
0.25754605, 0.25754605]),
|
2756
|
+
),
|
2757
|
+
])
|
2758
|
+
def test_gh_22250(filter_size, exp):
|
2759
|
+
rng = np.random.default_rng(42)
|
2760
|
+
image = np.zeros((20,))
|
2761
|
+
noisy_image = image + 0.4 * rng.random(image.shape)
|
2762
|
+
result = ndimage.median_filter(noisy_image, size=filter_size, mode='wrap')
|
2763
|
+
assert_allclose(result, exp)
|
2764
|
+
|
2765
|
+
|
2766
|
+
def test_gh_22333():
|
2767
|
+
x = np.array([272, 58, 67, 163, 463, 608, 87, 108, 1378])
|
2768
|
+
expected = [58, 67, 87, 108, 163, 108, 108, 108, 87]
|
2769
|
+
actual = ndimage.median_filter(x, size=9, mode='constant')
|
2770
|
+
assert_array_equal(actual, expected)
|
2771
|
+
|
2772
|
+
|
2773
|
+
@pytest.mark.filterwarnings("ignore:The given NumPy array is not writable:UserWarning")
|
2774
|
+
@pytest.mark.skip_xp_backends(cpu_only=True, exceptions=['cupy'])
|
2775
|
+
class TestVectorizedFilter:
|
2776
|
+
@pytest.mark.parametrize("axes, size",
|
2777
|
+
[(None, (3, 4, 5)), ((0, 2), (3, 4)), ((-1,), (5,))])
|
2778
|
+
@pytest.mark.parametrize("origin", [-1, 0, 1])
|
2779
|
+
@pytest.mark.parametrize("mode",
|
2780
|
+
['reflect', 'nearest', 'mirror', 'wrap', 'constant'])
|
2781
|
+
@pytest.mark.parametrize("use_output", [False, True])
|
2782
|
+
def test_against_generic_filter(self, axes, size, origin, mode, use_output, xp):
|
2783
|
+
rng = np.random.default_rng(435982456983456987356)
|
2784
|
+
|
2785
|
+
if use_output and (is_dask(xp) or is_jax(xp)):
|
2786
|
+
pytest.skip("Requires mutable arrays.")
|
2787
|
+
|
2788
|
+
input = rng.random(size=(11, 12, 13))
|
2789
|
+
input_copy = input.copy() # check that it is not modified
|
2790
|
+
output = xp.zeros(input.shape) if use_output else None
|
2791
|
+
|
2792
|
+
kwargs = dict(axes=axes, size=size, origin=origin, mode=mode)
|
2793
|
+
ref = ndimage.generic_filter(input, np.mean, **kwargs)
|
2794
|
+
kwargs['output'] = output
|
2795
|
+
res = ndimage.vectorized_filter(xp.asarray(input.tolist()),
|
2796
|
+
xp.mean, **kwargs)
|
2797
|
+
xp_assert_close(res, xp.asarray(ref.tolist()), atol=1e-15)
|
2798
|
+
if use_output:
|
2799
|
+
xp_assert_equal(output, res)
|
2800
|
+
|
2801
|
+
if not (is_array_api_strict(xp) or is_dask(xp)):
|
2802
|
+
# currently requires support for [..., mask] indexing
|
2803
|
+
kwargs.pop('size')
|
2804
|
+
kwargs.pop('output')
|
2805
|
+
kwargs['footprint'] = rng.random(size=size or input.shape) > 0.5
|
2806
|
+
ref = ndimage.generic_filter(input, np.mean, **kwargs)
|
2807
|
+
kwargs['footprint'] = xp.asarray(kwargs['footprint'])
|
2808
|
+
kwargs['output'] = output
|
2809
|
+
res = ndimage.vectorized_filter(xp.asarray(input.tolist()),
|
2810
|
+
xp.mean, **kwargs)
|
2811
|
+
xp_assert_close(res, xp.asarray(ref.tolist()), atol=1e-15)
|
2812
|
+
if use_output:
|
2813
|
+
xp_assert_equal(output, res)
|
2814
|
+
|
2815
|
+
xp_assert_equal(xp.asarray(input), xp.asarray(input_copy))
|
2816
|
+
|
2817
|
+
@pytest.mark.parametrize("dtype",
|
2818
|
+
["uint8", "uint16", "uint32", "uint64",
|
2819
|
+
"int8", "int16", "int32", "int64",
|
2820
|
+
"float32", "float64", "complex64", "complex128"])
|
2821
|
+
@pytest.mark.parametrize("batch_memory", [1, 16*3, np.inf])
|
2822
|
+
@pytest.mark.parametrize("use_footprint", [False, True])
|
2823
|
+
def test_dtype_batch_memory(self, dtype, batch_memory, use_footprint, xp):
|
2824
|
+
rng = np.random.default_rng(435982456983456987356)
|
2825
|
+
w = 3
|
2826
|
+
|
2827
|
+
if is_jax(xp) and not (batch_memory == 1):
|
2828
|
+
pytest.skip("Requires mutable array.")
|
2829
|
+
if is_torch(xp) and dtype in {'uint16', 'uint32', 'uint64'}:
|
2830
|
+
pytest.skip("Needs uint support.")
|
2831
|
+
|
2832
|
+
dtype = getattr(xp, dtype)
|
2833
|
+
|
2834
|
+
if use_footprint:
|
2835
|
+
if (is_dask(xp) or is_array_api_strict(xp)):
|
2836
|
+
pytest.skip("Requires [..., mask] indexing.")
|
2837
|
+
footprint = xp.asarray([True, False, True])
|
2838
|
+
kwargs = dict(footprint=footprint, batch_memory=batch_memory)
|
2839
|
+
else:
|
2840
|
+
footprint = xp.asarray([True, True, True])
|
2841
|
+
kwargs = dict(size=w, batch_memory=batch_memory)
|
2842
|
+
|
2843
|
+
# The intent here is to exercise all the code paths involved in `batch_memory`
|
2844
|
+
# and `output` handling. To test the limited-memory case, `batch_memory=16*3`
|
2845
|
+
# is chosen to be just large enough for a *single* window of `complex128` to
|
2846
|
+
# fit, and `n` is large enough that a whole sliding window view of `uint8`s
|
2847
|
+
# *won't* fit.
|
2848
|
+
n = 16*3 + 1
|
2849
|
+
input = rng.integers(0, 42, size=(n,))
|
2850
|
+
input = input + input*1j if xp.isdtype(dtype, 'complex floating') else input
|
2851
|
+
input_padded = xp.asarray(np.pad(input, [(1, 1)], mode='symmetric'),
|
2852
|
+
dtype=dtype)
|
2853
|
+
input = xp.asarray(input, dtype=dtype)
|
2854
|
+
|
2855
|
+
ref = [xp.sum(input_padded[i: i + w][footprint]) for i in range(n)]
|
2856
|
+
sum_dtype = xp.sum(input_padded).dtype
|
2857
|
+
|
2858
|
+
message = "`batch_memory` is insufficient for minimum chunk size."
|
2859
|
+
context = (pytest.raises(ValueError, match=message)
|
2860
|
+
if batch_memory == 1 else contextlib.nullcontext())
|
2861
|
+
with context:
|
2862
|
+
res = ndimage.vectorized_filter(input, xp.sum, **kwargs)
|
2863
|
+
xp_assert_close(res, xp.astype(xp.stack(ref), sum_dtype))
|
2864
|
+
assert res.dtype == sum_dtype
|
2865
|
+
|
2866
|
+
output = xp.empty_like(input)
|
2867
|
+
res = ndimage.vectorized_filter(input, xp.sum, output=output, **kwargs)
|
2868
|
+
xp_assert_close(res, xp.astype(xp.stack(ref), dtype))
|
2869
|
+
assert res.dtype == dtype
|
2870
|
+
|
2871
|
+
def test_mode_valid(self, xp):
|
2872
|
+
rng = np.random.default_rng(435982456983456987356)
|
2873
|
+
input = rng.random(size=(10, 11))
|
2874
|
+
input_xp = xp.asarray(input)
|
2875
|
+
input_xp_copy = xp_copy(input_xp) # check that it is not modified
|
2876
|
+
size = (3, 5)
|
2877
|
+
|
2878
|
+
res = ndimage.vectorized_filter(input_xp, xp.mean, size=size, mode='valid')
|
2879
|
+
|
2880
|
+
view = np.lib.stride_tricks.sliding_window_view(input, size)
|
2881
|
+
ref = np.mean(view, axis=(-2, -1))
|
2882
|
+
|
2883
|
+
xp_assert_close(res, xp.asarray(ref))
|
2884
|
+
assert res.shape == tuple(input.shape - np.asarray(size) + 1)
|
2885
|
+
xp_assert_equal(input_xp, input_xp_copy)
|
2886
|
+
|
2887
|
+
def test_input_validation(self, xp):
|
2888
|
+
input = xp.ones((10, 10))
|
2889
|
+
function = xp.mean
|
2890
|
+
size = 2
|
2891
|
+
footprint = xp.ones((2, 2))
|
2892
|
+
|
2893
|
+
message = "`function` must be a callable."
|
2894
|
+
with pytest.raises(ValueError, match=message):
|
2895
|
+
ndimage.vectorized_filter(input, "eggplant", size=size)
|
2896
|
+
|
2897
|
+
message = "Either `size` or `footprint` must be provided."
|
2898
|
+
with pytest.raises(ValueError, match=message):
|
2899
|
+
ndimage.vectorized_filter(input, function)
|
2900
|
+
|
2901
|
+
message = "Either `size` or `footprint` may be provided, not both."
|
2902
|
+
with pytest.raises(ValueError, match=message):
|
2903
|
+
ndimage.vectorized_filter(input, function, size=size, footprint=footprint)
|
2904
|
+
|
2905
|
+
message = "All elements of `size` must be positive integers."
|
2906
|
+
with pytest.raises(ValueError, match=message):
|
2907
|
+
ndimage.vectorized_filter(input, function, size=(1, -1))
|
2908
|
+
with pytest.raises(ValueError, match=message):
|
2909
|
+
ndimage.vectorized_filter(input, function, size=0)
|
2910
|
+
|
2911
|
+
message = "The length of `axes` may not exceed "
|
2912
|
+
axes = (0, 1, 2)
|
2913
|
+
with pytest.raises(ValueError, match=message):
|
2914
|
+
ndimage.vectorized_filter(input, function, size=(1, 2), axes=axes)
|
2915
|
+
with pytest.raises(ValueError, match=message):
|
2916
|
+
ndimage.vectorized_filter(input, function, footprint=xp.ones((2, 2)),
|
2917
|
+
axes=axes)
|
2918
|
+
|
2919
|
+
message = "`axes` must be compatible with the dimensionality..."
|
2920
|
+
with pytest.raises(ValueError, match=message):
|
2921
|
+
ndimage.vectorized_filter(input, function, size=(1,))
|
2922
|
+
with pytest.raises(ValueError, match=message):
|
2923
|
+
ndimage.vectorized_filter(input, function, size=(2,), axes=(0,1))
|
2924
|
+
|
2925
|
+
message = "All elements of `origin` must be integers"
|
2926
|
+
with pytest.raises(ValueError, match=message):
|
2927
|
+
ndimage.vectorized_filter(input, function, size=size, origin=(1, 1.5))
|
2928
|
+
|
2929
|
+
message = "`origin` must be an integer or tuple of integers with length..."
|
2930
|
+
with pytest.raises(ValueError, match=message):
|
2931
|
+
ndimage.vectorized_filter(input, function, size=size, origin=(1, 2, 3))
|
2932
|
+
|
2933
|
+
message = "`mode` must be one of..."
|
2934
|
+
with pytest.raises(ValueError, match=message):
|
2935
|
+
ndimage.vectorized_filter(input, function, size=size, mode='coconut')
|
2936
|
+
|
2937
|
+
message = "`mode='valid'` is incompatible with use of `origin`."
|
2938
|
+
with pytest.raises(ValueError, match=message):
|
2939
|
+
ndimage.vectorized_filter(input, function, size=size,
|
2940
|
+
mode='valid', origin=1)
|
2941
|
+
|
2942
|
+
message = "Use of `cval` is compatible only with `mode='constant'`."
|
2943
|
+
with pytest.raises(ValueError, match=message):
|
2944
|
+
ndimage.vectorized_filter(input, function, size=size, mode='valid', cval=1)
|
2945
|
+
|
2946
|
+
other_messages = "|Unsupported|The array_api_strict|new|Value 'a duck'"
|
2947
|
+
message = "`cval` must include only numbers." + other_messages
|
2948
|
+
with pytest.raises((ValueError, TypeError), match=message):
|
2949
|
+
ndimage.vectorized_filter(input, function, size=size,
|
2950
|
+
mode='constant', cval='a duck')
|
2951
|
+
|
2952
|
+
message = "`batch_memory` must be positive number." + other_messages
|
2953
|
+
with pytest.raises(ValueError, match=message):
|
2954
|
+
ndimage.vectorized_filter(input, function, size=size, batch_memory=0)
|
2955
|
+
with pytest.raises(ValueError, match=message):
|
2956
|
+
ndimage.vectorized_filter(input, function, size=size, batch_memory=(1, 2))
|
2957
|
+
with pytest.raises((ValueError, TypeError), match=message):
|
2958
|
+
ndimage.vectorized_filter(input, function, size=size, batch_memory="a duck")
|
2959
|
+
|
2960
|
+
@pytest.mark.parametrize('shape', [(0,), (1, 0), (0, 1, 0)])
|
2961
|
+
def test_zero_size(self, shape, xp):
|
2962
|
+
input = xp.empty(shape)
|
2963
|
+
res = ndimage.vectorized_filter(input, xp.mean, size=1)
|
2964
|
+
xp_assert_equal(res, input)
|
2965
|
+
|
2966
|
+
@pytest.mark.filterwarnings("ignore:Mean of empty slice.:RuntimeWarning")
|
2967
|
+
def test_edge_cases(self, xp):
|
2968
|
+
rng = np.random.default_rng(4835982345234982)
|
2969
|
+
function = xp.mean
|
2970
|
+
|
2971
|
+
# 0-D input
|
2972
|
+
input = xp.asarray(1.)
|
2973
|
+
res = ndimage.vectorized_filter(input, function, size=())
|
2974
|
+
xp_assert_equal(res, xp.asarray(function(input, axis=())))
|
2975
|
+
|
2976
|
+
if not (is_array_api_strict(xp) or is_dask(xp)):
|
2977
|
+
res = ndimage.vectorized_filter(input, function, footprint=True)
|
2978
|
+
xp_assert_equal(res, xp.asarray(function(input[True], axis=())))
|
2979
|
+
|
2980
|
+
res = ndimage.vectorized_filter(input, function, footprint=False)
|
2981
|
+
xp_assert_equal(res, xp.asarray(function(input[False], axis=())))
|
2982
|
+
|
2983
|
+
# 1x1 window
|
2984
|
+
input = xp.asarray(rng.random((5, 5)))
|
2985
|
+
res = ndimage.vectorized_filter(input, function, size=1)
|
2986
|
+
xp_assert_equal(res, input)
|
2987
|
+
|
2988
|
+
# window is bigger than input shouldn't be a problem
|
2989
|
+
res = ndimage.vectorized_filter(input, function, size=21)
|
2990
|
+
ref = ndimage.vectorized_filter(input, function, size=21)
|
2991
|
+
xp_assert_close(res, ref)
|
2992
|
+
|
2993
|
+
def test_gh23046_feature(self, xp):
|
2994
|
+
# The intent of gh-23046 was to always allow `size` to be a scalar.
|
2995
|
+
rng = np.random.default_rng(45982734597824)
|
2996
|
+
img = xp.asarray(rng.random((5, 5)))
|
2997
|
+
|
2998
|
+
ref = ndimage.vectorized_filter(img, xp.mean, size=2)
|
2999
|
+
res = ndimage.vectorized_filter(img, xp.mean, size=2, axes=(0, 1))
|
3000
|
+
xp_assert_close(res, ref)
|
3001
|
+
|
3002
|
+
ref = ndimage.vectorized_filter(img, xp.mean, size=(2,), axes=(0,))
|
3003
|
+
res = ndimage.vectorized_filter(img, xp.mean, size=2, axes=0)
|
3004
|
+
xp_assert_close(res, ref)
|
3005
|
+
|
3006
|
+
def test_gh23046_fix(self, xp):
|
3007
|
+
# While investigating the feasibility of gh-23046, I noticed a bug when the
|
3008
|
+
# length of an `axes` tuple equals the dimensionality of the image.
|
3009
|
+
rng = np.random.default_rng(45982734597824)
|
3010
|
+
img = xp.asarray(rng.random((5, 5)))
|
3011
|
+
size = (2, 3)
|
3012
|
+
ref = ndimage.vectorized_filter(img.T, xp.mean, size=size).T
|
3013
|
+
res = ndimage.vectorized_filter(img, xp.mean, size=size, axes=(1, 0))
|
3014
|
+
xp_assert_close(res, ref)
|
3015
|
+
|
3016
|
+
ref = ndimage.vectorized_filter(img, xp.mean, size=size, mode='constant')
|
3017
|
+
res = ndimage.vectorized_filter(img, xp.mean, size=size[::-1], axes=(1, 0),
|
3018
|
+
mode='constant')
|
3019
|
+
xp_assert_close(res, ref)
|
3020
|
+
|
3021
|
+
|
3022
|
+
|
3023
|
+
@given(x=npst.arrays(dtype=np.float64,
|
3024
|
+
shape=st.integers(min_value=1, max_value=1000)),
|
3025
|
+
size=st.integers(min_value=1, max_value=50),
|
3026
|
+
mode=st.sampled_from(["constant", "mirror", "wrap", "reflect",
|
3027
|
+
"nearest"]),
|
3028
|
+
)
|
3029
|
+
def test_gh_22586_crash_property(x, size, mode):
|
3030
|
+
# property-based test for median_filter resilience to hard crashing
|
3031
|
+
ndimage.median_filter(x, size=size, mode=mode)
|
3032
|
+
|
3033
|
+
|
3034
|
+
@pytest.mark.parametrize('samples, mode, size, expected', [
|
3035
|
+
([1, 2], "reflect", 5, [2, 1]),
|
3036
|
+
([2], "reflect", 5, [2]), # original failure from gh-23075
|
3037
|
+
([2], "nearest", 5, [2]),
|
3038
|
+
([2], "wrap", 5, [2]),
|
3039
|
+
([2], "mirror", 5, [2]),
|
3040
|
+
([2], "constant", 5, [0]),
|
3041
|
+
([2], "reflect", 1, [2]),
|
3042
|
+
([2], "nearest", 1, [2]),
|
3043
|
+
([2], "wrap", 1, [2]),
|
3044
|
+
([2], "mirror", 1, [2]),
|
3045
|
+
([2], "constant", 1, [2]),
|
3046
|
+
([2], "reflect", 100, [2]),
|
3047
|
+
([2], "nearest", 100, [2]),
|
3048
|
+
([2], "wrap", 100, [2]),
|
3049
|
+
([2], "mirror", 100, [2]),
|
3050
|
+
([2], "constant", 100, [0]),
|
3051
|
+
])
|
3052
|
+
def test_gh_23075(samples, mode, size, expected):
|
3053
|
+
# results verified against SciPy 1.14.1, before the median_filter
|
3054
|
+
# overhaul
|
3055
|
+
sample_array = np.asarray(samples, dtype=np.float32)
|
3056
|
+
expected = np.asarray(expected, dtype=np.float32)
|
3057
|
+
filtered_samples = ndimage.median_filter(sample_array, size=size, mode=mode)
|
3058
|
+
xp_assert_close(filtered_samples, expected, check_shape=True, check_dtype=True)
|
3059
|
+
|
3060
|
+
|
3061
|
+
@pytest.mark.parametrize('samples, size, cval, expected', [
|
3062
|
+
([2], 5, 17.7, [17.7]),
|
3063
|
+
([2], 1, 0, [2]),
|
3064
|
+
([2], 100, 1.4, [1.4]),
|
3065
|
+
([9], 137, -7807.7, [-7807.7]),
|
3066
|
+
])
|
3067
|
+
def test_gh_23075_constant(samples, size, cval, expected):
|
3068
|
+
# results verified against SciPy 1.14.1, before the median_filter
|
3069
|
+
# overhaul
|
3070
|
+
sample_array = np.asarray(samples, dtype=np.single)
|
3071
|
+
expected = np.asarray(expected, dtype=np.single)
|
3072
|
+
filtered_samples = ndimage.median_filter(sample_array,
|
3073
|
+
size=size,
|
3074
|
+
mode="constant",
|
3075
|
+
cval=cval)
|
3076
|
+
xp_assert_close(filtered_samples, expected, check_shape=True, check_dtype=True)
|
3077
|
+
|
3078
|
+
|
3079
|
+
def test_median_filter_lim2():
|
3080
|
+
sample_array = np.ones(8)
|
3081
|
+
expected = np.ones(8)
|
3082
|
+
filtered_samples = ndimage.median_filter(sample_array, size=19, mode="reflect")
|
3083
|
+
xp_assert_close(filtered_samples, expected, check_shape=True, check_dtype=True)
|