code: def test_affine_transform(plot=False):
      np.random.seed(1)
      corrs = [0, 0.6, 0.95, 0.999]
      for corr in corrs:
          for scaleratio in [1]:  # , 0.001]:
              covmatrix = np.array([[1.0, corr], [corr, 1.0]])
              # should draw uniformly sampled points
              points = genpoints_following_cov(covmatrix, size=400)
              print(
                  "settings: corr:",
                  corr,
                  "scaleratio:",
                  scaleratio,
                  "covmatrix:",
                  covmatrix.flatten(),
                  points.shape,
              )
              points[:, 0] = points[:, 0] * 0.01 * scaleratio + 0.5
              points[:, 1] = points[:, 1] * 0.01 + 0.5
  
              layer = AffineLayer()
              layer.optimize(points, points)
              points3 = layer.untransform(
                  genpoints_following_cov(np.diag([1, 1]), size=400)
              )
              # print('cov:', layer.cov, 'covmatrix:', covmatrix, 'ratio:', layer.cov / covmatrix)
              tpoints = layer.transform(points)
  
              assert tpoints.shape == points.shape, (
                  tpoints.shape,
                  points.shape,
              )
              points2 = layer.untransform(tpoints)
              assert tpoints.shape == points2.shape, (
                  tpoints.shape,
                  points2.shape,
              )
  
              if plot and scaleratio == 1:
                  plt.figure(figsize=(9, 4))
                  plt.subplot(1, 2, 1)
                  plt.scatter(points[:, 0], points[:, 1])
                  plt.scatter(points2[:, 0], points2[:, 1], marker="x")
                  plt.scatter(points3[:, 0], points3[:, 1], marker="+")
                  plt.subplot(1, 2, 2)
                  plt.scatter(tpoints[:, 0], tpoints[:, 1])
                  lo, hi = plt.xlim()
                  lo2, hi2 = plt.ylim()
                  lo, hi = min(lo, lo2), max(hi, hi2)
                  plt.xlim(lo, hi)
                  plt.ylim(lo, hi)
                  plt.savefig(
                      "testtransform_affine_corr%s_scale%s.pdf"
                      % (corr, scaleratio),
                      bbox_inches="tight",
                  )
                  plt.close()
              assert (points2 == points).all(), (
                  points,
                  tpoints,
                  points2,
              )
  
              # transform a single point
              points = points[0]
              tpoints = layer.transform(points)
              assert tpoints.shape == points.shape, (
                  tpoints.shape,
                  points.shape,
              )
              points2 = layer.untransform(tpoints)
              assert tpoints.shape == points2.shape, (
                  tpoints.shape,
                  points2.shape,
              )
  
              assert (points2 == points).all(), (
                  points,
                  tpoints,
                  points2,
              )
  
imports: from ultranest.mlfriends import ScalingLayer, AffineLayer
  import numpy
  import matplotlib.pyplot
label_desc: Use image node_id 3 for calling a global function with example usage: test_affine_transform(plot) without return types