scipy 1.15.3__cp313-cp313-macosx_12_0_arm64.whl → 1.16.0rc2__cp313-cp313-macosx_12_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/.dylibs/libscipy_openblas.dylib +0 -0
- scipy/__config__.py +8 -8
- scipy/__init__.py +3 -6
- scipy/_cyutility.cpython-313-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-313-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-313-darwin.so +0 -0
- scipy/_lib/_test_deprecation_def.cpython-313-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-313-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-313-darwin.so +0 -0
- scipy/cluster/_optimal_leaf_ordering.cpython-313-darwin.so +0 -0
- scipy/cluster/_vq.cpython-313-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-313-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-313-darwin.so +0 -0
- scipy/integrate/_lsoda.cpython-313-darwin.so +0 -0
- scipy/integrate/_ode.py +9 -2
- scipy/integrate/_odepack.cpython-313-darwin.so +0 -0
- scipy/integrate/_quad_vec.py +21 -29
- scipy/integrate/_quadpack.cpython-313-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-313-darwin.so +0 -0
- scipy/integrate/_vode.cpython-313-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-313-darwin.so +0 -0
- scipy/interpolate/_dierckx.cpython-313-darwin.so +0 -0
- scipy/interpolate/_fitpack.cpython-313-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-313-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-313-darwin.so +0 -0
- scipy/interpolate/_rbf.py +2 -2
- scipy/interpolate/_rbfinterp.py +1 -1
- scipy/interpolate/_rbfinterp_pythran.cpython-313-darwin.so +0 -0
- scipy/interpolate/_rgi.py +31 -26
- scipy/interpolate/_rgi_cython.cpython-313-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-313-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-313-darwin.so +0 -0
- scipy/io/matlab/_mio_utils.cpython-313-darwin.so +0 -0
- scipy/io/matlab/_miobase.py +4 -1
- scipy/io/matlab/_streams.cpython-313-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-313-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-313-darwin.so +0 -0
- scipy/linalg/_decomp_ldl.py +4 -1
- scipy/linalg/_decomp_lu.py +18 -6
- scipy/linalg/_decomp_lu_cython.cpython-313-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-313-darwin.so +0 -0
- scipy/linalg/_expm_frechet.py +4 -0
- scipy/linalg/_fblas.cpython-313-darwin.so +0 -0
- scipy/linalg/_flapack.cpython-313-darwin.so +0 -0
- scipy/linalg/_linalg_pythran.cpython-313-darwin.so +0 -0
- scipy/linalg/_matfuncs.py +187 -4
- scipy/linalg/_matfuncs_expm.cpython-313-darwin.so +0 -0
- scipy/linalg/_matfuncs_schur_sqrtm.cpython-313-darwin.so +0 -0
- scipy/linalg/_matfuncs_sqrtm.py +1 -99
- scipy/linalg/_matfuncs_sqrtm_triu.cpython-313-darwin.so +0 -0
- scipy/linalg/_procrustes.py +2 -0
- scipy/linalg/_sketches.py +17 -6
- scipy/linalg/_solve_toeplitz.cpython-313-darwin.so +0 -0
- scipy/linalg/_solvers.py +7 -2
- scipy/linalg/_special_matrices.py +26 -36
- scipy/linalg/cython_blas.cpython-313-darwin.so +0 -0
- scipy/linalg/cython_lapack.cpython-313-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-313-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-313-darwin.so +0 -0
- scipy/ndimage/_ni_docstrings.py +5 -1
- scipy/ndimage/_ni_label.cpython-313-darwin.so +0 -0
- scipy/ndimage/_ni_support.py +1 -5
- scipy/ndimage/_rank_filter_1d.cpython-313-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-313-darwin.so +0 -0
- scipy/optimize/_basinhopping.py +13 -7
- scipy/optimize/_bglu_dense.cpython-313-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-313-darwin.so +0 -0
- scipy/optimize/_dual_annealing.py +1 -1
- scipy/optimize/_elementwise.py +1 -4
- scipy/optimize/_group_columns.cpython-313-darwin.so +0 -0
- scipy/optimize/_lbfgsb.cpython-313-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-313-darwin.so +0 -0
- scipy/optimize/_lsq/common.py +3 -3
- scipy/optimize/_lsq/dogbox.py +16 -2
- scipy/optimize/_lsq/givens_elimination.cpython-313-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-313-darwin.so +0 -0
- scipy/optimize/_minpack_py.py +21 -14
- scipy/optimize/_moduleTNC.cpython-313-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-313-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-313-darwin.so +0 -0
- scipy/optimize/_spectral.py +1 -1
- scipy/optimize/_tnc.py +8 -1
- scipy/optimize/_trlib/_trlib.cpython-313-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-313-darwin.so +0 -0
- scipy/optimize/_zeros_py.py +97 -17
- scipy/optimize/cython_optimize/_zeros.cpython-313-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-313-darwin.so +0 -0
- scipy/signal/_peak_finding_utils.cpython-313-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-313-darwin.so +0 -0
- scipy/signal/_sosfilt.cpython-313-darwin.so +0 -0
- scipy/signal/_spectral_py.py +230 -50
- scipy/signal/_spline.cpython-313-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-313-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-313-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-313-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-313-darwin.so +0 -0
- scipy/sparse/csgraph/_matching.cpython-313-darwin.so +0 -0
- scipy/sparse/csgraph/_min_spanning_tree.cpython-313-darwin.so +0 -0
- scipy/sparse/csgraph/_reordering.cpython-313-darwin.so +0 -0
- scipy/sparse/csgraph/_shortest_path.cpython-313-darwin.so +0 -0
- scipy/sparse/csgraph/_tools.cpython-313-darwin.so +0 -0
- scipy/sparse/csgraph/_traversal.cpython-313-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-313-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-313-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-313-darwin.so +0 -0
- scipy/sparse/linalg/_propack/_dpropack.cpython-313-darwin.so +0 -0
- scipy/sparse/linalg/_propack/_spropack.cpython-313-darwin.so +0 -0
- scipy/sparse/linalg/_propack/_zpropack.cpython-313-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-313-darwin.so +0 -0
- scipy/spatial/_distance_pybind.cpython-313-darwin.so +0 -0
- scipy/spatial/_distance_wrap.cpython-313-darwin.so +0 -0
- scipy/spatial/_hausdorff.cpython-313-darwin.so +0 -0
- scipy/spatial/_qhull.cpython-313-darwin.so +0 -0
- scipy/spatial/_voronoi.cpython-313-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-313-darwin.so +0 -0
- scipy/spatial/transform/_rotation.cpython-313-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-313-darwin.so +0 -0
- scipy/special/_ellip_harm_2.cpython-313-darwin.so +0 -0
- scipy/special/_gufuncs.cpython-313-darwin.so +0 -0
- scipy/special/_logsumexp.py +67 -58
- scipy/special/_orthogonal.pyi +1 -1
- scipy/special/_specfun.cpython-313-darwin.so +0 -0
- scipy/special/_special_ufuncs.cpython-313-darwin.so +0 -0
- scipy/special/_spherical_bessel.py +4 -4
- scipy/special/_support_alternative_backends.py +212 -119
- scipy/special/_test_internal.cpython-313-darwin.so +0 -0
- scipy/special/_testutils.py +4 -4
- scipy/special/_ufuncs.cpython-313-darwin.so +0 -0
- scipy/special/_ufuncs.pyi +1 -0
- scipy/special/_ufuncs.pyx +215 -1400
- scipy/special/_ufuncs_cxx.cpython-313-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-313-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-313-darwin.so +0 -0
- scipy/stats/_axis_nan_policy.py +5 -12
- scipy/stats/_biasedurn.cpython-313-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-313-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-313-darwin.so +0 -0
- scipy/stats/_qmvnt.py +16 -95
- scipy/stats/_qmvnt_cy.cpython-313-darwin.so +0 -0
- scipy/stats/_quantile.py +335 -0
- scipy/stats/_rcont/rcont.cpython-313-darwin.so +0 -0
- scipy/stats/_resampling.py +4 -29
- scipy/stats/_sampling.py +1 -1
- scipy/stats/_sobol.cpython-313-darwin.so +0 -0
- scipy/stats/_stats.cpython-313-darwin.so +0 -0
- scipy/stats/_stats_mstats_common.py +21 -2
- scipy/stats/_stats_py.py +550 -476
- scipy/stats/_stats_pythran.cpython-313-darwin.so +0 -0
- scipy/stats/_unuran/unuran_wrapper.cpython-313-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 +561 -568
- 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-313-darwin.so +0 -0
- scipy/optimize/_cobyla.cpython-313-darwin.so +0 -0
- scipy/optimize/_cython_nnls.cpython-313-darwin.so +0 -0
- scipy/optimize/_slsqp.cpython-313-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-313-darwin.so +0 -0
- scipy-1.15.3.dist-info/WHEEL +0 -4
@@ -4,18 +4,24 @@ from warnings import warn
|
|
4
4
|
import numpy as np
|
5
5
|
from numpy.linalg import norm
|
6
6
|
|
7
|
-
from scipy.sparse import issparse
|
8
7
|
from scipy.sparse.linalg import LinearOperator
|
9
8
|
from scipy.optimize import _minpack, OptimizeResult
|
10
|
-
from scipy.optimize.
|
9
|
+
from scipy.optimize._differentiable_functions import VectorFunction
|
10
|
+
from scipy.optimize._numdiff import group_columns
|
11
11
|
from scipy.optimize._minimize import Bounds
|
12
|
+
from scipy._lib._sparse import issparse
|
13
|
+
from scipy._lib._array_api import array_namespace
|
14
|
+
from scipy._lib._util import _workers_wrapper
|
12
15
|
|
13
16
|
from .trf import trf
|
14
17
|
from .dogbox import dogbox
|
15
18
|
from .common import EPS, in_bounds, make_strictly_feasible
|
16
19
|
|
20
|
+
|
21
|
+
from scipy.optimize._optimize import _wrap_callback
|
17
22
|
|
18
23
|
TERMINATION_MESSAGES = {
|
24
|
+
-2: "Stopped because `callback` function raised `StopIteration` or returned `True`",
|
19
25
|
-1: "Improper input parameters status returned from `leastsq`",
|
20
26
|
0: "The maximum number of function evaluations is exceeded.",
|
21
27
|
1: "`gtol` termination condition is satisfied.",
|
@@ -37,52 +43,53 @@ FROM_MINPACK_TO_COMMON = {
|
|
37
43
|
}
|
38
44
|
|
39
45
|
|
40
|
-
def call_minpack(fun, x0, jac, ftol, xtol, gtol, max_nfev, x_scale,
|
46
|
+
def call_minpack(fun, x0, jac, ftol, xtol, gtol, max_nfev, x_scale, jac_method=None):
|
41
47
|
n = x0.size
|
42
48
|
|
43
|
-
if diff_step is None:
|
44
|
-
epsfcn = EPS
|
45
|
-
else:
|
46
|
-
epsfcn = diff_step**2
|
47
|
-
|
48
49
|
# Compute MINPACK's `diag`, which is inverse of our `x_scale` and
|
49
50
|
# ``x_scale='jac'`` corresponds to ``diag=None``.
|
50
|
-
|
51
|
+
|
52
|
+
# 1.16.0 - default x_scale changed to 'jac', with diag=None
|
53
|
+
if x_scale is None or (isinstance(x_scale, str) and x_scale == 'jac'):
|
51
54
|
diag = None
|
52
55
|
else:
|
56
|
+
# x_scale specified, so use that
|
53
57
|
diag = 1 / x_scale
|
54
58
|
|
55
59
|
full_output = True
|
56
60
|
col_deriv = False
|
57
61
|
factor = 100.0
|
58
62
|
|
59
|
-
if
|
60
|
-
|
61
|
-
# n squared to account for Jacobian evaluations.
|
62
|
-
max_nfev = 100 * n * (n + 1)
|
63
|
-
x, info, status = _minpack._lmdif(
|
64
|
-
fun, x0, (), full_output, ftol, xtol, gtol,
|
65
|
-
max_nfev, epsfcn, factor, diag)
|
66
|
-
else:
|
67
|
-
if max_nfev is None:
|
68
|
-
max_nfev = 100 * n
|
69
|
-
x, info, status = _minpack._lmder(
|
70
|
-
fun, jac, x0, (), full_output, col_deriv,
|
71
|
-
ftol, xtol, gtol, max_nfev, factor, diag)
|
63
|
+
if max_nfev is None:
|
64
|
+
max_nfev = 100 * n
|
72
65
|
|
73
|
-
|
66
|
+
# lmder is typically used for systems with analytic jacobians, with lmdif being
|
67
|
+
# used if there is only an objective fun (lmdif uses finite differences to estimate
|
68
|
+
# jacobian). Otherwise they're very similar internally.
|
69
|
+
# We now do all the finite differencing in VectorFunction, which means we can drop
|
70
|
+
# lmdif and just use lmder.
|
74
71
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
72
|
+
# for sending a copy of x0 into _lmder
|
73
|
+
xp = array_namespace(x0)
|
74
|
+
|
75
|
+
x, info, status = _minpack._lmder(
|
76
|
+
fun, jac, xp.astype(x0, x0.dtype), (), full_output, col_deriv,
|
77
|
+
ftol, xtol, gtol, max_nfev, factor, diag)
|
78
|
+
|
79
|
+
f = info['fvec']
|
80
|
+
J = jac(x)
|
79
81
|
|
80
82
|
cost = 0.5 * np.dot(f, f)
|
81
83
|
g = J.T.dot(f)
|
82
84
|
g_norm = norm(g, ord=np.inf)
|
83
85
|
|
84
86
|
nfev = info['nfev']
|
85
|
-
|
87
|
+
if callable(jac_method):
|
88
|
+
# user supplied a callable ("analytic") jac
|
89
|
+
njev = info.get('njev', None)
|
90
|
+
else:
|
91
|
+
# If there are no analytic jacobian evaluations we need to set `njev=None`.
|
92
|
+
njev = None
|
86
93
|
|
87
94
|
status = FROM_MINPACK_TO_COMMON[status]
|
88
95
|
active_mask = np.zeros_like(x0, dtype=int)
|
@@ -127,7 +134,14 @@ def check_tolerance(ftol, xtol, gtol, method):
|
|
127
134
|
return ftol, xtol, gtol
|
128
135
|
|
129
136
|
|
130
|
-
def check_x_scale(x_scale, x0):
|
137
|
+
def check_x_scale(x_scale, x0, method):
|
138
|
+
# normalise the default scaling
|
139
|
+
if x_scale is None:
|
140
|
+
if method == 'lm':
|
141
|
+
return 'jac'
|
142
|
+
else: # dogbox, trf
|
143
|
+
x_scale = 1.0
|
144
|
+
|
131
145
|
if isinstance(x_scale, str) and x_scale == 'jac':
|
132
146
|
return x_scale
|
133
147
|
|
@@ -238,11 +252,25 @@ def construct_loss_function(m, loss, f_scale):
|
|
238
252
|
return loss_function
|
239
253
|
|
240
254
|
|
255
|
+
class _WrapArgsKwargs:
|
256
|
+
# Supplies a user function with args and kwargs.
|
257
|
+
def __init__(self, f, args=(), kwargs=None):
|
258
|
+
self.f = f
|
259
|
+
self.args = args
|
260
|
+
self.kwargs = kwargs or {}
|
261
|
+
|
262
|
+
def __call__(self, x):
|
263
|
+
return self.f(x, *self.args, **self.kwargs)
|
264
|
+
|
265
|
+
|
266
|
+
@_workers_wrapper
|
241
267
|
def least_squares(
|
242
268
|
fun, x0, jac='2-point', bounds=(-np.inf, np.inf), method='trf',
|
243
|
-
ftol=1e-8, xtol=1e-8, gtol=1e-8, x_scale=
|
269
|
+
ftol=1e-8, xtol=1e-8, gtol=1e-8, x_scale=None, loss='linear',
|
244
270
|
f_scale=1.0, diff_step=None, tr_solver=None, tr_options=None,
|
245
|
-
jac_sparsity=None, max_nfev=None, verbose=0, args=(), kwargs=None
|
271
|
+
jac_sparsity=None, max_nfev=None, verbose=0, args=(), kwargs=None,
|
272
|
+
callback=None, workers=None
|
273
|
+
):
|
246
274
|
"""Solve a nonlinear least-squares problem with bounds on the variables.
|
247
275
|
|
248
276
|
Given the residuals f(x) (an m-D real function of n real
|
@@ -279,12 +307,16 @@ def least_squares(
|
|
279
307
|
twice as many operations as '2-point' (default). The scheme 'cs'
|
280
308
|
uses complex steps, and while potentially the most accurate, it is
|
281
309
|
applicable only when `fun` correctly handles complex inputs and
|
282
|
-
can be analytically continued to the complex plane.
|
283
|
-
always uses the '2-point' scheme. If callable, it is used as
|
310
|
+
can be analytically continued to the complex plane. If callable, it is used as
|
284
311
|
``jac(x, *args, **kwargs)`` and should return a good approximation
|
285
312
|
(or the exact value) for the Jacobian as an array_like (np.atleast_2d
|
286
|
-
is applied), a sparse
|
313
|
+
is applied), a sparse array (csr_array preferred for performance) or
|
287
314
|
a `scipy.sparse.linalg.LinearOperator`.
|
315
|
+
|
316
|
+
.. versionchanged:: 1.16.0
|
317
|
+
An ability to use the '3-point', 'cs' keywords with the 'lm' method.
|
318
|
+
Previously 'lm' was limited to '2-point' and callable.
|
319
|
+
|
288
320
|
bounds : 2-tuple of array_like or `Bounds`, optional
|
289
321
|
There are two ways to specify bounds:
|
290
322
|
|
@@ -346,7 +378,7 @@ def least_squares(
|
|
346
378
|
If None and 'method' is not 'lm', the termination by this condition is
|
347
379
|
disabled. If 'method' is 'lm', this tolerance must be higher than
|
348
380
|
machine epsilon.
|
349
|
-
x_scale : array_like
|
381
|
+
x_scale : {None, array_like, 'jac'}, optional
|
350
382
|
Characteristic scale of each variable. Setting `x_scale` is equivalent
|
351
383
|
to reformulating the problem in scaled variables ``xs = x / x_scale``.
|
352
384
|
An alternative view is that the size of a trust region along jth
|
@@ -355,7 +387,20 @@ def least_squares(
|
|
355
387
|
along any of the scaled variables has a similar effect on the cost
|
356
388
|
function. If set to 'jac', the scale is iteratively updated using the
|
357
389
|
inverse norms of the columns of the Jacobian matrix (as described in
|
358
|
-
[JJMore]_).
|
390
|
+
[JJMore]_). The default scaling for each method (i.e.
|
391
|
+
if ``x_scale is None``) is as follows:
|
392
|
+
|
393
|
+
* For 'trf' : ``x_scale == 1``
|
394
|
+
* For 'dogbox' : ``x_scale == 1``
|
395
|
+
* For 'jac' : ``x_scale == 'jac'``
|
396
|
+
|
397
|
+
.. versionchanged:: 1.16.0
|
398
|
+
The default keyword value is changed from 1 to None to indicate that
|
399
|
+
a default approach to scaling is used.
|
400
|
+
For the 'lm' method the default scaling is changed from 1 to 'jac'.
|
401
|
+
This has been found to give better performance, and is the same
|
402
|
+
scaling as performed by ``leastsq``.
|
403
|
+
|
359
404
|
loss : str or callable, optional
|
360
405
|
Determines the loss function. The following keyword values are allowed:
|
361
406
|
|
@@ -383,13 +428,16 @@ def least_squares(
|
|
383
428
|
no effect with ``loss='linear'``, but for other `loss` values it is
|
384
429
|
of crucial importance.
|
385
430
|
max_nfev : None or int, optional
|
386
|
-
|
387
|
-
|
431
|
+
For all methods this parameter controls the maximum number of function
|
432
|
+
evaluations used by each method, separate to those used in numerical
|
433
|
+
approximation of the jacobian.
|
434
|
+
If None (default), the value is chosen automatically as 100 * n.
|
388
435
|
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
436
|
+
.. versionchanged:: 1.16.0
|
437
|
+
The default for the 'lm' method is changed to 100 * n, for both a callable
|
438
|
+
and a numerically estimated jacobian. Previously the default when using an
|
439
|
+
estimated jacobian was 100 * n * (n + 1), because the method included
|
440
|
+
evaluations used in the estimation.
|
393
441
|
|
394
442
|
diff_step : None or array_like, optional
|
395
443
|
Determines the relative step size for the finite difference
|
@@ -423,7 +471,7 @@ def least_squares(
|
|
423
471
|
normal equation, which improves convergence if the Jacobian is
|
424
472
|
rank-deficient [Byrd]_ (eq. 3.4).
|
425
473
|
|
426
|
-
jac_sparsity : {None, array_like, sparse
|
474
|
+
jac_sparsity : {None, array_like, sparse array}, optional
|
427
475
|
Defines the sparsity structure of the Jacobian matrix for finite
|
428
476
|
difference estimation, its shape must be (m, n). If the Jacobian has
|
429
477
|
only few non-zero elements in *each* row, providing the sparsity
|
@@ -444,6 +492,32 @@ def least_squares(
|
|
444
492
|
Additional arguments passed to `fun` and `jac`. Both empty by default.
|
445
493
|
The calling signature is ``fun(x, *args, **kwargs)`` and the same for
|
446
494
|
`jac`.
|
495
|
+
callback : None or callable, optional
|
496
|
+
Callback function that is called by the algorithm on each iteration.
|
497
|
+
This can be used to print or plot the optimization results at each
|
498
|
+
step, and to stop the optimization algorithm based on some user-defined
|
499
|
+
condition. Only implemented for the `trf` and `dogbox` methods.
|
500
|
+
|
501
|
+
The signature is ``callback(intermediate_result: OptimizeResult)``
|
502
|
+
|
503
|
+
`intermediate_result is a `scipy.optimize.OptimizeResult`
|
504
|
+
which contains the intermediate results of the optimization at the
|
505
|
+
current iteration.
|
506
|
+
|
507
|
+
The callback also supports a signature like: ``callback(x)``
|
508
|
+
|
509
|
+
Introspection is used to determine which of the signatures is invoked.
|
510
|
+
|
511
|
+
If the `callback` function raises `StopIteration` the optimization algorithm
|
512
|
+
will stop and return with status code -2.
|
513
|
+
|
514
|
+
.. versionadded:: 1.16.0
|
515
|
+
workers : map-like callable, optional
|
516
|
+
A map-like callable, such as `multiprocessing.Pool.map` for evaluating
|
517
|
+
any numerical differentiation in parallel.
|
518
|
+
This evaluation is carried out as ``workers(fun, iterable)``.
|
519
|
+
|
520
|
+
.. versionadded:: 1.16.0
|
447
521
|
|
448
522
|
Returns
|
449
523
|
-------
|
@@ -456,7 +530,7 @@ def least_squares(
|
|
456
530
|
Value of the cost function at the solution.
|
457
531
|
fun : ndarray, shape (m,)
|
458
532
|
Vector of residuals at the solution.
|
459
|
-
jac : ndarray, sparse
|
533
|
+
jac : ndarray, sparse array or LinearOperator, shape (m, n)
|
460
534
|
Modified Jacobian matrix at the solution, in the sense that J^T J
|
461
535
|
is a Gauss-Newton approximation of the Hessian of the cost function.
|
462
536
|
The type is the same as the one used by the algorithm.
|
@@ -478,15 +552,21 @@ def least_squares(
|
|
478
552
|
sequence of strictly feasible iterates and `active_mask` is
|
479
553
|
determined within a tolerance threshold.
|
480
554
|
nfev : int
|
481
|
-
Number of function evaluations done.
|
482
|
-
|
483
|
-
|
555
|
+
Number of function evaluations done. This number does not include
|
556
|
+
the function calls used for numerical Jacobian approximation.
|
557
|
+
|
558
|
+
.. versionchanged:: 1.16.0
|
559
|
+
For the 'lm' method the number of function calls used in numerical
|
560
|
+
Jacobian approximation is no longer included. This is to bring all
|
561
|
+
methods into line.
|
562
|
+
|
484
563
|
njev : int or None
|
485
564
|
Number of Jacobian evaluations done. If numerical Jacobian
|
486
565
|
approximation is used in 'lm' method, it is set to None.
|
487
566
|
status : int
|
488
567
|
The reason for algorithm termination:
|
489
568
|
|
569
|
+
* -2 : terminated because callback raised StopIteration.
|
490
570
|
* -1 : improper input parameters status returned from MINPACK.
|
491
571
|
* 0 : the maximum number of function evaluations is exceeded.
|
492
572
|
* 1 : `gtol` termination condition is satisfied.
|
@@ -507,8 +587,8 @@ def least_squares(
|
|
507
587
|
|
508
588
|
Notes
|
509
589
|
-----
|
510
|
-
Method 'lm' (Levenberg-Marquardt) calls a wrapper over least-squares
|
511
|
-
|
590
|
+
Method 'lm' (Levenberg-Marquardt) calls a wrapper over a least-squares
|
591
|
+
algorithm implemented in MINPACK (lmder). It runs the
|
512
592
|
Levenberg-Marquardt algorithm formulated as a trust-region type algorithm.
|
513
593
|
The implementation is based on paper [JJMore]_, it is very robust and
|
514
594
|
efficient with a lot of smart tricks. It should be your first choice
|
@@ -647,9 +727,9 @@ def least_squares(
|
|
647
727
|
estimate it by finite differences and provide the sparsity structure of
|
648
728
|
Jacobian to significantly speed up this process.
|
649
729
|
|
650
|
-
>>> from scipy.sparse import
|
730
|
+
>>> from scipy.sparse import lil_array
|
651
731
|
>>> def sparsity_broyden(n):
|
652
|
-
... sparsity =
|
732
|
+
... sparsity = lil_array((n, n), dtype=int)
|
653
733
|
... i = np.arange(n)
|
654
734
|
... sparsity[i, i] = 1
|
655
735
|
... i = np.arange(1, n)
|
@@ -820,22 +900,43 @@ def least_squares(
|
|
820
900
|
if not in_bounds(x0, lb, ub):
|
821
901
|
raise ValueError("Initial guess is outside of provided bounds")
|
822
902
|
|
823
|
-
x_scale = check_x_scale(x_scale, x0)
|
903
|
+
x_scale = check_x_scale(x_scale, x0, method)
|
824
904
|
|
825
905
|
ftol, xtol, gtol = check_tolerance(ftol, xtol, gtol, method)
|
826
906
|
|
827
907
|
if method == 'trf':
|
828
908
|
x0 = make_strictly_feasible(x0, lb, ub)
|
829
909
|
|
830
|
-
if kwargs is None:
|
831
|
-
kwargs = {}
|
832
910
|
if tr_options is None:
|
833
911
|
tr_options = {}
|
834
912
|
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
913
|
+
###########################################################################
|
914
|
+
# assemble VectorFunction
|
915
|
+
###########################################################################
|
916
|
+
# first wrap the args/kwargs
|
917
|
+
fun_wrapped = _WrapArgsKwargs(fun, args=args, kwargs=kwargs)
|
918
|
+
jac_wrapped = jac
|
919
|
+
if callable(jac):
|
920
|
+
jac_wrapped = _WrapArgsKwargs(jac, args=args, kwargs=kwargs)
|
921
|
+
|
922
|
+
def _dummy_hess(x, *args):
|
923
|
+
# we don't care about Hessian evaluations
|
924
|
+
return x
|
925
|
+
|
926
|
+
vector_fun = VectorFunction(
|
927
|
+
fun_wrapped,
|
928
|
+
x0,
|
929
|
+
jac_wrapped,
|
930
|
+
_dummy_hess,
|
931
|
+
finite_diff_rel_step=diff_step,
|
932
|
+
finite_diff_jac_sparsity=jac_sparsity,
|
933
|
+
finite_diff_bounds=bounds,
|
934
|
+
workers=workers
|
935
|
+
)
|
936
|
+
###########################################################################
|
937
|
+
|
938
|
+
f0 = vector_fun.fun(x0)
|
939
|
+
J0 = vector_fun.jac(x0)
|
839
940
|
|
840
941
|
if f0.ndim != 1:
|
841
942
|
raise ValueError("`fun` must return at most 1-d array_like. "
|
@@ -863,90 +964,61 @@ def least_squares(
|
|
863
964
|
else:
|
864
965
|
initial_cost = 0.5 * np.dot(f0, f0)
|
865
966
|
|
866
|
-
if callable(jac):
|
867
|
-
|
868
|
-
|
869
|
-
if issparse(J0):
|
870
|
-
J0 = J0.tocsr()
|
871
|
-
|
872
|
-
def jac_wrapped(x, _=None):
|
873
|
-
return jac(x, *args, **kwargs).tocsr()
|
874
|
-
|
875
|
-
elif isinstance(J0, LinearOperator):
|
876
|
-
def jac_wrapped(x, _=None):
|
877
|
-
return jac(x, *args, **kwargs)
|
878
|
-
|
879
|
-
else:
|
880
|
-
J0 = np.atleast_2d(J0)
|
881
|
-
|
882
|
-
def jac_wrapped(x, _=None):
|
883
|
-
return np.atleast_2d(jac(x, *args, **kwargs))
|
884
|
-
|
885
|
-
else: # Estimate Jacobian by finite differences.
|
967
|
+
if not callable(jac):
|
968
|
+
# Estimate Jacobian by finite differences.
|
886
969
|
if method == 'lm':
|
887
970
|
if jac_sparsity is not None:
|
888
971
|
raise ValueError("method='lm' does not support "
|
889
972
|
"`jac_sparsity`.")
|
890
|
-
|
891
|
-
if jac != '2-point':
|
892
|
-
warn(f"jac='{jac}' works equivalently to '2-point' for method='lm'.",
|
893
|
-
stacklevel=2)
|
894
|
-
|
895
|
-
J0 = jac_wrapped = None
|
896
973
|
else:
|
974
|
+
# this will raise a ValueError if the jac_sparsity isn't correct
|
975
|
+
_ = check_jac_sparsity(jac_sparsity, m, n)
|
976
|
+
|
897
977
|
if jac_sparsity is not None and tr_solver == 'exact':
|
898
978
|
raise ValueError("tr_solver='exact' is incompatible "
|
899
979
|
"with `jac_sparsity`.")
|
900
980
|
|
901
|
-
|
981
|
+
if J0.shape != (m, n):
|
982
|
+
raise ValueError(
|
983
|
+
f"The return value of `jac` has wrong shape: expected {(m, n)}, "
|
984
|
+
f"actual {J0.shape}."
|
985
|
+
)
|
902
986
|
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
if J.ndim != 2: # J is guaranteed not sparse.
|
908
|
-
J = np.atleast_2d(J)
|
987
|
+
if not isinstance(J0, np.ndarray):
|
988
|
+
if method == 'lm':
|
989
|
+
raise ValueError("method='lm' works only with dense "
|
990
|
+
"Jacobian matrices.")
|
909
991
|
|
910
|
-
|
992
|
+
if tr_solver == 'exact':
|
993
|
+
raise ValueError(
|
994
|
+
"tr_solver='exact' works only with dense "
|
995
|
+
"Jacobian matrices.")
|
911
996
|
|
912
|
-
|
997
|
+
jac_scale = isinstance(x_scale, str) and x_scale == 'jac'
|
998
|
+
if isinstance(J0, LinearOperator) and jac_scale:
|
999
|
+
raise ValueError("x_scale='jac' can't be used when `jac` "
|
1000
|
+
"returns LinearOperator.")
|
913
1001
|
|
914
|
-
if
|
915
|
-
if J0
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
if method == 'lm':
|
923
|
-
raise ValueError("method='lm' works only with dense "
|
924
|
-
"Jacobian matrices.")
|
925
|
-
|
926
|
-
if tr_solver == 'exact':
|
927
|
-
raise ValueError(
|
928
|
-
"tr_solver='exact' works only with dense "
|
929
|
-
"Jacobian matrices.")
|
930
|
-
|
931
|
-
jac_scale = isinstance(x_scale, str) and x_scale == 'jac'
|
932
|
-
if isinstance(J0, LinearOperator) and jac_scale:
|
933
|
-
raise ValueError("x_scale='jac' can't be used when `jac` "
|
934
|
-
"returns LinearOperator.")
|
935
|
-
|
936
|
-
if tr_solver is None:
|
937
|
-
if isinstance(J0, np.ndarray):
|
938
|
-
tr_solver = 'exact'
|
939
|
-
else:
|
940
|
-
tr_solver = 'lsmr'
|
1002
|
+
if tr_solver is None:
|
1003
|
+
if isinstance(J0, np.ndarray):
|
1004
|
+
tr_solver = 'exact'
|
1005
|
+
else:
|
1006
|
+
tr_solver = 'lsmr'
|
1007
|
+
|
1008
|
+
# Wrap callback function. If callback is None, callback_wrapped also is None
|
1009
|
+
callback_wrapped = _wrap_callback(callback)
|
941
1010
|
|
942
1011
|
if method == 'lm':
|
943
|
-
|
944
|
-
|
1012
|
+
if callback is not None:
|
1013
|
+
warn("Callback function specified, but not supported with `lm` method.",
|
1014
|
+
stacklevel=2)
|
1015
|
+
result = call_minpack(vector_fun.fun, x0, vector_fun.jac, ftol, xtol, gtol,
|
1016
|
+
max_nfev, x_scale, jac_method=jac)
|
945
1017
|
|
946
1018
|
elif method == 'trf':
|
947
|
-
result = trf(
|
1019
|
+
result = trf(vector_fun.fun, vector_fun.jac, x0, f0, J0, lb, ub, ftol, xtol,
|
948
1020
|
gtol, max_nfev, x_scale, loss_function, tr_solver,
|
949
|
-
tr_options.copy(), verbose)
|
1021
|
+
tr_options.copy(), verbose, callback=callback_wrapped)
|
950
1022
|
|
951
1023
|
elif method == 'dogbox':
|
952
1024
|
if tr_solver == 'lsmr' and 'regularize' in tr_options:
|
@@ -956,9 +1028,9 @@ def least_squares(
|
|
956
1028
|
tr_options = tr_options.copy()
|
957
1029
|
del tr_options['regularize']
|
958
1030
|
|
959
|
-
result = dogbox(
|
1031
|
+
result = dogbox(vector_fun.fun, vector_fun.jac, x0, f0, J0, lb, ub, ftol,
|
960
1032
|
xtol, gtol, max_nfev, x_scale, loss_function,
|
961
|
-
tr_solver, tr_options, verbose)
|
1033
|
+
tr_solver, tr_options, verbose, callback=callback_wrapped)
|
962
1034
|
|
963
1035
|
result.message = TERMINATION_MESSAGES[result.status]
|
964
1036
|
result.success = result.status > 0
|
@@ -1,7 +1,7 @@
|
|
1
1
|
"""Linear least squares with bound constraints on independent variables."""
|
2
2
|
import numpy as np
|
3
3
|
from numpy.linalg import norm
|
4
|
-
from scipy.sparse import issparse,
|
4
|
+
from scipy.sparse import issparse, csr_array
|
5
5
|
from scipy.sparse.linalg import LinearOperator, lsmr
|
6
6
|
from scipy.optimize import OptimizeResult
|
7
7
|
from scipy.optimize._minimize import Bounds
|
@@ -50,7 +50,7 @@ def lsq_linear(A, b, bounds=(-np.inf, np.inf), method='trf', tol=1e-10,
|
|
50
50
|
|
51
51
|
Parameters
|
52
52
|
----------
|
53
|
-
A : array_like, sparse
|
53
|
+
A : array_like, sparse array or LinearOperator, shape (m, n)
|
54
54
|
Design matrix. Can be `scipy.sparse.linalg.LinearOperator`.
|
55
55
|
b : array_like, shape (m,)
|
56
56
|
Target vector.
|
@@ -222,18 +222,18 @@ def lsq_linear(A, b, bounds=(-np.inf, np.inf), method='trf', tol=1e-10,
|
|
222
222
|
|
223
223
|
Examples
|
224
224
|
--------
|
225
|
-
In this example, a problem with a large sparse
|
225
|
+
In this example, a problem with a large sparse arrays and bounds on the
|
226
226
|
variables is solved.
|
227
227
|
|
228
228
|
>>> import numpy as np
|
229
|
-
>>> from scipy.sparse import
|
229
|
+
>>> from scipy.sparse import random_array
|
230
230
|
>>> from scipy.optimize import lsq_linear
|
231
231
|
>>> rng = np.random.default_rng()
|
232
232
|
...
|
233
233
|
>>> m = 2000
|
234
234
|
>>> n = 1000
|
235
235
|
...
|
236
|
-
>>> A =
|
236
|
+
>>> A = random_array((m, n), density=1e-4, random_state=rng)
|
237
237
|
>>> b = rng.standard_normal(m)
|
238
238
|
...
|
239
239
|
>>> lb = rng.standard_normal(n)
|
@@ -254,7 +254,7 @@ def lsq_linear(A, b, bounds=(-np.inf, np.inf), method='trf', tol=1e-10,
|
|
254
254
|
raise ValueError("`verbose` must be in [0, 1, 2].")
|
255
255
|
|
256
256
|
if issparse(A):
|
257
|
-
A =
|
257
|
+
A = csr_array(A)
|
258
258
|
elif not isinstance(A, LinearOperator):
|
259
259
|
A = np.atleast_2d(np.asarray(A))
|
260
260
|
|
scipy/optimize/_lsq/trf.py
CHANGED
@@ -107,10 +107,11 @@ from .common import (
|
|
107
107
|
CL_scaling_vector, compute_grad, compute_jac_scale, check_termination,
|
108
108
|
update_tr_radius, scale_for_robust_loss_function, print_header_nonlinear,
|
109
109
|
print_iteration_nonlinear)
|
110
|
+
from scipy._lib._util import _call_callback_maybe_halt
|
110
111
|
|
111
112
|
|
112
113
|
def trf(fun, jac, x0, f0, J0, lb, ub, ftol, xtol, gtol, max_nfev, x_scale,
|
113
|
-
loss_function, tr_solver, tr_options, verbose):
|
114
|
+
loss_function, tr_solver, tr_options, verbose, callback=None):
|
114
115
|
# For efficiency, it makes sense to run the simplified version of the
|
115
116
|
# algorithm when no bounds are imposed. We decided to write the two
|
116
117
|
# separate functions. It violates the DRY principle, but the individual
|
@@ -118,11 +119,11 @@ def trf(fun, jac, x0, f0, J0, lb, ub, ftol, xtol, gtol, max_nfev, x_scale,
|
|
118
119
|
if np.all(lb == -np.inf) and np.all(ub == np.inf):
|
119
120
|
return trf_no_bounds(
|
120
121
|
fun, jac, x0, f0, J0, ftol, xtol, gtol, max_nfev, x_scale,
|
121
|
-
loss_function, tr_solver, tr_options, verbose)
|
122
|
+
loss_function, tr_solver, tr_options, verbose, callback=callback)
|
122
123
|
else:
|
123
124
|
return trf_bounds(
|
124
125
|
fun, jac, x0, f0, J0, lb, ub, ftol, xtol, gtol, max_nfev, x_scale,
|
125
|
-
loss_function, tr_solver, tr_options, verbose)
|
126
|
+
loss_function, tr_solver, tr_options, verbose, callback=callback)
|
126
127
|
|
127
128
|
|
128
129
|
def select_step(x, J_h, diag_h, g_h, p, p_h, d, Delta, lb, ub, theta):
|
@@ -203,7 +204,8 @@ def select_step(x, J_h, diag_h, g_h, p, p_h, d, Delta, lb, ub, theta):
|
|
203
204
|
|
204
205
|
|
205
206
|
def trf_bounds(fun, jac, x0, f0, J0, lb, ub, ftol, xtol, gtol, max_nfev,
|
206
|
-
x_scale, loss_function, tr_solver, tr_options, verbose
|
207
|
+
x_scale, loss_function, tr_solver, tr_options, verbose,
|
208
|
+
callback=None):
|
207
209
|
x = x0.copy()
|
208
210
|
|
209
211
|
f = f0
|
@@ -371,7 +373,7 @@ def trf_bounds(fun, jac, x0, f0, J0, lb, ub, ftol, xtol, gtol, max_nfev,
|
|
371
373
|
|
372
374
|
cost = cost_new
|
373
375
|
|
374
|
-
J = jac(x
|
376
|
+
J = jac(x)
|
375
377
|
njev += 1
|
376
378
|
|
377
379
|
if loss_function is not None:
|
@@ -385,8 +387,20 @@ def trf_bounds(fun, jac, x0, f0, J0, lb, ub, ftol, xtol, gtol, max_nfev,
|
|
385
387
|
else:
|
386
388
|
step_norm = 0
|
387
389
|
actual_reduction = 0
|
388
|
-
|
390
|
+
|
389
391
|
iteration += 1
|
392
|
+
|
393
|
+
# Call callback function and possibly stop optimization
|
394
|
+
if callback is not None:
|
395
|
+
intermediate_result = OptimizeResult(
|
396
|
+
x=x, fun=f_true, nit=iteration, nfev=nfev)
|
397
|
+
intermediate_result["cost"] = cost
|
398
|
+
|
399
|
+
if _call_callback_maybe_halt(
|
400
|
+
callback, intermediate_result
|
401
|
+
):
|
402
|
+
termination_status = -2
|
403
|
+
break
|
390
404
|
|
391
405
|
if termination_status is None:
|
392
406
|
termination_status = 0
|
@@ -399,7 +413,8 @@ def trf_bounds(fun, jac, x0, f0, J0, lb, ub, ftol, xtol, gtol, max_nfev,
|
|
399
413
|
|
400
414
|
|
401
415
|
def trf_no_bounds(fun, jac, x0, f0, J0, ftol, xtol, gtol, max_nfev,
|
402
|
-
x_scale, loss_function, tr_solver, tr_options, verbose
|
416
|
+
x_scale, loss_function, tr_solver, tr_options, verbose,
|
417
|
+
callback=None):
|
403
418
|
x = x0.copy()
|
404
419
|
|
405
420
|
f = f0
|
@@ -533,7 +548,7 @@ def trf_no_bounds(fun, jac, x0, f0, J0, ftol, xtol, gtol, max_nfev,
|
|
533
548
|
|
534
549
|
cost = cost_new
|
535
550
|
|
536
|
-
J = jac(x
|
551
|
+
J = jac(x)
|
537
552
|
njev += 1
|
538
553
|
|
539
554
|
if loss_function is not None:
|
@@ -549,6 +564,18 @@ def trf_no_bounds(fun, jac, x0, f0, J0, ftol, xtol, gtol, max_nfev,
|
|
549
564
|
actual_reduction = 0
|
550
565
|
|
551
566
|
iteration += 1
|
567
|
+
|
568
|
+
# Call callback function and possibly stop optimization
|
569
|
+
if callback is not None:
|
570
|
+
intermediate_result = OptimizeResult(
|
571
|
+
x=x, fun=f_true, nit=iteration, nfev=nfev)
|
572
|
+
intermediate_result["cost"] = cost
|
573
|
+
|
574
|
+
if _call_callback_maybe_halt(
|
575
|
+
callback, intermediate_result
|
576
|
+
):
|
577
|
+
termination_status = -2
|
578
|
+
break
|
552
579
|
|
553
580
|
if termination_status is None:
|
554
581
|
termination_status = 0
|
scipy/optimize/_milp.py
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
import warnings
|
2
|
+
|
2
3
|
import numpy as np
|
4
|
+
from numpy.exceptions import VisibleDeprecationWarning
|
5
|
+
|
3
6
|
from scipy.sparse import csc_array, vstack, issparse
|
4
|
-
from scipy._lib._util import VisibleDeprecationWarning
|
5
7
|
from ._highspy._highs_wrapper import _highs_wrapper # type: ignore[import-not-found,import-untyped]
|
6
8
|
from ._constraints import LinearConstraint, Bounds
|
7
9
|
from ._optimize import OptimizeResult
|