scipy 1.16.0rc1__cp313-cp313t-musllinux_1_2_aarch64.whl → 1.16.1__cp313-cp313t-musllinux_1_2_aarch64.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.
Files changed (161) hide show
  1. scipy/__config__.py +8 -8
  2. scipy/_cyutility.cpython-313t-aarch64-linux-musl.so +0 -0
  3. scipy/_lib/_ccallback_c.cpython-313t-aarch64-linux-musl.so +0 -0
  4. scipy/_lib/_fpumode.cpython-313t-aarch64-linux-musl.so +0 -0
  5. scipy/_lib/_test_ccallback.cpython-313t-aarch64-linux-musl.so +0 -0
  6. scipy/_lib/_test_deprecation_call.cpython-313t-aarch64-linux-musl.so +0 -0
  7. scipy/_lib/_test_deprecation_def.cpython-313t-aarch64-linux-musl.so +0 -0
  8. scipy/_lib/_uarray/_uarray.cpython-313t-aarch64-linux-musl.so +0 -0
  9. scipy/_lib/_util.py +7 -0
  10. scipy/_lib/messagestream.cpython-313t-aarch64-linux-musl.so +0 -0
  11. scipy/cluster/_hierarchy.cpython-313t-aarch64-linux-musl.so +0 -0
  12. scipy/cluster/_optimal_leaf_ordering.cpython-313t-aarch64-linux-musl.so +0 -0
  13. scipy/cluster/_vq.cpython-313t-aarch64-linux-musl.so +0 -0
  14. scipy/conftest.py +25 -0
  15. scipy/fft/_pocketfft/pypocketfft.cpython-313t-aarch64-linux-musl.so +0 -0
  16. scipy/fftpack/convolve.cpython-313t-aarch64-linux-musl.so +0 -0
  17. scipy/integrate/_dop.cpython-313t-aarch64-linux-musl.so +0 -0
  18. scipy/integrate/_lsoda.cpython-313t-aarch64-linux-musl.so +0 -0
  19. scipy/integrate/_odepack.cpython-313t-aarch64-linux-musl.so +0 -0
  20. scipy/integrate/_quadpack.cpython-313t-aarch64-linux-musl.so +0 -0
  21. scipy/integrate/_test_multivariate.cpython-313t-aarch64-linux-musl.so +0 -0
  22. scipy/integrate/_test_odeint_banded.cpython-313t-aarch64-linux-musl.so +0 -0
  23. scipy/integrate/_vode.cpython-313t-aarch64-linux-musl.so +0 -0
  24. scipy/interpolate/_dfitpack.cpython-313t-aarch64-linux-musl.so +0 -0
  25. scipy/interpolate/_dierckx.cpython-313t-aarch64-linux-musl.so +0 -0
  26. scipy/interpolate/_fitpack.cpython-313t-aarch64-linux-musl.so +0 -0
  27. scipy/interpolate/_interpnd.cpython-313t-aarch64-linux-musl.so +0 -0
  28. scipy/interpolate/_ppoly.cpython-313t-aarch64-linux-musl.so +0 -0
  29. scipy/interpolate/_rbfinterp_pythran.cpython-313t-aarch64-linux-musl.so +0 -0
  30. scipy/interpolate/_rgi_cython.cpython-313t-aarch64-linux-musl.so +0 -0
  31. scipy/io/_fast_matrix_market/_fmm_core.cpython-313t-aarch64-linux-musl.so +0 -0
  32. scipy/io/_test_fortran.cpython-313t-aarch64-linux-musl.so +0 -0
  33. scipy/io/matlab/_mio5_utils.cpython-313t-aarch64-linux-musl.so +0 -0
  34. scipy/io/matlab/_mio_utils.cpython-313t-aarch64-linux-musl.so +0 -0
  35. scipy/io/matlab/_streams.cpython-313t-aarch64-linux-musl.so +0 -0
  36. scipy/io/matlab/tests/test_streams.py +9 -0
  37. scipy/linalg/_cythonized_array_utils.cpython-313t-aarch64-linux-musl.so +0 -0
  38. scipy/linalg/_decomp_interpolative.cpython-313t-aarch64-linux-musl.so +0 -0
  39. scipy/linalg/_decomp_lu_cython.cpython-313t-aarch64-linux-musl.so +0 -0
  40. scipy/linalg/_decomp_update.cpython-313t-aarch64-linux-musl.so +0 -0
  41. scipy/linalg/_fblas.cpython-313t-aarch64-linux-musl.so +0 -0
  42. scipy/linalg/_flapack.cpython-313t-aarch64-linux-musl.so +0 -0
  43. scipy/linalg/_linalg_pythran.cpython-313t-aarch64-linux-musl.so +0 -0
  44. scipy/linalg/_matfuncs_expm.cpython-313t-aarch64-linux-musl.so +0 -0
  45. scipy/linalg/_matfuncs_schur_sqrtm.cpython-313t-aarch64-linux-musl.so +0 -0
  46. scipy/linalg/_matfuncs_sqrtm_triu.cpython-313t-aarch64-linux-musl.so +0 -0
  47. scipy/linalg/_solve_toeplitz.cpython-313t-aarch64-linux-musl.so +0 -0
  48. scipy/linalg/blas.py +35 -24
  49. scipy/linalg/cython_blas.cpython-313t-aarch64-linux-musl.so +0 -0
  50. scipy/linalg/cython_lapack.cpython-313t-aarch64-linux-musl.so +0 -0
  51. scipy/linalg/tests/test_matfuncs.py +7 -0
  52. scipy/ndimage/_ctest.cpython-313t-aarch64-linux-musl.so +0 -0
  53. scipy/ndimage/_cytest.cpython-313t-aarch64-linux-musl.so +0 -0
  54. scipy/ndimage/_filters.py +52 -23
  55. scipy/ndimage/_nd_image.cpython-313t-aarch64-linux-musl.so +0 -0
  56. scipy/ndimage/_ni_label.cpython-313t-aarch64-linux-musl.so +0 -0
  57. scipy/ndimage/_rank_filter_1d.cpython-313t-aarch64-linux-musl.so +0 -0
  58. scipy/ndimage/tests/test_filters.py +94 -9
  59. scipy/odr/__odrpack.cpython-313t-aarch64-linux-musl.so +0 -0
  60. scipy/optimize/_bglu_dense.cpython-313t-aarch64-linux-musl.so +0 -0
  61. scipy/optimize/_direct.cpython-313t-aarch64-linux-musl.so +0 -0
  62. scipy/optimize/_group_columns.cpython-313t-aarch64-linux-musl.so +0 -0
  63. scipy/optimize/_highspy/_core.cpython-313t-aarch64-linux-musl.so +0 -0
  64. scipy/optimize/_highspy/_highs_options.cpython-313t-aarch64-linux-musl.so +0 -0
  65. scipy/optimize/_lbfgsb.cpython-313t-aarch64-linux-musl.so +0 -0
  66. scipy/optimize/_lbfgsb_py.py +23 -8
  67. scipy/optimize/_lsap.cpython-313t-aarch64-linux-musl.so +0 -0
  68. scipy/optimize/_lsq/givens_elimination.cpython-313t-aarch64-linux-musl.so +0 -0
  69. scipy/optimize/_lsq/least_squares.py +2 -2
  70. scipy/optimize/_minimize.py +0 -1
  71. scipy/optimize/_minpack.cpython-313t-aarch64-linux-musl.so +0 -0
  72. scipy/optimize/_moduleTNC.cpython-313t-aarch64-linux-musl.so +0 -0
  73. scipy/optimize/_pava_pybind.cpython-313t-aarch64-linux-musl.so +0 -0
  74. scipy/optimize/_shgo_lib/_complex.py +2 -2
  75. scipy/optimize/_slsqplib.cpython-313t-aarch64-linux-musl.so +0 -0
  76. scipy/optimize/_trlib/_trlib.cpython-313t-aarch64-linux-musl.so +0 -0
  77. scipy/optimize/_zeros.cpython-313t-aarch64-linux-musl.so +0 -0
  78. scipy/optimize/cython_optimize/_zeros.cpython-313t-aarch64-linux-musl.so +0 -0
  79. scipy/optimize/tests/test_lsq_linear.py +1 -1
  80. scipy/optimize/tests/test_optimize.py +3 -3
  81. scipy/signal/_filter_design.py +13 -1
  82. scipy/signal/_fir_filter_design.py +1 -1
  83. scipy/signal/_max_len_seq_inner.cpython-313t-aarch64-linux-musl.so +0 -0
  84. scipy/signal/_peak_finding_utils.cpython-313t-aarch64-linux-musl.so +0 -0
  85. scipy/signal/_polyutils.py +1 -1
  86. scipy/signal/_sigtools.cpython-313t-aarch64-linux-musl.so +0 -0
  87. scipy/signal/_sosfilt.cpython-313t-aarch64-linux-musl.so +0 -0
  88. scipy/signal/_spectral_py.py +9 -0
  89. scipy/signal/_spline.cpython-313t-aarch64-linux-musl.so +0 -0
  90. scipy/signal/_upfirdn_apply.cpython-313t-aarch64-linux-musl.so +0 -0
  91. scipy/signal/tests/test_filter_design.py +19 -0
  92. scipy/signal/tests/test_fir_filter_design.py +5 -0
  93. scipy/signal/tests/test_signaltools.py +1 -1
  94. scipy/signal/tests/test_spectral.py +31 -0
  95. scipy/sparse/_base.py +5 -2
  96. scipy/sparse/_csparsetools.cpython-313t-aarch64-linux-musl.so +0 -0
  97. scipy/sparse/_sparsetools.cpython-313t-aarch64-linux-musl.so +0 -0
  98. scipy/sparse/csgraph/_flow.cpython-313t-aarch64-linux-musl.so +0 -0
  99. scipy/sparse/csgraph/_matching.cpython-313t-aarch64-linux-musl.so +0 -0
  100. scipy/sparse/csgraph/_min_spanning_tree.cpython-313t-aarch64-linux-musl.so +0 -0
  101. scipy/sparse/csgraph/_reordering.cpython-313t-aarch64-linux-musl.so +0 -0
  102. scipy/sparse/csgraph/_shortest_path.cpython-313t-aarch64-linux-musl.so +0 -0
  103. scipy/sparse/csgraph/_tools.cpython-313t-aarch64-linux-musl.so +0 -0
  104. scipy/sparse/csgraph/_traversal.cpython-313t-aarch64-linux-musl.so +0 -0
  105. scipy/sparse/linalg/_dsolve/_superlu.cpython-313t-aarch64-linux-musl.so +0 -0
  106. scipy/sparse/linalg/_eigen/arpack/_arpack.cpython-313t-aarch64-linux-musl.so +0 -0
  107. scipy/sparse/linalg/_propack/_cpropack.cpython-313t-aarch64-linux-musl.so +0 -0
  108. scipy/sparse/linalg/_propack/_dpropack.cpython-313t-aarch64-linux-musl.so +0 -0
  109. scipy/sparse/linalg/_propack/_spropack.cpython-313t-aarch64-linux-musl.so +0 -0
  110. scipy/sparse/linalg/_propack/_zpropack.cpython-313t-aarch64-linux-musl.so +0 -0
  111. scipy/sparse/tests/test_base.py +10 -0
  112. scipy/spatial/_ckdtree.cpython-313t-aarch64-linux-musl.so +0 -0
  113. scipy/spatial/_distance_pybind.cpython-313t-aarch64-linux-musl.so +0 -0
  114. scipy/spatial/_distance_wrap.cpython-313t-aarch64-linux-musl.so +0 -0
  115. scipy/spatial/_hausdorff.cpython-313t-aarch64-linux-musl.so +0 -0
  116. scipy/spatial/_qhull.cpython-313t-aarch64-linux-musl.so +0 -0
  117. scipy/spatial/_voronoi.cpython-313t-aarch64-linux-musl.so +0 -0
  118. scipy/spatial/tests/test_distance.py +12 -0
  119. scipy/spatial/transform/_rigid_transform.cpython-313t-aarch64-linux-musl.so +0 -0
  120. scipy/spatial/transform/_rotation.cpython-313t-aarch64-linux-musl.so +0 -0
  121. scipy/special/_comb.cpython-313t-aarch64-linux-musl.so +0 -0
  122. scipy/special/_ellip_harm_2.cpython-313t-aarch64-linux-musl.so +0 -0
  123. scipy/special/_gufuncs.cpython-313t-aarch64-linux-musl.so +0 -0
  124. scipy/special/_specfun.cpython-313t-aarch64-linux-musl.so +0 -0
  125. scipy/special/_special_ufuncs.cpython-313t-aarch64-linux-musl.so +0 -0
  126. scipy/special/_test_internal.cpython-313t-aarch64-linux-musl.so +0 -0
  127. scipy/special/_ufuncs.cpython-313t-aarch64-linux-musl.so +0 -0
  128. scipy/special/_ufuncs_cxx.cpython-313t-aarch64-linux-musl.so +0 -0
  129. scipy/special/cython_special.cpython-313t-aarch64-linux-musl.so +0 -0
  130. scipy/stats/_ansari_swilk_statistics.cpython-313t-aarch64-linux-musl.so +0 -0
  131. scipy/stats/_axis_nan_policy.py +1 -9
  132. scipy/stats/_biasedurn.cpython-313t-aarch64-linux-musl.so +0 -0
  133. scipy/stats/_continuous_distns.py +19 -16
  134. scipy/stats/_correlation.py +1 -1
  135. scipy/stats/_distribution_infrastructure.py +20 -0
  136. scipy/stats/_entropy.py +2 -2
  137. scipy/stats/_hypotests.py +1 -1
  138. scipy/stats/_levy_stable/levyst.cpython-313t-aarch64-linux-musl.so +0 -0
  139. scipy/stats/_morestats.py +7 -7
  140. scipy/stats/_qmc_cy.cpython-313t-aarch64-linux-musl.so +0 -0
  141. scipy/stats/_qmvnt_cy.cpython-313t-aarch64-linux-musl.so +0 -0
  142. scipy/stats/_rcont/rcont.cpython-313t-aarch64-linux-musl.so +0 -0
  143. scipy/stats/_resampling.py +1 -1
  144. scipy/stats/_sobol.cpython-313t-aarch64-linux-musl.so +0 -0
  145. scipy/stats/_stats.cpython-313t-aarch64-linux-musl.so +0 -0
  146. scipy/stats/_stats_mstats_common.py +4 -2
  147. scipy/stats/_stats_py.py +19 -19
  148. scipy/stats/_stats_pythran.cpython-313t-aarch64-linux-musl.so +0 -0
  149. scipy/stats/_unuran/unuran_wrapper.cpython-313t-aarch64-linux-musl.so +0 -0
  150. scipy/stats/_variation.py +1 -1
  151. scipy/stats/tests/test_distributions.py +13 -0
  152. scipy/stats/tests/test_fast_gen_inversion.py +2 -0
  153. scipy/stats/tests/test_morestats.py +4 -4
  154. scipy/version.py +2 -2
  155. {scipy-1.16.0rc1.dist-info → scipy-1.16.1.dist-info}/LICENSE.txt +3 -3
  156. {scipy-1.16.0rc1.dist-info → scipy-1.16.1.dist-info}/METADATA +5 -4
  157. {scipy-1.16.0rc1.dist-info → scipy-1.16.1.dist-info}/RECORD +161 -161
  158. scipy.libs/{libgcc_s-69c45f16.so.1 → libgcc_s-2d945d6c.so.1} +0 -0
  159. scipy.libs/{libgfortran-db0b6589.so.5.0.0 → libgfortran-67378ab2.so.5.0.0} +0 -0
  160. scipy.libs/{libstdc++-1f1a71be.so.6.0.33 → libstdc++-85f2cd6d.so.6.0.33} +0 -0
  161. {scipy-1.16.0rc1.dist-info → scipy-1.16.1.dist-info}/WHEEL +0 -0
