code: def test_sample_domain_regular():
      # Test 2D sampling
      shape = np.array((10, 10), dtype=np.int32)
      affine = np.eye(3)
      invalid_affine = np.eye(2)
      sigma = 0
      dim = len(shape)
      n = shape[0] * shape[1]
      k = 2
      # Verify exception is raised with invalid affine
      assert_raises(
          ValueError,
          sample_domain_regular,
          k,
          shape,
          invalid_affine,
          sigma,
      )
      samples = sample_domain_regular(k, shape, affine, sigma)
      isamples = np.array(samples, dtype=np.int32)
      indices = isamples[:, 0] * shape[1] + isamples[:, 1]
      # Verify correct number of points sampled
      assert_array_equal(samples.shape, [n // k, dim])
      # Verify all sampled points are different
      assert_equal(len(set(indices)), len(indices))
      # Verify the sampling was regular at rate k
      assert_equal((indices % k).sum(), 0)
  
      # Test 3D sampling
      shape = np.array((5, 10, 10), dtype=np.int32)
      affine = np.eye(4)
      invalid_affine = np.eye(3)
      sigma = 0
      dim = len(shape)
      n = shape[0] * shape[1] * shape[2]
      k = 10
      # Verify exception is raised with invalid affine
      assert_raises(
          ValueError,
          sample_domain_regular,
          k,
          shape,
          invalid_affine,
          sigma,
      )
      samples = sample_domain_regular(k, shape, affine, sigma)
      isamples = np.array(samples, dtype=np.int32)
      indices = (
          isamples[:, 0] * shape[1] * shape[2]
          + isamples[:, 1] * shape[2]
          + isamples[:, 2]
      )
      # Verify correct number of points sampled
      assert_array_equal(samples.shape, [n // k, dim])
      # Verify all sampled points are different
      assert_equal(len(set(indices)), len(indices))
      # Verify the sampling was regular at rate k
      assert_equal((indices % k).sum(), 0)
  
imports: import numpy
  import scipy
  from functools import reduce
  from operator import mul
  from dipy.core.ndindex import ndindex
  from dipy.core.interpolation import interpolate_scalar_2d, interpolate_scalar_3d
  from dipy.data import get_fnames
  from dipy.align import vector_fields
  from dipy.align.transforms import regtransforms
  from dipy.align.parzenhist import ParzenJointHistogram, cubic_spline, cubic_spline_derivative, sample_domain_regular
  from numpy.testing import assert_array_equal, assert_array_almost_equal, assert_almost_equal, assert_equal, assert_raises
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 9 for calling a global function with example usage: test_sample_domain_regular() without return types