code: def test_nnls_jacobian_func(rng):
      b0 = 1000.0
      bval, bvecs = read_bvals_bvecs(*get_fnames("55dir_grad"))
      gtab = grad.gradient_table(bval, bvecs)
      B = bval[1]
  
      # Scale the eigenvalues and tensor by the B value so the units match
      D_orig = (
          np.array([1.0, 1.0, 1.0, 0.0, 0.0, 1.0, -np.log(b0) * B]) / B
      )
  
      # Design Matrix
      X = dti.design_matrix(gtab)
  
      # Signals
      Y = np.exp(np.dot(X, D_orig))
      scale = 10
      error = rng.normal(scale=scale, size=Y.shape)
      Y = Y + error
  
      # although sigma and gmm gradients seem correct from inspection,
      # they are not accurate enough to pass the tests, leaving out
      # for weighting in [None, "sigma", "gmm"]:
      for weighting in [None]:
          nlls = dti._NllsHelper()
  
          for D in [D_orig, np.zeros_like(D_orig)]:
              if weighting is None:
                  sigma = None
              if weighting == "sigma":
                  sigma = 1.0 / np.abs(
                      error
                  )  # use residuals as estimate
              if weighting == "gmm":
                  sigma = 1.4826 * np.median(
                      np.abs(error - np.median(error))
                  )
  
              # Test Jacobian at D
              args = [D, X, Y, weighting, sigma]
              # NOTE: call 'err_func' first, to set internal stuff in the class
              nlls.err_func(*args)
              # NOTE: cal 'jabobian_func' with D (ensure cached vars are for D)
              analytical = nlls.jacobian_func(*args)
              for i in range(len(X)):
                  if weighting is None:
                      args = [X[i], Y[i], weighting, sigma]
                  if weighting == "sigma":
                      args = [X[i], Y[i], weighting, sigma[i]]
                  if weighting == "gmm":
                      args = [X[i], Y[i], weighting, sigma]
                  approx = opt.approx_fprime(
                      D, nlls.err_func, 1e-8, *args
                  )
  
                  assert np.allclose(approx, analytical[i])
  
imports: import warnings
  import numpy
  import numpy.testing
  import scipy.optimize
  import dipy.reconst.dti
  from dipy.io.gradients import read_bvals_bvecs
  from dipy.reconst.dti import ols_resort_msg, axial_diffusivity, color_fa, fractional_anisotropy, from_lower_triangular, geodesic_anisotropy, lower_triangular, mean_diffusivity, radial_diffusivity, TensorModel, trace, linearity, planarity, sphericity, decompose_tensor, _decompose_tensor_nan
  from dipy.io.image import load_nifti_data
  from dipy.data import get_fnames, dsi_voxels, get_sphere
  from dipy.core.subdivide_octahedron import create_unit_sphere
  import dipy.core.gradients
  import dipy.core.sphere
  from dipy.sims.voxel import single_tensor
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 18 for calling a global function with example usage: test_nnls_jacobian_func(rng) without return types