code: def test_csd_xval(rng):
      # First, let's see that it works with some data:
      data = load_nifti_data(fdata)[1:3, 1:3, 1:3]  # Make it *small*
      gtab = gt.gradient_table(fbval, fbvec)
      S0 = np.mean(data[..., gtab.b0s_mask])
      response = ([0.0015, 0.0003, 0.0001], S0)
  
      # In simulation, it should work rather well (high COD):
      psphere = dpd.get_sphere("symmetric362")
      bvecs = np.concatenate(([[0, 0, 0]], psphere.vertices))
      bvals = np.zeros(len(bvecs)) + 1000
      bvals[0] = 0
      gtab = gt.gradient_table(bvals, bvecs)
      mevals = np.array(
          ([0.0015, 0.0003, 0.0001], [0.0015, 0.0003, 0.0003])
      )
      mevecs = [
          np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]),
          np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0]]),
      ]
      S0 = 100
      S = sims.single_tensor(gtab, S0, mevals[0], mevecs[0], snr=None)
      with warnings.catch_warnings():
          warnings.filterwarnings(
              "ignore",
              message=descoteaux07_legacy_msg,
              category=PendingDeprecationWarning,
          )
          sm = csd.ConstrainedSphericalDeconvModel(gtab, response)
      response = ([0.0015, 0.0003, 0.0001], S0)
      with warnings.catch_warnings():
          warnings.filterwarnings(
              "ignore",
              message=descoteaux07_legacy_msg,
              category=PendingDeprecationWarning,
          )
          kf_xval = xval.kfold_xval(
              sm, S, 2, response, sh_order=2, rng=rng
          )
      # Because of the regularization, COD is not going to be perfect here:
      cod = xval.coeff_of_determination(S, kf_xval)
      # We'll just test for regressions:
      csd_cod = 97  # pre-computed by hand for this random seed
  
      # We're going to be really lenient here:
      npt.assert_array_almost_equal(np.round(cod), csd_cod)
      # Test for sD data with more than one voxel for use of a mask:
      S = np.array([[S, S], [S, S]])
      mask = np.ones(S.shape[:-1], dtype=bool)
      mask[1, 1] = 0
      with warnings.catch_warnings():
          warnings.filterwarnings(
              "ignore",
              message=descoteaux07_legacy_msg,
              category=PendingDeprecationWarning,
          )
          kf_xval = xval.kfold_xval(
              sm, S, 2, response, sh_order=2, mask=mask, rng=rng
          )
  
      cod = xval.coeff_of_determination(S, kf_xval)
      npt.assert_array_almost_equal(np.round(cod[0]), csd_cod)
  
file_path: dipy/dipy/reconst/tests/test_cross_validation.py
imports: import warnings
  import numpy
  import numpy.testing
  import dipy.reconst.cross_validation
  import dipy.data
  import dipy.reconst.dti
  import dipy.core.gradients
  import dipy.sims.voxel
  import dipy.reconst.csdeconv
  import dipy.reconst.base
  from dipy.io.image import load_nifti_data
  from dipy.reconst.shm import descoteaux07_legacy_msg
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 3 for calling a global function with example usage: test_csd_xval(rng) without return types