code: def test_param_to_matrix_2d(rng):
      # Test translation matrix 2D
      transform = regtransforms[("TRANSLATION", 2)]
      dx, dy = rng.uniform(size=(2,))
      theta = np.array([dx, dy])
      expected = np.array([[1, 0, dx], [0, 1, dy], [0, 0, 1]])
      actual = transform.param_to_matrix(theta)
      assert_array_equal(actual, expected)
  
      # Test rotation matrix 2D
      transform = regtransforms[("ROTATION", 2)]
      angle = rng.uniform()
      theta = np.array([angle])
      ct = np.cos(angle)
      st = np.sin(angle)
      expected = np.array([[ct, -st, 0], [st, ct, 0], [0, 0, 1]])
      actual = transform.param_to_matrix(theta)
      assert_array_almost_equal(actual, expected)
  
      # Test rigid matrix 2D
      transform = regtransforms[("RIGID", 2)]
      angle, dx, dy = rng.uniform(size=(3,))
      theta = np.array([angle, dx, dy])
      ct = np.cos(angle)
      st = np.sin(angle)
      expected = np.array([[ct, -st, dx], [st, ct, dy], [0, 0, 1]])
      actual = transform.param_to_matrix(theta)
      assert_array_almost_equal(actual, expected)
  
      # Test scaling matrix 2D
      transform = regtransforms[("SCALING", 2)]
      factor = rng.uniform()
      theta = np.array([factor])
      expected = np.array([[factor, 0, 0], [0, factor, 0], [0, 0, 1]])
      actual = transform.param_to_matrix(theta)
      assert_array_almost_equal(actual, expected)
  
      # Test rigid isoscaling matrix 2D
      transform = regtransforms[("RIGIDISOSCALING", 2)]
      angle, dx, dy, factor = rng.uniform(size=(4,))
      theta = np.array([angle, dx, dy, factor])
      ct = np.cos(angle)
      st = np.sin(angle)
      expected = np.array(
          [
              [ct * factor, -st * factor, dx],
              [st * factor, ct * factor, dy],
              [0, 0, 1],
          ]
      )
      actual = transform.param_to_matrix(theta)
      assert_array_almost_equal(actual, expected)
  
      # Test rigid scaling matrix 2D
      transform = regtransforms[("RIGIDSCALING", 2)]
      angle, dx, dy, sx, sy = rng.uniform(size=(5,))
      theta = np.array([angle, dx, dy, sx, sy])
      ct = np.cos(angle)
      st = np.sin(angle)
      expected = np.array(
          [[ct * sx, -st * sx, dx], [st * sy, ct * sy, dy], [0, 0, 1]]
      )
      actual = transform.param_to_matrix(theta)
      assert_array_almost_equal(actual, expected)
  
      # Test affine 2D
      transform = regtransforms[("AFFINE", 2)]
      theta = rng.uniform(size=(6,))
      expected = np.eye(3)
      expected[0, :] = theta[:3]
      expected[1, :] = theta[3:6]
      actual = transform.param_to_matrix(theta)
      assert_array_almost_equal(actual, expected)
  
      # Verify that ValueError is raised if incorrect number of parameters
      for transform in regtransforms.values():
          n = transform.get_number_of_parameters()
          # Set incorrect number of parameters
          theta = np.zeros(n + 1, dtype=np.float64)
          assert_raises(ValueError, transform.param_to_matrix, theta)
  
file_path: dipy/dipy/align/tests/test_transforms.py
imports: import numpy
  from numpy.testing import assert_array_equal, assert_array_almost_equal, assert_equal, assert_raises
  from dipy.align.transforms import regtransforms, Transform
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 2 for calling a global function with example usage: test_param_to_matrix_2d(rng) without return types