scipy 1.15.3__cp313-cp313t-macosx_14_0_arm64.whl → 1.16.0rc2__cp313-cp313t-macosx_14_0_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 +3 -3
- scipy/__init__.py +3 -6
- scipy/_cyutility.cpython-313t-darwin.so +0 -0
- scipy/_lib/_array_api.py +486 -161
- scipy/_lib/_array_api_compat_vendor.py +9 -0
- scipy/_lib/_bunch.py +4 -0
- scipy/_lib/_ccallback_c.cpython-313t-darwin.so +0 -0
- scipy/_lib/_docscrape.py +1 -1
- scipy/_lib/_elementwise_iterative_method.py +15 -26
- scipy/_lib/_sparse.py +41 -0
- scipy/_lib/_test_deprecation_call.cpython-313t-darwin.so +0 -0
- scipy/_lib/_testutils.py +6 -2
- scipy/_lib/_util.py +222 -125
- scipy/_lib/array_api_compat/__init__.py +4 -4
- scipy/_lib/array_api_compat/_internal.py +19 -6
- scipy/_lib/array_api_compat/common/__init__.py +1 -1
- scipy/_lib/array_api_compat/common/_aliases.py +365 -193
- scipy/_lib/array_api_compat/common/_fft.py +94 -64
- scipy/_lib/array_api_compat/common/_helpers.py +413 -180
- scipy/_lib/array_api_compat/common/_linalg.py +116 -40
- scipy/_lib/array_api_compat/common/_typing.py +179 -10
- scipy/_lib/array_api_compat/cupy/__init__.py +1 -4
- scipy/_lib/array_api_compat/cupy/_aliases.py +61 -41
- scipy/_lib/array_api_compat/cupy/_info.py +16 -6
- scipy/_lib/array_api_compat/cupy/_typing.py +24 -39
- scipy/_lib/array_api_compat/dask/array/__init__.py +6 -3
- scipy/_lib/array_api_compat/dask/array/_aliases.py +267 -108
- scipy/_lib/array_api_compat/dask/array/_info.py +105 -34
- scipy/_lib/array_api_compat/dask/array/fft.py +5 -8
- scipy/_lib/array_api_compat/dask/array/linalg.py +21 -22
- scipy/_lib/array_api_compat/numpy/__init__.py +13 -15
- scipy/_lib/array_api_compat/numpy/_aliases.py +98 -49
- scipy/_lib/array_api_compat/numpy/_info.py +36 -16
- scipy/_lib/array_api_compat/numpy/_typing.py +27 -43
- scipy/_lib/array_api_compat/numpy/fft.py +11 -5
- scipy/_lib/array_api_compat/numpy/linalg.py +75 -22
- scipy/_lib/array_api_compat/torch/__init__.py +3 -5
- scipy/_lib/array_api_compat/torch/_aliases.py +262 -159
- scipy/_lib/array_api_compat/torch/_info.py +27 -16
- scipy/_lib/array_api_compat/torch/_typing.py +3 -0
- scipy/_lib/array_api_compat/torch/fft.py +17 -18
- scipy/_lib/array_api_compat/torch/linalg.py +16 -16
- scipy/_lib/array_api_extra/__init__.py +26 -3
- 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/decorator.py +2 -2
- scipy/_lib/doccer.py +1 -7
- scipy/_lib/messagestream.cpython-313t-darwin.so +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/test__util.py +105 -121
- scipy/_lib/tests/test_array_api.py +166 -35
- scipy/_lib/tests/test_bunch.py +7 -0
- scipy/_lib/tests/test_ccallback.py +2 -10
- scipy/_lib/tests/test_public_api.py +13 -0
- scipy/cluster/_hierarchy.cpython-313t-darwin.so +0 -0
- scipy/cluster/_optimal_leaf_ordering.cpython-313t-darwin.so +0 -0
- scipy/cluster/_vq.cpython-313t-darwin.so +0 -0
- scipy/cluster/hierarchy.py +393 -223
- scipy/cluster/tests/test_hierarchy.py +273 -335
- scipy/cluster/tests/test_vq.py +45 -61
- scipy/cluster/vq.py +39 -35
- scipy/conftest.py +263 -157
- scipy/constants/_constants.py +4 -1
- scipy/constants/tests/test_codata.py +2 -2
- scipy/constants/tests/test_constants.py +11 -18
- scipy/datasets/_download_all.py +15 -1
- scipy/datasets/_fetchers.py +7 -1
- scipy/datasets/_utils.py +1 -1
- scipy/differentiate/_differentiate.py +25 -25
- scipy/differentiate/tests/test_differentiate.py +24 -25
- scipy/fft/_basic.py +20 -0
- scipy/fft/_helper.py +3 -34
- scipy/fft/_pocketfft/helper.py +29 -1
- scipy/fft/_pocketfft/tests/test_basic.py +2 -4
- scipy/fft/_pocketfft/tests/test_real_transforms.py +4 -4
- scipy/fft/_realtransforms.py +13 -0
- scipy/fft/tests/test_basic.py +27 -25
- scipy/fft/tests/test_fftlog.py +16 -7
- scipy/fft/tests/test_helper.py +18 -34
- scipy/fft/tests/test_real_transforms.py +8 -10
- scipy/fftpack/convolve.cpython-313t-darwin.so +0 -0
- scipy/fftpack/tests/test_basic.py +2 -4
- scipy/fftpack/tests/test_real_transforms.py +8 -9
- scipy/integrate/_bvp.py +9 -3
- scipy/integrate/_cubature.py +3 -2
- scipy/integrate/_dop.cpython-313t-darwin.so +0 -0
- scipy/integrate/_lsoda.cpython-313t-darwin.so +0 -0
- scipy/integrate/_ode.py +9 -2
- scipy/integrate/_odepack.cpython-313t-darwin.so +0 -0
- scipy/integrate/_quad_vec.py +21 -29
- scipy/integrate/_quadpack.cpython-313t-darwin.so +0 -0
- scipy/integrate/_quadpack_py.py +11 -7
- scipy/integrate/_quadrature.py +3 -3
- scipy/integrate/_rules/_base.py +2 -2
- scipy/integrate/_tanhsinh.py +48 -47
- scipy/integrate/_test_odeint_banded.cpython-313t-darwin.so +0 -0
- scipy/integrate/_vode.cpython-313t-darwin.so +0 -0
- scipy/integrate/tests/test__quad_vec.py +0 -6
- scipy/integrate/tests/test_banded_ode_solvers.py +85 -0
- scipy/integrate/tests/test_cubature.py +21 -35
- scipy/integrate/tests/test_quadrature.py +6 -8
- scipy/integrate/tests/test_tanhsinh.py +56 -48
- scipy/interpolate/__init__.py +70 -58
- scipy/interpolate/_bary_rational.py +22 -22
- scipy/interpolate/_bsplines.py +119 -66
- scipy/interpolate/_cubic.py +65 -50
- scipy/interpolate/_dfitpack.cpython-313t-darwin.so +0 -0
- scipy/interpolate/_dierckx.cpython-313t-darwin.so +0 -0
- scipy/interpolate/_fitpack.cpython-313t-darwin.so +0 -0
- scipy/interpolate/_fitpack2.py +9 -6
- scipy/interpolate/_fitpack_impl.py +32 -26
- scipy/interpolate/_fitpack_repro.py +23 -19
- scipy/interpolate/_interpnd.cpython-313t-darwin.so +0 -0
- scipy/interpolate/_interpolate.py +30 -12
- scipy/interpolate/_ndbspline.py +13 -18
- scipy/interpolate/_ndgriddata.py +5 -8
- scipy/interpolate/_polyint.py +95 -31
- scipy/interpolate/_ppoly.cpython-313t-darwin.so +0 -0
- scipy/interpolate/_rbf.py +2 -2
- scipy/interpolate/_rbfinterp.py +1 -1
- scipy/interpolate/_rbfinterp_pythran.cpython-313t-darwin.so +0 -0
- scipy/interpolate/_rgi.py +31 -26
- scipy/interpolate/_rgi_cython.cpython-313t-darwin.so +0 -0
- scipy/interpolate/dfitpack.py +0 -20
- scipy/interpolate/interpnd.py +1 -2
- scipy/interpolate/tests/test_bary_rational.py +2 -2
- scipy/interpolate/tests/test_bsplines.py +97 -1
- scipy/interpolate/tests/test_fitpack2.py +39 -1
- scipy/interpolate/tests/test_interpnd.py +32 -20
- scipy/interpolate/tests/test_interpolate.py +48 -4
- scipy/interpolate/tests/test_rgi.py +2 -1
- scipy/io/_fast_matrix_market/__init__.py +2 -0
- scipy/io/_harwell_boeing/_fortran_format_parser.py +19 -16
- scipy/io/_harwell_boeing/hb.py +7 -11
- scipy/io/_idl.py +5 -7
- scipy/io/_netcdf.py +15 -5
- scipy/io/_test_fortran.cpython-313t-darwin.so +0 -0
- scipy/io/arff/tests/test_arffread.py +3 -3
- scipy/io/matlab/__init__.py +5 -3
- scipy/io/matlab/_mio.py +4 -1
- scipy/io/matlab/_mio5.py +19 -13
- scipy/io/matlab/_mio5_utils.cpython-313t-darwin.so +0 -0
- scipy/io/matlab/_mio_utils.cpython-313t-darwin.so +0 -0
- scipy/io/matlab/_miobase.py +4 -1
- scipy/io/matlab/_streams.cpython-313t-darwin.so +0 -0
- scipy/io/matlab/tests/test_mio.py +46 -18
- scipy/io/matlab/tests/test_mio_funcs.py +1 -1
- scipy/io/tests/test_mmio.py +7 -1
- scipy/io/tests/test_wavfile.py +41 -0
- scipy/io/wavfile.py +57 -10
- scipy/linalg/_basic.py +113 -86
- scipy/linalg/_cythonized_array_utils.cpython-313t-darwin.so +0 -0
- scipy/linalg/_decomp.py +22 -9
- scipy/linalg/_decomp_cholesky.py +28 -13
- scipy/linalg/_decomp_cossin.py +45 -30
- scipy/linalg/_decomp_interpolative.cpython-313t-darwin.so +0 -0
- scipy/linalg/_decomp_ldl.py +4 -1
- scipy/linalg/_decomp_lu.py +18 -6
- scipy/linalg/_decomp_lu_cython.cpython-313t-darwin.so +0 -0
- scipy/linalg/_decomp_polar.py +2 -0
- scipy/linalg/_decomp_qr.py +6 -2
- scipy/linalg/_decomp_qz.py +3 -0
- scipy/linalg/_decomp_schur.py +3 -1
- scipy/linalg/_decomp_svd.py +13 -2
- scipy/linalg/_decomp_update.cpython-313t-darwin.so +0 -0
- scipy/linalg/_expm_frechet.py +4 -0
- scipy/linalg/_fblas.cpython-313t-darwin.so +0 -0
- scipy/linalg/_flapack.cpython-313t-darwin.so +0 -0
- scipy/linalg/_linalg_pythran.cpython-313t-darwin.so +0 -0
- scipy/linalg/_matfuncs.py +187 -4
- scipy/linalg/_matfuncs_expm.cpython-313t-darwin.so +0 -0
- scipy/linalg/_matfuncs_schur_sqrtm.cpython-313t-darwin.so +0 -0
- scipy/linalg/_matfuncs_sqrtm.py +1 -99
- scipy/linalg/_matfuncs_sqrtm_triu.cpython-313t-darwin.so +0 -0
- scipy/linalg/_procrustes.py +2 -0
- scipy/linalg/_sketches.py +17 -6
- scipy/linalg/_solve_toeplitz.cpython-313t-darwin.so +0 -0
- scipy/linalg/_solvers.py +7 -2
- scipy/linalg/_special_matrices.py +26 -36
- scipy/linalg/cython_blas.cpython-313t-darwin.so +0 -0
- scipy/linalg/cython_lapack.cpython-313t-darwin.so +0 -0
- scipy/linalg/lapack.py +22 -2
- scipy/linalg/tests/_cython_examples/meson.build +7 -0
- scipy/linalg/tests/test_basic.py +31 -16
- scipy/linalg/tests/test_batch.py +588 -0
- scipy/linalg/tests/test_cythonized_array_utils.py +0 -2
- scipy/linalg/tests/test_decomp.py +40 -3
- scipy/linalg/tests/test_decomp_cossin.py +14 -0
- scipy/linalg/tests/test_decomp_ldl.py +1 -1
- scipy/linalg/tests/test_lapack.py +115 -7
- scipy/linalg/tests/test_matfuncs.py +157 -102
- scipy/linalg/tests/test_procrustes.py +0 -7
- scipy/linalg/tests/test_solve_toeplitz.py +1 -1
- scipy/linalg/tests/test_special_matrices.py +1 -5
- scipy/ndimage/__init__.py +1 -0
- scipy/ndimage/_cytest.cpython-313t-darwin.so +0 -0
- scipy/ndimage/_delegators.py +8 -2
- scipy/ndimage/_filters.py +453 -5
- scipy/ndimage/_interpolation.py +36 -6
- scipy/ndimage/_measurements.py +4 -2
- scipy/ndimage/_morphology.py +5 -0
- scipy/ndimage/_nd_image.cpython-313t-darwin.so +0 -0
- scipy/ndimage/_ni_docstrings.py +5 -1
- scipy/ndimage/_ni_label.cpython-313t-darwin.so +0 -0
- scipy/ndimage/_ni_support.py +1 -5
- scipy/ndimage/_rank_filter_1d.cpython-313t-darwin.so +0 -0
- scipy/ndimage/_support_alternative_backends.py +18 -6
- scipy/ndimage/tests/test_filters.py +370 -259
- scipy/ndimage/tests/test_fourier.py +7 -9
- scipy/ndimage/tests/test_interpolation.py +68 -61
- scipy/ndimage/tests/test_measurements.py +18 -35
- scipy/ndimage/tests/test_morphology.py +143 -131
- scipy/ndimage/tests/test_splines.py +1 -3
- scipy/odr/__odrpack.cpython-313t-darwin.so +0 -0
- scipy/optimize/_basinhopping.py +13 -7
- scipy/optimize/_bglu_dense.cpython-313t-darwin.so +0 -0
- scipy/optimize/_bracket.py +17 -24
- scipy/optimize/_chandrupatla.py +9 -10
- scipy/optimize/_cobyla_py.py +104 -123
- scipy/optimize/_constraints.py +14 -10
- scipy/optimize/_differentiable_functions.py +371 -230
- scipy/optimize/_differentialevolution.py +4 -3
- scipy/optimize/_direct.cpython-313t-darwin.so +0 -0
- scipy/optimize/_dual_annealing.py +1 -1
- scipy/optimize/_elementwise.py +1 -4
- scipy/optimize/_group_columns.cpython-313t-darwin.so +0 -0
- scipy/optimize/_lbfgsb.cpython-313t-darwin.so +0 -0
- scipy/optimize/_lbfgsb_py.py +57 -16
- scipy/optimize/_linprog_doc.py +2 -2
- scipy/optimize/_linprog_highs.py +2 -2
- scipy/optimize/_linprog_ip.py +25 -10
- scipy/optimize/_linprog_util.py +14 -16
- scipy/optimize/_lsap.cpython-313t-darwin.so +0 -0
- scipy/optimize/_lsq/common.py +3 -3
- scipy/optimize/_lsq/dogbox.py +16 -2
- scipy/optimize/_lsq/givens_elimination.cpython-313t-darwin.so +0 -0
- scipy/optimize/_lsq/least_squares.py +198 -126
- scipy/optimize/_lsq/lsq_linear.py +6 -6
- scipy/optimize/_lsq/trf.py +35 -8
- scipy/optimize/_milp.py +3 -1
- scipy/optimize/_minimize.py +105 -36
- scipy/optimize/_minpack.cpython-313t-darwin.so +0 -0
- scipy/optimize/_minpack_py.py +21 -14
- scipy/optimize/_moduleTNC.cpython-313t-darwin.so +0 -0
- scipy/optimize/_nnls.py +20 -21
- scipy/optimize/_nonlin.py +34 -3
- scipy/optimize/_numdiff.py +288 -110
- scipy/optimize/_optimize.py +86 -48
- scipy/optimize/_pava_pybind.cpython-313t-darwin.so +0 -0
- scipy/optimize/_remove_redundancy.py +5 -5
- scipy/optimize/_root_scalar.py +1 -1
- scipy/optimize/_shgo.py +6 -0
- scipy/optimize/_shgo_lib/_complex.py +1 -1
- scipy/optimize/_slsqp_py.py +216 -124
- scipy/optimize/_slsqplib.cpython-313t-darwin.so +0 -0
- scipy/optimize/_spectral.py +1 -1
- scipy/optimize/_tnc.py +8 -1
- scipy/optimize/_trlib/_trlib.cpython-313t-darwin.so +0 -0
- scipy/optimize/_trustregion.py +20 -6
- scipy/optimize/_trustregion_constr/canonical_constraint.py +7 -7
- scipy/optimize/_trustregion_constr/equality_constrained_sqp.py +1 -1
- scipy/optimize/_trustregion_constr/minimize_trustregion_constr.py +11 -3
- scipy/optimize/_trustregion_constr/projections.py +12 -8
- scipy/optimize/_trustregion_constr/qp_subproblem.py +9 -9
- scipy/optimize/_trustregion_constr/tests/test_projections.py +7 -7
- scipy/optimize/_trustregion_constr/tests/test_qp_subproblem.py +77 -77
- scipy/optimize/_trustregion_constr/tr_interior_point.py +5 -5
- scipy/optimize/_trustregion_exact.py +0 -1
- scipy/optimize/_zeros.cpython-313t-darwin.so +0 -0
- scipy/optimize/_zeros_py.py +97 -17
- scipy/optimize/cython_optimize/_zeros.cpython-313t-darwin.so +0 -0
- scipy/optimize/slsqp.py +0 -1
- scipy/optimize/tests/test__basinhopping.py +1 -1
- scipy/optimize/tests/test__differential_evolution.py +4 -4
- scipy/optimize/tests/test__linprog_clean_inputs.py +5 -3
- scipy/optimize/tests/test__numdiff.py +66 -22
- scipy/optimize/tests/test__remove_redundancy.py +2 -2
- scipy/optimize/tests/test__shgo.py +9 -1
- scipy/optimize/tests/test_bracket.py +36 -46
- scipy/optimize/tests/test_chandrupatla.py +133 -135
- scipy/optimize/tests/test_cobyla.py +74 -45
- scipy/optimize/tests/test_constraints.py +1 -1
- scipy/optimize/tests/test_differentiable_functions.py +226 -6
- scipy/optimize/tests/test_lbfgsb_hessinv.py +22 -0
- scipy/optimize/tests/test_least_squares.py +125 -13
- scipy/optimize/tests/test_linear_assignment.py +3 -3
- scipy/optimize/tests/test_linprog.py +3 -3
- scipy/optimize/tests/test_lsq_linear.py +6 -6
- scipy/optimize/tests/test_minimize_constrained.py +2 -2
- scipy/optimize/tests/test_minpack.py +4 -4
- scipy/optimize/tests/test_nnls.py +43 -3
- scipy/optimize/tests/test_nonlin.py +36 -0
- scipy/optimize/tests/test_optimize.py +95 -17
- scipy/optimize/tests/test_slsqp.py +36 -4
- scipy/optimize/tests/test_zeros.py +34 -1
- scipy/signal/__init__.py +12 -23
- scipy/signal/_delegators.py +568 -0
- scipy/signal/_filter_design.py +459 -241
- scipy/signal/_fir_filter_design.py +262 -90
- scipy/signal/_lti_conversion.py +3 -2
- scipy/signal/_ltisys.py +118 -91
- scipy/signal/_max_len_seq_inner.cpython-313t-darwin.so +0 -0
- scipy/signal/_peak_finding_utils.cpython-313t-darwin.so +0 -0
- scipy/signal/_polyutils.py +172 -0
- scipy/signal/_short_time_fft.py +519 -70
- scipy/signal/_signal_api.py +30 -0
- scipy/signal/_signaltools.py +719 -399
- scipy/signal/_sigtools.cpython-313t-darwin.so +0 -0
- scipy/signal/_sosfilt.cpython-313t-darwin.so +0 -0
- scipy/signal/_spectral_py.py +230 -50
- scipy/signal/_spline.cpython-313t-darwin.so +0 -0
- scipy/signal/_spline_filters.py +108 -68
- scipy/signal/_support_alternative_backends.py +73 -0
- scipy/signal/_upfirdn.py +4 -1
- scipy/signal/_upfirdn_apply.cpython-313t-darwin.so +0 -0
- scipy/signal/_waveforms.py +2 -11
- scipy/signal/_wavelets.py +1 -1
- scipy/signal/fir_filter_design.py +1 -0
- scipy/signal/spline.py +4 -11
- scipy/signal/tests/_scipy_spectral_test_shim.py +2 -171
- scipy/signal/tests/test_bsplines.py +114 -79
- scipy/signal/tests/test_cont2discrete.py +9 -2
- scipy/signal/tests/test_filter_design.py +721 -481
- scipy/signal/tests/test_fir_filter_design.py +332 -140
- scipy/signal/tests/test_savitzky_golay.py +4 -3
- scipy/signal/tests/test_short_time_fft.py +221 -3
- scipy/signal/tests/test_signaltools.py +2144 -1348
- scipy/signal/tests/test_spectral.py +50 -6
- scipy/signal/tests/test_splines.py +161 -96
- scipy/signal/tests/test_upfirdn.py +84 -50
- scipy/signal/tests/test_waveforms.py +20 -0
- scipy/signal/tests/test_windows.py +607 -466
- scipy/signal/windows/_windows.py +287 -148
- scipy/sparse/__init__.py +23 -4
- scipy/sparse/_base.py +270 -108
- scipy/sparse/_bsr.py +7 -4
- scipy/sparse/_compressed.py +59 -231
- scipy/sparse/_construct.py +90 -38
- scipy/sparse/_coo.py +115 -181
- scipy/sparse/_csc.py +4 -4
- scipy/sparse/_csparsetools.cpython-313t-darwin.so +0 -0
- scipy/sparse/_csr.py +2 -2
- scipy/sparse/_data.py +48 -48
- scipy/sparse/_dia.py +105 -18
- scipy/sparse/_dok.py +0 -23
- scipy/sparse/_index.py +4 -4
- scipy/sparse/_matrix.py +23 -0
- scipy/sparse/_sparsetools.cpython-313t-darwin.so +0 -0
- scipy/sparse/_sputils.py +37 -22
- scipy/sparse/base.py +0 -9
- scipy/sparse/bsr.py +0 -14
- scipy/sparse/compressed.py +0 -23
- scipy/sparse/construct.py +0 -6
- scipy/sparse/coo.py +0 -14
- scipy/sparse/csc.py +0 -3
- scipy/sparse/csgraph/_flow.cpython-313t-darwin.so +0 -0
- scipy/sparse/csgraph/_matching.cpython-313t-darwin.so +0 -0
- scipy/sparse/csgraph/_min_spanning_tree.cpython-313t-darwin.so +0 -0
- scipy/sparse/csgraph/_reordering.cpython-313t-darwin.so +0 -0
- scipy/sparse/csgraph/_shortest_path.cpython-313t-darwin.so +0 -0
- scipy/sparse/csgraph/_tools.cpython-313t-darwin.so +0 -0
- scipy/sparse/csgraph/_traversal.cpython-313t-darwin.so +0 -0
- scipy/sparse/csgraph/tests/test_matching.py +14 -2
- scipy/sparse/csgraph/tests/test_pydata_sparse.py +4 -1
- scipy/sparse/csgraph/tests/test_shortest_path.py +83 -27
- scipy/sparse/csr.py +0 -5
- scipy/sparse/data.py +1 -6
- scipy/sparse/dia.py +0 -7
- scipy/sparse/dok.py +0 -10
- scipy/sparse/linalg/_dsolve/_superlu.cpython-313t-darwin.so +0 -0
- scipy/sparse/linalg/_dsolve/linsolve.py +9 -0
- scipy/sparse/linalg/_dsolve/tests/test_linsolve.py +35 -28
- scipy/sparse/linalg/_eigen/arpack/_arpack.cpython-313t-darwin.so +0 -0
- scipy/sparse/linalg/_eigen/arpack/arpack.py +23 -17
- scipy/sparse/linalg/_eigen/lobpcg/lobpcg.py +6 -6
- scipy/sparse/linalg/_interface.py +17 -18
- scipy/sparse/linalg/_isolve/_gcrotmk.py +4 -4
- scipy/sparse/linalg/_isolve/iterative.py +51 -45
- scipy/sparse/linalg/_isolve/lgmres.py +6 -6
- scipy/sparse/linalg/_isolve/minres.py +5 -5
- scipy/sparse/linalg/_isolve/tfqmr.py +7 -7
- scipy/sparse/linalg/_isolve/utils.py +2 -8
- scipy/sparse/linalg/_matfuncs.py +1 -1
- scipy/sparse/linalg/_norm.py +1 -1
- scipy/sparse/linalg/_propack/_cpropack.cpython-313t-darwin.so +0 -0
- scipy/sparse/linalg/_propack/_dpropack.cpython-313t-darwin.so +0 -0
- scipy/sparse/linalg/_propack/_spropack.cpython-313t-darwin.so +0 -0
- scipy/sparse/linalg/_propack/_zpropack.cpython-313t-darwin.so +0 -0
- scipy/sparse/linalg/_special_sparse_arrays.py +39 -38
- scipy/sparse/linalg/tests/test_pydata_sparse.py +14 -0
- scipy/sparse/tests/test_arithmetic1d.py +5 -2
- scipy/sparse/tests/test_base.py +214 -42
- scipy/sparse/tests/test_common1d.py +7 -7
- scipy/sparse/tests/test_construct.py +1 -1
- scipy/sparse/tests/test_coo.py +272 -4
- scipy/sparse/tests/test_sparsetools.py +5 -0
- scipy/sparse/tests/test_sputils.py +36 -7
- scipy/spatial/_ckdtree.cpython-313t-darwin.so +0 -0
- scipy/spatial/_distance_pybind.cpython-313t-darwin.so +0 -0
- scipy/spatial/_distance_wrap.cpython-313t-darwin.so +0 -0
- scipy/spatial/_hausdorff.cpython-313t-darwin.so +0 -0
- scipy/spatial/_qhull.cpython-313t-darwin.so +0 -0
- scipy/spatial/_voronoi.cpython-313t-darwin.so +0 -0
- scipy/spatial/distance.py +49 -42
- scipy/spatial/tests/test_distance.py +15 -1
- scipy/spatial/tests/test_kdtree.py +1 -0
- scipy/spatial/tests/test_qhull.py +7 -2
- scipy/spatial/transform/__init__.py +5 -3
- scipy/spatial/transform/_rigid_transform.cpython-313t-darwin.so +0 -0
- scipy/spatial/transform/_rotation.cpython-313t-darwin.so +0 -0
- scipy/spatial/transform/tests/test_rigid_transform.py +1221 -0
- scipy/spatial/transform/tests/test_rotation.py +1213 -832
- scipy/spatial/transform/tests/test_rotation_groups.py +3 -3
- scipy/spatial/transform/tests/test_rotation_spline.py +29 -8
- scipy/special/__init__.py +1 -47
- scipy/special/_add_newdocs.py +34 -772
- scipy/special/_basic.py +22 -25
- scipy/special/_comb.cpython-313t-darwin.so +0 -0
- scipy/special/_ellip_harm_2.cpython-313t-darwin.so +0 -0
- scipy/special/_gufuncs.cpython-313t-darwin.so +0 -0
- scipy/special/_logsumexp.py +67 -58
- scipy/special/_orthogonal.pyi +1 -1
- scipy/special/_specfun.cpython-313t-darwin.so +0 -0
- scipy/special/_special_ufuncs.cpython-313t-darwin.so +0 -0
- scipy/special/_spherical_bessel.py +4 -4
- scipy/special/_support_alternative_backends.py +212 -119
- scipy/special/_test_internal.cpython-313t-darwin.so +0 -0
- scipy/special/_testutils.py +4 -4
- scipy/special/_ufuncs.cpython-313t-darwin.so +0 -0
- scipy/special/_ufuncs.pyi +1 -0
- scipy/special/_ufuncs.pyx +215 -1400
- scipy/special/_ufuncs_cxx.cpython-313t-darwin.so +0 -0
- scipy/special/_ufuncs_cxx.pxd +2 -15
- scipy/special/_ufuncs_cxx.pyx +5 -44
- scipy/special/_ufuncs_cxx_defs.h +2 -16
- scipy/special/_ufuncs_defs.h +0 -8
- scipy/special/cython_special.cpython-313t-darwin.so +0 -0
- scipy/special/cython_special.pxd +1 -1
- scipy/special/tests/_cython_examples/meson.build +10 -1
- scipy/special/tests/test_basic.py +153 -20
- scipy/special/tests/test_boost_ufuncs.py +3 -0
- scipy/special/tests/test_cdflib.py +35 -11
- scipy/special/tests/test_gammainc.py +16 -0
- scipy/special/tests/test_hyp2f1.py +2 -2
- scipy/special/tests/test_log1mexp.py +85 -0
- scipy/special/tests/test_logsumexp.py +206 -64
- scipy/special/tests/test_mpmath.py +1 -0
- scipy/special/tests/test_nan_inputs.py +1 -1
- scipy/special/tests/test_orthogonal.py +17 -18
- scipy/special/tests/test_sf_error.py +3 -2
- scipy/special/tests/test_sph_harm.py +6 -7
- scipy/special/tests/test_support_alternative_backends.py +211 -76
- scipy/stats/__init__.py +4 -1
- scipy/stats/_ansari_swilk_statistics.cpython-313t-darwin.so +0 -0
- scipy/stats/_axis_nan_policy.py +5 -12
- scipy/stats/_biasedurn.cpython-313t-darwin.so +0 -0
- scipy/stats/_continued_fraction.py +387 -0
- scipy/stats/_continuous_distns.py +277 -310
- scipy/stats/_correlation.py +1 -1
- scipy/stats/_covariance.py +6 -3
- scipy/stats/_discrete_distns.py +39 -32
- scipy/stats/_distn_infrastructure.py +39 -12
- scipy/stats/_distribution_infrastructure.py +900 -238
- scipy/stats/_entropy.py +9 -10
- scipy/{_lib → stats}/_finite_differences.py +1 -1
- scipy/stats/_hypotests.py +83 -50
- scipy/stats/_kde.py +53 -49
- scipy/stats/_ksstats.py +1 -1
- scipy/stats/_levy_stable/__init__.py +7 -15
- scipy/stats/_levy_stable/levyst.cpython-313t-darwin.so +0 -0
- scipy/stats/_morestats.py +118 -73
- scipy/stats/_mstats_basic.py +13 -17
- scipy/stats/_mstats_extras.py +8 -8
- scipy/stats/_multivariate.py +89 -113
- scipy/stats/_new_distributions.py +97 -20
- scipy/stats/_page_trend_test.py +12 -5
- scipy/stats/_probability_distribution.py +265 -43
- scipy/stats/_qmc.py +14 -9
- scipy/stats/_qmc_cy.cpython-313t-darwin.so +0 -0
- scipy/stats/_qmvnt.py +16 -95
- scipy/stats/_qmvnt_cy.cpython-313t-darwin.so +0 -0
- scipy/stats/_quantile.py +335 -0
- scipy/stats/_rcont/rcont.cpython-313t-darwin.so +0 -0
- scipy/stats/_resampling.py +4 -29
- scipy/stats/_sampling.py +1 -1
- scipy/stats/_sobol.cpython-313t-darwin.so +0 -0
- scipy/stats/_stats.cpython-313t-darwin.so +0 -0
- scipy/stats/_stats_mstats_common.py +21 -2
- scipy/stats/_stats_py.py +550 -476
- scipy/stats/_stats_pythran.cpython-313t-darwin.so +0 -0
- scipy/stats/_unuran/unuran_wrapper.cpython-313t-darwin.so +0 -0
- scipy/stats/_unuran/unuran_wrapper.pyi +2 -1
- scipy/stats/_variation.py +6 -8
- scipy/stats/_wilcoxon.py +13 -7
- scipy/stats/tests/common_tests.py +6 -4
- scipy/stats/tests/test_axis_nan_policy.py +62 -24
- scipy/stats/tests/test_continued_fraction.py +173 -0
- scipy/stats/tests/test_continuous.py +379 -60
- scipy/stats/tests/test_continuous_basic.py +18 -12
- scipy/stats/tests/test_discrete_basic.py +14 -8
- scipy/stats/tests/test_discrete_distns.py +16 -16
- scipy/stats/tests/test_distributions.py +95 -75
- scipy/stats/tests/test_entropy.py +40 -48
- scipy/stats/tests/test_fit.py +4 -3
- scipy/stats/tests/test_hypotests.py +153 -24
- scipy/stats/tests/test_kdeoth.py +109 -41
- scipy/stats/tests/test_marray.py +289 -0
- scipy/stats/tests/test_morestats.py +79 -47
- scipy/stats/tests/test_mstats_basic.py +3 -3
- scipy/stats/tests/test_multivariate.py +434 -83
- scipy/stats/tests/test_qmc.py +13 -10
- scipy/stats/tests/test_quantile.py +199 -0
- scipy/stats/tests/test_rank.py +119 -112
- scipy/stats/tests/test_resampling.py +47 -56
- scipy/stats/tests/test_sampling.py +9 -4
- scipy/stats/tests/test_stats.py +799 -939
- scipy/stats/tests/test_variation.py +8 -6
- scipy/version.py +2 -2
- {scipy-1.15.3.dist-info → scipy-1.16.0rc2.dist-info}/LICENSE.txt +4 -4
- {scipy-1.15.3.dist-info → scipy-1.16.0rc2.dist-info}/METADATA +11 -11
- {scipy-1.15.3.dist-info → scipy-1.16.0rc2.dist-info}/RECORD +559 -566
- scipy-1.16.0rc2.dist-info/WHEEL +6 -0
- scipy/_lib/array_api_extra/_funcs.py +0 -484
- scipy/_lib/array_api_extra/_typing.py +0 -8
- scipy/interpolate/_bspl.cpython-313t-darwin.so +0 -0
- scipy/optimize/_cobyla.cpython-313t-darwin.so +0 -0
- scipy/optimize/_cython_nnls.cpython-313t-darwin.so +0 -0
- scipy/optimize/_slsqp.cpython-313t-darwin.so +0 -0
- scipy/spatial/qhull_src/COPYING.txt +0 -38
- scipy/special/libsf_error_state.dylib +0 -0
- scipy/special/tests/test_log_softmax.py +0 -109
- scipy/special/tests/test_xsf_cuda.py +0 -114
- scipy/special/xsf/binom.h +0 -89
- scipy/special/xsf/cdflib.h +0 -100
- scipy/special/xsf/cephes/airy.h +0 -307
- scipy/special/xsf/cephes/besselpoly.h +0 -51
- scipy/special/xsf/cephes/beta.h +0 -257
- scipy/special/xsf/cephes/cbrt.h +0 -131
- scipy/special/xsf/cephes/chbevl.h +0 -85
- scipy/special/xsf/cephes/chdtr.h +0 -193
- scipy/special/xsf/cephes/const.h +0 -87
- scipy/special/xsf/cephes/ellie.h +0 -293
- scipy/special/xsf/cephes/ellik.h +0 -251
- scipy/special/xsf/cephes/ellpe.h +0 -107
- scipy/special/xsf/cephes/ellpk.h +0 -117
- scipy/special/xsf/cephes/expn.h +0 -260
- scipy/special/xsf/cephes/gamma.h +0 -398
- scipy/special/xsf/cephes/hyp2f1.h +0 -596
- scipy/special/xsf/cephes/hyperg.h +0 -361
- scipy/special/xsf/cephes/i0.h +0 -149
- scipy/special/xsf/cephes/i1.h +0 -158
- scipy/special/xsf/cephes/igam.h +0 -421
- scipy/special/xsf/cephes/igam_asymp_coeff.h +0 -195
- scipy/special/xsf/cephes/igami.h +0 -313
- scipy/special/xsf/cephes/j0.h +0 -225
- scipy/special/xsf/cephes/j1.h +0 -198
- scipy/special/xsf/cephes/jv.h +0 -715
- scipy/special/xsf/cephes/k0.h +0 -164
- scipy/special/xsf/cephes/k1.h +0 -163
- scipy/special/xsf/cephes/kn.h +0 -243
- scipy/special/xsf/cephes/lanczos.h +0 -112
- scipy/special/xsf/cephes/ndtr.h +0 -275
- scipy/special/xsf/cephes/poch.h +0 -85
- scipy/special/xsf/cephes/polevl.h +0 -167
- scipy/special/xsf/cephes/psi.h +0 -194
- scipy/special/xsf/cephes/rgamma.h +0 -111
- scipy/special/xsf/cephes/scipy_iv.h +0 -811
- scipy/special/xsf/cephes/shichi.h +0 -248
- scipy/special/xsf/cephes/sici.h +0 -224
- scipy/special/xsf/cephes/sindg.h +0 -221
- scipy/special/xsf/cephes/tandg.h +0 -139
- scipy/special/xsf/cephes/trig.h +0 -58
- scipy/special/xsf/cephes/unity.h +0 -186
- scipy/special/xsf/cephes/zeta.h +0 -172
- scipy/special/xsf/config.h +0 -304
- scipy/special/xsf/digamma.h +0 -205
- scipy/special/xsf/error.h +0 -57
- scipy/special/xsf/evalpoly.h +0 -47
- scipy/special/xsf/expint.h +0 -266
- scipy/special/xsf/hyp2f1.h +0 -694
- scipy/special/xsf/iv_ratio.h +0 -173
- scipy/special/xsf/lambertw.h +0 -150
- scipy/special/xsf/loggamma.h +0 -163
- scipy/special/xsf/sici.h +0 -200
- scipy/special/xsf/tools.h +0 -427
- scipy/special/xsf/trig.h +0 -164
- scipy/special/xsf/wright_bessel.h +0 -843
- scipy/special/xsf/zlog1.h +0 -35
- scipy/stats/_mvn.cpython-313t-darwin.so +0 -0
- scipy-1.15.3.dist-info/WHEEL +0 -4
scipy/optimize/_minimize.py
CHANGED
@@ -10,6 +10,7 @@ Functions
|
|
10
10
|
__all__ = ['minimize', 'minimize_scalar']
|
11
11
|
|
12
12
|
|
13
|
+
import inspect
|
13
14
|
from warnings import warn
|
14
15
|
|
15
16
|
import numpy as np
|
@@ -46,7 +47,7 @@ MINIMIZE_METHODS = ['nelder-mead', 'powell', 'cg', 'bfgs', 'newton-cg',
|
|
46
47
|
# These methods support the new callback interface (passed an OptimizeResult)
|
47
48
|
MINIMIZE_METHODS_NEW_CB = ['nelder-mead', 'powell', 'cg', 'bfgs', 'newton-cg',
|
48
49
|
'l-bfgs-b', 'trust-constr', 'dogleg', 'trust-ncg',
|
49
|
-
'trust-exact', 'trust-krylov', 'cobyqa']
|
50
|
+
'trust-exact', 'trust-krylov', 'cobyqa', 'cobyla']
|
50
51
|
|
51
52
|
MINIMIZE_SCALAR_METHODS = ['brent', 'bounded', 'golden']
|
52
53
|
|
@@ -166,8 +167,8 @@ def minimize(fun, x0, args=(), method=None, jac=None, hess=None,
|
|
166
167
|
constraints : {Constraint, dict} or List of {Constraint, dict}, optional
|
167
168
|
Constraints definition. Only for COBYLA, COBYQA, SLSQP and trust-constr.
|
168
169
|
|
169
|
-
Constraints for 'trust-constr' and '
|
170
|
-
or a list of objects specifying constraints to the optimization problem.
|
170
|
+
Constraints for 'trust-constr', 'cobyqa', and 'cobyla' are defined as a single
|
171
|
+
object or a list of objects specifying constraints to the optimization problem.
|
171
172
|
Available constraints are:
|
172
173
|
|
173
174
|
- `LinearConstraint`
|
@@ -210,17 +211,17 @@ def minimize(fun, x0, args=(), method=None, jac=None, hess=None,
|
|
210
211
|
callback : callable, optional
|
211
212
|
A callable called after each iteration.
|
212
213
|
|
213
|
-
All methods except TNC
|
214
|
+
All methods except TNC and SLSQP support a callable with
|
214
215
|
the signature::
|
215
216
|
|
216
217
|
callback(intermediate_result: OptimizeResult)
|
217
218
|
|
218
219
|
where ``intermediate_result`` is a keyword parameter containing an
|
219
220
|
`OptimizeResult` with attributes ``x`` and ``fun``, the present values
|
220
|
-
of the parameter vector and objective function.
|
221
|
-
of the parameter must be
|
222
|
-
to be passed an `OptimizeResult`.
|
223
|
-
the callback raises ``StopIteration``.
|
221
|
+
of the parameter vector and objective function. Not all attributes of
|
222
|
+
`OptimizeResult` may be present. The name of the parameter must be
|
223
|
+
``intermediate_result`` for the callback to be passed an `OptimizeResult`.
|
224
|
+
These methods will also terminate if the callback raises ``StopIteration``.
|
224
225
|
|
225
226
|
All methods except trust-constr (also) support a signature like::
|
226
227
|
|
@@ -338,13 +339,11 @@ def minimize(fun, x0, args=(), method=None, jac=None, hess=None,
|
|
338
339
|
|
339
340
|
**Constrained Minimization**
|
340
341
|
|
341
|
-
Method :ref:`COBYLA <optimize.minimize-cobyla>` uses the
|
342
|
+
Method :ref:`COBYLA <optimize.minimize-cobyla>` uses the PRIMA
|
343
|
+
implementation [19]_ of the
|
342
344
|
Constrained Optimization BY Linear Approximation (COBYLA) method
|
343
345
|
[9]_, [10]_, [11]_. The algorithm is based on linear
|
344
|
-
approximations to the objective function and each constraint.
|
345
|
-
method wraps a FORTRAN implementation of the algorithm. The
|
346
|
-
constraints functions 'fun' may return either a single number
|
347
|
-
or an array or list of numbers.
|
346
|
+
approximations to the objective function and each constraint.
|
348
347
|
|
349
348
|
Method :ref:`COBYQA <optimize.minimize-cobyqa>` uses the Constrained
|
350
349
|
Optimization BY Quadratic Approximations (COBYQA) method [18]_. The
|
@@ -488,6 +487,11 @@ def minimize(fun, x0, args=(), method=None, jac=None, hess=None,
|
|
488
487
|
and Software*. PhD thesis, Department of Applied Mathematics, The Hong
|
489
488
|
Kong Polytechnic University, Hong Kong, China, 2022. URL:
|
490
489
|
https://theses.lib.polyu.edu.hk/handle/200/12294.
|
490
|
+
.. [19] Zhang, Z. "PRIMA: Reference Implementation for Powell's Methods with
|
491
|
+
Modernization and Amelioration", https://www.libprima.net,
|
492
|
+
:doi:`10.5281/zenodo.8052654`
|
493
|
+
.. [20] Karush-Kuhn-Tucker conditions,
|
494
|
+
https://en.wikipedia.org/wiki/Karush%E2%80%93Kuhn%E2%80%93Tucker_conditions
|
491
495
|
|
492
496
|
Examples
|
493
497
|
--------
|
@@ -527,7 +531,6 @@ def minimize(fun, x0, args=(), method=None, jac=None, hess=None,
|
|
527
531
|
[ 0.09495377, 0.18996269, 0.38165151, 0.7664427, 1.53713523]
|
528
532
|
])
|
529
533
|
|
530
|
-
|
531
534
|
Next, consider a minimization problem with several constraints (namely
|
532
535
|
Example 16.4 from [5]_). The objective function is:
|
533
536
|
|
@@ -545,10 +548,42 @@ def minimize(fun, x0, args=(), method=None, jac=None, hess=None,
|
|
545
548
|
|
546
549
|
The optimization problem is solved using the SLSQP method as:
|
547
550
|
|
548
|
-
>>> res = minimize(fun, (2, 0), method='SLSQP', bounds=bnds,
|
549
|
-
|
551
|
+
>>> res = minimize(fun, (2, 0), method='SLSQP', bounds=bnds, constraints=cons)
|
552
|
+
|
553
|
+
It should converge to the theoretical solution ``[1.4 ,1.7]``. *SLSQP* also
|
554
|
+
returns the multipliers that are used in the solution of the problem. These
|
555
|
+
multipliers, when the problem constraints are linear, can be thought of as the
|
556
|
+
Karush-Kuhn-Tucker (KKT) multipliers, which are a generalization
|
557
|
+
of Lagrange multipliers to inequality-constrained optimization problems ([20]_).
|
558
|
+
|
559
|
+
Notice that at the solution, the first constraint is active. Let's evaluate the
|
560
|
+
function at solution:
|
561
|
+
|
562
|
+
>>> cons[0]['fun'](res.x)
|
563
|
+
np.float64(1.4901224698604665e-09)
|
564
|
+
|
565
|
+
Also, notice that at optimality there is a non-zero multiplier:
|
566
|
+
|
567
|
+
>>> res.multipliers
|
568
|
+
array([0.8, 0. , 0. ])
|
569
|
+
|
570
|
+
This can be understood as the local sensitivity of the optimal value of the
|
571
|
+
objective function with respect to changes in the first constraint. If we
|
572
|
+
tighten the constraint by a small amount ``eps``:
|
550
573
|
|
551
|
-
|
574
|
+
>>> eps = 0.01
|
575
|
+
>>> cons[0]['fun'] = lambda x: x[0] - 2 * x[1] + 2 - eps
|
576
|
+
|
577
|
+
we expect the optimal value of the objective function to increase by
|
578
|
+
approximately ``eps * res.multipliers[0]``:
|
579
|
+
|
580
|
+
>>> eps * res.multipliers[0] # Expected change in f0
|
581
|
+
np.float64(0.008000000027153205)
|
582
|
+
>>> f0 = res.fun # Keep track of the previous optimal value
|
583
|
+
>>> res = minimize(fun, (2, 0), method='SLSQP', bounds=bnds, constraints=cons)
|
584
|
+
>>> f1 = res.fun # New optimal value
|
585
|
+
>>> f1 - f0
|
586
|
+
np.float64(0.008019998807885509)
|
552
587
|
|
553
588
|
"""
|
554
589
|
x0 = np.atleast_1d(np.asarray(x0))
|
@@ -701,25 +736,37 @@ def minimize(fun, x0, args=(), method=None, jac=None, hess=None,
|
|
701
736
|
x_fixed = (bounds.lb)[i_fixed]
|
702
737
|
x0 = x0[~i_fixed]
|
703
738
|
bounds = _remove_from_bounds(bounds, i_fixed)
|
704
|
-
fun =
|
739
|
+
fun = _Remove_From_Func(fun, i_fixed, x_fixed)
|
740
|
+
|
705
741
|
if callable(callback):
|
706
|
-
|
742
|
+
sig = inspect.signature(callback)
|
743
|
+
if set(sig.parameters) == {'intermediate_result'}:
|
744
|
+
# callback(intermediate_result)
|
745
|
+
print(callback)
|
746
|
+
callback = _Patch_Callback_Equal_Variables(
|
747
|
+
callback, i_fixed, x_fixed
|
748
|
+
)
|
749
|
+
else:
|
750
|
+
# callback(x)
|
751
|
+
callback = _Remove_From_Func(callback, i_fixed, x_fixed)
|
752
|
+
|
707
753
|
if callable(jac):
|
708
|
-
jac =
|
754
|
+
jac = _Remove_From_Func(jac, i_fixed, x_fixed, remove=1)
|
709
755
|
|
710
756
|
# make a copy of the constraints so the user's version doesn't
|
711
757
|
# get changed. (Shallow copy is ok)
|
712
758
|
constraints = [con.copy() for con in constraints]
|
713
759
|
for con in constraints: # yes, guaranteed to be a list
|
714
|
-
con['fun'] =
|
760
|
+
con['fun'] = _Remove_From_Func(con['fun'], i_fixed,
|
715
761
|
x_fixed, min_dim=1,
|
716
762
|
remove=0)
|
717
763
|
if callable(con.get('jac', None)):
|
718
|
-
con['jac'] =
|
764
|
+
con['jac'] = _Remove_From_Func(con['jac'], i_fixed,
|
719
765
|
x_fixed, min_dim=2,
|
720
766
|
remove=1)
|
721
767
|
bounds = standardize_bounds(bounds, x0, meth)
|
722
768
|
|
769
|
+
# selects whether to use callback(x) or callback(intermediate_result)
|
723
770
|
callback = _wrap_callback(callback, meth)
|
724
771
|
|
725
772
|
if meth == 'nelder-mead':
|
@@ -1000,27 +1047,49 @@ def _remove_from_bounds(bounds, i_fixed):
|
|
1000
1047
|
return Bounds(lb, ub) # don't mutate original Bounds object
|
1001
1048
|
|
1002
1049
|
|
1003
|
-
|
1050
|
+
class _Patch_Callback_Equal_Variables:
|
1051
|
+
# Patches a callback that accepts an intermediate_result
|
1052
|
+
def __init__(self, callback, i_fixed, x_fixed):
|
1053
|
+
self.callback = callback
|
1054
|
+
self.i_fixed = i_fixed
|
1055
|
+
self.x_fixed = x_fixed
|
1056
|
+
|
1057
|
+
def __call__(self, intermediate_result):
|
1058
|
+
x_in = intermediate_result.x
|
1059
|
+
x_out = np.zeros_like(self.i_fixed, dtype=x_in.dtype)
|
1060
|
+
x_out[self.i_fixed] = self.x_fixed
|
1061
|
+
x_out[~self.i_fixed] = x_in
|
1062
|
+
intermediate_result.x = x_out
|
1063
|
+
return self.callback(intermediate_result)
|
1064
|
+
|
1065
|
+
|
1066
|
+
class _Remove_From_Func:
|
1004
1067
|
"""Wraps a function such that fixed variables need not be passed in"""
|
1005
|
-
def
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1068
|
+
def __init__(self, fun_in, i_fixed, x_fixed, min_dim=None, remove=0):
|
1069
|
+
self.fun_in = fun_in
|
1070
|
+
self.i_fixed = i_fixed
|
1071
|
+
self.x_fixed = x_fixed
|
1072
|
+
self.min_dim = min_dim
|
1073
|
+
self.remove = remove
|
1074
|
+
|
1075
|
+
def __call__(self, x_in, *args, **kwargs):
|
1076
|
+
x_out = np.zeros_like(self.i_fixed, dtype=x_in.dtype)
|
1077
|
+
x_out[self.i_fixed] = self.x_fixed
|
1078
|
+
x_out[~self.i_fixed] = x_in
|
1079
|
+
y_out = self.fun_in(x_out, *args, **kwargs)
|
1010
1080
|
y_out = np.array(y_out)
|
1011
1081
|
|
1012
|
-
if min_dim == 1:
|
1082
|
+
if self.min_dim == 1:
|
1013
1083
|
y_out = np.atleast_1d(y_out)
|
1014
|
-
elif min_dim == 2:
|
1084
|
+
elif self.min_dim == 2:
|
1015
1085
|
y_out = np.atleast_2d(y_out)
|
1016
1086
|
|
1017
|
-
if remove == 1:
|
1018
|
-
y_out = y_out[..., ~i_fixed]
|
1019
|
-
elif remove == 2:
|
1020
|
-
y_out = y_out[~i_fixed, ~i_fixed]
|
1087
|
+
if self.remove == 1:
|
1088
|
+
y_out = y_out[..., ~self.i_fixed]
|
1089
|
+
elif self.remove == 2:
|
1090
|
+
y_out = y_out[~self.i_fixed, ~self.i_fixed]
|
1021
1091
|
|
1022
1092
|
return y_out
|
1023
|
-
return fun_out
|
1024
1093
|
|
1025
1094
|
|
1026
1095
|
def _add_to_array(x_in, i_fixed, x_fixed):
|
@@ -1074,7 +1143,7 @@ def standardize_constraints(constraints, x0, meth):
|
|
1074
1143
|
else:
|
1075
1144
|
constraints = list(constraints) # ensure it's a mutable sequence
|
1076
1145
|
|
1077
|
-
if meth in ['trust-constr', 'cobyqa', 'new']:
|
1146
|
+
if meth in ['trust-constr', 'cobyqa', 'new', 'cobyla']:
|
1078
1147
|
for i, con in enumerate(constraints):
|
1079
1148
|
if not isinstance(con, new_constraint_types):
|
1080
1149
|
constraints[i] = old_constraint_to_new(i, con)
|
Binary file
|
scipy/optimize/_minpack_py.py
CHANGED
@@ -7,8 +7,9 @@ from numpy import (atleast_1d, triu, shape, transpose, zeros, prod, greater,
|
|
7
7
|
finfo, inexact, issubdtype, dtype)
|
8
8
|
from scipy import linalg
|
9
9
|
from scipy.linalg import svd, cholesky, solve_triangular, LinAlgError
|
10
|
-
from scipy._lib._util import _asarray_validated,
|
10
|
+
from scipy._lib._util import _asarray_validated, _contains_nan
|
11
11
|
from scipy._lib._util import getfullargspec_no_self as _getfullargspec
|
12
|
+
import scipy._lib.array_api_extra as xpx
|
12
13
|
from ._optimize import OptimizeResult, _check_unknown_options, OptimizeWarning
|
13
14
|
from ._lsq import least_squares
|
14
15
|
# from ._lsq.common import make_strictly_feasible
|
@@ -260,7 +261,7 @@ def _root_hybr(func, x0, args=(), jac=None,
|
|
260
261
|
errors = {0: "Improper input parameters were entered.",
|
261
262
|
1: "The solution converged.",
|
262
263
|
2: "The number of calls to function has "
|
263
|
-
|
264
|
+
f"reached maxfev = {maxfev}.",
|
264
265
|
3: f"xtol={xtol:f} is too small, no further improvement "
|
265
266
|
"in the approximate\n solution is possible.",
|
266
267
|
4: "The iteration is not making good progress, as measured "
|
@@ -461,7 +462,7 @@ def leastsq(func, x0, args=(), Dfun=None, full_output=False,
|
|
461
462
|
f"column of the\n Jacobian is at most {gtol:f} in "
|
462
463
|
"absolute value", None],
|
463
464
|
5: ["Number of calls to function has reached "
|
464
|
-
"maxfev =
|
465
|
+
f"maxfev = {maxfev}.", ValueError],
|
465
466
|
6: [f"ftol={ftol:f} is too small, no further reduction "
|
466
467
|
"in the sum of squares\n is possible.",
|
467
468
|
ValueError],
|
@@ -799,6 +800,11 @@ def curve_fit(f, xdata, ydata, p0=None, sigma=None, absolute_sigma=False,
|
|
799
800
|
'dogbox' methods, the `x_scale` keyword argument can be used to scale
|
800
801
|
the parameters.
|
801
802
|
|
803
|
+
`curve_fit` is for local optimization of parameters to minimize the sum of squares
|
804
|
+
of residuals. For global optimization, other choices of objective function, and
|
805
|
+
other advanced features, consider using SciPy's :ref:`tutorial_optimize_global`
|
806
|
+
tools or the `LMFIT <https://lmfit.github.io/lmfit-py/index.html>`_ package.
|
807
|
+
|
802
808
|
References
|
803
809
|
----------
|
804
810
|
.. [1] K. Vugrin et al. Confidence region estimation techniques for nonlinear
|
@@ -931,7 +937,7 @@ def curve_fit(f, xdata, ydata, p0=None, sigma=None, absolute_sigma=False,
|
|
931
937
|
else:
|
932
938
|
ydata = np.asarray(ydata, float)
|
933
939
|
|
934
|
-
if isinstance(xdata,
|
940
|
+
if isinstance(xdata, list | tuple | np.ndarray):
|
935
941
|
# `xdata` is passed straight to the user-defined `f`, so allow
|
936
942
|
# non-array_like `xdata`.
|
937
943
|
if check_finite:
|
@@ -946,14 +952,15 @@ def curve_fit(f, xdata, ydata, p0=None, sigma=None, absolute_sigma=False,
|
|
946
952
|
# the x-y data are already checked, and they don't contain nans.
|
947
953
|
if not check_finite and nan_policy is not None:
|
948
954
|
if nan_policy == "propagate":
|
949
|
-
|
950
|
-
|
955
|
+
msg = "`nan_policy='propagate'` is not supported by this function."
|
956
|
+
raise ValueError(msg)
|
957
|
+
if nan_policy not in ("raise", "omit"):
|
958
|
+
# Override error message raised by _contains_nan
|
959
|
+
msg = "nan_policy must be one of {None, 'raise', 'omit'}"
|
960
|
+
raise ValueError(msg)
|
951
961
|
|
952
|
-
|
953
|
-
|
954
|
-
policies=policies)
|
955
|
-
y_contains_nan, nan_policy = _contains_nan(ydata, nan_policy,
|
956
|
-
policies=policies)
|
962
|
+
x_contains_nan = _contains_nan(xdata, nan_policy)
|
963
|
+
y_contains_nan = _contains_nan(ydata, nan_policy)
|
957
964
|
|
958
965
|
if (x_contains_nan or y_contains_nan) and nan_policy == 'omit':
|
959
966
|
# ignore NaNs for N dimensional arrays
|
@@ -1113,14 +1120,14 @@ def _fixed_point_helper(func, x0, args, xtol, maxiter, use_accel):
|
|
1113
1120
|
if use_accel:
|
1114
1121
|
p2 = func(p1, *args)
|
1115
1122
|
d = p2 - 2.0 * p1 + p0
|
1116
|
-
p =
|
1123
|
+
p = xpx.apply_where(d != 0, (p0, p1, d), _del2, fill_value=p2)
|
1117
1124
|
else:
|
1118
1125
|
p = p1
|
1119
|
-
relerr =
|
1126
|
+
relerr = xpx.apply_where(p0 != 0, (p, p0), _relerr, fill_value=p)
|
1120
1127
|
if np.all(np.abs(relerr) < xtol):
|
1121
1128
|
return p
|
1122
1129
|
p0 = p
|
1123
|
-
msg = "Failed to converge after
|
1130
|
+
msg = f"Failed to converge after {maxiter} iterations, value is {p}"
|
1124
1131
|
raise RuntimeError(msg)
|
1125
1132
|
|
1126
1133
|
|
Binary file
|
scipy/optimize/_nnls.py
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
import numpy as np
|
2
|
-
from .
|
2
|
+
from ._slsqplib import nnls as _nnls
|
3
|
+
from scipy._lib.deprecation import _deprecate_positional_args, _NoValue
|
3
4
|
|
4
5
|
|
5
6
|
__all__ = ['nnls']
|
6
7
|
|
7
8
|
|
8
|
-
|
9
|
+
@_deprecate_positional_args(version='1.18.0',
|
10
|
+
deprecated_args={'atol'})
|
11
|
+
def nnls(A, b, *, maxiter=None, atol=_NoValue):
|
9
12
|
"""
|
10
13
|
Solve ``argmin_x || Ax - b ||_2`` for ``x>=0``.
|
11
14
|
|
@@ -22,13 +25,10 @@ def nnls(A, b, maxiter=None, *, atol=None):
|
|
22
25
|
Right-hand side vector.
|
23
26
|
maxiter: int, optional
|
24
27
|
Maximum number of iterations, optional. Default value is ``3 * n``.
|
25
|
-
atol: float
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
be selected as ``max(m, n) * np.linalg.norm(a, 1) * np.spacing(1.)``.
|
30
|
-
This value is not set as default since the norm operation becomes
|
31
|
-
expensive for large problems hence can be used only when necessary.
|
28
|
+
atol : float, optional
|
29
|
+
.. deprecated:: 1.18.0
|
30
|
+
This parameter is deprecated and will be removed in SciPy 1.18.0.
|
31
|
+
It is not used in the implementation.
|
32
32
|
|
33
33
|
Returns
|
34
34
|
-------
|
@@ -43,17 +43,14 @@ def nnls(A, b, maxiter=None, *, atol=None):
|
|
43
43
|
|
44
44
|
Notes
|
45
45
|
-----
|
46
|
-
The code is based on [
|
47
|
-
|
48
|
-
|
46
|
+
The code is based on the classical algorithm of [1]_. It utilizes an active
|
47
|
+
set method and solves the KKK (Karush-Kuhn-Tucker) conditions for the
|
48
|
+
non-negative least squares problem.
|
49
49
|
|
50
50
|
References
|
51
51
|
----------
|
52
52
|
.. [1] : Lawson C., Hanson R.J., "Solving Least Squares Problems", SIAM,
|
53
53
|
1995, :doi:`10.1137/1.9781611971217`
|
54
|
-
.. [2] : Bro, Rasmus and de Jong, Sijmen, "A Fast Non-Negativity-
|
55
|
-
Constrained Least Squares Algorithm", Journal Of Chemometrics, 1997,
|
56
|
-
:doi:`10.1002/(SICI)1099-128X(199709/10)11:5<393::AID-CEM483>3.0.CO;2-L`
|
57
54
|
|
58
55
|
Examples
|
59
56
|
--------
|
@@ -75,11 +72,13 @@ def nnls(A, b, maxiter=None, *, atol=None):
|
|
75
72
|
b = np.asarray_chkfinite(b, dtype=np.float64)
|
76
73
|
|
77
74
|
if len(A.shape) != 2:
|
78
|
-
raise ValueError("Expected a
|
79
|
-
|
80
|
-
if
|
81
|
-
raise ValueError("Expected a
|
82
|
-
f"
|
75
|
+
raise ValueError(f"Expected a 2D array, but the shape of A is {A.shape}")
|
76
|
+
|
77
|
+
if (b.ndim > 2) or ((b.ndim == 2) and (b.shape[1] != 1)):
|
78
|
+
raise ValueError("Expected a 1D array,(or 2D with one column), but the,"
|
79
|
+
f" shape of b is {b.shape}")
|
80
|
+
elif (b.ndim == 2) and (b.shape[1] == 1):
|
81
|
+
b = b.ravel()
|
83
82
|
|
84
83
|
m, n = A.shape
|
85
84
|
|
@@ -91,7 +90,7 @@ def nnls(A, b, maxiter=None, *, atol=None):
|
|
91
90
|
if not maxiter:
|
92
91
|
maxiter = 3*n
|
93
92
|
x, rnorm, info = _nnls(A, b, maxiter)
|
94
|
-
if info ==
|
93
|
+
if info == 3:
|
95
94
|
raise RuntimeError("Maximum number of iterations reached.")
|
96
95
|
|
97
96
|
return x, rnorm
|
scipy/optimize/_nonlin.py
CHANGED
@@ -15,6 +15,8 @@ from scipy.linalg import get_blas_funcs
|
|
15
15
|
from scipy._lib._util import copy_if_needed
|
16
16
|
from scipy._lib._util import getfullargspec_no_self as _getfullargspec
|
17
17
|
from ._linesearch import scalar_search_wolfe1, scalar_search_armijo
|
18
|
+
from inspect import signature
|
19
|
+
from difflib import get_close_matches
|
18
20
|
|
19
21
|
|
20
22
|
__all__ = [
|
@@ -241,8 +243,7 @@ def nonlin_solve(F, x0, jacobian='krylov', iter=None, verbose=False,
|
|
241
243
|
|
242
244
|
# Print status
|
243
245
|
if verbose:
|
244
|
-
sys.stdout.write("
|
245
|
-
n, tol_norm(Fx), s))
|
246
|
+
sys.stdout.write(f"{n}: |F(x)| = {tol_norm(Fx):g}; step {s:g}\n")
|
246
247
|
sys.stdout.flush()
|
247
248
|
else:
|
248
249
|
if raise_exception:
|
@@ -1492,9 +1493,39 @@ class KrylovJacobian(Jacobian):
|
|
1492
1493
|
self.method_kw.setdefault('store_outer_Av', False)
|
1493
1494
|
self.method_kw.setdefault('atol', 0)
|
1494
1495
|
|
1496
|
+
# Retrieve the signature of the method to find the valid parameters
|
1497
|
+
valid_inner_params = [
|
1498
|
+
k for k in signature(self.method).parameters
|
1499
|
+
if k not in ('self', 'args', 'kwargs')
|
1500
|
+
]
|
1501
|
+
|
1495
1502
|
for key, value in kw.items():
|
1496
|
-
if not key.startswith(
|
1503
|
+
if not key.startswith("inner_"):
|
1497
1504
|
raise ValueError(f"Unknown parameter {key}")
|
1505
|
+
if key[6:] not in valid_inner_params:
|
1506
|
+
# Use difflib to find close matches to the invalid key
|
1507
|
+
inner_param_suggestions = get_close_matches(key[6:],
|
1508
|
+
valid_inner_params,
|
1509
|
+
n=1)
|
1510
|
+
if inner_param_suggestions:
|
1511
|
+
suggestion_msg = (f" Did you mean '"
|
1512
|
+
f"{inner_param_suggestions[0]}'?")
|
1513
|
+
else:
|
1514
|
+
suggestion_msg = ""
|
1515
|
+
|
1516
|
+
# warn user that the parameter is not valid for the inner method
|
1517
|
+
warnings.warn(
|
1518
|
+
f"Option '{key}' is invalid for the inner method: {method}."
|
1519
|
+
" It will be ignored."
|
1520
|
+
"Please check inner method documentation for valid options."
|
1521
|
+
+ suggestion_msg,
|
1522
|
+
stacklevel=3,
|
1523
|
+
category=UserWarning,
|
1524
|
+
# using `skip_file_prefixes` would be a good idea
|
1525
|
+
# and should be added once we drop support for Python 3.11
|
1526
|
+
)
|
1527
|
+
# ignore this parameter and continue
|
1528
|
+
continue
|
1498
1529
|
self.method_kw[key[6:]] = value
|
1499
1530
|
|
1500
1531
|
def _update_diff_step(self):
|