@@ -2571,7 +2571,7 @@ class TestThreading:
2571
2571
  for i in range(n):
2572
2572
  fun(*args, output=out[i, ...])
2573
2573
 
2574
- @xfail_xp_backends("cupy",
2574
+ @xfail_xp_backends("cupy",
2575
2575
  reason="XXX thread exception; cannot repro outside of pytest")
2576
2576
  def test_correlate1d(self, xp):
2577
2577
  d = np.random.randn(5000)
@@ -2585,7 +2585,7 @@ class TestThreading:
2585
2585
  self.check_func_thread(4, ndimage.correlate1d, (d, k), ot)
2586
2586
  xp_assert_equal(os, ot)
2587
2587
 
2588
- @xfail_xp_backends("cupy",
2588
+ @xfail_xp_backends("cupy",
2589
2589
  reason="XXX thread exception; cannot repro outside of pytest")
2590
2590
  def test_correlate(self, xp):
2591
2591
  d = xp.asarray(np.random.randn(500, 500))
@@ -2596,7 +2596,7 @@ class TestThreading:
2596
2596
  self.check_func_thread(4, ndimage.correlate, (d, k), ot)
2597
2597
  xp_assert_equal(os, ot)
2598
2598
 
2599
- @xfail_xp_backends("cupy",
2599
+ @xfail_xp_backends("cupy",
2600
2600
  reason="XXX thread exception; cannot repro outside of pytest")
2601
2601
  def test_median_filter(self, xp):
2602
2602
  d = xp.asarray(np.random.randn(500, 500))
@@ -2606,7 +2606,7 @@ class TestThreading:
2606
2606
  self.check_func_thread(4, ndimage.median_filter, (d, 3), ot)
2607
2607
  xp_assert_equal(os, ot)
2608
2608
 
2609
- @xfail_xp_backends("cupy",
2609
+ @xfail_xp_backends("cupy",
2610
2610
  reason="XXX thread exception; cannot repro outside of pytest")
2611
2611
  def test_uniform_filter1d(self, xp):
2612
2612
  d = np.random.randn(5000)
@@ -2619,7 +2619,7 @@ class TestThreading:
2619
2619
  self.check_func_thread(4, ndimage.uniform_filter1d, (d, 5), ot)
2620
2620
  xp_assert_equal(os, ot)
2621
2621
 
2622
- @xfail_xp_backends("cupy",
2622
+ @xfail_xp_backends("cupy",
2623
2623
  reason="XXX thread exception; cannot repro outside of pytest")
2624
2624
  def test_minmax_filter(self, xp):
2625
2625
  d = xp.asarray(np.random.randn(500, 500))
@@ -2908,15 +2908,19 @@ class TestVectorizedFilter:
2908
2908
  with pytest.raises(ValueError, match=message):
2909
2909
  ndimage.vectorized_filter(input, function, size=0)
2910
2910
 
2911
- message = "The dimensionality of the window"
2911
+ message = "The length of `axes` may not exceed "
2912
+ axes = (0, 1, 2)
2912
2913
  with pytest.raises(ValueError, match=message):
2913
- ndimage.vectorized_filter(input, function, size=(1, 2, 3))
2914
+ ndimage.vectorized_filter(input, function, size=(1, 2), axes=axes)
2914
2915
  with pytest.raises(ValueError, match=message):
2915
- ndimage.vectorized_filter(input, function, footprint=xp.ones((2, 2, 2)))
2916
+ ndimage.vectorized_filter(input, function, footprint=xp.ones((2, 2)),
2917
+ axes=axes)
2916
2918
 
2917
- message = "`axes` must be provided if the dimensionality..."
2919
+ message = "`axes` must be compatible with the dimensionality..."
2918
2920
  with pytest.raises(ValueError, match=message):
2919
2921
  ndimage.vectorized_filter(input, function, size=(1,))
2922
+ with pytest.raises(ValueError, match=message):
2923
+ ndimage.vectorized_filter(input, function, size=(2,), axes=(0,1))
2920
2924
 
2921
2925
  message = "All elements of `origin` must be integers"
2922
2926
  with pytest.raises(ValueError, match=message):
@@ -2986,6 +2990,35 @@ class TestVectorizedFilter:
2986
2990
  ref = ndimage.vectorized_filter(input, function, size=21)
2987
2991
  xp_assert_close(res, ref)
2988
2992
 
2993
+ def test_gh23046_feature(self, xp):
2994
+ # The intent of gh-23046 was to always allow `size` to be a scalar.
2995
+ rng = np.random.default_rng(45982734597824)
2996
+ img = xp.asarray(rng.random((5, 5)))
2997
+
2998
+ ref = ndimage.vectorized_filter(img, xp.mean, size=2)
2999
+ res = ndimage.vectorized_filter(img, xp.mean, size=2, axes=(0, 1))
3000
+ xp_assert_close(res, ref)
3001
+
3002
+ ref = ndimage.vectorized_filter(img, xp.mean, size=(2,), axes=(0,))
3003
+ res = ndimage.vectorized_filter(img, xp.mean, size=2, axes=0)
3004
+ xp_assert_close(res, ref)
3005
+
3006
+ def test_gh23046_fix(self, xp):
3007
+ # While investigating the feasibility of gh-23046, I noticed a bug when the
3008
+ # length of an `axes` tuple equals the dimensionality of the image.
3009
+ rng = np.random.default_rng(45982734597824)
3010
+ img = xp.asarray(rng.random((5, 5)))
3011
+ size = (2, 3)
3012
+ ref = ndimage.vectorized_filter(img.T, xp.mean, size=size).T
3013
+ res = ndimage.vectorized_filter(img, xp.mean, size=size, axes=(1, 0))
3014
+ xp_assert_close(res, ref)
3015
+
3016
+ ref = ndimage.vectorized_filter(img, xp.mean, size=size, mode='constant')
3017
+ res = ndimage.vectorized_filter(img, xp.mean, size=size[::-1], axes=(1, 0),
3018
+ mode='constant')
3019
+ xp_assert_close(res, ref)
3020
+
3021
+
2989
3022
 
2990
3023
  @given(x=npst.arrays(dtype=np.float64,
2991
3024
  shape=st.integers(min_value=1, max_value=1000)),
@@ -2996,3 +3029,55 @@ class TestVectorizedFilter:
2996
3029
  def test_gh_22586_crash_property(x, size, mode):
2997
3030
  # property-based test for median_filter resilience to hard crashing
2998
3031
  ndimage.median_filter(x, size=size, mode=mode)
3032
+
3033
+
3034
+ @pytest.mark.parametrize('samples, mode, size, expected', [
3035
+ ([1, 2], "reflect", 5, [2, 1]),
3036
+ ([2], "reflect", 5, [2]), # original failure from gh-23075
3037
+ ([2], "nearest", 5, [2]),
3038
+ ([2], "wrap", 5, [2]),
3039
+ ([2], "mirror", 5, [2]),
3040
+ ([2], "constant", 5, [0]),
3041
+ ([2], "reflect", 1, [2]),
3042
+ ([2], "nearest", 1, [2]),
3043
+ ([2], "wrap", 1, [2]),
3044
+ ([2], "mirror", 1, [2]),
3045
+ ([2], "constant", 1, [2]),
3046
+ ([2], "reflect", 100, [2]),
3047
+ ([2], "nearest", 100, [2]),
3048
+ ([2], "wrap", 100, [2]),
3049
+ ([2], "mirror", 100, [2]),
3050
+ ([2], "constant", 100, [0]),
3051
+ ])
3052
+ def test_gh_23075(samples, mode, size, expected):
3053
+ # results verified against SciPy 1.14.1, before the median_filter
3054
+ # overhaul
3055
+ sample_array = np.asarray(samples, dtype=np.float32)
3056
+ expected = np.asarray(expected, dtype=np.float32)
3057
+ filtered_samples = ndimage.median_filter(sample_array, size=size, mode=mode)
3058
+ xp_assert_close(filtered_samples, expected, check_shape=True, check_dtype=True)
3059
+
3060
+
3061
+ @pytest.mark.parametrize('samples, size, cval, expected', [
3062
+ ([2], 5, 17.7, [17.7]),
3063
+ ([2], 1, 0, [2]),
3064
+ ([2], 100, 1.4, [1.4]),
3065
+ ([9], 137, -7807.7, [-7807.7]),
3066
+ ])
3067
+ def test_gh_23075_constant(samples, size, cval, expected):
3068
+ # results verified against SciPy 1.14.1, before the median_filter
3069
+ # overhaul
3070
+ sample_array = np.asarray(samples, dtype=np.single)
3071
+ expected = np.asarray(expected, dtype=np.single)
3072
+ filtered_samples = ndimage.median_filter(sample_array,
3073
+ size=size,
3074
+ mode="constant",
3075
+ cval=cval)
3076
+ xp_assert_close(filtered_samples, expected, check_shape=True, check_dtype=True)
3077
+
3078
+
3079
+ def test_median_filter_lim2():
3080
+ sample_array = np.ones(8)
3081
+ expected = np.ones(8)
3082
+ filtered_samples = ndimage.median_filter(sample_array, size=19, mode="reflect")
3083
+ xp_assert_close(filtered_samples, expected, check_shape=True, check_dtype=True)
@@ -42,6 +42,8 @@ from ._optimize import (MemoizeJac, OptimizeResult, _call_callback_maybe_halt,
42
42
  from ._constraints import old_bound_to_new
43
43
 
44
44
  from scipy.sparse.linalg import LinearOperator
45
+ from scipy._lib.deprecation import _NoValue
46
+ import warnings
45
47
 
46
48
  __all__ = ['fmin_l_bfgs_b', 'LbfgsInvHessProduct']
47
49
 
@@ -93,7 +95,7 @@ def fmin_l_bfgs_b(func, x0, fprime=None, args=(),
93
95
  approx_grad=0,
94
96
  bounds=None, m=10, factr=1e7, pgtol=1e-5,
95
97
  epsilon=1e-8,
96
- iprint=-1, maxfun=15000, maxiter=15000, disp=None,
98
+ iprint=_NoValue, maxfun=15000, maxiter=15000, disp=_NoValue,
97
99
  callback=None, maxls=20):
98
100
  """
99
101
  Minimize a function func using the L-BFGS-B algorithm.
@@ -144,7 +146,7 @@ def fmin_l_bfgs_b(func, x0, fprime=None, args=(),
144
146
  output and this keyword has no function.
145
147
 
146
148
  .. deprecated:: 1.15.0
147
- This keyword is deprecated and will be removed from SciPy 1.17.0.
149
+ This keyword is deprecated and will be removed from SciPy 1.18.0.
148
150
 
149
151
  disp : int, optional
150
152
  Deprecated option that previously controlled the text printed on the
@@ -152,7 +154,7 @@ def fmin_l_bfgs_b(func, x0, fprime=None, args=(),
152
154
  output and this keyword has no function.
153
155
 
154
156
  .. deprecated:: 1.15.0
155
- This keyword is deprecated and will be removed from SciPy 1.17.0.
157
+ This keyword is deprecated and will be removed from SciPy 1.18.0.
156
158
 
157
159
  maxfun : int, optional
158
160
  Maximum number of function evaluations. Note that this function
@@ -265,7 +267,9 @@ def fmin_l_bfgs_b(func, x0, fprime=None, args=(),
265
267
 
266
268
  # build options
267
269
  callback = _wrap_callback(callback)
268
- opts = {'maxcor': m,
270
+ opts = {'disp': disp,
271
+ 'iprint': iprint,
272
+ 'maxcor': m,
269
273
  'ftol': factr * np.finfo(float).eps,
270
274
  'gtol': pgtol,
271
275
  'eps': epsilon,
@@ -288,9 +292,9 @@ def fmin_l_bfgs_b(func, x0, fprime=None, args=(),
288
292
 
289
293
 
290
294
  def _minimize_lbfgsb(fun, x0, args=(), jac=None, bounds=None,
291
- disp=None, maxcor=10, ftol=2.2204460492503131e-09,
295
+ disp=_NoValue, maxcor=10, ftol=2.2204460492503131e-09,
292
296
  gtol=1e-5, eps=1e-8, maxfun=15000, maxiter=15000,
293
- iprint=-1, callback=None, maxls=20,
297
+ iprint=_NoValue, callback=None, maxls=20,
294
298
  finite_diff_rel_step=None, workers=None,
295
299
  **unknown_options):
296
300
  """
@@ -305,7 +309,7 @@ def _minimize_lbfgsb(fun, x0, args=(), jac=None, bounds=None,
305
309
  output and this keyword has no function.
306
310
 
307
311
  .. deprecated:: 1.15.0
308
- This keyword is deprecated and will be removed from SciPy 1.17.0.
312
+ This keyword is deprecated and will be removed from SciPy 1.18.0.
309
313
 
310
314
  maxcor : int
311
315
  The maximum number of variable metric corrections used to
@@ -334,7 +338,7 @@ def _minimize_lbfgsb(fun, x0, args=(), jac=None, bounds=None,
334
338
  output and this keyword has no function.
335
339
 
336
340
  .. deprecated:: 1.15.0
337
- This keyword is deprecated and will be removed from SciPy 1.17.0.
341
+ This keyword is deprecated and will be removed from SciPy 1.18.0.
338
342
 
339
343
  maxls : int, optional
340
344
  Maximum number of line search steps (per iteration). Default is 20.
@@ -373,6 +377,17 @@ def _minimize_lbfgsb(fun, x0, args=(), jac=None, bounds=None,
373
377
 
374
378
  x0 = asarray(x0).ravel()
375
379
  n, = x0.shape
380
+ if disp is not _NoValue:
381
+ warnings.warn("scipy.optimize: The `disp` and `iprint` options of the "
382
+ "L-BFGS-B solver are deprecated and will be removed in "
383
+ "SciPy 1.18.0.",
384
+ DeprecationWarning, stacklevel=3)
385
+
386
+ if iprint is not _NoValue:
387
+ warnings.warn("scipy.optimize: The `disp` and `iprint` options of the "
388
+ "L-BFGS-B solver are deprecated and will be removed in "
389
+ "SciPy 1.18.0.",
390
+ DeprecationWarning, stacklevel=3)
376
391
 
377
392
  # historically old-style bounds were/are expected by lbfgsb.
378
393
  # That's still the case but we'll deal with new-style from here on,
@@ -17,7 +17,7 @@ from .trf import trf
17
17
  from .dogbox import dogbox
18
18
  from .common import EPS, in_bounds, make_strictly_feasible
19
19
 
20
-
20
+
21
21
  from scipy.optimize._optimize import _wrap_callback
22
22
 
23
23
  TERMINATION_MESSAGES = {
@@ -392,7 +392,7 @@ def least_squares(
392
392
 
393
393
  * For 'trf' : ``x_scale == 1``
394
394
  * For 'dogbox' : ``x_scale == 1``
395
- * For 'jac' : ``x_scale == 'jac'``
395
+ * For 'lm' : ``x_scale == 'jac'``
396
396
 
397
397
  .. versionchanged:: 1.16.0
398
398
  The default keyword value is changed from 1 to None to indicate that
@@ -188,7 +188,6 @@ def minimize(fun, x0, args=(), method=None, jac=None, hess=None,
188
188
 
189
189
  Equality constraint means that the constraint function result is to
190
190
  be zero whereas inequality means that it is to be non-negative.
191
- Note that COBYLA only supports inequality constraints.
192
191
 
193
192
  tol : float, optional
194
193
  Tolerance for termination. When `tol` is specified, the selected
@@ -183,6 +183,7 @@ class Complex:
183
183
  self.V = VertexCacheIndex()
184
184
 
185
185
  self.V_non_symm = [] # List of non-symmetric vertices
186
+ self.split_edge = cache(self._split_edge)
186
187
 
187
188
  def __call__(self):
188
189
  return self.H
@@ -995,8 +996,7 @@ class Complex:
995
996
  d_v0v1.connect(d_v1v2)
996
997
  return
997
998
 
998
- @cache
999
- def split_edge(self, v1, v2):
999
+ def _split_edge(self, v1, v2):
1000
1000
  v1 = self.V[v1]
1001
1001
  v2 = self.V[v2]
1002
1002
  # Destroy original edge, if it exists:
@@ -239,7 +239,7 @@ class SparseMixin:
239
239
 
240
240
  # Default lsmr arguments should not fully converge the solution
241
241
  default_lsmr_sol = lsq_linear(A, b, lsq_solver='lsmr')
242
- with pytest.raises(AssertionError, match=""):
242
+ with pytest.raises(AssertionError):
243
243
  assert_allclose(exact_sol.x, default_lsmr_sol.x)
244
244
 
245
245
  # By increasing the maximum lsmr iters, it will converge
@@ -1126,7 +1126,7 @@ class TestOptimizeSimple(CheckOptimize):
1126
1126
 
1127
1127
  def test_minimize_l_bfgs_b(self):
1128
1128
  # Minimize with L-BFGS-B method
1129
- opts = {'disp': False, 'maxiter': self.maxiter}
1129
+ opts = {'maxiter': self.maxiter}
1130
1130
  r = optimize.minimize(self.func, self.startparams,
1131
1131
  method='L-BFGS-B', jac=self.grad,
1132
1132
  options=opts)
@@ -1156,7 +1156,7 @@ class TestOptimizeSimple(CheckOptimize):
1156
1156
  # Check that the `ftol` parameter in l_bfgs_b works as expected
1157
1157
  v0 = None
1158
1158
  for tol in [1e-1, 1e-4, 1e-7, 1e-10]:
1159
- opts = {'disp': False, 'maxiter': self.maxiter, 'ftol': tol}
1159
+ opts = {'maxiter': self.maxiter, 'ftol': tol}
1160
1160
  sol = optimize.minimize(self.func, self.startparams,
1161
1161
  method='L-BFGS-B', jac=self.grad,
1162
1162
  options=opts)
@@ -1173,7 +1173,7 @@ class TestOptimizeSimple(CheckOptimize):
1173
1173
  # check that the maxls is passed down to the Fortran routine
1174
1174
  sol = optimize.minimize(optimize.rosen, np.array([-1.2, 1.0]),
1175
1175
  method='L-BFGS-B', jac=optimize.rosen_der,
1176
- options={'disp': False, 'maxls': 1})
1176
+ options={'maxls': 1})
1177
1177
  assert not sol.success
1178
1178
 
1179
1179
  def test_minimize_l_bfgs_b_maxfun_interruption(self):
@@ -60,6 +60,17 @@ def _is_int_type(x):
60
60
  return True
61
61
 
62
62
 
63
+ def _real_dtype_for_complex(dtyp, *, xp):
64
+ if xp.isdtype(dtyp, 'real floating'):
65
+ return dtyp
66
+ if dtyp == xp.complex64:
67
+ return xp.float32
68
+ elif dtyp == xp.complex128:
69
+ return xp.float64
70
+ else:
71
+ raise ValueError(f"Unknown dtype {dtyp}.")
72
+
73
+
63
74
  # https://github.com/numpy/numpy/blob/v2.2.0/numpy/_core/function_base.py#L195-L302
64
75
  def _logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None, *, xp):
65
76
  if not isinstance(base, float | int) and xp.asarray(base).ndim > 0:
@@ -488,6 +499,7 @@ def freqz(b, a=1, worN=512, whole=False, plot=None, fs=2*pi,
488
499
  if xp.isdtype(a.dtype, 'integral'):
489
500
  a = xp.astype(a, xp_default_dtype(xp))
490
501
  res_dtype = xp.result_type(b, a)
502
+ real_dtype = _real_dtype_for_complex(res_dtype, xp=xp)
491
503
 
492
504
  b = xpx.atleast_nd(b, ndim=1, xp=xp)
493
505
  a = xpx.atleast_nd(a, ndim=1, xp=xp)
@@ -509,7 +521,7 @@ def freqz(b, a=1, worN=512, whole=False, plot=None, fs=2*pi,
509
521
  # if include_nyquist is true and whole is false, w should
510
522
  # include end point
511
523
  w = xp.linspace(0, lastpoint, N,
512
- endpoint=include_nyquist and not whole, dtype=res_dtype)
524
+ endpoint=include_nyquist and not whole, dtype=real_dtype)
513
525
  n_fft = N if whole else 2 * (N - 1) if include_nyquist else 2 * N
514
526
  if (xp_size(a) == 1 and (b.ndim == 1 or (b.shape[-1] == 1))
515
527
  and n_fft >= b.shape[0]
@@ -834,7 +834,7 @@ def remez(numtaps, bands, desired, *, weight=None, type='bandpass',
834
834
  xp = array_namespace(bands, desired, weight)
835
835
  bands = np.asarray(bands)
836
836
  desired = np.asarray(desired)
837
- if weight:
837
+ if weight is not None:
838
838
  weight = np.asarray(weight)
839
839
 
840
840
  fs = _validate_fs(fs, allow_none=True)
@@ -117,7 +117,7 @@ def poly(seq_of_zeros, *, xp):
117
117
  if xp.isdtype(a.dtype, 'complex floating'):
118
118
  # if complex roots are all complex conjugates, the roots are real.
119
119
  roots = xp.asarray(seq_of_zeros, dtype=xp.complex128)
120
- if xp.all(_sort_cmplx(roots, xp) == _sort_cmplx(xp.conj(roots), xp)):
120
+ if xp.all(xp.sort(xp.imag(roots)) == xp.sort(xp.imag(xp.conj(roots)))):
121
121
  a = xp.asarray(xp.real(a), copy=True)
122
122
 
123
123
  return a
@@ -897,6 +897,15 @@ def csd(x, y, fs=1.0, window='hann', nperseg=None, noverlap=None, nfft=None,
897
897
  if np.iscomplexobj(x) and return_onesided:
898
898
  return_onesided = False
899
899
 
900
+ if x.shape[axis] < y.shape[axis]: # zero-pad x to shape of y:
901
+ z_shape = list(y.shape)
902
+ z_shape[axis] = y.shape[axis] - x.shape[axis]
903
+ x = np.concatenate((x, np.zeros(z_shape)), axis=axis)
904
+ elif y.shape[axis] < x.shape[axis]: # zero-pad y to shape of x:
905
+ z_shape = list(x.shape)
906
+ z_shape[axis] = x.shape[axis] - y.shape[axis]
907
+ y = np.concatenate((y, np.zeros(z_shape)), axis=axis)
908
+
900
909
  # using cast() to make mypy happy:
901
910
  fft_mode = cast(FFT_MODE_TYPE, 'onesided' if return_onesided else 'twosided')
902
911
  if scaling not in (scales := {'spectrum': 'magnitude', 'density': 'psd'}):
@@ -382,6 +382,19 @@ class TestTf2Sos:
382
382
  sos2 = tf2sos(b, a, analog=analog)
383
383
  assert_array_almost_equal(sos, sos2, decimal=4)
384
384
 
385
+ def test_gh_23221(self):
386
+ # Tests that this tf2sos call below does not produce ComplexWarnings
387
+ # This test is specific for scipy==1.16.0: later scipy versions do not produce
388
+ # the warning.
389
+ with suppress_warnings():
390
+ warnings.simplefilter("error")
391
+ tf2sos([0.21860986786301265, -0.4372197357260253, -0.2186098678630126,
392
+ 0.8744394714520509, -0.21860986786301248, -0.4372197357260253,
393
+ 0.21860986786301265],
394
+ [1., -4.18323041786553, 6.829924151626914, -5.407777865686045,
395
+ 2.0773105450802336, -0.33482732571537893, 0.0186009178695853 ]
396
+ )
397
+
385
398
 
386
399
  @skip_xp_backends(
387
400
  cpu_only=True, reason="XXX zpk2sos is numpy-only", exceptions=['cupy']
@@ -754,6 +767,12 @@ class TestFreqz:
754
767
  xp_assert_equal(w, xp.asarray([0. , 0.1]))
755
768
  xp_assert_equal(h, xp.asarray([1.+0.j, 1.+0.j]))
756
769
 
770
+ def test_gh_23277(self):
771
+ # backwards compatibility: `w` array must be real, not complex
772
+ filt = [0.5 + 0.0j, 0.5 + 0.0j]
773
+ w, _ = freqz(filt, worN=8)
774
+ assert w.dtype == np.float64
775
+
757
776
  def test_basic(self, xp):
758
777
  w, h = freqz(xp.asarray([1.0]), worN=8)
759
778
  assert_array_almost_equal(w, xp.pi * xp.arange(8, dtype=w.dtype) / 8.)
@@ -546,6 +546,11 @@ class TestRemez:
546
546
  with pytest.raises(ValueError, match="Sampling.*single scalar"):
547
547
  remez(11, .1, 1, fs=np.array([10, 20]))
548
548
 
549
+ def test_gh_23266(self, xp):
550
+ bands = xp.asarray([0.0, 0.2, 0.3, 0.5])
551
+ desired = xp.asarray([1.0, 0.0])
552
+ weight = xp.asarray([1.0, 2.0])
553
+ remez(21, bands, desired, weight=weight)
549
554
 
550
555
 
551
556
  @skip_xp_backends(cpu_only=True, reason="lstsq")
@@ -1295,7 +1295,7 @@ class TestMedFilt:
1295
1295
  # us into wrong memory if used (but it does not need to be used)
1296
1296
  dummy = xp.arange(10, dtype=xp.float64)
1297
1297
  a = dummy[5:6]
1298
- a.strides = 16
1298
+ a = np.lib.stride_tricks.as_strided(a, strides=(16,))
1299
1299
  xp_assert_close(signal.medfilt(a, 1), xp.asarray([5.]))
1300
1300
 
1301
1301
  @skip_xp_backends(
@@ -8,6 +8,7 @@ import pytest
8
8
  from pytest import raises as assert_raises
9
9
 
10
10
  from scipy import signal
11
+ from scipy._lib._array_api import xp_assert_close
11
12
  from scipy.fft import fftfreq, rfftfreq, fft, irfft
12
13
  from scipy.integrate import trapezoid
13
14
  from scipy.signal import (periodogram, welch, lombscargle, coherence, csd,
@@ -591,6 +592,36 @@ class TestCSD:
591
592
  assert_allclose(f, f1)
592
593
  assert_allclose(c, c1)
593
594
 
595
+ def test_unequal_length_input_1D(self):
596
+ """Test zero-padding for input `x.shape[axis] != y.shape[axis]` for 1d arrays.
597
+
598
+ This test ensures that issue 23036 is fixed.
599
+ """
600
+ x = np.tile([4, 0, -4, 0], 4)
601
+
602
+ kw = dict(fs=len(x), window='boxcar', nperseg=4)
603
+ X0 = signal.csd(x, np.copy(x), **kw)[1] # `x is x` must be False
604
+ X1 = signal.csd(x, x[:8], **kw)[1]
605
+ X2 = signal.csd(x[:8], x, **kw)[1]
606
+ xp_assert_close(X1, X0 / 2)
607
+ xp_assert_close(X2, X0 / 2)
608
+
609
+ def test_unequal_length_input_3D(self):
610
+ """Test zero-padding for input `x.shape[axis] != y.shape[axis]` for 3d arrays.
611
+
612
+ This test ensures that issue 23036 is fixed.
613
+ """
614
+ n = 8
615
+ x = np.zeros(2 * 3 * n).reshape(2, n, 3)
616
+ x[:, 0, :] = n
617
+
618
+ kw = dict(fs=n, window='boxcar', nperseg=n, detrend=None, axis=1)
619
+ X0 = signal.csd(x, x.copy(), **kw)[1] # `x is x` must be False
620
+ X1 = signal.csd(x, x[:, :2, :], **kw)[1]
621
+ X2 = signal.csd(x[:, :2, :], x, **kw)[1]
622
+ xp_assert_close(X1, X0)
623
+ xp_assert_close(X2, X0)
624
+
594
625
  def test_real_onesided_even(self):
595
626
  x = np.zeros(16)
596
627
  x[0] = 1
scipy/sparse/_base.py CHANGED
@@ -494,7 +494,10 @@ class _spbase(SparseABC):
494
494
  return self._mul_scalar(other)
495
495
 
496
496
  if self.ndim < 3:
497
- return self.tocsr()._multiply_2d_with_broadcasting(other)
497
+ try:
498
+ return self._multiply_2d_with_broadcasting(other)
499
+ except AttributeError:
500
+ return self.tocsr()._multiply_2d_with_broadcasting(other)
498
501
 
499
502
  if not (issparse(other) or isdense(other)):
500
503
  # If it's a list or whatever, treat it like an array
@@ -658,7 +661,7 @@ class _spbase(SparseABC):
658
661
  # eq and ne return True or False instead of an array when the shapes
659
662
  # don't match. Numpy doesn't do this. Is this what we want?
660
663
  if op in (operator.eq, operator.ne):
661
- return op == operator.eq
664
+ return op is operator.ne
662
665
  raise ValueError("inconsistent shape")
663
666
 
664
667
  csr_self = (self if self.ndim < 3 else self.reshape(1, -1)).tocsr()