code: def test_MIMetric_invalid_params(rng):
      transform = regtransforms[("AFFINE", 3)]
      static = rng.random((20, 20, 20))
      moving = rng.random((20, 20, 20))
      n = transform.get_number_of_parameters()
      sampling_proportion = 0.3
      theta_sing = np.zeros(n)
      theta_nan = np.zeros(n)
      theta_nan[...] = np.nan
      theta_inf = np.zeros(n)
      theta_nan[...] = np.inf
  
      mi_metric = imaffine.MutualInformationMetric(
          32, sampling_proportion
      )
      mi_metric.setup(transform, static, moving)
      for theta in [theta_sing, theta_nan, theta_inf]:
          # Test metric value at invalid params
          actual_val = mi_metric.distance(theta)
          assert np.isinf(actual_val)
  
          # Test gradient at invalid params
          expected_grad = np.zeros(n)
          actual_grad = mi_metric.gradient(theta)
          assert_equal(actual_grad, expected_grad)
  
          # Test both
          actual_val, actual_grad = mi_metric.distance_and_gradient(
              theta
          )
          assert np.isinf(actual_val)
          assert_equal(actual_grad, expected_grad)
  
file_path: dipy/dipy/align/tests/test_imaffine.py
imports: import numpy
  import numpy.linalg
  from numpy.testing import assert_array_equal, assert_array_almost_equal, assert_equal, assert_raises, assert_warns
  from dipy.core import geometry
  from dipy.align import vector_fields
  from dipy.align import imaffine
  from dipy.align.imaffine import AffineInversionError, AffineInvalidValuesError, AffineMap, _number_dim_affine_matrix
  from dipy.align.transforms import regtransforms
  from dipy.align.tests.test_parzenhist import setup_random_transform
  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_MIMetric_invalid_params(rng) without return types