code: def test_least_squares_cov_x(peakdata, bounds):
      """Test calculation of cov. matrix from Jacobian, with/without bounds."""
      x = peakdata[0]
      y = peakdata[1]
  
      # define the model and initialize parameters
      mod = VoigtModel()
      params = mod.guess(y, x=x)
  
      if bounds:
          params["amplitude"].set(min=25, max=70)
          params["sigma"].set(min=0, max=1)
          params["center"].set(min=5, max=15)
      else:
          params["sigma"].set(min=-np.inf)
  
      # do fit with least_squares and leastsq algorithm
      result = mod.fit(y, params, x=x, method="least_squares")
      result_lsq = mod.fit(
          y, params, x=x, method="leastsq", fit_kws={"epsfcn": 1.0e-14}
      )
  
      # assert that fit converged to the same result
      vals = [
          result.params[p].value for p in result.params.valuesdict()
      ]
      vals_lsq = [
          result_lsq.params[p].value
          for p in result_lsq.params.valuesdict()
      ]
      assert_allclose(vals, vals_lsq, rtol=1e-5)
      assert_allclose(result.chisqr, result_lsq.chisqr)
  
      # assert that parameter uncertainties obtained from the leastsq method and
      # those from the covariance matrix estimated from the Jacbian matrix in
      # least_squares are similar
      stderr = [
          result.params[p].stderr for p in result.params.valuesdict()
      ]
      stderr_lsq = [
          result_lsq.params[p].stderr
          for p in result_lsq.params.valuesdict()
      ]
      assert_allclose(stderr, stderr_lsq, rtol=1e-4)
  
      # assert that parameter correlations obtained from the leastsq method and
      # those from the covariance matrix estimated from the Jacbian matrix in
      # least_squares are similar
      for par1 in result.var_names:
          cor = [
              result.params[par1].correl[par2]
              for par2 in result.params[par1].correl.keys()
          ]
          cor_lsq = [
              result_lsq.params[par1].correl[par2]
              for par2 in result_lsq.params[par1].correl.keys()
          ]
  
          assert_allclose(cor, cor_lsq, rtol=0.01, atol=1.0e-6)
  
file_path: lmfit-py/tests/test_least_squares.py
imports: import numpy
  from numpy.testing import assert_allclose
  import pytest
  from scipy.sparse import bsr_matrix
  from scipy.sparse.linalg import aslinearoperator
  import lmfit
  from lmfit.models import VoigtModel
label_desc: Use image node_id 2 for calling a global function with example usage: test_least_squares_cov_x(peakdata, bounds) without return types